@rjsf/fluent-ui
Version:
Fluent UI theme, fields and widgets for react-jsonschema-form
36 lines • 2.59 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { Checkbox } from '@fluentui/react';
import { ariaDescribedByIds, enumOptionsDeselectValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, labelValue, optionId, } from '@rjsf/utils';
import _pick from 'lodash/pick';
import FluentLabel, { styles_red } from '../FluentLabel/FluentLabel.js';
import { allowedProps } from '../CheckboxWidget/index.js';
export default function CheckboxesWidget({ label, hideLabel, id, disabled, options, value, autofocus, readonly, required, onChange, onBlur, onFocus, rawErrors = [], }) {
const { enumOptions, enumDisabled, emptyValue } = options;
const checkboxesValues = Array.isArray(value) ? value : [value];
const _onChange = (index) => (_ev, checked) => {
if (checked) {
onChange(enumOptionsSelectValue(index, checkboxesValues, enumOptions));
}
else {
onChange(enumOptionsDeselectValue(index, checkboxesValues, enumOptions));
}
};
const _onBlur = ({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
const _onFocus = ({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue));
const uiProps = _pick(options.props || {}, allowedProps);
return (_jsxs(_Fragment, { children: [labelValue(_jsx(FluentLabel, { label: label || undefined, required: required }), hideLabel), Array.isArray(enumOptions) &&
enumOptions.map((option, index) => {
const checked = enumOptionsIsSelected(option.value, checkboxesValues);
const itemDisabled = Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1;
return (_jsx(Checkbox, { id: optionId(id, index), name: id, checked: checked, label: option.label, disabled: disabled || itemDisabled || readonly, inputProps: {
autoFocus: autofocus && index === 0,
onBlur: _onBlur,
onFocus: _onFocus,
}, onChange: _onChange(index), ...uiProps, "aria-describedby": ariaDescribedByIds(id), ...{
autoFocus: autofocus && index === 0,
onBlur: _onBlur,
onFocus: _onFocus,
} }, index));
}), _jsx("span", { style: styles_red, children: (rawErrors || []).join('\n') })] }));
}
//# sourceMappingURL=CheckboxesWidget.js.map