Adrià Vilanova MartÃnez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame^] | 1 | // Copyright 2021 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import React from 'react'; |
| 6 | import { makeStyles, withStyles } from '@material-ui/styles'; |
| 7 | import { blue, grey } from '@material-ui/core/colors'; |
| 8 | import Radio, { RadioProps } from '@material-ui/core/Radio'; |
| 9 | |
| 10 | const useStyles = makeStyles({ |
| 11 | container: { |
| 12 | width: '320px', |
| 13 | height: '150px', |
| 14 | position: 'relative', |
| 15 | display: 'inline-block', |
| 16 | cursor: 'pointer', |
| 17 | }, |
| 18 | text: { |
| 19 | position: 'absolute', |
| 20 | display: 'inline-block', |
| 21 | left: '55px', |
| 22 | }, |
| 23 | title: { |
| 24 | marginTop: '7px', |
| 25 | fontSize: '20px', |
| 26 | color: grey[900], |
| 27 | }, |
| 28 | subheader: { |
| 29 | fontSize: '16px', |
| 30 | color: grey[800], |
| 31 | }, |
| 32 | line: { |
| 33 | position: 'absolute', |
| 34 | bottom: 0, |
| 35 | width: '300px', |
| 36 | left: '20px', |
| 37 | } |
| 38 | }); |
| 39 | |
| 40 | const BlueRadio = withStyles({ |
| 41 | root: { |
| 42 | color: blue[400], |
| 43 | '&$checked': { |
| 44 | color: blue[600], |
| 45 | }, |
| 46 | }, |
| 47 | checked: {}, |
| 48 | })((props: RadioProps) => <Radio color="default" {...props} />); |
| 49 | |
| 50 | interface RoleSelectionProps { |
| 51 | /* Whether or not the radio button should be checked */ |
| 52 | checked: boolean |
| 53 | /* onClick callback defined in parent component */ |
| 54 | handleOnClick: (event: React.MouseEvent<HTMLElement>) => void |
| 55 | /* |
| 56 | A string representing the type of user; this is the value of the input |
| 57 | see `userGroups`, which is defined in RadioDescription |
| 58 | */ |
| 59 | value: string |
| 60 | /* Descriptive text to be displayed along with the radio button */ |
| 61 | description: string |
| 62 | /* Additional props for the radio button component */ |
| 63 | inputProps: { [key: string]: string } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * RoleSelection encapsulates the radio button and details |
| 68 | * for selecting a role as an issue reporter in the issue wizard |
| 69 | * @see RadioDescription |
| 70 | */ |
| 71 | |
| 72 | export const RoleSelection = ({ |
| 73 | checked, |
| 74 | handleOnClick, |
| 75 | value, |
| 76 | description, |
| 77 | inputProps |
| 78 | }: RoleSelectionProps): React.ReactElement => { |
| 79 | const classes = useStyles(); |
| 80 | return ( |
| 81 | <div className={classes.container} onClick={handleOnClick}> |
| 82 | <BlueRadio |
| 83 | checked={checked} |
| 84 | value={value} |
| 85 | inputProps={inputProps} |
| 86 | /> |
| 87 | <div className={classes.text}> |
| 88 | <p className={classes.title}>{value}</p> |
| 89 | <p className={classes.subheader}>{description}</p> |
| 90 | </div> |
| 91 | <hr color={grey[200]} className={classes.line} /> |
| 92 | </div> |
| 93 | ) |
| 94 | } |
| 95 | |