Clipboard

Copies text to the clipboard and shows that it was copied.

Usage

Code
import { Clipboard } from '@leverui/components';
Code
<Clipboard.Root>
  <Clipboard.Trigger>
    <Clipboard.CopyText />
    <Clipboard.Indicator />
  </Clipboard.Trigger>
  <Clipboard.Input />
</Clipboard.Root>

Examples

Button

Use the Clipboard.Trigger component to create a copy button.

Input

Use the Clipboard.Input component to create a copy input.

Timeout

Use the timeout prop to change the duration of the copy message.

Here's an example that combines the Clipboard.Trigger and Clipboard.ValueText components to create a link appearance.

https://leverui.com

Store

Alternatively, you can use the useClipboard hook to create a custom component.

Props

Root

PropDefaultTypeDescription
timeout3000numberTime the copied state lasts, in milliseconds.
asChild—Solid render functionRender your own element with the clipboard's props.
defaultValue—stringInitial text to copy.
id—stringUnique id.
ids—Element ID mapYour own ids for the clipboard's elements.
onStatusChange—(details) => voidCalled when the value is copied.
onValueChange—(details) => voidCalled when the value changes.
translations—IntlTranslationsTranslated text for screen readers.
value—stringText to copy. Controlled.

With a signal as value, Clipboard.Input and Clipboard.ValueText update with it. Give an icon-only trigger an accessible name, such as an aria-label.

Explorer

Click a part name to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts