diff options
Diffstat (limited to 'client/src/components/CustomSelect/CustomSelect.jsx')
-rw-r--r-- | client/src/components/CustomSelect/CustomSelect.jsx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/client/src/components/CustomSelect/CustomSelect.jsx b/client/src/components/CustomSelect/CustomSelect.jsx new file mode 100644 index 0000000..9969a6d --- /dev/null +++ b/client/src/components/CustomSelect/CustomSelect.jsx @@ -0,0 +1,42 @@ +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 ( + <div className={styles.select}> + <div className={styles.selected__option} onClick={toggleDropdown}> + {selectedOption ? selectedOption.label : "Select an option"} + </div> + {isOpen && ( + <div className={styles.options}> + {options.map((option) => ( + <div + key={option.value} + className={styles.option} + onClick={() => handleOptionClick(option)} + > + {option.label} + </div> + ))} + </div> + )} + </div> + ); +}; + +export default CustomSelect; |