Created
January 17, 2021 16:09
-
-
Save vinodchauhan7/529963172cb091e3d7313e6ab3d455dc to your computer and use it in GitHub Desktop.
Radio Button with materia UI
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
import { Button, Radio } from '@material-ui/core'; | |
function renderOptions(): ReactElement[] { | |
const options: ReactElement[] = []; | |
for (let i = 0; i < 4; i += 1) { | |
const label = i === 0 ? translate('none') : `${i} ${i === 1 ? translate('time') : translate('times')}`; | |
options.push( | |
<Button | |
className={clsx(styles.card, { [styles.selected]: enteritisCount === i })} | |
key={`option-${i}`} | |
onClick={() => setEnteritisCount(i)} | |
> | |
<div>{label}</div> | |
<Radio color="primary" checked={enteritisCount === i} /> | |
</Button> | |
); | |
} | |
return options; | |
} |
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
import { | |
createStyles, | |
makeStyles | |
} from '@material-ui/core/styles'; | |
const cardMargin = 5; | |
const cardPadding = 15; | |
const selectedBorderWidth = 1; | |
export const useStyles = makeStyles((theme) => createStyles({ | |
enteritisContainer: { | |
flex: 1, | |
display: 'flex', | |
flexDirection: 'column', | |
overflow: 'hidden' | |
}, | |
optionsContainer: { | |
flex: 1, | |
display: 'flex', | |
flexDirection: 'column', | |
overflowY: 'scroll', | |
margin: '0px 16px' | |
}, | |
card: { | |
margin: `${cardMargin}px`, | |
padding: `${cardPadding}px`, | |
borderRadius: '8px', | |
boxShadow: '0px 2px 10px rgba(130, 130, 130, 0.4)', | |
justifyContent: 'space-between', | |
transition: 'border 0s', | |
textTransform: 'none' | |
}, | |
selected: { | |
border: `${selectedBorderWidth}px solid ${theme.palette.primary.main}`, | |
padding: `${cardPadding - selectedBorderWidth}px` | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment