import clsx from "clsx"; import { ComponentProps, useEffect, useState } from "react"; import ReactSelect, { GroupBase, StylesConfig } from "react-select"; import Option from "@/interfaces/option"; interface Props { defaultValue?: Option; value?: Option | null; options: Option[]; disabled?: boolean; placeholder?: string; isClearable?: boolean; styles?: StylesConfig>; className?: string; label?: string; } interface MultiProps { isMulti: true onChange: (value: Option[] | null) => void } interface SingleProps { isMulti?: false onChange: (value: Option | null) => void } export default function Select({ value, isMulti, defaultValue, options, placeholder, disabled, onChange, styles, isClearable, label, className }: Props & (MultiProps | SingleProps)) { const [target, setTarget] = useState(); useEffect(() => { if (document) setTarget(document.body); }, []); return (
{label && } ({ ...base, zIndex: 9999 }), control: (styles) => ({ ...styles, paddingLeft: "4px", border: "none", outline: "none", ":focus": { outline: "none", }, }), option: (styles, state) => ({ ...styles, backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white", color: state.isFocused ? "black" : styles.color, }), } } isDisabled={disabled} isClearable={isClearable} />
); }