diff --git a/src/components/Select.tsx b/src/components/Select.tsx index 7b833a5..1606b01 100644 --- a/src/components/Select.tsx +++ b/src/components/Select.tsx @@ -1,13 +1,15 @@ +import { cn } from "@/utils/cn" +import { Check, ChevronsUpDown } from "lucide-react" import { useState } from "react" -import { twMerge as clsx } from "tailwind-merge" -import { ChevronDown, CheckIcon } from "lucide-react" +import { Button } from "./ui/button" import { - Combobox, - ComboboxInput, - ComboboxOption, - ComboboxOptions, - ComboboxButton, -} from "@headlessui/react" + Command, + CommandGroup, + CommandInput, + CommandItem, + CommandList, +} from "./ui/command" +import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover" export const SearchableSelect = ({ value, @@ -18,60 +20,54 @@ export const SearchableSelect = ({ setValue: (val: T | null) => void options: { value: T; text: string }[] }) => { - const [query, setQuery] = useState("") - - const filteredOptions = - query === "" - ? options - : options.filter((option) => { - return option.text.toLowerCase().includes(query.toLowerCase()) - }) + const [open, setOpen] = useState(false) return ( - <> - setValue(value)} - onClose={() => setQuery("")} - immediate - > -
- - options.find((_option) => _option.value === option)?.text ?? "" - } - onChange={(event) => setQuery(event.target.value)} - placeholder="Select" - autoComplete="off" - /> - - - -
- - + + + + + + + + + {options.map((option, i) => ( + { + setValue(option.value) + setOpen(false) + }} + > + {option.text} + + + ))} + + + + + ) } diff --git a/src/components/ui/popover.tsx b/src/components/ui/popover.tsx new file mode 100644 index 0000000..b118b92 --- /dev/null +++ b/src/components/ui/popover.tsx @@ -0,0 +1,29 @@ +import * as React from "react" +import * as PopoverPrimitive from "@radix-ui/react-popover" + +import { cn } from "@/lib/utils" + +const Popover = PopoverPrimitive.Root + +const PopoverTrigger = PopoverPrimitive.Trigger + +const PopoverContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( + + + +)) +PopoverContent.displayName = PopoverPrimitive.Content.displayName + +export { Popover, PopoverTrigger, PopoverContent }