/* eslint-disable react-hooks/exhaustive-deps */ import { motion } from "motion/react"; import { AnimatePresence } from "motion/react"; import { useEffect, useRef, useState } from "react"; import { useClickAway } from "@uidotdev/usehooks"; import clsx from "clsx"; import ChevronDownIcon from "../icons/ChevronDownIcon"; import CheckIcon from "../icons/CheckIcon"; function Select({ options, onSelect, className = "", label = "", defaultOption = "", }: { options: string[]; onSelect: (option: string) => void; defaultOption: string; className?: string; label?: string; }) { const [isShow, setIsShow] = useState(false); const [selectedOption, setSelectedOption] = useState(defaultOption); const ref = useClickAway(() => setIsShow(false)); const dropDownRef = useRef(null); useEffect(() => setSelectedOption(defaultOption), [defaultOption]); useEffect(() => onSelect(selectedOption), [selectedOption]); function handleScroll() { if (dropDownRef.current) dropDownRef.current.style.maxHeight = `calc(100vh - ${ dropDownRef.current?.getBoundingClientRect().y }px - 0.278vw)`; } useEffect(() => { handleScroll(); document.addEventListener("scroll", handleScroll); return () => document.removeEventListener("scroll", handleScroll); }, [isShow]); return (
{label && (

{label}

)} {isShow && ( {options.map((option, index) => ( ))} )}
); } export default Select;