"use client" import * as React from "react" import { Combobox as ComboboxPrimitive } from "@base-ui/react" import { cn } from "@/lib/utils" import { searchItems } from "@/lib/search" import { Button } from "@/components/ui/button" import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, } from "@/components/ui/input-group" import { ChevronDownIcon, XIcon, CheckIcon } from "lucide-react" const Combobox = ComboboxPrimitive.Root function FuzzyCombobox({ items = [], searchNames, searchText, children, onInputValueChange, ...props }: ComboboxPrimitive.Root.Props & { items: Value[]; searchNames: (item: Value) => readonly string[]; searchText?: (item: Value) => string; }) { const [query, setQuery] = React.useState("") const result = React.useMemo(() => searchItems(items, query, searchText ?? ((item) => searchNames(item).join(" ")), searchNames), [items, query, searchNames, searchText]) return ( { setQuery(details.reason === "input-change" ? value : "") onInputValueChange?.(value, details) }} >{children} ) } function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) { return } function ComboboxTrigger({ className, children, ...props }: ComboboxPrimitive.Trigger.Props) { return ( {children} ) } function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) { return ( } className={cn(className)} {...props} > ) } function ComboboxInput({ className, children, disabled = false, showTrigger = true, showClear = false, ...props }: ComboboxPrimitive.Input.Props & { showTrigger?: boolean showClear?: boolean }) { return ( } {...props} /> {showTrigger && ( } data-slot="input-group-button" className="group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent" disabled={disabled} /> )} {showClear && } {children} ) } function ComboboxContent({ children, className, side = "bottom", sideOffset = 6, align = "start", alignOffset = 0, anchor, ...props }: ComboboxPrimitive.Popup.Props & Pick< ComboboxPrimitive.Positioner.Props, "side" | "align" | "sideOffset" | "alignOffset" | "anchor" >) { return ( {children} ) } function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) { return ( ) } function ComboboxItem({ className, children, ...props }: ComboboxPrimitive.Item.Props) { return ( {children} } > ) } function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) { return ( ) } function ComboboxLabel({ className, ...props }: ComboboxPrimitive.GroupLabel.Props) { return ( ) } function ComboboxCollection({ ...props }: ComboboxPrimitive.Collection.Props) { return ( ) } function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) { return ( ) } function ComboboxSeparator({ className, ...props }: ComboboxPrimitive.Separator.Props) { return ( ) } function ComboboxChips({ className, ...props }: React.ComponentPropsWithRef & ComboboxPrimitive.Chips.Props) { return ( ) } function ComboboxChip({ className, children, showRemove = true, ...props }: ComboboxPrimitive.Chip.Props & { showRemove?: boolean }) { return ( {children} {showRemove && ( } className="-ml-1 opacity-50 hover:opacity-100" data-slot="combobox-chip-remove" > )} ) } function ComboboxChipsInput({ className, ...props }: ComboboxPrimitive.Input.Props) { return ( ) } function useComboboxAnchor() { return React.useRef(null) } export { FuzzyCombobox, Combobox, ComboboxInput, ComboboxContent, ComboboxList, ComboboxItem, ComboboxGroup, ComboboxLabel, ComboboxCollection, ComboboxEmpty, ComboboxSeparator, ComboboxChips, ComboboxChip, ComboboxChipsInput, ComboboxTrigger, ComboboxValue, useComboboxAnchor, }