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 { StyleRulesCallback, WithStyles, withStyles, FormControl, InputLabel, Select, FormHelperText } from '@material-ui/core';
10 type CssRules = 'formControl' | 'selectWrapper' | 'select' | 'option';
12 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
17 backgroundColor: theme.palette.common.white,
19 borderBottomColor: 'rgba(0, 0, 0, 0.42)',
28 backgroundColor: 'rgba(0, 0, 0, 0.0)',
33 backgroundColor: theme.palette.common.white,
38 interface NativeSelectFieldProps {
42 export const NativeSelectField = withStyles(styles)((props: WrappedFieldProps & NativeSelectFieldProps & WithStyles<CssRules> & { items: any[] }) => (
43 <FormControl className={props.classes.formControl}>
45 className={props.classes.selectWrapper}
47 value={props.input.value}
48 onChange={props.input.onChange}
49 disabled={props.meta.submitting || props.disabled}
50 name={props.input.name}
52 id: `id-${props.input.name}`,
53 className: props.classes.select,
55 {props.items.map(item => (
59 className={props.classes.option}>
67 interface SelectFieldProps {
68 children: React.ReactNode;
72 type SelectFieldCssRules = 'formControl';
74 const selectFieldStyles: StyleRulesCallback<SelectFieldCssRules> = (theme: ArvadosTheme) => ({
76 marginBottom: theme.spacing.unit * 3,
79 export const SelectField = withStyles(selectFieldStyles)((props: WrappedFieldProps & SelectFieldProps & WithStyles<SelectFieldCssRules>) => (
81 error={props.meta.invalid}
82 className={props.classes.formControl}>
83 <InputLabel>{props.label}</InputLabel>
84 <Select {...props.input}>{props.children}</Select>
85 <FormHelperText>{props.meta.error}</FormHelperText>