{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-search-input",
  "type": "registry:component",
  "title": "Search input",
  "description": "A single-line search field with a clear affordance",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-icons.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/controllable.ts",
      "target": "@ui/gpuixui/components/internal/controllable.ts",
      "type": "registry:lib",
      "content": "import { useCallback, useState } from \"react\";\n\nexport type ControllableState<Value> = readonly [Value, (next: Value) => void];\n\nexport interface ControllableStateOptions<Value> {\n  readonly value: Value | undefined;\n\n  readonly defaultValue: Value;\n\n  readonly onChange?: (next: Value) => void;\n}\n\nexport const useControllableState = <Value>({\n  value,\n  defaultValue,\n  onChange,\n}: ControllableStateOptions<Value>): ControllableState<Value> => {\n  const [internal, setInternal] = useState(defaultValue);\n  const controlled = value !== undefined;\n\n  const setValue = useCallback(\n    (next: Value) => {\n      if (!controlled) setInternal(next);\n      if (value !== next) onChange?.(next);\n    },\n    [controlled, value, onChange],\n  );\n\n  return [controlled ? value : internal, setValue];\n};\n"
    },
    {
      "path": "packages/components/src/internal/key.ts",
      "target": "@ui/gpuixui/components/internal/key.ts",
      "type": "registry:lib",
      "content": "import type { EventPayload, KeyEvent, Props } from \"@gpuix/react\";\nimport * as Option from \"effect/Option\";\n\nexport type KeyPhase = \"down\" | \"up\";\n\nexport const isActivation = (event: EventPayload, phase: KeyPhase): boolean => {\n  if (event.isHeld === true) return false;\n  if (event.key === \"enter\") return phase === \"down\";\n  return event.key === \"space\" && phase === \"up\";\n};\n\nexport const swallowsDefault = (\n  event: EventPayload,\n  phase: KeyPhase,\n): boolean => event.key === \"space\" && phase === \"down\";\n\nexport const activationHandlers = (\n  activate: (event: KeyEvent) => void,\n  observe: Pick<Props, \"onKeyDown\" | \"onKeyUp\"> = {},\n): Pick<Props, \"onKeyDown\" | \"onKeyUp\"> => ({\n  onKeyDown: (event: KeyEvent) => {\n    if (swallowsDefault(event, \"down\")) event.preventDefault();\n    if (isActivation(event, \"down\")) activate(event);\n    observe.onKeyDown?.(event);\n  },\n  onKeyUp: (event: KeyEvent) => {\n    if (isActivation(event, \"up\")) activate(event);\n    observe.onKeyUp?.(event);\n  },\n});\n\nexport const isEnter = (event: EventPayload): boolean => event.key === \"enter\";\n\nexport const isDown = (event: EventPayload): boolean =>\n  event.key === \"down\" || (event.key === \"n\" && event.modifiers?.ctrl === true);\n\nexport const isUp = (event: EventPayload): boolean =>\n  event.key === \"up\" || (event.key === \"p\" && event.modifiers?.ctrl === true);\n\nexport const isRight = (event: EventPayload): boolean => event.key === \"right\";\n\nexport const isLeft = (event: EventPayload): boolean => event.key === \"left\";\n\nexport const isFirst = (event: EventPayload): boolean => event.key === \"home\";\n\nexport const isLast = (event: EventPayload): boolean => event.key === \"end\";\n\nexport const isPageUp = (event: EventPayload): boolean =>\n  event.key === \"pageup\";\n\nexport const isPageDown = (event: EventPayload): boolean =>\n  event.key === \"pagedown\";\n\nexport const isDismiss = (event: EventPayload): boolean =>\n  event.key === \"escape\";\n\nexport const isTab = (event: EventPayload): boolean => event.key === \"tab\";\n\nexport const isSelectAll = (event: EventPayload): boolean =>\n  event.key === \"a\" &&\n  (event.modifiers?.cmd === true || event.modifiers?.ctrl === true);\n\nexport const isMenuKey = (event: EventPayload): boolean =>\n  (event.key === \"f10\" && event.modifiers?.shift === true) ||\n  event.key === \"contextmenu\";\n\nexport const axisDirection = (\n  event: EventPayload,\n  orientation: \"horizontal\" | \"vertical\",\n): Option.Option<1 | -1> => {\n  if (event.key === \"right\") return Option.some(1);\n  if (event.key === \"left\") return Option.some(-1);\n  if (orientation === \"vertical\") {\n    if (isDown(event)) return Option.some(1);\n    if (isUp(event)) return Option.some(-1);\n  }\n  return Option.none();\n};\n"
    },
    {
      "path": "packages/components/src/internal/recipe.ts",
      "target": "@ui/gpuixui/components/internal/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { createRecipeCache } from \"../../tw/index.js\";\nimport type { Theme } from \"./theme.js\";\n\nexport const recipeStyle: (recipe: string, theme: Theme) => StyleDesc =\n  createRecipeCache(512);\n"
    },
    {
      "path": "packages/components/src/internal/ref.ts",
      "target": "@ui/gpuixui/components/internal/ref.ts",
      "type": "registry:lib",
      "content": "import type { Ref, RefCallback } from \"react\";\nimport { useCallback } from \"react\";\n\nconst assign = <T>(ref: Ref<T> | undefined, value: T): void => {\n  if (ref === null || ref === undefined) return;\n  if (typeof ref === \"function\") {\n    ref(value);\n    return;\n  }\n  ref.current = value;\n};\n\nexport const useMergedRef = <T>(\n  internal: Ref<T>,\n  caller: Ref<T> | undefined,\n): RefCallback<T> =>\n  useCallback(\n    (value: T) => {\n      assign(internal, value);\n      assign(caller, value);\n    },\n    [internal, caller],\n  );\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/search-input.tsx",
      "target": "@ui/gpuixui/components/search-input.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { KeyEvent, InputProps, PublicInstance } from \"@gpuix/react\";\nimport { useGpuix } from \"@gpuix/react\";\nimport {\n  mergeStyles,\n  resolveStyle,\n  type StateStyle,\n} from \"@gpuix/react/floating\";\nimport { Icon } from \"../icons/index.js\";\nimport {\n  cn,\n  SEARCH_INPUT,\n  SEARCH_INPUT_CLEAR,\n  SEARCH_INPUT_CONTROL,\n  SEARCH_INPUT_ICON,\n} from \"../tw/index.js\";\nimport * as Option from \"effect/Option\";\nimport { useCallback, useRef, useState } from \"react\";\nimport { useControllableState } from \"./internal/controllable.js\";\nimport {\n  fieldHelp,\n  fieldHint,\n  hintHost,\n  renderFieldHint,\n} from \"../primitives/components/hint.js\";\nimport { activationHandlers, isDismiss } from \"./internal/key.js\";\nimport { recipeStyle } from \"./internal/recipe.js\";\nimport { useMergedRef } from \"./internal/ref.js\";\nimport {\n  controlHeight,\n  disabledFade,\n  keepContent,\n  keyboardRing,\n  nativeTextTheme,\n  selectionWash,\n  targetSize,\n  useTheme,\n} from \"./internal/theme.js\";\n\nexport interface SearchInputProps extends Omit<\n  InputProps,\n  \"onSubmit\" | \"style\"\n> {\n  readonly value?: string;\n  readonly defaultValue?: string;\n\n  readonly onValueChange?: (value: string) => void;\n\n  readonly onSubmit?: (value: string) => void;\n\n  readonly onClear?: () => void;\n\n  readonly placeholder?: string;\n  readonly disabled?: boolean;\n\n  readonly className?: string;\n\n  readonly style?: StateStyle<SearchInputState>;\n}\n\nexport interface SearchInputState {\n  readonly disabled: boolean;\n  readonly focused: boolean;\n}\n\nexport const SearchInput = ({\n  value: valueProp,\n  defaultValue = \"\",\n  onValueChange,\n  onSubmit,\n  onClear,\n  placeholder = \"Search…\",\n  disabled = false,\n  className,\n  style,\n  onChange,\n  onKeyDown,\n  ref,\n  ...rest\n}: SearchInputProps) => {\n  const theme = useTheme();\n  const renderer = useGpuix().renderer;\n  const [value, setValue] = useControllableState({\n    value: valueProp,\n    defaultValue,\n    onChange: onValueChange,\n  });\n  const [focused, setFocused] = useState(false);\n  const input = useRef<PublicInstance | null>(null);\n  const attach = useCallback((next: PublicInstance | null) => {\n    input.current = next;\n  }, []);\n  const setInput = useMergedRef<PublicInstance | null>(attach, ref);\n\n  const clear = (): void => {\n    if (disabled) return;\n    if (value === \"\") return;\n    setValue(\"\");\n    onClear?.();\n    const instance = input.current;\n    if (instance !== null) renderer?.focusElement?.(instance.id);\n  };\n  const state: SearchInputState = { disabled, focused };\n  const controlStyle = mergeStyles(recipeStyle(SEARCH_INPUT_CONTROL, theme), {\n    ...(disabled ? {} : keyboardRing(theme)),\n    ...selectionWash(theme),\n    ...keepContent,\n  });\n  const testId = rest.testId ?? \"search-input\";\n  const hint = fieldHint({ placeholder, disabled }, theme, value, {\n    origin: \"host\",\n    align: \"center\",\n    style: controlStyle,\n  });\n\n  return (\n    <div\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(SEARCH_INPUT, className), theme), {\n          height: controlHeight(theme, \"md\"),\n          ...disabledFade(disabled),\n        }),\n        resolveStyle(style, state),\n      )}\n    >\n      <div style={recipeStyle(SEARCH_INPUT_ICON, theme)}>\n        <Icon name=\"search\" size=\"sm\" color={theme.colors.mutedForeground} />\n      </div>\n      <div style={hintHost({ flexGrow: 1, alignSelf: \"stretch\", minWidth: 0 })}>\n        <input\n          {...rest}\n          theme={nativeTextTheme(theme, \"background\")}\n          ref={setInput}\n          testId={testId}\n          value={value}\n          readOnly={disabled}\n          tabIndex={disabled ? -1 : 0}\n          aria-description={fieldHelp(\n            { description: rest[\"aria-description\"], placeholder },\n            value,\n          )}\n          onChange={(event) => {\n            onChange?.(event);\n            setValue(event.value ?? \"\");\n          }}\n          onKeyDown={(event: KeyEvent) => {\n            onKeyDown?.(event);\n            if (isDismiss(event)) clear();\n          }}\n          onSubmit={() => onSubmit?.(value)}\n          onFocus={(event) => {\n            setFocused(true);\n            rest.onFocus?.(event);\n          }}\n          onBlur={(event) => {\n            setFocused(false);\n            rest.onBlur?.(event);\n          }}\n          style={controlStyle}\n        />\n        {Option.match(hint, {\n          onNone: () => null,\n          onSome: (painted) => renderFieldHint(painted, testId),\n        })}\n      </div>\n      {value === \"\" ? null : (\n        <div\n          role=\"button\"\n          aria-label=\"Clear search\"\n          testId=\"search-clear\"\n          tabIndex={disabled ? -1 : 0}\n          onClick={clear}\n          {...activationHandlers(clear)}\n          style={mergeStyles(recipeStyle(SEARCH_INPUT_CLEAR, theme), {\n            ...(disabled ? {} : keyboardRing(theme)),\n            width: targetSize.minimum,\n            height: targetSize.minimum,\n            flexShrink: 0,\n\n            cursor: disabled ? \"not-allowed\" : \"pointer\",\n            hover: disabled\n              ? undefined\n              : { backgroundColor: theme.colors.accent },\n          })}\n        >\n          <Icon name=\"x\" size=\"sm\" color={theme.colors.mutedForeground} />\n        </div>\n      )}\n    </div>\n  );\n};\n\nexport const searchInputMeta = {\n  name: \"Search inputs\",\n  tier: 2,\n  status: \"done\",\n  gpuixSupport: \"yes\",\n  limitations: [\n    \"no debounce: the consumer debounces its own query\",\n    \"Enter arrives as submit, Escape as keyDown (measured in 0.11.0)\",\n  ],\n  docs: \"docs/search-input.mdx\",\n  example: \"examples/search-input.example.tsx\",\n  testFile: \"src/behaviour/search-input.test.tsx\",\n} as const;\n"
    }
  ],
  "docs": "[Search input](https://gpuixui.sudokw.com/components/search-input) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/components/search-input",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}