frontPanel/src/ui_kit/CustomCheckbox.tsx

68 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-12-26 10:00:03 +00:00
import { FormControlLabel, Checkbox, useTheme, Box } 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;
2022-12-26 10:00:03 +00:00
}
2023-09-15 12:37:12 +00:00
export default function CustomCheckbox({ label, handleChange, checked, sx }: Props) {
const theme = useTheme();
2023-09-15 12:37:12 +00:00
return (
<FormControlLabel
control={<Checkbox icon={<Icon />} checkedIcon={<CheckedIcon />} onChange={handleChange} checked={checked} />}
label={label}
sx={{
color: theme.palette.grey2.main,
ml: "-9px",
userSelect: "none",
...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={{
height: "26px",
width: "26px",
borderRadius: "8px",
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={{
height: "26px",
width: "26px",
borderRadius: "8px",
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>
);
}