1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { WrappedFieldProps } from 'redux-form';
7 import { ArvadosTheme } from 'common/custom-theme';
8 import { CustomStyleRulesCallback } from 'common/custom-theme';
9 import { FormControl, InputLabel, Select, FormHelperText } from '@mui/material';
11 import { WithStyles } from '@mui/styles';
12 import withStyles from '@mui/styles/withStyles';
14 type CssRules = 'formControl' | 'selectWrapper' | 'select' | 'option';
16 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
21 backgroundColor: theme.palette.common.white,
23 borderBottomColor: 'rgba(0, 0, 0, 0.42)',
32 backgroundColor: 'rgba(0, 0, 0, 0.0)',
37 backgroundColor: theme.palette.common.white,
42 interface NativeSelectFieldProps {
46 export const NativeSelectField = withStyles(styles)((props: WrappedFieldProps & NativeSelectFieldProps & WithStyles<CssRules> & { items: any[] }) => (
47 <FormControl variant="standard" className={props.classes.formControl}>
50 className={props.classes.selectWrapper}
52 value={props.input.value}
53 onChange={props.input.onChange}
54 disabled={props.meta.submitting || props.disabled}
55 name={props.input.name}
57 id: `id-${props.input.name}`,
58 className: props.classes.select,
60 {props.items.map(item => (
64 className={props.classes.option}>
72 interface SelectFieldProps {
73 children: React.ReactNode;
77 type SelectFieldCssRules = 'formControl';
79 const selectFieldStyles: CustomStyleRulesCallback<SelectFieldCssRules> = (theme: ArvadosTheme) => ({
81 marginBottom: theme.spacing(3),
84 export const SelectField = withStyles(selectFieldStyles)((props: WrappedFieldProps & SelectFieldProps & WithStyles<SelectFieldCssRules>) => (
87 error={props.meta.invalid}
88 className={props.classes.formControl}>
89 <InputLabel>{props.label}</InputLabel>
90 <Select variant="standard" {...props.input}>{props.children}</Select>
91 <FormHelperText>{props.meta.error}</FormHelperText>