import React, { useState } from "react"; import styles from "./CustomSelect.module.css"; const CustomSelect = ({ options, onSelect }) => { const [isOpen, setIsOpen] = useState(false); const [selectedOption, setSelectedOption] = useState( options.length > 0 ? options[0] : null, ); const toggleDropdown = () => { setIsOpen(!isOpen); }; const handleOptionClick = (option) => { setSelectedOption(option); onSelect(option.value); setIsOpen(false); }; return (
{selectedOption ? ( <> </> {selectedOption.label} ) : ( "Select an option" )}
{isOpen && (
{options.map((option) => (
handleOptionClick(option)} > {option.label}
))}
)}
); }; export default CustomSelect;