front-hub/src/components/CustomRadioButtons.tsx

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-03-20 11:40:19 +00:00
import { useState } from "react";
2023-03-23 16:44:09 +00:00
import { List, ListItem, Typography, useMediaQuery, useTheme } from "@mui/material";
2023-03-20 11:40:19 +00:00
type Props = {
2023-03-23 12:03:08 +00:00
setType: React.Dispatch<React.SetStateAction<string>>;
_mocsk_: { name: string; type: string }[];
2023-03-20 11:40:19 +00:00
};
2023-03-23 12:03:08 +00:00
export const CustomRadioButtons: React.FC<Props> = ({ setType, _mocsk_ }) => {
2023-03-23 16:44:09 +00:00
const theme = useTheme();
const upSm = useMediaQuery(theme.breakpoints.up("sm"));
2023-03-23 12:03:08 +00:00
const [active, setActive] = useState<number>(0);
2023-03-23 16:44:09 +00:00
const activeType = (index: number, type: string) => {
2023-03-23 12:03:08 +00:00
setActive(index);
setType(type);
};
2023-03-20 11:40:19 +00:00
return (
<List
sx={{
marginLeft: "-10px",
width: "430px",
display: "flex",
fontWeight: "500",
fontSize: " 16px",
whiteSpace: "nowrap",
2023-03-23 16:44:09 +00:00
overflow: upSm ? "" : "hidden",
2023-03-20 11:40:19 +00:00
}}
>
2023-03-23 12:03:08 +00:00
{_mocsk_.map(({ name, type }, index) =>
2023-03-20 11:40:19 +00:00
active === index ? (
2023-03-23 16:44:09 +00:00
<ListItem key={type} onClick={() => activeType(index, type)} sx={{ color: "#7E2AEA", cursor: "pointer" }}>
2023-03-20 11:40:19 +00:00
<Typography component="span" sx={{ borderBottom: "1px solid #7E2AEA", fontSize: " 16px" }}>
{name}
</Typography>
</ListItem>
) : (
2023-03-23 16:44:09 +00:00
<ListItem key={type} onClick={() => activeType(index, type)} sx={{ cursor: "pointer" }}>
2023-03-20 11:40:19 +00:00
{name}
</ListItem>
)
)}
</List>
);
};