{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-affix",
  "type": "registry:ui",
  "title": "react-tw/affix.tsx",
  "description": "A field's `prefixText` / `suffixText` (TextInput, NumberInput), as `<ui-text-input>` / Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [],
  "registryDependencies": [
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/affix.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/affix.tsx",
      "content": "import { useLayoutEffect, type ReactNode, type RefObject } from 'react';\nimport { cn } from './lib/utils.ts';\n\n/**\n * A field's `prefixText` / `suffixText` (TextInput, NumberInput), as `<ui-text-input>` /\n * `<ui-number-input>`: secondary text inside the field before / after the value.\n */\n\nconst filled = (node: ReactNode) => node != null && node !== '' && node !== false;\n\n/**\n * Whether each shows, the input's description (prefix, suffix, message), and their widths as\n * `--prefix-width` / `--suffix-width` on the field row, followed as they change (a font loading\n * late, a new text).\n */\nexport function useAffixes(row: RefObject<HTMLDivElement | null>, id: string, prefixText: ReactNode, suffixText: ReactNode, messageId: string | undefined) {\n    const hasPrefix = filled(prefixText);\n    const hasSuffix = filled(suffixText);\n    useLayoutEffect(() => {\n        const el = row.current;\n        if (!el || (!hasPrefix && !hasSuffix)) return;\n        const affixes = [...el.querySelectorAll<HTMLElement>('[data-affix]')];\n        const measure = () => {\n            for (const affix of affixes) el.style.setProperty(`--${affix.dataset.affix}-width`, `${affix.getBoundingClientRect().width}px`);\n        };\n        measure(); // before the first paint\n        const observer = new ResizeObserver(measure);\n        for (const affix of affixes) observer.observe(affix);\n        return () => observer.disconnect();\n    }, [row, hasPrefix, hasSuffix]);\n    const ids = [hasPrefix && `${id}-prefix`, hasSuffix && `${id}-suffix`, messageId].filter(Boolean);\n    return { hasPrefix, hasSuffix, describedBy: ids.length > 0 ? ids.join(' ') : undefined };\n}\n\n/** The prefix or suffix (secondary text in the value's type), placed by `className`; nothing when empty. */\nexport function Affix({ id, kind, className, children }: Readonly<{ id: string; kind: 'prefix' | 'suffix'; className?: string; children: ReactNode }>) {\n    if (!filled(children)) return null;\n    return (\n        <span id={`${id}-${kind}`} data-affix={kind} className={cn('whitespace-nowrap text-ink-muted type-body-sm', className)}>\n            {children}\n        </span>\n    );\n}\n"
    }
  ]
}
