add name prop to radio component

This commit is contained in:
Alex Holliday committed 2025-06-18 10:10:14 +08:00
1 parent 79b5a33874
commit c78f43e32e
2 files changed
+21 -14

No files matched your search

+20 -14
View File
@@ -16,26 +16,27 @@ import "./index.css";
* size="small" * size="small"
* /> * />
* *
* @param {Object} props - The component props. * @param {Object} props - The component
* @param {string} props.id - The id of the radio button. * @param {string} id - The id of the radio button.
* @param {string} props.title - The title of the radio button. * @param {string} title - The title of the radio button.
* @param {string} [props.desc] - The description of the radio button. * @param {string} [desc] - The description of the radio button.
* @param {string} [props.size="small"] - The size of the radio button. * @param {string} [size="small"] - The size of the radio button.
* @returns {JSX.Element} - The rendered Radio component. * @returns {JSX.Element} - The rendered Radio component.
*/ */
const Radio = (props) => { const Radio = ({ name, checked, value, id, size, title, desc, onChange }) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
<FormControlLabel <FormControlLabel
className="custom-radio-button" className="custom-radio-button"
checked={props.checked} name={name}
value={props.value} checked={checked}
value={value}
control={ control={
<MUIRadio <MUIRadio
id={props.id} id={id}
size={props.size} size={size}
checkedIcon={<RadioChecked />} checkedIcon={<RadioChecked />}
sx={{ sx={{
color: "transparent", color: "transparent",
@@ -49,16 +50,16 @@ const Radio = (props) => {
}} }}
/> />
} }
onChange={props.onChange} onChange={onChange}
label={ label={
<> <>
<Typography component="p">{props.title}</Typography> <Typography component="p">{title}</Typography>
<Typography <Typography
component="h6" component="h6"
mt={theme.spacing(1)} mt={theme.spacing(1)}
color={theme.palette.primary.contrastTextSecondary} color={theme.palette.primary.contrastTextSecondary}
> >
{props.desc} {desc}
</Typography> </Typography>
</> </>
} }
@@ -81,9 +82,14 @@ const Radio = (props) => {
}; };
Radio.propTypes = { Radio.propTypes = {
title: PropTypes.string.isRequired, title: PropTypes.string,
desc: PropTypes.string, desc: PropTypes.string,
size: PropTypes.string, size: PropTypes.string,
name: PropTypes.string,
checked: PropTypes.bool,
value: PropTypes.string,
id: PropTypes.string,
onChange: PropTypes.func,
}; };
export default Radio; export default Radio;
+1
View File
@@ -147,6 +147,7 @@ const CreateMonitor = () => {
const onChange = (event) => { const onChange = (event) => {
const { name, value, checked } = event.target; const { name, value, checked } = event.target;
let newValue = value; let newValue = value;
if (name === "ignoreTlsErrors") { if (name === "ignoreTlsErrors") {
newValue = checked; newValue = checked;