Command palette

@yasinsensoy/web

Web · Components

CopyButton

A button that copies a value to the clipboard: on click the icon briefly becomes ✓ and "Copied" is read to the screen reader.

2 exports

Live example

Preview

sk_live_51H…a9Xq

Code

import { CopyButton } from "@yasinsensoy/web";

<CopyButton value="sk_live_51H…a9Xq" />

Events

  1. Events appear here when you interact with the preview.

Value from the server (a function; loading while waiting)

Import

import { CopyButton } from "@yasinsensoy/web";

CopyButton

componentClient component

A button that copies a value to the clipboard: on click the icon briefly becomes ✓ and "Copied" is read to the screen reader. Falls back to the old method when the Clipboard API is unavailable (http). Style and size are the same as Button.

For your own button see useClipboard.

CopyButton({ value, children, label, copiedLabel, timeout, onCopy, onError, disabled, ...props }: CopyButtonProps): JSX.Element

Examples

<CopyButton value={apiKey} />
<CopyButton value={url} variant="outline">Copy link</CopyButton>
<CopyButton value={() => createInviteLink(teamId)} label="Copy invite link" />

Props of the CopyButton component.

Extends: Omit<ButtonAsButtonProps, "value" | "children" | "onCopy" | "onError" | "icon">

NameTypeDefaultDescription
valueClipboardValue | (() => ClipboardValue | Promise<ClipboardValue>)Value to copy: text, rich content ({ text, html }) or a function returning the value (can be a Promise; e.g. a share link from the server). The function is called only on click.
children?ReactNodeButton text. When given a text button is drawn and copiedLabel appears after copying; otherwise an icon-only square button (its name is still label, shown as a tooltip).
label?string"Kopyala"Name of the button (tooltip of the icon-only button).
copiedLabel?string"Kopyalandı"Name shown after copying.
timeout?number2000Duration of the "Copied" state (ms).
onCopy?(text: string) => voidCalled with the copied text when copying succeeds.
onError?(error: unknown) => voidCalled when copying fails (no permission).