{"name":"command","type":"registry:ui","files":[{"path":"command.tsx","type":"registry:ui","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { Autocomplete as AutocompletePrimitive } from \"@base-ui/react/autocomplete\"\nimport { Dialog as DialogPrimitive } from \"@base-ui/react/dialog\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype CommandContextValue = {\n  inputValue: string\n  usesItemsProp: boolean\n}\n\nconst CommandContext = React.createContext<CommandContextValue | null>(null)\n\nfunction useCommandContext() {\n  const context = React.useContext(CommandContext)\n\n  if (!context) {\n    throw new Error(\"Command parts must be used within Command\")\n  }\n\n  return context\n}\n\nfunction getTextContent(node: React.ReactNode): string {\n  return React.Children.toArray(node)\n    .map((child) => {\n      if (typeof child === \"string\" || typeof child === \"number\") {\n        return String(child)\n      }\n\n      if (React.isValidElement<{ children?: React.ReactNode }>(child)) {\n        return getTextContent(child.props.children)\n      }\n\n      return \"\"\n    })\n    .join(\" \")\n}\n\nfunction matchesSearch(\n  value: unknown,\n  children: React.ReactNode,\n  query: string\n) {\n  const searchableValue =\n    typeof value === \"string\" ? value : getTextContent(children)\n\n  return searchableValue\n    .toLocaleLowerCase()\n    .includes(query.trim().toLocaleLowerCase())\n}\n\ntype CommandProps<ItemValue = string> = Omit<\n  AutocompletePrimitive.Root.Props<ItemValue>,\n  \"items\"\n> & {\n  className?: string\n  items?: readonly ItemValue[]\n}\n\nfunction Command<ItemValue = string>({\n  value: controlledValue,\n  defaultValue,\n  onValueChange,\n  items,\n  inline = true,\n  open = true,\n  autoHighlight = \"always\",\n  keepHighlight = true,\n  className,\n  children,\n  ...props\n}: CommandProps<ItemValue>) {\n  const [uncontrolledValue, setUncontrolledValue] = React.useState(\n    typeof defaultValue === \"string\" ? defaultValue : \"\"\n  )\n  const inputValue =\n    typeof controlledValue === \"string\" ? controlledValue : uncontrolledValue\n\n  const handleValueChange = React.useCallback<\n    NonNullable<AutocompletePrimitive.Root.Props<ItemValue>[\"onValueChange\"]>\n  >(\n    (nextValue, eventDetails) => {\n      if (controlledValue === undefined) {\n        setUncontrolledValue(nextValue)\n      }\n      onValueChange?.(nextValue, eventDetails)\n    },\n    [controlledValue, onValueChange]\n  )\n\n  const context = React.useMemo<CommandContextValue>(\n    () => ({\n      inputValue,\n      usesItemsProp: items !== undefined,\n    }),\n    [inputValue, items]\n  )\n\n  return (\n    <CommandContext.Provider value={context}>\n      <AutocompletePrimitive.Root<ItemValue>\n        inline={inline}\n        open={open}\n        autoHighlight={autoHighlight}\n        keepHighlight={keepHighlight}\n        value={controlledValue}\n        defaultValue={defaultValue}\n        onValueChange={handleValueChange}\n        items={items}\n        {...props}\n      >\n        <div\n          data-slot=\"command\"\n          className={cn(\n            \"isolate flex w-full flex-col overflow-hidden bg-[var(--hui-color-background-base-primary)]\",\n            className\n          )}\n        >\n          {children}\n        </div>\n      </AutocompletePrimitive.Root>\n    </CommandContext.Provider>\n  )\n}\n\ntype CommandInputProps = Omit<AutocompletePrimitive.Input.Props, \"size\"> & {\n  leadingIcon?: React.ReactNode\n  size?: \"sm\" | \"default\" | \"lg\"\n}\n\nfunction CommandInput({\n  className,\n  leadingIcon,\n  size = \"lg\",\n  placeholder = \"Search...\",\n  autoFocus = true,\n  \"aria-label\": ariaLabel = \"Search commands\",\n  ...props\n}: CommandInputProps) {\n  return (\n    <div\n      data-slot=\"command-input-container\"\n      className=\"flex flex-col bg-[var(--hui-color-background-base-primary)] p-[var(--hui-space-2)]\"\n    >\n      <div className=\"flex items-center gap-[var(--hui-space-2)] rounded-[var(--hui-radius-2)] border-0 bg-transparent px-[var(--hui-space-3)] shadow-none outline-none forced-colors:focus-within:outline forced-colors:focus-within:outline-1 forced-colors:focus-within:outline-offset-[-2px]\">\n        {leadingIcon ? (\n          <span\n            aria-hidden=\"true\"\n            className=\"flex shrink-0 items-center justify-center text-[var(--hui-color-foreground-base-secondary)] [&_svg]:size-[var(--hui-space-5)]\"\n          >\n            {leadingIcon}\n          </span>\n        ) : null}\n        <AutocompletePrimitive.Input\n          data-slot=\"command-input\"\n          type=\"search\"\n          aria-label={ariaLabel}\n          autoFocus={autoFocus}\n          placeholder={placeholder}\n          className={cn(\n            \"m-0 w-full min-w-0 border-0 bg-transparent p-0 text-[var(--hui-color-foreground-base-primary)] shadow-none outline-none [font-size:var(--hui-font-size-small)] [font-weight:var(--hui-font-weight-regular)] [letter-spacing:var(--hui-letter-spacing-small)] [line-height:var(--hui-line-height-small)] placeholder:text-[var(--hui-color-foreground-base-tertiary)] focus-visible:ring-0 focus-visible:outline-none [&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none\",\n            size === \"sm\" && \"h-[var(--hui-space-7)]\",\n            size === \"default\" && \"h-[var(--hui-space-9)]\",\n            size === \"lg\" && \"h-[var(--hui-space-11)]\",\n            className\n          )}\n          {...props}\n        />\n      </div>\n    </div>\n  )\n}\n\ntype CommandContentProps = AutocompletePrimitive.List.Props\n\nfunction CommandContent({ className, ...props }: CommandContentProps) {\n  return (\n    <AutocompletePrimitive.List\n      data-slot=\"command-content\"\n      className={cn(\n        \"flex max-h-80 flex-col overflow-x-hidden overflow-y-auto overscroll-contain px-[var(--hui-space-2)] empty:p-0 [&:has([role=option])>[data-slot=command-empty]]:hidden [&:not(:has([data-slot=command-group]))]:gap-[var(--hui-space-1)] [&:not(:has([data-slot=command-group]))]:py-[var(--hui-space-3)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\ntype CommandItemProps = AutocompletePrimitive.Item.Props & {\n  leadingIcon?: React.ReactNode\n  trailingIcon?: React.ReactNode\n}\n\nfunction CommandItem({\n  className,\n  children,\n  value: providedValue,\n  leadingIcon,\n  trailingIcon,\n  ...props\n}: CommandItemProps) {\n  const { inputValue, usesItemsProp } = useCommandContext()\n  const value =\n    providedValue !== undefined\n      ? providedValue\n      : typeof children === \"string\"\n        ? children\n        : undefined\n\n  if (\n    !usesItemsProp &&\n    inputValue &&\n    !matchesSearch(value, children, inputValue)\n  ) {\n    return null\n  }\n\n  return (\n    <AutocompletePrimitive.Item\n      data-slot=\"command-item\"\n      value={value}\n      className={cn(\n        \"flex min-h-9 cursor-pointer scroll-my-[var(--hui-space-2)] items-center gap-[var(--hui-space-3)] rounded-[var(--hui-radius-2)] bg-[var(--hui-color-background-base-primary)] p-[var(--hui-space-3)] text-[var(--hui-color-foreground-base-primary)] outline-none select-none [font-size:var(--hui-font-size-small)] [font-weight:var(--hui-font-weight-regular)] [letter-spacing:var(--hui-letter-spacing-small)] [line-height:var(--hui-line-height-small)] data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-[var(--hui-color-background-base-primary-hover)]\",\n        className\n      )}\n      {...props}\n    >\n      {leadingIcon ? (\n        <span\n          data-slot=\"command-item-leading-icon\"\n          aria-hidden=\"true\"\n          className=\"inline-flex shrink-0 items-center justify-center text-[var(--hui-color-foreground-base-secondary)] [&_svg]:size-[var(--hui-space-5)]\"\n        >\n          {leadingIcon}\n        </span>\n      ) : null}\n      <span\n        data-slot=\"command-item-label\"\n        className=\"min-w-0 flex-1 truncate\"\n      >\n        {children}\n      </span>\n      {trailingIcon ? (\n        <span\n          data-slot=\"command-item-trailing-icon\"\n          className=\"ms-auto inline-flex shrink-0 items-center justify-center text-[var(--hui-color-foreground-base-tertiary)] [&_svg]:size-[var(--hui-space-5)]\"\n        >\n          {trailingIcon}\n        </span>\n      ) : null}\n    </AutocompletePrimitive.Item>\n  )\n}\n\ntype CommandEmptyProps = React.ComponentProps<\"div\">\n\nfunction CommandEmpty({ className, ...props }: CommandEmptyProps) {\n  return (\n    <div\n      data-slot=\"command-empty\"\n      className={cn(\n        \"px-[var(--hui-space-3)] py-[var(--hui-space-7)] text-center text-[var(--hui-color-foreground-base-secondary)] [font-size:var(--hui-font-size-small)] [line-height:var(--hui-line-height-small)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\ntype CommandGroupProps = AutocompletePrimitive.Group.Props\n\nfunction CommandGroup({ children, className, ...props }: CommandGroupProps) {\n  const { inputValue, usesItemsProp } = useCommandContext()\n\n  if (!usesItemsProp && inputValue) return <>{children}</>\n\n  return (\n    <AutocompletePrimitive.Group\n      data-slot=\"command-group\"\n      className={cn(\n        \"flex flex-col gap-[var(--hui-space-1)] py-[var(--hui-space-3)]\",\n        className\n      )}\n      {...props}\n    >\n      {children}\n    </AutocompletePrimitive.Group>\n  )\n}\n\ntype CommandLabelProps = AutocompletePrimitive.GroupLabel.Props\n\nfunction CommandLabel({ className, ...props }: CommandLabelProps) {\n  const { inputValue, usesItemsProp } = useCommandContext()\n\n  if (!usesItemsProp && inputValue) return null\n\n  return (\n    <AutocompletePrimitive.GroupLabel\n      data-slot=\"command-label\"\n      className={cn(\n        \"flex items-center px-[var(--hui-space-3)] py-[var(--hui-space-2)] text-[var(--hui-color-foreground-base-tertiary)] [font-size:var(--hui-font-size-micro)] [font-weight:var(--hui-font-weight-regular)] [letter-spacing:var(--hui-letter-spacing-micro)] [line-height:var(--hui-line-height-micro)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\ntype CommandSeparatorProps = AutocompletePrimitive.Separator.Props\n\nfunction CommandSeparator({ className, ...props }: CommandSeparatorProps) {\n  const { inputValue, usesItemsProp } = useCommandContext()\n\n  if (!usesItemsProp && inputValue) return null\n\n  return (\n    <AutocompletePrimitive.Separator\n      data-slot=\"command-separator\"\n      className={cn(\n        \"my-[var(--hui-space-1)] h-px bg-[var(--hui-color-border-base-primary)]\",\n        className\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction CommandDialog(props: DialogPrimitive.Root.Props) {\n  return <DialogPrimitive.Root {...props} />\n}\n\nfunction CommandDialogTrigger(props: DialogPrimitive.Trigger.Props) {\n  return (\n    <DialogPrimitive.Trigger data-slot=\"command-dialog-trigger\" {...props} />\n  )\n}\n\ntype CommandDialogContentProps = DialogPrimitive.Popup.Props & {\n  title?: string\n  width?: React.CSSProperties[\"width\"]\n}\n\nfunction CommandDialogContent({\n  className,\n  children,\n  title = \"Command palette\",\n  width,\n  style,\n  ...props\n}: CommandDialogContentProps) {\n  return (\n    <DialogPrimitive.Portal>\n      <DialogPrimitive.Viewport\n        data-slot=\"command-dialog-viewport\"\n        className=\"pointer-events-none fixed inset-0 z-[var(--hui-z-index-portal)]\"\n      >\n        <DialogPrimitive.Popup\n          data-slot=\"command-dialog-content\"\n          className={cn(\n            \"pointer-events-auto fixed top-0 left-1/2 isolate flex max-h-[min(420px,80vh)] min-h-0 w-[540px] max-w-[90vw] flex-col overflow-hidden rounded-[var(--hui-radius-2)] bg-[var(--hui-color-background-base-primary)] shadow-[var(--hui-shadow-floating)] [transform:translate(-50%,min(160px,calc(50vh-50%)))] outline-none motion-safe:[transition:opacity_var(--hui-duration-fast)_var(--hui-ease-out)] motion-safe:data-ending-style:opacity-0 motion-safe:data-starting-style:opacity-0\",\n            className\n          )}\n          style={{ width, ...style }}\n          {...props}\n        >\n          <DialogPrimitive.Title className=\"sr-only\">\n            {title}\n          </DialogPrimitive.Title>\n          {children}\n        </DialogPrimitive.Popup>\n      </DialogPrimitive.Viewport>\n    </DialogPrimitive.Portal>\n  )\n}\n\nexport {\n  Command,\n  CommandContent,\n  CommandDialog,\n  CommandDialogContent,\n  CommandDialogTrigger,\n  CommandEmpty,\n  CommandGroup,\n  CommandInput,\n  CommandItem,\n  CommandLabel,\n  CommandSeparator,\n}\n\nexport type {\n  CommandContentProps,\n  CommandDialogContentProps,\n  CommandEmptyProps,\n  CommandGroupProps,\n  CommandInputProps,\n  CommandItemProps,\n  CommandLabelProps,\n  CommandProps,\n  CommandSeparatorProps,\n}\n","target":"components/ui/command.tsx"}],"dependencies":["@base-ui/react"]}