{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-search-bar",
  "title": "Search Bar",
  "description": "A full-width composable search bar with visual variants, keyboard shortcut hint, voice input, debounce, custom icon, and skeleton loading.",
  "dependencies": [
    "lucide-react",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/input",
    "@lema-ds/kbd",
    "@lema-ds/skeleton",
    "@lema-ds/ui-i18n",
    "@lema-ds/button",
    "@lema-ds/spinner",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-search-bar.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { SearchIcon, XIcon, MicIcon } from \"lucide-react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport type { HTMLAttributes } from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { useSpeechRecognition } from \"@/hooks/use-speech-recognition\"\nimport { Button } from \"@/components/ui/button\"\nimport { Input } from \"@/components/ui/input\"\nimport { Kbd } from \"@/components/ui/kbd\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport { Spinner } from \"@/components/ui/spinner\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport type SearchBarSize = \"sm\" | \"md\" | \"lg\"\nexport type SearchBarVariant = \"outline\" | \"filled\" | \"ghost\"\nexport type SearchBarRounded = \"none\" | \"sm\" | \"md\" | \"lg\" | \"xl\" | \"full\"\n\nexport interface SearchBarProps extends Omit<\n  HTMLAttributes<HTMLDivElement>,\n  \"onChange\"\n> {\n  value?: string\n  defaultValue?: string\n  onChange?: (value: string) => void\n  onSearch?: (value: string) => void\n  onClear?: () => void\n  placeholder?: string\n  size?: SearchBarSize\n  variant?: SearchBarVariant\n  rounded?: SearchBarRounded\n  /** Custom leading icon. Defaults to SearchIcon. */\n  icon?: React.ElementType\n  /** Shows a loading spinner, suppresses clear button. */\n  loading?: boolean\n  /**\n   * Keyboard shortcut hint shown when the input is empty (e.g. \"⌘K\").\n   * Rendered via the Kbd component on the trailing side.\n   */\n  shortcut?: string\n  /**\n   * Arbitrary trailing content rendered after the clear button —\n   * useful for filter badges, action buttons, or separators.\n   */\n  trailingSlot?: React.ReactNode\n  /** Debounce onChange calls by N milliseconds. 0 = no debounce. */\n  debounceMs?: number\n  /** Enables the voice input button (requires browser Web Speech API support). */\n  voice?: boolean\n  /** Callback fired when voice recording starts. */\n  onVoiceStart?: () => void\n  /** Callback fired when voice recording ends. */\n  onVoiceEnd?: () => void\n  /** Callback fired when voice recognition encounters an error. */\n  onVoiceError?: (error: string) => void\n  disabled?: boolean\n  autoFocus?: boolean\n  locale?: UILocale\n}\n\nexport interface SearchBarSkeletonProps {\n  size?: SearchBarSize\n  rounded?: SearchBarRounded\n  className?: string\n}\n\nexport type SearchBarVariantProps = VariantProps<typeof searchBarVariants>\n\n// ── Variants ───────────────────────────────────────────────────────────────\n\nexport const searchBarVariants = cva(\n  [\n    \"relative flex w-full items-center border\",\n    \"motion-safe:transition-colors motion-safe:duration-150\",\n    \"focus-within:border-ring focus-within:ring-2 focus-within:ring-ring\",\n  ],\n  {\n    variants: {\n      variant: {\n        outline: [\"border-border bg-background\", \"hover:border-ring/50\"],\n        filled: [\"border-transparent bg-muted\", \"hover:border-border\"],\n        ghost: [\n          \"border-transparent bg-transparent\",\n          \"hover:border-border/60 hover:bg-accent\",\n        ],\n      },\n      size: {\n        sm: \"h-8 gap-1.5 px-2.5\",\n        md: \"h-10 gap-2 px-3\",\n        lg: \"h-12 gap-2.5 px-4\",\n      },\n      rounded: {\n        none: \"rounded-none\",\n        sm: \"rounded-sm\",\n        md: \"rounded-md\",\n        lg: \"rounded-lg\",\n        xl: \"rounded-xl\",\n        full: \"rounded-full\",\n      },\n    },\n    defaultVariants: {\n      variant: \"outline\",\n      size: \"md\",\n      rounded: \"lg\",\n    },\n  }\n)\n\nexport const searchBarIconVariants = cva(\"shrink-0 text-muted-foreground\", {\n  variants: {\n    size: {\n      sm: \"size-3.5\",\n      md: \"size-4\",\n      lg: \"size-5\",\n    },\n  },\n  defaultVariants: { size: \"md\" },\n})\n\nexport const searchBarInputVariants = cva(\n  [\n    \"min-w-0 flex-1 bg-transparent outline-none\",\n    \"text-foreground placeholder:text-muted-foreground\",\n    \"disabled:cursor-not-allowed\",\n  ],\n  {\n    variants: {\n      size: {\n        sm: \"text-xs\",\n        md: \"text-sm\",\n        lg: \"text-base\",\n      },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\n// ── Helpers ────────────────────────────────────────────────────────────────\n\nconst skeletonHeightMap: Record<SearchBarSize, string> = {\n  sm: \"h-8\",\n  md: \"h-10\",\n  lg: \"h-12\",\n}\n\nconst skeletonRoundedMap: Record<SearchBarRounded, string> = {\n  none: \"rounded-none\",\n  sm: \"rounded-sm\",\n  md: \"rounded-md\",\n  lg: \"rounded-lg\",\n  xl: \"rounded-xl\",\n  full: \"rounded-full\",\n}\n\n// ── Component ──────────────────────────────────────────────────────────────\n\nexport const SearchBar = React.forwardRef<HTMLDivElement, SearchBarProps>(\n  (\n    {\n      value: valueProp,\n      defaultValue = \"\",\n      onChange,\n      onSearch,\n      onClear,\n      placeholder,\n      size = \"md\",\n      variant = \"outline\",\n      rounded = \"lg\",\n      icon: Icon = SearchIcon,\n      loading = false,\n      shortcut,\n      trailingSlot,\n      debounceMs = 0,\n      voice = false,\n      onVoiceStart,\n      onVoiceEnd,\n      onVoiceError,\n      disabled = false,\n      autoFocus = false,\n      locale: localeProp,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const i18n = UI_I18N[locale].searchBar\n    const isControlled = valueProp !== undefined\n    const [internalValue, setInternalValue] = React.useState(defaultValue)\n    const value = isControlled ? valueProp : internalValue\n    const inputRef = React.useRef<HTMLInputElement>(null)\n    const debounceTimer = React.useRef<ReturnType<typeof setTimeout> | null>(\n      null\n    )\n\n    const {\n      isListening,\n      isSupported: voiceSupported,\n      start: startVoice,\n      stop: stopVoice,\n    } = useSpeechRecognition({\n      lang: locale,\n      onStart: onVoiceStart,\n      onEnd: onVoiceEnd,\n      onError: onVoiceError,\n      onResult: (transcript: string) => {\n        if (!isControlled) setInternalValue(transcript)\n        if (debounceTimer.current) clearTimeout(debounceTimer.current)\n        onChange?.(transcript)\n      },\n    })\n\n    React.useEffect(() => {\n      return () => {\n        if (debounceTimer.current) clearTimeout(debounceTimer.current)\n      }\n    }, [])\n\n    const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n      const next = e.target.value\n      if (!isControlled) setInternalValue(next)\n      if (debounceTimer.current) clearTimeout(debounceTimer.current)\n      if (debounceMs > 0) {\n        debounceTimer.current = setTimeout(() => onChange?.(next), debounceMs)\n      } else {\n        onChange?.(next)\n      }\n    }\n\n    const handleClear = () => {\n      if (!isControlled) setInternalValue(\"\")\n      if (debounceTimer.current) clearTimeout(debounceTimer.current)\n      onChange?.(\"\")\n      onClear?.()\n      inputRef.current?.focus()\n    }\n\n    const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n      if (e.key === \"Enter\") onSearch?.(value)\n      if (e.key === \"Escape\" && value) handleClear()\n    }\n\n    const hasValue = value.length > 0\n\n    return (\n      <div\n        ref={ref}\n        role=\"search\"\n        data-slot=\"search-bar\"\n        aria-busy={loading || undefined}\n        className={cn(\n          searchBarVariants({ variant, size, rounded }),\n          disabled && \"pointer-events-none cursor-not-allowed opacity-50\",\n          className\n        )}\n        {...props}\n      >\n        <span data-slot=\"search-bar-icon\" aria-hidden=\"true\">\n          {loading ? (\n            <Spinner\n              className={searchBarIconVariants({ size })}\n              aria-hidden=\"true\"\n            />\n          ) : (\n            <Icon className={searchBarIconVariants({ size })} />\n          )}\n        </span>\n\n        <Input\n          ref={inputRef}\n          data-slot=\"search-bar-input\"\n          type=\"text\"\n          role=\"searchbox\"\n          autoComplete=\"off\"\n          autoFocus={autoFocus}\n          disabled={disabled}\n          value={value}\n          onChange={handleChange}\n          onKeyDown={handleKeyDown}\n          placeholder={placeholder ?? i18n.placeholder}\n          aria-label={i18n.label}\n          className={cn(\n            \"h-auto rounded-none border-none bg-transparent px-0 py-0\",\n            \"focus-visible:border-transparent focus-visible:ring-0 focus-visible:ring-transparent\",\n            searchBarInputVariants({ size })\n          )}\n        />\n\n        {hasValue && !loading && (\n          <Button\n            type=\"button\"\n            variant=\"ghost\"\n            size=\"icon\"\n            data-slot=\"search-bar-clear\"\n            onClick={handleClear}\n            disabled={disabled}\n            aria-label={i18n.clear}\n            className={cn(\n              \"rounded text-muted-foreground\",\n              { sm: \"size-5\", md: \"size-6\", lg: \"size-7\" }[size]\n            )}\n          >\n            <XIcon className={searchBarIconVariants({ size })} />\n          </Button>\n        )}\n\n        {voice && voiceSupported && !loading && (\n          <Button\n            type=\"button\"\n            variant=\"ghost\"\n            size=\"icon\"\n            data-slot=\"search-bar-voice\"\n            onClick={isListening ? stopVoice : startVoice}\n            disabled={disabled}\n            aria-label={isListening ? i18n.stopVoice : i18n.startVoice}\n            aria-pressed={isListening}\n            className={cn(\n              \"rounded text-muted-foreground\",\n              { sm: \"size-5\", md: \"size-6\", lg: \"size-7\" }[size],\n              isListening && \"text-destructive motion-safe:animate-pulse\"\n            )}\n          >\n            <MicIcon className={searchBarIconVariants({ size })} />\n          </Button>\n        )}\n\n        {shortcut && !hasValue && !loading && (\n          <span\n            data-slot=\"search-bar-shortcut\"\n            aria-hidden=\"true\"\n            className=\"flex shrink-0 items-center\"\n          >\n            <Kbd>{shortcut}</Kbd>\n          </span>\n        )}\n\n        {trailingSlot && (\n          <span\n            data-slot=\"search-bar-trailing\"\n            className=\"flex shrink-0 items-center\"\n          >\n            {trailingSlot}\n          </span>\n        )}\n      </div>\n    )\n  }\n)\n\nSearchBar.displayName = \"SearchBar\"\n\nexport function SearchBarSkeleton({\n  size = \"md\",\n  rounded = \"lg\",\n  className,\n}: SearchBarSkeletonProps) {\n  return (\n    <Skeleton\n      className={cn(\n        \"w-full\",\n        skeletonHeightMap[size],\n        skeletonRoundedMap[rounded],\n        className\n      )}\n    />\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
