docs/components/clipboard
Clipboardpreview
A button that copies a value and shows that it was copied.
pnpm add @logic-ui/reactAnatomy#
Import the component and assemble its parts:
Examples#
Copied state#
Every part has a data-copied attribute while the value was copied less than timeout milliseconds ago (2 seconds by default).
Style the parts with it, and listen to onCopiedChange to react in code.
Errors#
Browsers can refuse to write to the clipboard, for example on an insecure origin or without a user gesture.
The copied state then stays off and onCopyError receives the error.
Indicator#
Clipboard.Indicator renders only while copied. Set keepMounted to keep it in the DOM and animate it with data-copied.
Styling#
Every part has data-copied while copied, so Tailwind's data-copied: variant styles it, and group-data-copied: styles what's inside a part.
API reference#
Clipboard.Root#
Groups the clipboard parts and holds the copied state.
Renders a <div> element.
Props
- value*
stringThe text written to the clipboard.
- timeout
numberdefault2000Time in milliseconds before
copiedgoes back tofalse.- onCopiedChange
(copied: boolean) => voidCalled when
copiedchanges.- onCopyError
(error: unknown) => voidCalled when the browser refuses to write to the clipboard.
- className
stringCSS class applied to the element.
- style
React.CSSPropertiesStyle applied to the element.
- render
React.ReactElement | ((props, state) => React.ReactElement)Replaces the element with another tag or component, or composes it with one. Takes an element, or a function that receives the props and the state.
Data attributes
- data-copied
- Present while the value was copied less than
timeoutms ago.
Clipboard.Trigger#
A button that copies the value of Clipboard.Root.
Renders a <button> element.
Props
- className
stringCSS class applied to the element.
- style
React.CSSPropertiesStyle applied to the element.
- render
React.ReactElement | ((props, state) => React.ReactElement)Replaces the element with another tag or component, or composes it with one. Takes an element, or a function that receives the props and the state.
Data attributes
- data-copied
- Present while the value was copied less than
timeoutms ago.
Clipboard.Indicator#
Shows that the value was just copied, for example a check icon.
Renders a <span> element, only while copied is true unless keepMounted is set.
Props
- keepMounted
booleandefaultfalseKeep the element in the DOM when the value is not copied. Style it with
data-copied.- className
stringCSS class applied to the element.
- style
React.CSSPropertiesStyle applied to the element.
- render
React.ReactElement | ((props, state) => React.ReactElement)Replaces the element with another tag or component, or composes it with one. Takes an element, or a function that receives the props and the state.
Data attributes
- data-copied
- Present while the value was copied less than
timeoutms ago.