blob: 683776e923edd3a44da0b691f010b976dcf917e4 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2021 The Chromium Authors
Adrià Vilanova Martínez535e7312021-10-17 00:48:12 +02002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import React from 'react';
6import { makeStyles, withStyles } from '@material-ui/styles';
7import { blue, grey } from '@material-ui/core/colors';
8import Radio, { RadioProps } from '@material-ui/core/Radio';
9
10const useStyles = makeStyles({
11 container: {
12 width: '320px',
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020013 minWidth: '140px',
14 height: '160px',
Adrià Vilanova Martínez535e7312021-10-17 00:48:12 +020015 position: 'relative',
16 display: 'inline-block',
17 cursor: 'pointer',
18 },
19 text: {
20 position: 'absolute',
21 display: 'inline-block',
Adrià Vilanova Martínez535e7312021-10-17 00:48:12 +020022 },
23 title: {
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020024 margin: '0.5rem 0',
25 fontSize: '1.125rem',
Adrià Vilanova Martínez535e7312021-10-17 00:48:12 +020026 color: grey[900],
27 },
28 subheader: {
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020029 fontSize: '0.875rem',
Adrià Vilanova Martínez535e7312021-10-17 00:48:12 +020030 color: grey[800],
31 },
32 line: {
33 position: 'absolute',
34 bottom: 0,
35 width: '300px',
36 left: '20px',
37 }
38});
39
40const 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
50interface 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
72export 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}