Primitives
Animated Number Avatar Badge Button Button Group Toggle Toggle Group Checkbox Chip Countdown Divider Fab Grid Icon Image Input Search Input Textarea Label Loader Marquee Masked Input Message Bubble Notification Banner Offline Banner Progress Progress Ring Radio Group Range Slider Rating Separator Skeleton Slider Stack Stepper Switch Text Theme Toggle Ticker Typing IndicatorComposed
Accordion Achievement Badge Action Bar Action Sheet Action Swap Activity Rings Add to Cart Button Address Card Agenda List Alert Amount Keypad Animated Icons App Bar Audio Message Audio Recorder Autocomplete Avatar Group Balance Display Bar List Barcode Before After Biometric Gate Bloom Menu Bottom Sheet Paywall Sheet Side Sheet Breadcrumb Calendar Calendar Strip Card Carousel Cart Item Character Charts Chat Composer Chat List Item Choice Card Circle Reveal Coach Marks Collapsible Collapsible Header Color Picker Combobox Command Palette Comment Thread Confetti Consent Sheet Context Menu Copy Field Country Picker Coupon Input Currency Input Data Table Date Range Picker Day Schedule Dialog Dock Donut Chart Drawer Driver Card Dropdown Menu Drum Picker Emoji Picker Empty State Error State Event Card Expandable Control Fader Feature Gate File Picker Filter Bar Follow Button Form Gauge Glass Glass Cluster Glass Dock Morph Glass Fab Morph Glass Lab Glass Orb Glass Search Morph Glass Sheet Edge Gradient Button Headline New Heatmap Image Cropper Image Viewer Kanban Card Keyboard Avoiding Keyboard Toolbar Leaderboard Level Progress Lightbox Like Button Line Chart List Reorderable List Swipeable Row Location Card Location Search Map Sheet Map View Markdown View Media Controls Media Picker Media Tile Mention Input Meter Bar Mini Player Mood Slider Morphing Modal Multi Select Navigation Rail Notification Item Number Input Onboarding Pager Order Card Order Summary OTP Input Pagination Paper Clip New Parallax Header Pass Card Password Strength Payment Button Payment Card Payment Method Permission Primer Phone Input PIN Pad Polaroid New Poll Popover Post Card Postage Stamp New Price Tag Pricing Table Product Card Product Gallery Profile Header Promo Banner Prompt Input Property Card Pull To Refresh QR Code Quick Actions Quick Replies Rating Summary Reaction Picker Resend Timer Review Card Review Prompt Ride Option Save Button Scan Frame Scroll Spy Tabs Seat Map Section Header Section Index Segmented Control Select Share Button Share Sheet Shutter Button Signature Pad Slide to Confirm Slot Picker Smart Banner Social Login Button Sparkline Splash Screen Split Button Stat Card Stateful Button Status Dot Step Flow Steps Sticker New Stopwatch Stories Progress Stories Viewer Story Ring Streak Counter Streaming Text Success Seal Swipe Deck Tabs Tag Input Tape New Text Reveal Thinking Indicator Time Picker Timeline Timer Ring Tip Selector Toast Toolbar Tooltip Track Row Transaction Row Trip Progress Variant Picker Video Controls Waveform Weather Card Weekday Picker Zoom TransitionScreens
Account Switcher Biometric Setup Delete Account Forgot Password Grow Auth Login Login — Dark Stage Login — Dense Work Login — Editorial Login — Illustrated Login — Minimal Ink Login — Social Login — Video Loop Food Onboarding Onboarding Onboarding Dark Objects Onboarding Editorial Onboarding Illustrated Onboarding Personalize Onboarding Photo Carousel OTP Verification Passkey — Create Password Reset Permission — Notifications Phone Verification Onboarding Quiz Session Devices Signup Sign-up Chat Sign-up Photo Sheet Social Auth Split Auth Verify Identity Welcome AI Chat AI Assistant Channels List Chat Info Chat List Chat Media Chat Thread Create Group Group Info Message Requests New Message Kept Messages Accessibility Activity Log Appearance Authenticator Blocked Accounts Export Your Data Downloads Edit Profile Edit Profile — Rows Emergency Call Empty States Set Error State Send Feedback Device Locator Help Center Home — Bento Home — Dark Home — Editorial Home Feed Invite Friends Language & Region Linked Accounts Not Found (404) Notification Settings Notifications Password Vault Paywall Paywall — Comparison Paywall — Dark Stage Paywall — Editorial Paywall — Photo Paywall — Trial Timeline Privacy Profile Profile — Gamified Profile — Minimal Profile — Photo Hero QR Scanner Report Issue Saved Items Phone Time Search Search — Command Palette Search — Visual Account Health Settings Settings — Dark Device Settings — Search Storage & Data Terms & Privacy Dating Chat Dating Filters Profile Discover Its A Match Into You Matches Profile Detail Profile Editor Courier Matching Delivery History Delivery Support Package Schedule Parcel Tracking Proof Of Delivery Quick Aisle Quick Home Send Package Substitutions Add Payment Address Book Cart Categories Checkout Checkout — Steps Checkout Success Delivery Filters & Sort Flash Sale Gift Cards Loyalty Points Order Cancel Order Detail Orders Pay Later Checkout Payment Methods Product Detail Product Detail — Hero Product Grid Product Reviews Promo Codes Recently Viewed Return Items Search Results Shop Assistant Store Home Tip & Rate Courier Order Tracking Wishlist Write a Review Event Checkin Event Hero Events Discover My Tickets Seat Selection Ticket Checkout Add Card Bank Accounts Dashboard — Bento Bill Pay Budgets Card Details Crypto Portfolio Finance Dashboard Dashboard — Dark Exchange Currency Expense List Invoice Detail Manage Cards Plan Management Savings Goals Send Money Spending Analytics Split Bill Subscriptions Token Detail Token Swap Transactions Wallet Home Wallet Movers Courier Tracking Food Cart Food Home Food Orders Grocery List Recipe Detail Restaurant — Dark Restaurant Detail Activity Rings Fitness Home Habit Quest Habit Tracker Meal Planner Med Store Meditation Player Mood Check-in Nutrition Home Period Tracker Prior Auth Prior Auth Cases Quest Complete Run Tracking Rx Scan Sleep Tracker Telehealth Booking Walk Map Water Tracker Workout Complete Workout Detail Workout Session Applications Apply Company Interview Schedule Job Detail Job Feed Resume Saved Jobs Create Listing Item Chat Listing Detail Make Offer Market Checkout Market Home Market Search My Listings Offers Inbox Seller Profile Audiobook Player Camera Gallery Albums Game Store Mini Player Music Player Photo Editor Photo Gallery Playlist Detail Podcast Player Clips Feed Serene Home Sound Mixer Stories Video Call Video Player Article Reader Course Detail Event Detail Memory Onboarding Icon Lab Leaderboard Lesson Player Match Detail News Editorial News Home Plant Care Prediction Live Prediction Welcome Smart Home Standings Ticket Wallet Topics Follow Weather Detail Add Task Sheet Alarm Clock Calendar Day Calendar Month Doc Scanner File Manager Focus Timer Journal Kanban Board Mail Inbox Mail Thread Note Editor Notes List Reminders Task List Time Blocks Agent Profile Compare Homes Mortgage Calculator Property Detail Rental Application Saved Homes Schedule Tour Search List Search Map Complete Destination Driver Arriving Ev Charging History Home In Trip Matching Options Parking Receipt Safety Schedule Scooter Unlock Booking Confirmed Booking Review Booking Slots My Bookings Pro On The Way Provider Detail Provider List Rate Service Services Home Arc Create Arc Detail Arc Onboarding Avatar Creator Comments Sheet Create Post Explore Grid Followers List Hashtag Feed Mentions Post Detail Post Hero Social Profile Boarding Pass Booking Confirm Car Rental Trip Discover Flight Live Flight Preferences Flight Results Flight Search Hotel Detail Live Transit Trip — Map Day Trip — Rideshare Request Seat Select Travel Home Trip Itinerary Trip OnboardingNothing matches — try another word.
Copy Field
Read-only value you copy with one tap: the copy icon turns into a check and it confirms inline, no toast. Comes as a field, row or promo code, with masking; on phones it needs a clipboard package.
Preview
import * as React from "react";
import { forwardRef } from "react";
import { Platform, Pressable, View, type GestureResponderEvent, type ViewProps } from "react-native";
import Animated, {
Easing,
useAnimatedProps,
useAnimatedStyle,
useSharedValue,
withDelay,
withSequence,
withSpring,
withTiming,
} from "react-native-reanimated";
import Svg from "react-native-svg";
import {
AnimatedPath,
AnimatedPressable,
announce,
cn,
ease,
optionalRequire,
Sheen,
spring,
timing,
useHaptic,
usePressAnimation,
useReducedMotion,
useTheme,
} from "@lumioui/core";
import { Icon } from "../icon/icon";
import { Text } from "../text/text";
/**
* CopyField — a read-only value with a copy affordance. Tapping anywhere on
* the field copies: one accent sheen crosses the value as if the light had
* picked it up, the value holds in accent ink for 700ms and settles back,
* while the copy glyph dims and a check draws itself in its place, a
* success haptic lands, and the label row says "Copied" for a moment. No
* toast: the feedback stays where the finger is.
*
* <CopyField label="Invite link" value="https://pace.example/i/maya-7Q2K" />
* <CopyField label="IBAN" value={iban} groupSize={4} mono appearance="inline" />
* <CopyField value="HARVEST15" appearance="box" />
* <CopyField label="Account number" value="40221987" masked />
*
* Appearances: `field` (filled row, label above), `inline` (bare value with
* a trailing icon button, for list rows), `box` (large dashed code with a
* labelled button, for promo and referral codes). `display` and `groupSize`
* only change what is SHOWN — the clipboard always gets `value` verbatim.
* `masked` hides all but the last four characters until the eye is tapped
* (copying never needs the reveal).
*
* Clipboard: writes through `expo-clipboard` when the host app provides it
* (optional peer, never a hard import) and `navigator.clipboard` on web.
* `onCopy(value)` always fires, so hosts can route the write themselves.
* `CopyButton` is the standalone pill for "Copy all"-style actions.
*/
/** Lumio check on the 24 grid — short stroke, long stroke (length ≈17.7). */
const CHECK_PATH = "M6 12.5l4 4 8-9";
const CHECK_LEN = 18;
/** Ignite — opacity of anything arriving; the check draws on the same curve. */
const IGNITE = { duration: timing.fast.duration, easing: Easing.bezier(...ease.out) };
/** Dim — the leaving glyph or label goes first and faster. */
const DIM = { duration: timing.recede.duration, easing: Easing.bezier(...ease.in) };
/** Check draws over 240ms with no beat in front — it starts on the tap. */
const CHECK_DRAW = { duration: 240, easing: Easing.bezier(...ease.out) };
/** Glyphs bloom wider than labels — 4% is invisible on a 16px icon. */
const GLYPH_FROM = 0.86;
/** Labels swap in place at the standard 0.96 bloom. */
const LABEL_FROM = 0.96;
/** The "Copied" note ignites with a small slide in from the trailing side. */
const NOTE_SLIDE = 4;
/** Copied state lingers long enough to be read, short enough to copy again. */
const DEFAULT_RESET_MS = 1800;
/** The value holds its picked-up light this long before settling back (act → hold → resolve). */
const VALUE_HOLD = 700;
/** Settle back to resting ink — slower than the ignite, it's the resolve. */
const VALUE_SETTLE = { duration: timing.slow.duration, easing: Easing.bezier(...ease.inOut) };
/** Accent sheen on paper — faint; the light picks the value up, it doesn't flash. */
const COPY_SHEEN = 0.25;
interface ClipboardModule {
setStringAsync: (text: string) => Promise<boolean | void>;
}
// Resolved once — optional peer, invisible to Metro's static require analysis.
const clipboardModule = (() => {
const mod = optionalRequire<ClipboardModule>("expo-clipboard");
return mod && typeof mod.setStringAsync === "function" ? mod : null;
})();
/** Write text to the system clipboard. Resolves false when no clipboard is reachable. */
export async function copyToClipboard(text: string): Promise<boolean> {
try {
if (clipboardModule) {
await clipboardModule.setStringAsync(text);
return true;
}
const nav =
Platform.OS === "web" && typeof navigator !== "undefined"
? (navigator as { clipboard?: { writeText: (v: string) => Promise<void> } })
: undefined;
if (nav?.clipboard) {
await nav.clipboard.writeText(text);
return true;
}
} catch {
/* fall through */
}
return false;
}
export interface UseCopyOptions {
onCopy?: (value: string) => void;
/** ms the copied state lasts. Default 1800. */
resetAfter?: number;
/** Spoken confirmation, e.g. "IBAN copied". Default "Copied". */
announcement?: string;
/** ms between the write and the visible confirmation (check, label,
* haptic) — room for what was copied to light up first. Default 0. */
confirmAfter?: number;
}
/** Copy state machine shared by CopyField and CopyButton. `runs` counts
* confirmed copies — bump-to-fire for light that marks each one. */
export function useCopy(
value: string,
{ onCopy, resetAfter = DEFAULT_RESET_MS, announcement = "Copied", confirmAfter = 0 }: UseCopyOptions = {}
) {
const haptic = useHaptic();
const [copied, setCopied] = React.useState(false);
const [runs, setRuns] = React.useState(0);
const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
const confirmTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
React.useEffect(
() => () => {
if (timer.current) clearTimeout(timer.current);
if (confirmTimer.current) clearTimeout(confirmTimer.current);
},
[]
);
const copy = React.useCallback(() => {
void copyToClipboard(value);
onCopy?.(value);
const confirm = () => {
haptic.success();
announce(announcement);
setCopied(true);
setRuns((n) => n + 1);
if (timer.current) clearTimeout(timer.current);
timer.current = setTimeout(() => setCopied(false), resetAfter);
};
if (confirmTimer.current) clearTimeout(confirmTimer.current);
if (confirmAfter > 0) confirmTimer.current = setTimeout(confirm, confirmAfter);
else confirm();
}, [value, onCopy, haptic, announcement, resetAfter, confirmAfter]);
return { copied, copy, runs };
}
/**
* The value text and its picked-up light: an accent-ink twin over the
* resting text ignites when `run` bumps, holds VALUE_HOLD, then settles back
* to the resting ink. Opacity only — it reads the same under reduced motion.
*/
function LitValue({
children,
run,
highlight = 0,
highlightDelay = 0,
className,
numberOfLines,
ellipsizeMode,
wrapClassName,
}: {
children: string;
run: number;
highlight?: number;
highlightDelay?: number;
className?: string;
numberOfLines?: number;
ellipsizeMode?: "middle" | "tail";
wrapClassName?: string;
}) {
const lit = useSharedValue(0);
const flash = React.useCallback(
(delay: number) => {
lit.value = withDelay(
delay,
withSequence(withTiming(1, IGNITE), withDelay(VALUE_HOLD, withTiming(0, VALUE_SETTLE)))
);
},
[lit]
);
React.useEffect(() => {
if (run) flash(0);
}, [run, flash]);
React.useEffect(() => {
if (highlight) flash(highlightDelay);
}, [highlight, highlightDelay, flash]);
const litStyle = useAnimatedStyle(() => ({ opacity: lit.value }));
return (
<View className={wrapClassName}>
<Text className={className} numberOfLines={numberOfLines} ellipsizeMode={ellipsizeMode}>
{children}
</Text>
<Animated.Text
style={litStyle}
className={cn("text-base", className, "absolute left-0 right-0 top-0 text-primary-text")}
numberOfLines={numberOfLines}
ellipsizeMode={ellipsizeMode}
accessibilityElementsHidden
importantForAccessibility="no-hide-descendants"
>
{children}
</Animated.Text>
</View>
);
}
/** Copy glyph that hands over to a drawn check. */
function CopyGlyph({ copied, size = 20, tone = "foreground" }: { copied: boolean; size?: number; tone?: "foreground" | "primaryForeground" | "secondaryForeground" }) {
const reduced = useReducedMotion();
const { colors } = useTheme();
const copyO = useSharedValue(copied ? 0 : 1);
const copyS = useSharedValue(copied ? GLYPH_FROM : 1);
const checkO = useSharedValue(copied ? 1 : 0);
const draw = useSharedValue(copied ? 1 : 0);
React.useEffect(() => {
if (copied) {
// The copy glyph dims while the check ignites and draws — no beat.
copyO.value = withTiming(0, DIM);
copyS.value = reduced ? 1 : withTiming(GLYPH_FROM, DIM);
checkO.value = withTiming(1, IGNITE);
draw.value = reduced ? 1 : 0;
if (!reduced) draw.value = withTiming(1, CHECK_DRAW);
} else {
// Clearing never un-draws — the check dims and the copy glyph ignites.
checkO.value = withTiming(0, DIM);
copyO.value = withTiming(1, IGNITE);
if (reduced) copyS.value = 1;
else {
copyS.value = GLYPH_FROM;
copyS.value = withSpring(1, spring.swap);
}
}
}, [copied, reduced, copyO, copyS, checkO, draw]);
const copyStyle = useAnimatedStyle(() => ({
opacity: copyO.value,
transform: [{ scale: copyS.value }],
}));
const checkStyle = useAnimatedStyle(() => ({
opacity: checkO.value,
}));
const pathProps = useAnimatedProps(() => ({ strokeDashoffset: (1 - draw.value) * CHECK_LEN }));
const checkColor = tone === "primaryForeground" ? colors.primaryForeground : colors.success;
return (
<View style={{ width: size, height: size }} className="items-center justify-center">
<Animated.View style={copyStyle} className="absolute">
<Icon name="copy" size="sm" color={tone} />
</Animated.View>
<Animated.View style={checkStyle} className="absolute">
<Svg width={size} height={size} viewBox="0 0 24 24">
<AnimatedPath
d={CHECK_PATH}
stroke={checkColor}
strokeWidth={2.6}
strokeLinecap="round"
strokeLinejoin="round"
fill="none"
strokeDasharray={CHECK_LEN}
animatedProps={pathProps}
/>
</Svg>
</Animated.View>
</View>
);
}
/** "Copy" ↔ "Copied" label that swaps in place; sized to the longer word. */
function SwapLabel({ copied, copyLabel, copiedLabel, className }: { copied: boolean; copyLabel: string; copiedLabel: string; className?: string }) {
const reduced = useReducedMotion();
const idleO = useSharedValue(copied ? 0 : 1);
const idleS = useSharedValue(1);
const doneO = useSharedValue(copied ? 1 : 0);
const doneS = useSharedValue(1);
React.useEffect(() => {
const [inO, inS, outO, outS] = copied ? [doneO, doneS, idleO, idleS] : [idleO, idleS, doneO, doneS];
outO.value = withTiming(0, DIM);
inO.value = withTiming(1, IGNITE);
if (reduced) {
outS.value = 1;
inS.value = 1;
return;
}
outS.value = withTiming(LABEL_FROM, DIM);
inS.value = LABEL_FROM;
inS.value = withSpring(1, spring.swap);
}, [copied, reduced, idleO, idleS, doneO, doneS]);
const outStyle = useAnimatedStyle(() => ({
opacity: idleO.value,
transform: [{ scale: idleS.value }],
}));
const inStyle = useAnimatedStyle(() => ({
opacity: doneO.value,
transform: [{ scale: doneS.value }],
}));
const longer = copiedLabel.length > copyLabel.length ? copiedLabel : copyLabel;
return (
<View className="justify-center overflow-hidden">
<Text className={cn("opacity-0", className)} accessibilityElementsHidden importantForAccessibility="no">
{longer}
</Text>
<Animated.Text style={outStyle} className={cn("absolute", className)} numberOfLines={1}>
{copyLabel}
</Animated.Text>
<Animated.Text style={inStyle} className={cn("absolute", className)} numberOfLines={1}>
{copiedLabel}
</Animated.Text>
</View>
);
}
function groupDisplay(value: string, size?: number) {
if (!size) return value;
const raw = value.replace(/\s+/g, "");
return raw.match(new RegExp(`.{1,${size}}`, "g"))?.join(" ") ?? raw;
}
export interface CopyFieldProps extends Omit<ViewProps, "className"> {
/** Copied verbatim. */
value: string;
/** Shown instead of `value` (formatting only). */
display?: string;
/** Caption above the value (field / box) — also names the copy action for screen readers. */
label?: string;
/** Helper line under the field. */
description?: string;
/** Default "field". */
appearance?: "field" | "inline" | "box";
/** Monospaced value — codes, IBANs, keys. */
mono?: boolean;
/** Insert a space every n characters in the displayed value. */
groupSize?: number;
/** Where a long value is cut. Default "middle" (keeps both ends of links and addresses). */
truncate?: "middle" | "tail" | "none";
/** Hide all but the last `maskVisible` characters until revealed. */
masked?: boolean;
/** Characters left visible while masked. Default 4. */
maskVisible?: number;
copyLabel?: string;
copiedLabel?: string;
/** ms the copied state lasts. Default 1800. */
resetAfter?: number;
onCopy?: (value: string) => void;
/** Bump to light the value as if it were just copied — e.g. every row
* lighting in turn when a "Copy all" button copies the set. */
highlight?: number;
/** ms before a `highlight` lights the value (row stagger). Default 0. */
highlightDelay?: number;
disabled?: boolean;
className?: string;
valueClassName?: string;
}
export const CopyField = forwardRef<React.ElementRef<typeof View>, CopyFieldProps>(function CopyField(
{
value,
display,
label,
description,
appearance = "field",
mono = false,
groupSize,
truncate = "middle",
masked = false,
maskVisible = 4,
copyLabel = "Copy",
copiedLabel = "Copied",
resetAfter,
onCopy,
highlight = 0,
highlightDelay = 0,
disabled = false,
className,
valueClassName,
...props
},
ref
) {
const haptic = useHaptic();
const reduced = useReducedMotion();
const { colors } = useTheme();
const press = usePressAnimation({ pressedScale: appearance === "box" ? 0.98 : 0.99, disabled });
const [revealed, setRevealed] = React.useState(false);
const { copied, copy, runs } = useCopy(value, {
onCopy,
resetAfter,
announcement: label ? `${label} copied` : "Copied",
});
// A direct copy lights the value at once; an outside highlight after its stagger.
const light = { run: runs, highlight, highlightDelay };
// Promo box: the dashed edge brightens to a solid accent line for the hold.
const edge = useSharedValue(0);
React.useEffect(() => {
if (!runs || appearance !== "box") return;
edge.value = withSequence(withTiming(1, IGNITE), withDelay(VALUE_HOLD, withTiming(0, VALUE_SETTLE)));
}, [runs, appearance, edge]);
const edgeStyle = useAnimatedStyle(() => ({ opacity: edge.value }));
const sheen = <Sheen run={runs} color={colors.primary} strength={COPY_SHEEN} />;
const shown = React.useMemo(() => {
const base = groupDisplay(display ?? value, groupSize);
if (!masked || revealed) return base;
const raw = (display ?? value).replace(/\s+/g, "");
return `•••• ${raw.slice(-maskVisible)}`;
}, [display, value, groupSize, masked, revealed, maskVisible]);
const ellipsize = truncate === "none" ? undefined : truncate;
const lines = truncate === "none" ? undefined : 1;
// "Copied" note in the label row — the inline confirmation.
const noteO = useSharedValue(0);
React.useEffect(() => {
noteO.value = withTiming(copied ? 1 : 0, copied ? IGNITE : DIM);
}, [copied, noteO]);
const noteStyle = useAnimatedStyle(() => ({
opacity: noteO.value,
transform: [{ translateX: reduced ? 0 : (1 - noteO.value) * NOTE_SLIDE }],
}));
const onPress = (_e: GestureResponderEvent) => {
if (disabled) return;
copy();
};
const eye = masked ? (
<Pressable
onPress={() => {
haptic.selection();
setRevealed((r) => !r);
}}
hitSlop={4}
className="h-11 w-11 items-center justify-center rounded-full"
accessibilityRole="button"
accessibilityState={{ expanded: revealed }}
accessibilityLabel={revealed ? `Hide ${label ?? "value"}` : `Show ${label ?? "value"}`}
>
<Icon name={revealed ? "eye-off" : "eye"} size="sm" color="mutedForeground" />
</Pressable>
) : null;
const a11y = {
accessibilityRole: "button" as const,
accessibilityLabel: `${label ? `${label}, ` : ""}${masked && !revealed ? "hidden" : shown}`,
accessibilityHint: `Double tap to ${copyLabel.toLowerCase()}`,
accessibilityState: { disabled },
};
const labelRow =
label && appearance !== "inline" ? (
<View className="flex-row items-center justify-between">
<Text className="text-sm font-medium text-muted-foreground">{label}</Text>
<Animated.View style={noteStyle} className="flex-row items-center gap-1">
<Icon name="check" size="sm" color="success" />
<Text className="text-sm font-medium text-success">{copiedLabel}</Text>
</Animated.View>
</View>
) : null;
if (appearance === "box") {
return (
<View ref={ref} className={cn("w-full gap-2", className)} {...props}>
{labelRow}
<AnimatedPressable
onPress={onPress}
onPressIn={press.onPressIn}
onPressOut={press.onPressOut}
disabled={disabled}
style={press.animatedStyle}
className={cn(
"w-full items-center gap-4 rounded-2xl border-2 border-dashed border-border px-5 py-6",
disabled && "opacity-50"
)}
{...a11y}
>
{/* Solid accent edge over the dashed one — lit for the hold. */}
<Animated.View
pointerEvents="none"
style={[{ position: "absolute", top: -2, left: -2, right: -2, bottom: -2 }, edgeStyle]}
className="rounded-2xl border-2 border-primary"
/>
<View className="w-full items-center overflow-hidden rounded-xl">
<LitValue
{...light}
className={cn("text-3xl font-bold tracking-widest", mono && "font-mono", valueClassName)}
numberOfLines={lines}
ellipsizeMode={ellipsize}
>
{shown}
</LitValue>
{sheen}
</View>
<View className="h-11 flex-row items-center gap-2 rounded-full bg-primary px-5">
<CopyGlyph copied={copied} tone="primaryForeground" />
<SwapLabel
copied={copied}
copyLabel={copyLabel}
copiedLabel={copiedLabel}
className="text-[15px] font-semibold text-primary-foreground"
/>
</View>
</AnimatedPressable>
{description ? <Text className="text-center text-sm text-muted-foreground">{description}</Text> : null}
</View>
);
}
if (appearance === "inline") {
return (
<AnimatedPressable
ref={ref}
onPress={onPress}
onPressIn={press.onPressIn}
onPressOut={press.onPressOut}
disabled={disabled}
style={press.animatedStyle}
className={cn("min-h-11 flex-row items-center gap-1", disabled && "opacity-50", className)}
{...a11y}
{...props}
>
<View className="flex-1 justify-center self-stretch overflow-hidden">
<LitValue
{...light}
className={cn("text-[15px] font-medium", mono && "font-mono tracking-wide", valueClassName)}
numberOfLines={lines}
ellipsizeMode={ellipsize}
>
{shown}
</LitValue>
{sheen}
</View>
{eye}
<View className="h-11 w-11 items-center justify-center">
<View className="h-8 w-8 items-center justify-center rounded-full bg-secondary">
<CopyGlyph copied={copied} size={18} tone="secondaryForeground" />
</View>
</View>
</AnimatedPressable>
);
}
return (
<View ref={ref} className={cn("w-full gap-2", className)} {...props}>
{labelRow}
<AnimatedPressable
onPress={onPress}
onPressIn={press.onPressIn}
onPressOut={press.onPressOut}
disabled={disabled}
style={press.animatedStyle}
className={cn(
"min-h-14 w-full flex-row items-center overflow-hidden rounded-2xl bg-secondary pl-4 pr-1",
disabled && "opacity-50"
)}
{...a11y}
>
<LitValue
{...light}
wrapClassName="flex-1"
className={cn("text-base text-secondary-foreground", mono && "font-mono tracking-wide", valueClassName)}
numberOfLines={lines}
ellipsizeMode={ellipsize}
>
{shown}
</LitValue>
{eye}
<View className="h-12 w-12 items-center justify-center">
<CopyGlyph copied={copied} tone="secondaryForeground" />
</View>
{sheen}
</AnimatedPressable>
{description ? <Text className="text-sm text-muted-foreground">{description}</Text> : null}
</View>
);
});
CopyField.displayName = "CopyField";
export interface CopyButtonProps extends Omit<ViewProps, "className"> {
/** Copied verbatim. */
value: string;
/** Default "Copy". */
label?: string;
/** Default "Copied". */
copiedLabel?: string;
/** "default" — accent/ink pill; "secondary" — neutral pill. */
variant?: "default" | "secondary";
/** md 44 · lg 52. Default "md". */
size?: "md" | "lg";
resetAfter?: number;
onCopy?: (value: string) => void;
disabled?: boolean;
/** Spoken confirmation. Default "Copied". */
announcement?: string;
/** ms between the copy and the button's confirmation — let what was
* copied light up first (pair with CopyField `highlight`). Default 0. */
confirmAfter?: number;
className?: string;
}
/** Standalone pill — "Copy all codes", "Copy link". Glyph hands over to a check, label swaps in place. */
export const CopyButton = forwardRef<React.ElementRef<typeof View>, CopyButtonProps>(function CopyButton(
{
value,
label = "Copy",
copiedLabel = "Copied",
variant = "secondary",
size = "md",
resetAfter,
onCopy,
disabled = false,
announcement,
confirmAfter,
className,
...props
},
ref
) {
const press = usePressAnimation({ pressedScale: size === "lg" ? 0.97 : 0.95, disabled });
const { copied, copy } = useCopy(value, { onCopy, resetAfter, announcement, confirmAfter });
const filled = variant === "default";
return (
<AnimatedPressable
ref={ref}
onPress={() => !disabled && copy()}
onPressIn={press.onPressIn}
onPressOut={press.onPressOut}
disabled={disabled}
style={press.animatedStyle}
className={cn(
"flex-row items-center justify-center gap-2 rounded-full px-5",
size === "lg" ? "h-14" : "h-11",
filled ? "bg-primary" : "bg-secondary",
disabled && "opacity-50",
className
)}
accessibilityRole="button"
accessibilityLabel={copied ? copiedLabel : label}
accessibilityState={{ disabled }}
{...props}
>
<CopyGlyph copied={copied} tone={filled ? "primaryForeground" : "secondaryForeground"} />
<SwapLabel
copied={copied}
copyLabel={label}
copiedLabel={copiedLabel}
className={cn("font-semibold", size === "lg" ? "text-base" : "text-[15px]", filled ? "text-primary-foreground" : "text-secondary-foreground")}
/>
</AnimatedPressable>
);
});
CopyButton.displayName = "CopyButton"; import { CopyField } from "@/components/ui/copy-field/copy-field";
export function Example() {
return (
<CopyField />
);
} Installation
Install the dependencies
npx expo install react-native-reanimated react-native-svgAdd the components it builds on
Copy the source from the Code tab into your project
components/ui/copy-field/copy-field.tsxcomponents/ui/copy-field/index.tsIcons it renders
Update the import paths to match your project setup.
Usage
import { useCopy, CopyField, CopyButton } from "@/components/ui/copy-field/copy-field"; <CopyField /> Also exported: useCopy, CopyButton.
Examples
Two-factor recovery codes in a password vault.
import * as React from "react";
import { View } from "react-native";
import { rowDelay, timing } from "@lumioui/core";
import { CopyButton, CopyField } from "../copy-field";
import { Icon } from "../../icon/icon";
import { Text } from "../../text/text";
const CODES = ["48219930", "71056624", "39904187", "55620318", "82147759", "10938462", "66473015", "93358201"];
const COLS = 2;
/** "Copy all" confirms once the last row of codes has lit. */
const CONFIRM_AFTER = rowDelay(Math.ceil(CODES.length / COLS) - 1) + timing.fast.duration;
/** CopyFieldBackupCodes — two-factor recovery codes in a password vault.
* Codes read in monospace pairs of four; any one copies on a tap. "Copy
* all" lights the codes row by row, top to bottom 40ms apart, and only
* then does the button confirm. */
export function CopyFieldBackupCodes() {
const [lit, setLit] = React.useState(0);
return (
<View className="w-full gap-5 rounded-3xl bg-card p-5">
<View className="flex-row items-start gap-3">
<View className="h-11 w-11 items-center justify-center rounded-full bg-secondary">
<Icon name="shield" size="sm" color="foreground" />
</View>
<View className="flex-1 gap-1">
<Text className="text-xl font-bold tracking-tight">Backup codes</Text>
<Text className="text-[15px] text-muted-foreground">
Each code signs you in once if you lose your phone. Keep them offline.
</Text>
</View>
</View>
<View className="flex-row flex-wrap rounded-2xl border border-border px-3 py-2">
{CODES.map((c, i) => (
<View key={c} className="w-1/2 pr-1">
<CopyField
appearance="inline"
label={`Backup code ${c.slice(0, 4)}`}
value={c}
groupSize={4}
mono
truncate="none"
valueClassName="text-base"
highlight={lit}
highlightDelay={rowDelay(Math.floor(i / COLS))}
/>
</View>
))}
</View>
<Text className="text-sm text-muted-foreground">8 of 10 unused · created Sep 30</Text>
<CopyButton
value={CODES.map((c) => `${c.slice(0, 4)} ${c.slice(4)}`).join("\n")}
label="Copy all codes"
copiedLabel="Codes copied"
variant="default"
size="lg"
announcement="All backup codes copied"
confirmAfter={CONFIRM_AFTER}
onCopy={() => setLit((n) => n + 1)}
/>
</View>
);
} A bank's "receive money" sheet.
import * as React from "react";
import { View } from "react-native";
import { Accent } from "@lumioui/core";
import { CopyButton, CopyField } from "../copy-field";
import { Text } from "../../text/text";
const DETAILS = [
{ label: "Account holder", value: "Jonah Achterberg" },
{ label: "IBAN", value: "NL47 KSTR 0612 9934 81", mono: true, group: 4 },
{ label: "BIC", value: "KSTRNL2A", mono: true },
{ label: "Account number", value: "0612993481", mono: true, masked: true },
];
/** CopyFieldIBAN — a bank's "receive money" sheet. Each detail copies on
* its own from a grouped list; the IBAN reads in groups of four but pastes
* as one unbroken string, and the account number stays masked until
* revealed. "Copy all" puts the whole block on the clipboard. */
export function CopyFieldIBAN() {
const all = DETAILS.map((d) => `${d.label}: ${d.value.replace(/\s/g, "")}`).join("\n");
return (
<Accent color="green" className="w-full">
<View className="w-full gap-4">
<View className="gap-1">
<Text className="text-2xl font-bold tracking-tight">Euro account</Text>
<Text className="text-[15px] text-muted-foreground">Share these to get paid by bank transfer</Text>
</View>
<View className="overflow-hidden rounded-2xl bg-card">
{DETAILS.map((d, i) => (
<View key={d.label} className={i > 0 ? "border-t border-border pl-4 pr-1 pt-2" : "pl-4 pr-1 pt-2"}>
<Text className="text-sm text-muted-foreground">{d.label}</Text>
<CopyField
appearance="inline"
label={d.label}
value={d.value.replace(/\s/g, "")}
groupSize={d.group}
mono={d.mono}
masked={d.masked}
/>
</View>
))}
</View>
<CopyButton value={all} label="Copy all details" copiedLabel="All details copied" variant="default" size="lg" announcement="Account details copied" />
</View>
</Accent>
);
} A running club's bring-a-friend screen.
import * as React from "react";
import { View } from "react-native";
import { Accent } from "@lumioui/core";
import { CopyField } from "../copy-field";
import { AvatarGroup } from "../../avatar-group/avatar-group";
import { Button } from "../../button/button";
import { Icon } from "../../icon/icon";
import { Text } from "../../text/text";
const JOINED = [12, 25, 49].map((n) => ({ id: n, source: { uri: `https://i.pravatar.cc/150?img=${n}` }, alt: "" }));
/** CopyFieldInvite — a running club's bring-a-friend screen. The personal
* link truncates in the middle so both the domain and the code stay
* visible; copy it or hand it to the share sheet. */
export function CopyFieldInvite() {
return (
<Accent color="red" className="w-full">
<View className="w-full gap-6 rounded-3xl bg-card p-5">
<View className="gap-2">
<Text className="text-2xl font-bold tracking-tight">Run with a friend</Text>
<Text className="text-[15px] text-muted-foreground">
When they log their first 5 km, you both get a month of Lumio Pro.
</Text>
</View>
<View className="flex-row items-center gap-3">
<AvatarGroup items={JOINED} size="md" />
<View className="flex-1">
<Text className="text-[15px] font-semibold">3 of 5 friends joined</Text>
<Text className="text-sm text-muted-foreground">2 free months left to earn</Text>
</View>
</View>
<CopyField label="Your invite link" value="https://pacer.example/join/maya-ren-7Q2KX9" />
<Button size="lg" icon={<Icon name="share" size="sm" color="primaryForeground" />}>
Share invite
</Button>
</View>
</Accent>
);
} A meal-kit offer shaped like a torn coupon.
import * as React from "react";
import { Image, View } from "react-native";
import { Accent } from "@lumioui/core";
import { CopyField } from "../copy-field";
import { Text } from "../../text/text";
const PHOTO = "https://images.unsplash.com/photo-1512621776951-a57141f2eefd?w=800&h=480&fit=crop&q=70&auto=format";
/** CopyFieldPromo — a meal-kit offer shaped like a torn coupon. The code
* is the hero: big, dashed, one tap to copy, with the terms underneath. */
export function CopyFieldPromo() {
return (
<Accent color="orange" className="w-full">
<View className="w-full overflow-hidden rounded-3xl bg-card">
<Image
source={{ uri: PHOTO }}
className="h-40 w-full bg-muted"
resizeMode="cover"
accessibilityIgnoresInvertColors
accessibilityLabel="Grain bowl with greens and roasted vegetables"
/>
<View className="gap-1 px-5 pt-5">
<Text className="text-2xl font-bold tracking-tight">15% off your next 3 boxes</Text>
<Text className="text-[15px] text-muted-foreground">Harvest Table · autumn menu is live</Text>
</View>
{/* Perforation between the offer and the code stub. */}
<View className="my-5 h-6 flex-row items-center">
<View className="absolute -left-3 h-6 w-6 rounded-full bg-background" />
<View className="mx-5 flex-1 border-t border-dashed border-border" />
<View className="absolute -right-3 h-6 w-6 rounded-full bg-background" />
</View>
<View className="px-5 pb-5">
<CopyField
appearance="box"
value="HARVEST15"
mono
copyLabel="Copy code"
copiedLabel="Code copied"
description="Ends Sunday · minimum order $40"
/>
</View>
</View>
</Accent>
);
} API reference
CopyField
value* string Copied verbatim.
—display string Shown instead of value (formatting only).
label string Caption above the value (field / box) — also names the copy action for screen readers.
—description string Helper line under the field.
—appearance "field" | "inline" | "box" Default "field".
"field" mono boolean Monospaced value — codes, IBANs, keys.
false groupSize number Insert a space every n characters in the displayed value.
—truncate "middle" | "tail" | "none" Where a long value is cut. Default "middle" (keeps both ends of links and addresses).
"middle" masked boolean Hide all but the last maskVisible characters until revealed.
false maskVisible number Characters left visible while masked. Default 4.
4 copyLabel string "Copy" copiedLabel string "Copied" resetAfter number ms the copied state lasts. Default 1800.
—onCopy (value: string) => void — highlight number Bump to light the value as if it were just copied — e.g. every row lighting in turn when a "Copy all" button copies the set.
0 highlightDelay number ms before a highlight lights the value (row stagger). Default 0.
0 disabled boolean false className string — valueClassName string — CopyButton
value* string Copied verbatim.
—label string Default "Copy".
"Copy" copiedLabel string Default "Copied".
"Copied" variant "default" | "secondary" "default" — accent/ink pill; "secondary" — neutral pill.
"secondary" size "md" | "lg" md 44 · lg 52. Default "md".
"md" resetAfter number — onCopy (value: string) => void — disabled boolean false announcement string Spoken confirmation. Default "Copied".
—confirmAfter number ms between the copy and the button's confirmation — let what was copied light up first (pair with CopyField highlight). Default 0.
className string —