Files
Checkmate/client/src/Components/Inputs/Radio/index.jsx
T

95 lines
2.2 KiB
React
Raw Normal View History

2024-08-27 17:01:28 -04:00
import PropTypes from "prop-types";
import { FormControlLabel, Radio as MUIRadio, Typography } from "@mui/material";
import { useTheme } from "@emotion/react";
import RadioChecked from "../../../assets/icons/radio-checked.svg?react";
import "./index.css";
2024-06-20 19:53:08 +03:30
/**
2024-08-27 17:01:28 -04:00
* Radio component.
2024-06-20 19:53:08 +03:30
*
* @component
* @example
* // Usage:
2024-08-27 17:01:28 -04:00
* <Radio
2024-06-20 19:53:08 +03:30
* title="Radio Button Title"
* desc="Radio Button Description"
* size="small"
* />
*
2025-06-18 10:10:14 +08:00
* @param {Object} props - The component
* @param {string} id - The id of the radio button.
* @param {string} title - The title of the radio button.
* @param {string} [desc] - The description of the radio button.
* @param {string} [size="small"] - The size of the radio button.
2024-08-27 17:01:28 -04:00
* @returns {JSX.Element} - The rendered Radio component.
2024-06-20 19:53:08 +03:30
*/
2025-06-18 10:10:14 +08:00
const Radio = ({ name, checked, value, id, size, title, desc, onChange }) => {
const theme = useTheme();
2024-08-27 17:01:28 -04:00
return (
<FormControlLabel
className="custom-radio-button"
2025-06-18 10:10:14 +08:00
name={name}
checked={checked}
value={value}
control={
<MUIRadio
2025-06-18 10:10:14 +08:00
id={id}
size={size}
checkedIcon={<RadioChecked />}
sx={{
color: "transparent",
width: 16,
height: 16,
boxShadow: `inset 0 0 0 1px ${theme.palette.secondary.main}`,
2024-12-16 18:59:29 +00:00
"&:not(.Mui-checked)": {
2025-01-12 09:39:31 -05:00
boxShadow: `inset 0 0 0 1px ${theme.palette.primary.contrastText}70`, // Use theme text color for the outline
2024-12-16 18:59:29 +00:00
},
mt: theme.spacing(0.5),
}}
/>
}
2025-06-18 10:10:14 +08:00
onChange={onChange}
label={
<>
2025-06-18 10:10:14 +08:00
<Typography component="p">{title}</Typography>
<Typography
component="h6"
mt={theme.spacing(1)}
2025-01-12 09:39:31 -05:00
color={theme.palette.primary.contrastTextSecondary}
>
2025-06-18 10:10:14 +08:00
{desc}
</Typography>
</>
}
labelPlacement="end"
sx={{
alignItems: "flex-start",
p: theme.spacing(2.5),
m: theme.spacing(-2.5),
borderRadius: theme.shape.borderRadius,
"&:hover": {
backgroundColor: theme.palette.tertiary.main,
},
"& .MuiButtonBase-root": {
p: 0,
mr: theme.spacing(6),
},
}}
/>
);
2024-08-27 17:01:28 -04:00
};
2024-06-20 19:53:08 +03:30
2024-08-27 17:01:28 -04:00
Radio.propTypes = {
2025-06-18 10:10:14 +08:00
title: PropTypes.string,
desc: PropTypes.string,
size: PropTypes.string,
2025-06-18 10:10:14 +08:00
name: PropTypes.string,
checked: PropTypes.bool,
value: PropTypes.string,
id: PropTypes.string,
onChange: PropTypes.func,
2024-06-20 19:53:08 +03:30
};
2024-08-27 17:01:28 -04:00
export default Radio;