{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "copy-button",
  "title": "Copy Button",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/copy-button/CopyButton.tsx",
      "content": "import * as React from 'react'\nimport type { GestureResponderEvent } from 'react-native'\nimport { setStringAsync } from 'expo-clipboard'\nimport { Button, type ButtonProps } from '@/components/ui/button'\n\nexport interface CopyButtonProps extends ButtonProps {\n  /** Text written to the system clipboard when pressed. */\n  value: string\n  /** Label shown briefly after a confirmed clipboard write. Defaults to `'Copied'`. */\n  copiedLabel?: React.ReactNode\n  /** Milliseconds to display `copiedLabel` before restoring `children`. Defaults to `2000`. */\n  copiedDuration?: number\n  /** Called only when `expo-clipboard` confirms the write (`true`). */\n  onCopied?: (value: string) => void\n  /** Called when `expo-clipboard` returns `false` or rejects. */\n  onError?: (error: Error) => void\n}\n\n/**\n * Copies `value` to the clipboard using `expo-clipboard`.\n *\n * Bare React Native apps require `expo-modules` (Expo Modules autolinking) to use `expo-clipboard`.\n * On web, clipboard writes require a secure context (HTTPS or localhost) and an\n * active user gesture; otherwise `setStringAsync` resolves to `false` or rejects.\n */\nconst CopyButton = React.forwardRef<React.ComponentRef<typeof Button>, CopyButtonProps>(\n  (\n    {\n      value,\n      copiedLabel = 'Copied',\n      copiedDuration = 2000,\n      onCopied,\n      onError,\n      onPress,\n      disabled,\n      loading = false,\n      children = 'Copy',\n      accessibilityLiveRegion = 'polite',\n      ...props\n    },\n    ref,\n  ) => {\n    const [pending, setPending] = React.useState(false)\n    const [copied, setCopied] = React.useState(false)\n    const mountedRef = React.useRef(true)\n    const pendingRef = React.useRef(false)\n    const valueGenerationRef = React.useRef(0)\n    const timerRef = React.useRef<ReturnType<typeof setTimeout> | null>(null)\n    const previousValueRef = React.useRef(value)\n\n    React.useEffect(() => {\n      mountedRef.current = true\n      return () => {\n        mountedRef.current = false\n        valueGenerationRef.current += 1\n        if (timerRef.current !== null) {\n          clearTimeout(timerRef.current)\n          timerRef.current = null\n        }\n      }\n    }, [])\n\n    React.useEffect(() => {\n      if (previousValueRef.current === value) return\n      previousValueRef.current = value\n      valueGenerationRef.current += 1\n      if (timerRef.current !== null) {\n        clearTimeout(timerRef.current)\n        timerRef.current = null\n      }\n      setCopied(false)\n    }, [value])\n\n    async function handlePress(event: GestureResponderEvent) {\n      if (disabled || loading || pendingRef.current) return\n      onPress?.(event)\n      if (event?.defaultPrevented) return\n\n      pendingRef.current = true\n      setPending(true)\n      const generation = valueGenerationRef.current\n      let ok = false\n      let nativeError: Error | undefined\n\n      try {\n        ok = (await setStringAsync(value)) === true\n      } catch (error) {\n        nativeError = error instanceof Error ? error : new Error(String(error))\n      }\n\n      pendingRef.current = false\n      if (!mountedRef.current) return\n      setPending(false)\n\n      if (valueGenerationRef.current !== generation) return\n\n      if (nativeError || !ok) {\n        setCopied(false)\n        onError?.(nativeError ?? new Error('Unable to copy to clipboard.'))\n        return\n      }\n\n      setCopied(true)\n      if (timerRef.current !== null) {\n        clearTimeout(timerRef.current)\n        timerRef.current = null\n      }\n      if (Number.isFinite(copiedDuration) && copiedDuration > 0) {\n        timerRef.current = setTimeout(() => {\n          timerRef.current = null\n          if (mountedRef.current) setCopied(false)\n        }, copiedDuration)\n      }\n      onCopied?.(value)\n    }\n\n    return (\n      <Button\n        ref={ref}\n        disabled={disabled}\n        loading={loading || pending}\n        accessibilityLiveRegion={accessibilityLiveRegion}\n        onPress={handlePress}\n        {...props}\n      >\n        {copied ? copiedLabel : children}\n      </Button>\n    )\n  },\n)\nCopyButton.displayName = 'CopyButton'\n\nexport { CopyButton }\n",
      "type": "registry:ui",
      "target": "~/components/ui/copy-button/CopyButton.tsx"
    },
    {
      "path": "packages/registry-native/components/copy-button/index.ts",
      "content": "export { CopyButton, type CopyButtonProps } from './CopyButton'\n",
      "type": "registry:ui",
      "target": "~/components/ui/copy-button/index.ts"
    }
  ],
  "dependencies": [
    "expo-clipboard"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/button.json"
  ],
  "description": "Action button that copies text with expo-clipboard, guards rapid presses, and shows temporary confirmation only after a verified write.",
  "categories": [
    "control"
  ]
}