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', |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 13 | minWidth: '140px', |
| 14 | height: '160px', |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 15 | position: 'relative', |
| 16 | display: 'inline-block', |
| 17 | cursor: 'pointer', |
| 18 | }, |
| 19 | text: { |
| 20 | position: 'absolute', |
| 21 | display: 'inline-block', |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 22 | }, |
| 23 | title: { |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 24 | margin: '0.5rem 0', |
| 25 | fontSize: '1.125rem', |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 26 | color: grey[900], |
| 27 | }, |
| 28 | subheader: { |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 29 | fontSize: '0.875rem', |
Adrià Vilanova Martínez | 535e731 | 2021-10-17 00:48:12 +0200 | [diff] [blame] | 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 | |