X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3c7e3cdc547ad5468421e1c049daa94b0d4b8bc0..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 2b2a8a03e3..02a5e9a68d 100644 --- a/src/components/checkbox-field/checkbox-field.tsx +++ b/src/components/checkbox-field/checkbox-field.tsx @@ -4,7 +4,14 @@ import React from 'react'; import { WrappedFieldProps } from 'redux-form'; -import { FormControlLabel, Checkbox } from '@material-ui/core'; +import { + FormControlLabel, + Checkbox, + FormControl, + FormGroup, + FormLabel, + FormHelperText +} from '@material-ui/core'; export const CheckboxField = (props: WrappedFieldProps & { label?: string }) => disabled={props.meta.submitting} color="primary" /> } - 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