Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [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 userGroups = Object.freeze({ |
| 11 | END_USER: 'End User', |
| 12 | WEB_DEVELOPER: 'Web Developer', |
| 13 | CONTRIBUTOR: 'Chromium Contributor', |
| 14 | }); |
| 15 | |
| 16 | const BlueRadio = withStyles({ |
| 17 | root: { |
| 18 | color: blue[400], |
| 19 | '&$checked': { |
| 20 | color: blue[600], |
| 21 | }, |
| 22 | }, |
| 23 | checked: {}, |
| 24 | })((props: RadioProps) => <Radio color="default" {...props} />); |
| 25 | |
| 26 | const useStyles = makeStyles({ |
| 27 | flex: { |
| 28 | display: 'flex', |
| 29 | justifyContent: 'space-between', |
| 30 | }, |
| 31 | container: { |
| 32 | width: '320px', |
| 33 | height: '150px', |
| 34 | position: 'relative', |
| 35 | display: 'inline-block', |
| 36 | }, |
| 37 | text: { |
| 38 | position: 'absolute', |
| 39 | display: 'inline-block', |
| 40 | left: '55px', |
| 41 | }, |
| 42 | title: { |
| 43 | marginTop: '7px', |
| 44 | fontSize: '20px', |
| 45 | color: grey[900], |
| 46 | }, |
| 47 | subheader: { |
| 48 | fontSize: '16px', |
| 49 | color: grey[800], |
| 50 | }, |
| 51 | line: { |
| 52 | position: 'absolute', |
| 53 | bottom: 0, |
| 54 | width: '300px', |
| 55 | left: '20px', |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | /** |
| 60 | * `<RadioDescription />` |
| 61 | * |
| 62 | * React component for radio buttons and their descriptions |
| 63 | * on the landing step of the Issue Wizard. |
| 64 | * |
| 65 | * @return ReactElement. |
| 66 | */ |
| 67 | export default function RadioDescription({value, setValue} : {value: string, setValue: Function}): React.ReactElement { |
| 68 | const classes = useStyles(); |
| 69 | |
| 70 | const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 71 | setValue(event.target.value); |
| 72 | }; |
| 73 | |
| 74 | return ( |
| 75 | <div className={classes.flex}> |
| 76 | <div className={classes.container}> |
| 77 | <BlueRadio |
| 78 | checked={value === userGroups.END_USER} |
| 79 | onChange={handleChange} |
| 80 | value={userGroups.END_USER} |
| 81 | inputProps={{ 'aria-label': userGroups.END_USER}} |
| 82 | /> |
| 83 | <div className={classes.text}> |
| 84 | <p className={classes.title}>{userGroups.END_USER}</p> |
| 85 | <p className={classes.subheader}>I am a user trying to do something on a website.</p> |
| 86 | </div> |
| 87 | <hr color={grey[200]} className={classes.line}/> |
| 88 | </div> |
| 89 | <div className={classes.container}> |
| 90 | <BlueRadio |
| 91 | checked={value === userGroups.WEB_DEVELOPER} |
| 92 | onChange={handleChange} |
| 93 | value={userGroups.WEB_DEVELOPER} |
| 94 | inputProps={{ 'aria-label': userGroups.WEB_DEVELOPER }} |
| 95 | /> |
| 96 | <div className={classes.text}> |
| 97 | <p className={classes.title}>{userGroups.WEB_DEVELOPER}</p> |
| 98 | <p className={classes.subheader}>I am a web developer trying to build something.</p> |
| 99 | </div> |
| 100 | <hr color={grey[200]} className={classes.line}/> |
| 101 | </div> |
| 102 | <div className={classes.container}> |
| 103 | <BlueRadio |
| 104 | checked={value === userGroups.CONTRIBUTOR} |
| 105 | onChange={handleChange} |
| 106 | value={userGroups.CONTRIBUTOR} |
| 107 | inputProps={{ 'aria-label': userGroups.CONTRIBUTOR }} |
| 108 | /> |
| 109 | <div className={classes.text}> |
| 110 | <p className={classes.title}>{userGroups.CONTRIBUTOR}</p> |
| 111 | <p className={classes.subheader}>I know about a problem in specific tests or code.</p> |
| 112 | </div> |
| 113 | <hr color={grey[200]} className={classes.line}/> |
| 114 | </div> |
| 115 | </div> |
| 116 | ); |
| 117 | } |