{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "copyable-readonly-field",
  "title": "Copyable Read-Only Field",
  "description": "A read-only input for values people need to copy (links, IDs, commands) with a Copy button that confirms in text and aria-live, selects everything on focus, and falls back when the clipboard is blocked. Use this when the value is for pasting elsewhere.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "input",
    "button",
    "label"
  ],
  "files": [
    {
      "path": "registry/patterns/copyable-readonly-field/copyable-readonly-field.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { CheckIcon, CopyIcon } from \"lucide-react\"\n\nimport { Button } from \"@/components/ui/button\"\nimport { Input } from \"@/components/ui/input\"\nimport { Label } from \"@/components/ui/label\"\n\nexport interface CopyableReadOnlyFieldProps {\n  label?: string\n  value?: string\n  /** Text read out and shown after copying. */\n  copiedMessage?: string\n  onCopy?: (value: string) => void\n}\n\nexport function CopyableReadOnlyField({\n  label = \"Share link\",\n  value = \"https://example.com/share/8f2a91c4\",\n  copiedMessage = \"Link copied to the clipboard.\",\n  onCopy,\n}: CopyableReadOnlyFieldProps) {\n  const [state, setState] = React.useState<\"idle\" | \"copied\" | \"blocked\">(\n    \"idle\"\n  )\n  const inputRef = React.useRef<HTMLInputElement>(null)\n\n  async function copy() {\n    try {\n      await navigator.clipboard.writeText(value)\n      setState(\"copied\")\n      onCopy?.(value)\n      setTimeout(() => setState(\"idle\"), 2000)\n    } catch {\n      // Clipboard blocked (permissions, insecure origin): select the text so Ctrl+C works.\n      inputRef.current?.focus()\n      inputRef.current?.select()\n      setState(\"blocked\")\n    }\n  }\n\n  return (\n    <div className=\"flex w-full max-w-md flex-col gap-1.5\">\n      <Label htmlFor=\"crf-input\">{label}</Label>\n      <div className=\"flex gap-2\">\n        <Input\n          id=\"crf-input\"\n          ref={inputRef}\n          readOnly\n          value={value}\n          className=\"font-mono text-sm\"\n          onFocus={(e) => e.currentTarget.select()}\n          aria-describedby=\"crf-status\"\n        />\n        <Button\n          type=\"button\"\n          variant=\"outline\"\n          onClick={copy}\n          aria-label={\n            state === \"copied\" ? \"Copied\" : `Copy ${label.toLowerCase()}`\n          }\n        >\n          {state === \"copied\" ? (\n            <CheckIcon aria-hidden=\"true\" />\n          ) : (\n            <CopyIcon aria-hidden=\"true\" />\n          )}\n          {state === \"copied\" ? \"Copied\" : \"Copy\"}\n        </Button>\n      </div>\n      <p\n        id=\"crf-status\"\n        role=\"status\"\n        className=\"text-muted-foreground text-xs\"\n      >\n        {state === \"copied\"\n          ? copiedMessage\n          : state === \"blocked\"\n            ? \"Copying was blocked. The text is selected: press Ctrl+C or Cmd+C.\"\n            : \"\"}\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}