frontPanel/src/ui_kit/CustomCheckbox.tsx

79 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-09-25 13:43:15 +00:00
import { FormControlLabel, Checkbox, useTheme, Box, useMediaQuery } from "@mui/material";
import React from "react";
2022-12-26 10:00:03 +00:00
2023-09-07 14:14:48 +00:00
import type { SxProps } from "@mui/material";
2022-12-26 10:00:03 +00:00
interface Props {
2023-09-15 12:37:12 +00:00
label: string;
handleChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
checked?: boolean;
sx?: SxProps;
2023-11-04 17:04:24 +00:00
dataCy?: string;
2022-12-26 10:00:03 +00:00
}
2023-11-04 17:04:24 +00:00
export default function CustomCheckbox({ label, handleChange, checked, sx, dataCy }: Props) {
2023-09-15 12:37:12 +00:00
const theme = useTheme();
2023-09-25 13:43:15 +00:00
const isMobile = useMediaQuery(theme.breakpoints.down(790));
2023-09-15 12:37:12 +00:00
return (
<FormControlLabel
2023-09-25 13:43:15 +00:00
control={
<Checkbox
sx={{ padding: "0px 13px 1px 11px" }}
disableRipple
icon={<Icon />}
checkedIcon={<CheckedIcon />}
onChange={handleChange}
checked={checked}
2023-11-04 17:04:24 +00:00
data-cy={dataCy}
2023-09-25 13:43:15 +00:00
/>
}
2023-09-15 12:37:12 +00:00
label={label}
sx={{
color: theme.palette.grey2.main,
2023-09-25 13:43:15 +00:00
height: "26px",
2023-09-15 12:37:12 +00:00
...sx,
}}
/>
);
2022-12-26 10:00:03 +00:00
}
function Icon() {
2023-09-15 12:37:12 +00:00
const theme = useTheme();
2022-12-26 10:00:03 +00:00
2023-09-15 12:37:12 +00:00
return (
<Box
sx={{
2023-09-25 13:43:15 +00:00
height: "24px",
width: "24px",
borderRadius: "6px",
2023-09-15 12:37:12 +00:00
backgroundColor: theme.palette.background.default,
border: `1px solid ${theme.palette.grey2.main}`,
}}
/>
);
2022-12-26 10:00:03 +00:00
}
function CheckedIcon() {
2023-09-15 12:37:12 +00:00
const theme = useTheme();
2022-12-26 10:00:03 +00:00
2023-09-15 12:37:12 +00:00
return (
<Box
sx={{
2023-09-25 13:43:15 +00:00
height: "24px",
width: "24px",
borderRadius: "6px",
2023-09-15 12:37:12 +00:00
display: "flex",
justifyContent: "center",
alignItems: "center",
backgroundColor: theme.palette.brightPurple.main,
border: `1px solid ${theme.palette.grey2.main}`,
}}
>
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 25 18" fill="none">
<path d="M2 9L10 16.5L22.5 1.5" stroke="#ffffff" strokeWidth="4" strokeLinecap="round" />
</svg>
</Box>
);
}