"use client"; import { useState } from "react"; import { Button } from "./button"; import { Command, CommandGroup, CommandInput, CommandItem, CommandList, } from "./command"; import { cn } from "../lib/utils"; interface Option { value: string; label: string; } interface ComboboxWithCreateProps { options: Option[]; onSelect: (value: string) => void; onSubmit: (newName: string) => void; selectedSpaces: number[]; setSelectedSpaces: React.Dispatch>; className?: string; placeholder?: string; } const ComboboxWithCreate = ({ options, onSelect, onSubmit, selectedSpaces, setSelectedSpaces, className, placeholder, }: ComboboxWithCreateProps) => { const [inputValue, setInputValue] = useState(""); const handleInputChange = (e: React.ChangeEvent) => { setInputValue(e.target.value); }; const handleKeyDown = (e: React.KeyboardEvent) => { if ( e.key === "Backspace" && inputValue === "" && selectedSpaces.length > 0 ) { setSelectedSpaces((prev) => prev.slice(0, -1)); } }; const filteredOptions = options.filter( (option) => !selectedSpaces.includes(parseInt(option.value)), ); return ( 0 && "p-2"} transition-all mt-4 mb-4`, className, )} >
{selectedSpaces.map((spaceId) => ( ))}
0 ? "translate-y-20" : "translate-y-12"}`} > {filteredOptions.map((option) => ( onSelect(option.value)} > {option.label} ))} {!options.map((opt) => opt.label).includes(inputValue) && ( )}
); }; export default ComboboxWithCreate;