blob: 3dec29cbb9cf3d1f76e43373774fc31af3363e0a [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2021 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// 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 {createTheme, Theme} from '@material-ui/core/styles';
7import {makeStyles} from '@material-ui/styles';
8import MenuItem from '@material-ui/core/MenuItem';
9import TextField from '@material-ui/core/TextField';
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020010import {SelectMenuOption} from './IssueWizardTypes.tsx';
Copybara854996b2021-09-07 19:36:02 +000011
12const theme: Theme = createTheme();
13
14const useStyles = makeStyles((theme: Theme) => ({
15 container: {
16 display: 'flex',
17 flexWrap: 'wrap',
18 maxWidth: '65%',
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020019 marginRight: '1rem',
Copybara854996b2021-09-07 19:36:02 +000020 },
21 textField: {
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020022 margin: '0',
Copybara854996b2021-09-07 19:36:02 +000023 },
24 menu: {
25 width: '100%',
26 minWidth: '300px',
27 },
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020028 description: {
29 fontSize: 'small',
30 color: 'gray',
31 },
Copybara854996b2021-09-07 19:36:02 +000032}), {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ínezac4a6442022-05-15 19:05:13 +020041type Props = {
42 optionsList: SelectMenuOption[] | null,
43 selectedOption: SelectMenuOption | null,
44 setOption: Function,
45};
46
47export default function SelectMenu(props: Props) {
Copybara854996b2021-09-07 19:36:02 +000048 const classes = useStyles();
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020049
50 const {optionsList, selectedOption, setOption} = props;
51
Copybara854996b2021-09-07 19:36:02 +000052 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ínezac4a6442022-05-15 19:05:13 +020063 value={selectedOption}
Copybara854996b2021-09-07 19:36:02 +000064 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ínezac4a6442022-05-15 19:05:13 +020075 {
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 }
Copybara854996b2021-09-07 19:36:02 +000093 </TextField>
94 </form>
95 );
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020096}