// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import React from 'react'; import { WrappedFieldProps } from 'redux-form'; import { FormControlLabel, Checkbox, FormControl, FormGroup, FormLabel, FormHelperText } from '@material-ui/core'; export const CheckboxField = (props: WrappedFieldProps & { label?: string }) => } label={props.label} />; type MultiCheckboxFieldProps = { items: string[]; defaultValues?: 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)); if (props.input.value.length === 0 && (props.defaultValues || []).length !== 0) { props.input.value = props.defaultValues ? [...props.defaultValues] : []; } 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} };