Vesyl UI

Clipboard

Copy a value to the clipboard and confirm the action with a transient copied state. The Clipboard namespace ships three parts that share one context: Clipboard.Root (holds the value and the copied flag), Clipboard.Trigger (the control that copies), and Clipboard.Indicator (swaps its content while the copied flag is set).

Clipboard.Root writes its value to navigator.clipboard on copy, flips copied to true, and resets it after 2 seconds. There is nothing to wire up — drop a trigger and an indicator inside the root.

Copy button

Give Clipboard.Trigger a render element to inherit a real control’s styling — here a Button. Each Clipboard.Indicator shows its children normally and its copied content while the value is on the clipboard, so you can swap both the icon and the label at once.

Copy from a field

For a longer value the reader needs to see — a tracking number, an API key, a webhook URL — show it in a read-only InputGroup and place the trigger in an inline-end addon. This is the pattern used on the WMS label-purchased screen.

Inline icon trigger

Without a render element, Clipboard.Trigger renders a bare <button> — style it with className for an unobtrusive icon button beside a label. Useful for copying a value that is already shown elsewhere, like a customer’s contact details.

Contact information

Reference

Clipboard.Root

Provides the clipboard context. On copy it writes value to navigator.clipboard, sets copied, and clears it after 2000ms.

PropTypeDefaultDescription
valuestringText written to the clipboard on copy
childrenReact.ReactNodeTriggers and indicators for this value

Clipboard.Trigger

The control that fires the copy. With no render, it renders a <button type="button"> (cursor-pointer). With render, it clones that element and attaches the onClick copy handler and merged className.

PropTypeDefaultDescription
renderReact.ReactElementElement to render as the trigger; receives the copy onClick
childrenReact.ReactNodeTrigger content, typically a Clipboard.Indicator
classNamestringMerged onto the rendered element

Clipboard.Indicator

Swaps content based on the copied flag — renders children normally, copied while the value is on the clipboard.

PropTypeDefaultDescription
childrenReact.ReactNodeContent shown in the idle state
copiedReact.ReactNodeContent shown for 2s after a copy

useClipboard

Hook returning the current clipboard context — { value, copied, copy }. Must be called inside a Clipboard.Root; throws otherwise. Reach for it when you need the copied state or the copy() function outside the provided parts.