import { useId, useMemo, useState } from "react"; import type { BaseProps, HTMLProps, IOption } from "../../shared/types"; import { cn } from "../../shared/utils/cn"; import ReactSelect, { createFilter } from "react-select"; import { Typography } from "../typography/Typography"; import { DropdownIndicator } from "./components/DropdownIndicator"; import { Placeholder } from "./components/Placeholder"; import { SingleValue } from "./components/SingleValue"; import { Option } from "./components/Option"; export type SelectProps = Omit, "value" | "onChange"> & { error?: string; hint?: string; label: string; value?: IOption | null; options: IOption[]; noOptionsText?: string; onChange(value: IOption | null): void; } & BaseProps; export const Select = (props: SelectProps) => { const { error, hint, options, value, id: propId, autoFocus, placeholder, disabled, label, onChange, readOnly, noOptionsText, className, testId, } = props; const [inputValue, setInputValue] = useState(""); const generatedId = useId(); const id = propId ?? generatedId; const filterOption = useMemo( () => createFilter({ ignoreCase: true, ignoreAccents: true, trim: true, matchFrom: "any", }), [] ); return ( ); };