UNPKG

@astarte-platform/react-bootstrap

Version:

React Bootstrap theme, fields and widgets for react-jsonschema-form, powered by react-bootstrap, this is a package from a fork of official project

24 lines 1.86 kB
import { jsx as _jsx } from "react/jsx-runtime"; import Form from 'react-bootstrap/Form'; import { ariaDescribedByIds, enumOptionsDeselectValue, enumOptionsIsSelected, enumOptionsSelectValue, enumOptionsValueForIndex, optionId, } from '@rjsf/utils'; export default function CheckboxesWidget({ id, disabled, options, value, autofocus, readonly, required, onChange, onBlur, onFocus }) { const { enumOptions, enumDisabled, inline, emptyValue } = options; const checkboxesValues = Array.isArray(value) ? value : [value]; const _onChange = (index) => ({ target: { checked } }) => { if (checked) { onChange(enumOptionsSelectValue(index, checkboxesValues, enumOptions)); } else { onChange(enumOptionsDeselectValue(index, checkboxesValues, enumOptions)); } }; const _onBlur = ({ target: { value } }) => onBlur(id, enumOptionsValueForIndex(value, enumOptions, emptyValue)); const _onFocus = ({ target: { value } }) => onFocus(id, enumOptionsValueForIndex(value, enumOptions, emptyValue)); return (_jsx(Form.Group, { children: 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(Form.Check, { inline: inline, required: required, checked: checked, className: 'bg-transparent border-0', type: 'checkbox', id: optionId(id, index), name: id, label: option.label, autoFocus: autofocus && index === 0, onChange: _onChange(index), onBlur: _onBlur, onFocus: _onFocus, disabled: disabled || itemDisabled || readonly, "aria-describedby": ariaDescribedByIds(id) }, option.value)); }) })); } //# sourceMappingURL=CheckboxesWidget.js.map