X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2820212ec0df02a85ae74ede8c52d3b5e936c6aa..20063f6f7bb9ad7c6a9a0b49b3c5ba4b0abc532e:/src/components/checkbox-field/checkbox-field.tsx diff --git a/src/components/checkbox-field/checkbox-field.tsx b/src/components/checkbox-field/checkbox-field.tsx index b8f18e7fdc..02a5e9a68d 100644 --- a/src/components/checkbox-field/checkbox-field.tsx +++ b/src/components/checkbox-field/checkbox-field.tsx @@ -2,26 +2,67 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +import React from 'react'; import { WrappedFieldProps } from 'redux-form'; -import { ArvadosTheme } from '~/common/custom-theme'; -import { FormControlLabel, Checkbox, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core'; +import { + FormControlLabel, + Checkbox, + FormControl, + FormGroup, + FormLabel, + FormHelperText +} from '@material-ui/core'; -type CssRules = 'checkboxField'; - -const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ - checkboxField: { - - } -}); - -export const CheckboxField = withStyles(styles)((props: WrappedFieldProps & WithStyles & { label?: string }) => +export const CheckboxField = (props: WrappedFieldProps & { label?: string }) => } - label={props.label} - />); \ No newline at end of file + label={props.label} + />; + +type MultiCheckboxFieldProps = { + items: string[]; + label?: string; + minSelection?: number; + maxSelection?: number; + helperText?: string; + rowLayout?: boolean; +} + +export const MultiCheckboxField = (props: WrappedFieldProps & MultiCheckboxFieldProps) => { + const isValid = (items: string[]) => (items.length >= (props.minSelection || 0)) && + (items.length <= (props.maxSelection || items.length)); + return + {props.label} + + { props.items.map((item, idx) => + { + const newValue = [...props.input.value]; + if (e.target.checked) { + newValue.push(item); + } else { + newValue.splice(newValue.indexOf(item), 1); + } + if (!isValid(newValue)) { return; } + return props.input.onChange(newValue); + }} + disabled={props.meta.submitting} + color="primary" /> + } + label={item} />) } + + {props.helperText} + }; \ No newline at end of file