Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 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 {createTheme, Theme} from '@material-ui/core/styles'; |
| 7 | import {makeStyles} from '@material-ui/styles'; |
| 8 | import MenuItem from '@material-ui/core/MenuItem'; |
| 9 | import TextField from '@material-ui/core/TextField'; |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 10 | import {SelectMenuOption} from './IssueWizardTypes.tsx'; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 11 | |
| 12 | const theme: Theme = createTheme(); |
| 13 | |
| 14 | const useStyles = makeStyles((theme: Theme) => ({ |
| 15 | container: { |
| 16 | display: 'flex', |
| 17 | flexWrap: 'wrap', |
| 18 | maxWidth: '65%', |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 19 | marginRight: '1rem', |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 20 | }, |
| 21 | textField: { |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 22 | margin: '0', |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 23 | }, |
| 24 | menu: { |
| 25 | width: '100%', |
| 26 | minWidth: '300px', |
| 27 | }, |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 28 | description: { |
| 29 | fontSize: 'small', |
| 30 | color: 'gray', |
| 31 | }, |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 32 | }), {defaultTheme: theme}); |
| 33 | |
| 34 | /** |
| 35 | * Select menu component that is located on the landing step if the |
| 36 | * Issue Wizard. The menu is used for the user to indicate the category |
| 37 | * of their bug when filing an issue. |
| 38 | * |
| 39 | * @return ReactElement. |
| 40 | */ |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 41 | type Props = { |
| 42 | optionsList: SelectMenuOption[] | null, |
| 43 | selectedOption: SelectMenuOption | null, |
| 44 | setOption: Function, |
| 45 | }; |
| 46 | |
| 47 | export default function SelectMenu(props: Props) { |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 48 | const classes = useStyles(); |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 49 | |
| 50 | const {optionsList, selectedOption, setOption} = props; |
| 51 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 52 | const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => { |
| 53 | setOption(event.target.value as string); |
| 54 | }; |
| 55 | |
| 56 | return ( |
| 57 | <form className={classes.container} noValidate autoComplete="off"> |
| 58 | <TextField |
| 59 | id="outlined-select-category" |
| 60 | select |
| 61 | label='' |
| 62 | className={classes.textField} |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 63 | value={selectedOption} |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 64 | onChange={handleChange} |
| 65 | InputLabelProps={{shrink: false}} |
| 66 | SelectProps={{ |
| 67 | MenuProps: { |
| 68 | className: classes.menu, |
| 69 | }, |
| 70 | }} |
| 71 | margin="normal" |
| 72 | variant="outlined" |
| 73 | fullWidth={true} |
| 74 | > |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 75 | { |
| 76 | optionsList?.map(option => ( |
| 77 | <MenuItem |
| 78 | className={classes.menu} |
| 79 | key={option.name} |
| 80 | value={option.name} |
| 81 | data-testid="select-menu-item" |
| 82 | > |
| 83 | <div> |
| 84 | <div>{option.name}</div> |
| 85 | { |
| 86 | option.description ? |
| 87 | <div className={classes.description}>{option.description}</div> |
| 88 | : null |
| 89 | } |
| 90 | </div> |
| 91 | </MenuItem>)) |
| 92 | } |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 93 | </TextField> |
| 94 | </form> |
| 95 | ); |
Adrià Vilanova Martínez | ac4a644 | 2022-05-15 19:05:13 +0200 | [diff] [blame] | 96 | } |