blob: f588d38449c482d7704b8cc12a9f45a5691a88bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
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 ? (
<>
<span></></span>
<span>{selectedOption.label}</span>
<span>▼</span>
</>
) : (
"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;
|