{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-field",
  "type": "registry:ui",
  "title": "File Field",
  "description": "A styled file input with label, chosen file names announced to screen readers, a hint and an error.",
  "dependencies": [
    "lucide-react@^1.49.0"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/file-field.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/file-field.tsx",
      "content": "import { useId, useRef, useState, type ReactNode } from 'react';\nimport { Paperclip } from 'lucide-react';\nimport { cn } from '../lib/utils';\nimport { Button } from './button';\n\nexport interface FileFieldProps {\n  label: ReactNode;\n  hint?: ReactNode;\n  /** Replaces the hint and is announced as the description. */\n  error?: ReactNode;\n  accept?: string;\n  multiple?: boolean;\n  disabled?: boolean;\n  /** Form field name; the native input stays in the DOM (hidden), so a surrounding <form> submits the files. */\n  name?: string;\n  onFiles?: (files: File[]) => void;\n  /** Pass these translated; the English defaults are only a fallback. */\n  buttonLabel?: ReactNode;\n  emptyLabel?: ReactNode;\n  className?: string;\n}\n\n/** A styled replacement for <input type=\"file\">: label, button, the chosen file names (announced), a hint or an error. */\nexport function FileField({ label, hint, error, accept, multiple, disabled, name, onFiles, buttonLabel = 'Choose file', emptyLabel = 'No file chosen', className }: FileFieldProps) {\n  const id = useId();\n  const input = useRef<HTMLInputElement>(null);\n  const [names, setNames] = useState<string[]>([]);\n  const desc = error || hint ? `${id}-d` : undefined;\n  return (\n    <div className={cn('flex flex-col gap-1.5', className)}>\n      <label id={`${id}-l`} htmlFor={id} className=\"text-kh-small font-medium text-kh-ink\">{label}</label>\n      <div className=\"flex flex-wrap items-center gap-3\">\n        <Button id={id} variant=\"secondary\" icon={<Paperclip aria-hidden className=\"size-4\" />} disabled={disabled} aria-labelledby={`${id}-l ${id}-b`} aria-describedby={desc} onClick={() => input.current?.click()}>\n          <span id={`${id}-b`}>{buttonLabel}</span>\n        </Button>\n        <span aria-live=\"polite\" className=\"min-w-0 break-words text-kh-small text-kh-muted\" data-testid=\"file-names\">{names.length ? names.join(', ') : emptyLabel}</span>\n      </div>\n      <input\n        ref={input}\n        type=\"file\"\n        hidden\n        name={name}\n        accept={accept}\n        multiple={multiple}\n        disabled={disabled}\n        onChange={(e) => {\n          const files = Array.from(e.currentTarget.files ?? []);\n          setNames(files.map((f) => f.name));\n          onFiles?.(files);\n        }}\n      />\n      {(error || hint) && <p id={desc} className={cn('text-kh-small', error ? 'text-kh-danger' : 'text-kh-muted')}>{error || hint}</p>}\n    </div>\n  );\n}\n"
    }
  ]
}
