-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import RadioGroup, { useRadioGroup } from '@material-ui/core/RadioGroup'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import Radio from '@material-ui/core/Radio'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
labelChecked: { | ||
color: theme.palette.secondary.main, | ||
fontWeight: 'bold', | ||
textDecoration: 'underline', | ||
}, | ||
})); | ||
|
||
const MyFormControlLabel = (props) => { | ||
const classes = useStyles(); | ||
|
||
const radioGroup = useRadioGroup(); | ||
|
||
let checked = false; | ||
|
||
if (radioGroup) { | ||
checked = radioGroup.value === props.value; | ||
} | ||
|
||
return ( | ||
<FormControlLabel | ||
classes={{ | ||
label: checked ? classes.labelChecked : '', | ||
}} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
MyFormControlLabel.propTypes = { | ||
value: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default function UseRadioGroup() { | ||
return ( | ||
<RadioGroup defaultValue="first"> | ||
<MyFormControlLabel value="first" label="First" control={<Radio />} /> | ||
<MyFormControlLabel value="second" label="Second" control={<Radio />} /> | ||
</RadioGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import RadioGroup, { useRadioGroup } from '@material-ui/core/RadioGroup'; | ||
import FormControlLabel, { | ||
FormControlLabelProps, | ||
} from '@material-ui/core/FormControlLabel'; | ||
import Radio from '@material-ui/core/Radio'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
labelChecked: { | ||
color: theme.palette.secondary.main, | ||
fontWeight: 'bold', | ||
textDecoration: 'underline', | ||
}, | ||
})); | ||
|
||
const MyFormControlLabel = (props: FormControlLabelProps) => { | ||
const classes = useStyles(); | ||
|
||
const radioGroup = useRadioGroup(); | ||
|
||
let checked = false; | ||
|
||
if (radioGroup) { | ||
checked = radioGroup.value === props.value; | ||
} | ||
|
||
return ( | ||
<FormControlLabel | ||
classes={{ | ||
label: checked ? classes.labelChecked : '', | ||
}} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default function UseRadioGroup() { | ||
return ( | ||
<RadioGroup defaultValue="first"> | ||
<MyFormControlLabel value="first" label="First" control={<Radio />} /> | ||
|
||
<MyFormControlLabel value="second" label="Second" control={<Radio />} /> | ||
</RadioGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters