SwipeUI

Copy button

Copy text, generate a share link or reveal a masked value, with pending and outcome feedback on the control.

npx @swipeui/cli add copy-button
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Copying codes, links, wallet addresses or invite text with one tap.
  • Code snippets and API keys in developer or settings screens.
  • Referral or promo codes people paste elsewhere.
  • Anywhere the result of copying should be confirmed visibly.

When not to use it

  • Sharing to other apps. Use the system share sheet.
  • Copying sensitive secrets without the user asking; copy only on tap.
  • Long passages of text; let people select text instead.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add copy-button
  • Adds components/swipeui/ui/copy-button.tsx, components/swipeui/ui/use-copy-button.ts and 14 shared helpers.
  • Installs expo-clipboard, react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg, react-native-gesture-handler, react-native-safe-area-context. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/invite.tsx
import { CopyButton } from '@/components/swipeui/ui/copy-button';

<CopyButton value={inviteUrl} accessibilityLabel="Copy invitation link" />;

The appearances preview compares a labelled button, a compact icon action and a value field. Share link creates a value before copying it. Secrets keeps a fake invitation masked until revealed. Failure lets you fail the next attempt, then retry. The app uses these same specimens.

Settings

PropDefaultBehavior
valuerequiredA string or stable function returning a string or promise. Invoked only on press.
appearancebuttonbutton shows an icon and label; icon speaks its label; field shows a mono value with middle truncation.
labelssee belowLocalize action, pending, outcome, toast details and reveal labels. The control fits the current label.
resetAfter1800Milliseconds before success/error returns to idle.
minPending450Minimum pending visibility in milliseconds, including async work. Content timing.
maskfalseReplace a field value with eight bullets; hidden accessible text never contains the value.
revealabletrueOffer a labelled eye toggle when the field is masked.
clearClipboardAfter0Opt-in delay in milliseconds. Reads once and clears only if the clipboard still contains our latest value.
iconMorphtrueMorph copy to check; false swaps endpoints with motion disabled.
effectstrueDraw the success check once. Reduce Motion skips effects.
labelMorphtrueAnimate changed labels without ellipsis while resizing; false updates text in place. Width follows the current label unless explicitly reserved.
reserveLabelWidthfalseOpt into the old widest-label reservation. Default labelled buttons spring between current text widths.
fieldDividertrueHairline between reveal and copy when the eye control is present.
toastDuration1800Toast lifetime in milliseconds; zero persists.
shakeOnErrortrueOne short failure shake; Reduce Motion removes travel.
toastfalseEnqueue a localized success/error toast. Requires a surrounding ToastProvider and ToastHost.
hapticstrueGlobal switch or { copy, error }, each defaulting to true. No duplicate press haptic.
onCopyundefinedCalled once after the latest successful copy.
onErrorundefinedCalled once after generation or clipboard failure. Retry remains available.
variantoutlineShared Button styles: solid, tinted, outline, ghost, plain; 1.x aliases remain supported. Field actions use ghost inside a neutral tinted chip.
toneButton defaultButton tone; success/error temporarily use success/destructive feedback.
sizemdsm, md, lg; small icon controls retain a 44pt touch target.
shapepresetPreset control corners or pill, with inset corners on field actions.
disabledfalsePrevent copy and reveal; pending also prevents repeated copy presses.
motioninheritedOverride the shared motion feel. Reduce Motion keeps short fades.
accessibilityLabelCopyDescribe the idle action. Pending and outcomes use localized labels.
Button material propsButton defaultspressEffect, highlight, glow, disabledStyle, palette and block follow Button.
View/style propsundefinedclassName, style, textClassName, testID and supported native props pass through. Field root owns its class/style.

labels defaults: copy: 'Copy', pending: 'Copying', success: 'Copied', error: "Couldn't copy", reveal: 'Show value', conceal: 'Hide value', valuePlaceholder: 'Generated on copy', hiddenValue: 'Hidden value', successDescription: 'Text copied to your clipboard.', errorDescription: 'Please try copying again.'.

Masked or generated values

<CopyButton appearance="field" value={invitationCode} mask clearClipboardAfter={4000} />
<CopyButton value={createShareLink} labels={{ copy: 'Copy share link', pending: 'Creating link' }} />

Keep a generator stable with useCallback. Changing value invalidates the previous request; an old generator cannot write after replacement or unmount. Clipboard writes already handed to the platform cannot be cancelled. Nothing is copied on mount.

Clearing is best effort while mounted. Unmount cancels it, and changing clipboard contents prevents it. A read and write cannot be atomic, and clearing is not secure erasure. Web clipboard permissions and user activation restrictions apply; an asynchronously generated value may require another attempt on browsers that restrict activation. Leave clearing off when clipboard reads are inappropriate.

In appearances, enable Toast confirmation, then toggle Toast at top to compare both safe-area edges. A toast has a leading icon, title and description with an icon-only close button, and dismisses after 1.8 seconds or on close. Configure ToastHost placement="top" or "bottom" in your app; use haptics={false} on that host when CopyButton already owns the outcome haptic.

Feedback appears on the control, with one spoken announcement. When toast is enabled, the toast owns that announcement. Reduce Motion removes the shake and geometric icon travel, and skips draw-on effects.

API reference

PropTypeDefaultDescription
layout?union—

Optional layout transition for composed controls; derive its values from useMotion.

motion?MotionOverridethe app's feel (`smooth` without a provider)

The app's press character, or a local override. The app's motion feel, or a local override for the press, label and width springs.

variant?ButtonVariant'solid'

How much the button stands out: solid, tinted (a soft wash of the tone), outline, ghost (no fill until pressed) or plain (text only). The 1.x names default, secondary and destructive still work as solid primary, neutral and destructive.

tone?ButtonTone'primary' for solid, tinted and plain; 'neutral' for outline and ghost

The colour family: primary, neutral, destructive or success.

size?ButtonSize'md'

The height: sm 36pt (with a 44pt touch target), md 44pt, lg 52pt.

shape?ButtonShape'preset'

preset follows your preset's control radius; pill is a capsule.

block?booleanfalse

Stretches the button to the full width of its container.

trailingIconNudge?booleanfalse

Slides the trailing icon a little forward while pressed, mirrored in right-to-left layouts.

singleLine?booleanfalse

Keep string labels and loading words on one clipped line.

highlight?booleantrue

A faint rim of light along the top edge of solid buttons.

glow?booleanfalse

A soft shadow in the tone's colour under solid buttons.

pressEffect?ButtonPressEffect'both'

Feedback while pressed: both scales and washes the surface, scale, wash or none. Text-only buttons dim their label instead of washing.

disabledStyle?ButtonDisabledStyle'muted'

How a disabled button looks: muted mutes its fill and label; dim halves its opacity.

glassStatus?ThemeSurfaceTone—

Keeps a completed or failed action’s Glass status visible when the control is locked.

palette?Partial<ButtonPalette>BUTTON_PALETTE

Colours that belong to the button's material rather than the theme (the top highlight).

className?string—

Classes merged over the style.

textClassName?string—

Classes for the label text.

style?StyleProp<ViewStyle>—

Style escape hatch for the container.

valueCopyValue—

Text, or a generator invoked only on an explicit press.

appearance?"button" | "field" | "icon"'button'

Labelled action, icon-only action, or value chip with a copy action at its end.

labels?Partial<CopyButtonLabels>Copy / Copying / Copied / Couldn't copy / Show value / Hide value

Overrides for feedback and reveal labels.

resetAfter?number1800

Retain success or error for this many milliseconds.

minPending?number450

Minimum pending visibility, in milliseconds. Content timing, not motion.

mask?booleanfalse

Hide the field's text with a fixed-length mask.

revealable?booleantrue

Show an eye toggle for a masked field.

clearClipboardAfter?number0

Milliseconds after writing to check and clear only our own value, while mounted. Zero disables reads/clearing.

iconMorph?booleantrue

Animate copy to check on success; false swaps complete endpoints.

effects?booleantrue

Draw the check once on success.

labelMorph?booleantrue

Animate changed labels; the button's width follows the shared morph role.

shakeOnError?booleantrue

Shake once on failure, suppressed under Reduce Motion.

reserveLabelWidth?booleanfalse

Keep space for the longest action label instead of fitting the current label.

fieldDivider?booleantrue

Show a hairline between a field's reveal and copy controls.

toastDuration?number1800

Outcome toast visibility in milliseconds; zero persists.

toast?booleanfalse

Enqueue success/failure through the surrounding ToastProvider/ToastHost.

haptics?boolean | CopyButtonHapticstrue

Outcome haptics, globally or per copy/error feature.

onCopy?(() => void)undefined

Called once after the latest successful copy.

onError?((error: unknown) => void)undefined

Clipboard or value-generation failure callback.

Behavior and gestures

  • Press to copy supplied text or invoke a value generator. No clipboard work happens on mount.
  • The pending spinner holds the control busy, then copy morphs to a drawn check and the label confirms the result.
  • A failure shakes once, uses a destructive tone and offers another press to retry. Each feedback feature can be disabled.
  • Masked fields reveal only on request. Optional clearing reads the clipboard and clears it only if the value still matches our latest write.
  • The masked field separates reveal and copy with an optional hairline. Toast confirmations include a description and expire after 1800ms by default.

Accessibility

  • The button exposes busy during pending and announces a single localized outcome. Optional toast owns its own announcement.
  • Icon and field appearances retain spoken action labels; a hidden field exposes a generic label, never its secret.
  • Use accessibilityLabel to explain what is being copied. Controls have at least a 44-point touch target.
  • Reduce Motion removes shake and icon travel, retaining short fades and readable outcome labels. Native screen reader checks remain pending.

Motion

  • Uses the press, morph, toggle and ambient motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Composes Button press feedback and pending ButtonSpinner, plus IconMorph copy-check geometry and draw-on.
  • Failure shake uses the press timing role; label changes use morph entry and exit roles.
  • Under Reduce Motion, outcomes remain visible without geometric travel or effects.

Performance

  • Request tokens ignore outdated generated values and outcomes after replacement or unmount. Repeated pending presses are ignored.
  • All timers are cancelled on unmount. Clipboard clearing is best effort while mounted; it is disabled by default and reads only when opted in.
  • Clipboard equality checks cannot make a platform read/write atomic. Do not treat clipboard clearing as secure erasure.

Notes for AI

  • Pass a stable value generator to preserve an operation across parent rerenders. It runs only on press.
  • Every optional feedback has its own prop. Set haptics globally or separately for copy and error.
  • toast requires the surrounding ToastProvider and ToastHost. Browser clipboard permission and user activation restrictions still apply.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items