{ "name": "searchInput", "displayName": "SearchInput", "type": "component", "files": [ { "name": "SearchInput.tsx", "content": "import { forwardRef, useEffect, useRef, useState } from 'react';\nimport { Input, type InputProps } from '../Input';\nimport { Icon } from '../Icon';\nimport { Spinner } from '../Spinner';\n\nexport interface SearchInputProps extends Omit<\n InputProps,\n 'onChange' | 'type' | 'label'\n> {\n label?: string;\n onSearch?: (value: string) => void;\n debounceMs?: number;\n loading?: boolean;\n onClear?: () => void;\n value?: string;\n defaultValue?: string;\n onChange?: (e: React.ChangeEvent) => void;\n}\n\nexport const SearchInput = forwardRef(\n function SearchInput(\n {\n label = 'Search',\n onSearch,\n debounceMs = 300,\n loading = false,\n onClear,\n value,\n defaultValue = '',\n onChange,\n placeholder = 'Search…',\n ...rest\n },\n ref,\n ) {\n const [inner, setInner] = useState(String(value ?? defaultValue));\n const isControlled = value !== undefined;\n const current = isControlled ? String(value) : inner;\n const timer = useRef | null>(null);\n\n useEffect(\n () => () => {\n if (timer.current) clearTimeout(timer.current);\n },\n [],\n );\n\n const setValue = (v: string) => {\n if (!isControlled) setInner(v);\n };\n\n const handleChange = (e: React.ChangeEvent) => {\n setValue(e.target.value);\n onChange?.(e);\n if (!onSearch) return;\n if (timer.current) clearTimeout(timer.current);\n const v = e.target.value;\n timer.current = setTimeout(() => onSearch(v), debounceMs);\n };\n\n const handleClear = () => {\n setValue('');\n if (timer.current) clearTimeout(timer.current);\n onSearch?.('');\n onClear?.();\n };\n\n const hasValue = current.length > 0;\n\n return (\n }\n rightAddon={\n loading ? (\n \n ) : hasValue ? (\n \n \n \n ) : undefined\n }\n {...rest}\n />\n );\n },\n);\n" }, { "name": "SearchInput.module.css", "content": "/* SearchInput composes Input for styling; nothing custom needed here.\n File exists to preserve the per-component convention. */\n" }, { "name": "index.ts", "content": "export { SearchInput } from './SearchInput';\nexport type { SearchInputProps } from './SearchInput';\n" } ], "registryDependencies": [ "input", "icon", "spinner" ], "dependencies": [], "devDependencies": [] }