"use client"; import * as React from "react"; import { Check } from "lucide-react"; import { cn } from "@/lib/utils"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { useState } from "react"; interface ComboBoxProps { elements: T[]; trigger: (value?: string) => React.ReactNode; onSubmit?: (value: string) => void; value: string; setValue: React.Dispatch>; children: ( ItemComponent: ( props: React.ComponentProps & { label: string }, ) => React.JSX.Element, element: T, ) => React.ReactNode; } const ComboBox = ({ elements, trigger, children, onSubmit, value, setValue, }: ComboBoxProps) => { const [open, setOpen] = useState(false); const [searchValue, setSearchValue] = useState(""); const handleSubmit = (e: React.KeyboardEvent) => { if (e.key !== "Enter") return; e.preventDefault(); setValue(searchValue); onSubmit?.(searchValue); }; return ( {trigger(value.length > 0 ? value : undefined)} setSearchValue((e.target as HTMLInputElement).value) } placeholder="Search framework..." /> Créer une nouvelle catégorie {elements.map((element, index) => children( ({ value: elementValue, label, onSelect, ...props }) => ( { setValue(_value); console.log(elementValue); setOpen(false); onSelect?.(_value); }} {...props} > {label} ), element, ), )} ); }; export default ComboBox;