Skip to main content

CopyButton

Copies a value, then shows a check for a moment: an API key, an invite code, a link. On the web it uses the browser clipboard. React Native has no clipboard of its own, so on iOS and Android pass onCopy from your clipboard library; Patine stays free of native code.

import { CopyButton } from 'patine-ui';
import * as Clipboard from 'expo-clipboard';

<CopyButton value={apiKey} onCopy={Clipboard.setStringAsync} />
Loading…
<Box border radius="lg" padding="md" gap="sm" style={{ maxWidth: 420 }}>
  <Text weight="semibold">API key</Text>
  <HStack justify="space-between" style={{ backgroundColor: 'rgba(0,0,0,0.04)', borderRadius: 8, paddingStart: 12 }}>
    <Text style={{ fontFamily: 'monospace' }}>sk_live_51Hx…9fQ2</Text>
    <CopyButton value="sk_live_51Hx7Lk2eZvKYlo2C9fQ2" accessibilityLabel="Copy API key" />
  </HStack>
  <CopyButton value="https://patine.dev/invite/7Q2K" label="Copy invite link" variant="outline" />
</Box>

Try the props​

Props
label
variant
design
<CopyButton value="npm i patine-ui" />

Example: invite a friend​

A referral screen: the code and the link each have their own copy button, and onCopy counts the copies so the screen can thank you.

Loading…
<Box border radius="lg" padding="lg" gap="md" style={{ width: '100%', maxWidth: 420 }}>
  <VStack gap="xs">
    <Text weight="semibold">Give €20, get €20</Text>
    <Text color="textSecondary">Friends get €20 off their first order over €60. You get €20 when it ships.</Text>
  </VStack>
  <Row label="Your code" value={CODE} onCopy={copied} />
  <Row label="Your link" value={LINK} onCopy={copied} />
  <CopyButton value={`Use my code ${CODE} for €20 off: ${LINK}`} label="Copy a message to send" variant="outline" onCopy={copied} />
  {copies ? <Text size="sm" color="success">Copied. Paste it anywhere to share.</Text> : null}
</Box>

Accessibility​

A button named "Copy" (or accessibilityLabel, or its label), then "Copied" for timeout ms, announced politely.

Props​

Also takes Button's props.

PropTypeDefaultDescription
valuestring—The text to copy.
onCopy(value: string) => unknownbrowser clipboardCopies it; pass your clipboard library's on native.
labelstring—A word beside the icon. Default: icon only.
copiedLabelstring'Copied'What it says after copying.
timeoutnumber2000How long the check shows, in ms.
variant, sizeas Button'ghost'The button's look.