2023-11-05 23:33:40 +00:00
|
|
|
import { useState, useRef } from "react"
|
|
|
|
import { Select as MuiSelect, MenuItem, Box, Typography, useTheme } from "@mui/material"
|
|
|
|
import classnames from "classnames"
|
2023-07-25 22:31:04 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
import checkIcon from "@root/assets/Icons/check.svg"
|
2023-07-25 22:31:04 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
import "./select.css"
|
2023-07-25 22:31:04 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
import type { SelectChangeEvent } from "@mui/material"
|
2023-07-25 22:31:04 +00:00
|
|
|
|
|
|
|
type SelectProps = {
|
|
|
|
items: string[];
|
|
|
|
selectedItem: number;
|
|
|
|
setSelectedItem: (num: number) => void;
|
|
|
|
};
|
|
|
|
|
2023-09-04 20:01:24 +00:00
|
|
|
export const Select = ({ items, selectedItem, setSelectedItem }: SelectProps) => {
|
2023-11-05 23:33:40 +00:00
|
|
|
const [opened, setOpened] = useState<boolean>(false)
|
|
|
|
const [currentValue, setCurrentValue] = useState<string>(items[selectedItem])
|
|
|
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
|
|
const theme = useTheme()
|
2023-07-25 22:31:04 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
const selectItem = (event: SelectChangeEvent<HTMLDivElement>) => {
|
|
|
|
setCurrentValue(items[Number(event.target.value)])
|
|
|
|
setSelectedItem(Number(event.target.value))
|
|
|
|
}
|
2023-08-02 11:34:48 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
zIndex: 1,
|
|
|
|
position: "relative",
|
|
|
|
width: "100%",
|
|
|
|
height: "56px",
|
|
|
|
padding: "16px 50px 16px 14px",
|
|
|
|
color: theme.palette.purple.main,
|
|
|
|
border: "2px solid #ffffff",
|
|
|
|
borderRadius: "30px",
|
|
|
|
background: "#EFF0F5",
|
|
|
|
boxShadow: "0px 5px 40px #d2d0e194, 0px 2.76726px 8.55082px rgba(210, 208, 225, 0.4)",
|
|
|
|
}}
|
|
|
|
onClick={() => ref.current?.click()}
|
|
|
|
>
|
|
|
|
<Typography
|
|
|
|
sx={{
|
|
|
|
fontWeight: "bold",
|
|
|
|
fontSize: "16px",
|
|
|
|
textOverflow: "ellipsis",
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
overflow: "hidden",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{currentValue}
|
|
|
|
</Typography>
|
|
|
|
<img
|
|
|
|
src={checkIcon}
|
|
|
|
alt="check"
|
|
|
|
style={{
|
|
|
|
position: "absolute",
|
|
|
|
top: "50%",
|
|
|
|
right: "10px",
|
|
|
|
transform: "translateY(-50%)",
|
|
|
|
height: "36px",
|
|
|
|
width: "36px",
|
|
|
|
}}
|
|
|
|
className={classnames("select-icon", { opened })}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
<MuiSelect
|
|
|
|
ref={ref}
|
|
|
|
className="select"
|
|
|
|
value=""
|
|
|
|
open={opened}
|
|
|
|
MenuProps={{ disablePortal: true }}
|
|
|
|
sx={{ width: "100%" }}
|
|
|
|
onChange={selectItem}
|
|
|
|
onClick={() => setOpened((isOpened) => !isOpened)}
|
|
|
|
>
|
|
|
|
{items.map((item, index) => (
|
|
|
|
<MenuItem key={item + index} value={index} sx={{ padding: "12px" }}>
|
|
|
|
{item}
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
|
|
|
</MuiSelect>
|
|
|
|
</Box>
|
|
|
|
)
|
|
|
|
}
|