Command palette

@yasinsensoy/native

React Native · Components

CopyButton

Button that copies a value to the clipboard: when pressed the icon briefly becomes ✓ and "Copied" is read to the screen reader.

2 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

sk_live_51H…a9Xq

Code

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

<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/native";

CopyButton

component

Button that copies a value to the clipboard: when pressed the icon briefly becomes ✓ and "Copied" is read to the screen reader. Its variant and size are the same as Button; without text an IconButton is drawn.

For your own button see useClipboard.

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

Examples

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

Props of the CopyButton component (same names as on web).

Extends: Omit<ButtonProps, "children" | "icon" | "onPress" | "accessibilityLabel">

NameTypeDefaultDescription
valueClipboardValue | (() => ClipboardValue | Promise<ClipboardValue>)Value to copy: text, rich content ({ text, html }; on mobile text is copied) or a function returning the value (may be a Promise; e.g. a share link from the server). The function is only called when pressed.
children?ReactNodeButton text. When given, a text button is drawn and copiedLabel shows after copying; otherwise an icon-only square button (its name is still label, shown as a tooltip on long press).
label?string{@link UIProvider} `copy` text ("Kopyala")Button name.
copiedLabel?stringcopied` text ("Kopyalandı")Name shown after copying.
timeout?number2000Duration of the "copied" state (ms).
sensitive?booleanSensitive data (password, code): hidden in previews, not shared across devices.
onCopy?(text: string) => voidCalled with the copied text when copying succeeds.
onError?(error: unknown) => voidCalled when copying fails.