UNPKG

@rjsf/fluent-ui

Version:

Fluent UI theme, fields and widgets for react-jsonschema-form

41 lines 1.96 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { ChoiceGroup } from '@fluentui/react'; import { ariaDescribedByIds, enumOptionsIndexForValue, enumOptionsValueForIndex, labelValue, optionId, } from '@rjsf/utils'; import _pick from 'lodash/pick'; const allowedProps = [ 'componentRef', 'options', 'defaultSelectedKey', 'selectedKey', 'onChange', 'label', /* Backward compatibility with fluentui v7 */ 'onChanged', 'theme', 'styles', 'ariaLabelledBy', ]; export default function RadioWidget({ id, options, value, required, label, hideLabel, onChange, onBlur, onFocus, disabled, readonly, }) { const { enumOptions, enumDisabled, emptyValue } = options; function _onChange(_ev, option) { if (option) { onChange(enumOptionsValueForIndex(option.key, enumOptions, emptyValue)); } } const _onBlur = ({ target }) => onBlur(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const _onFocus = ({ target }) => onFocus(id, enumOptionsValueForIndex(target && target.value, enumOptions, emptyValue)); const newOptions = Array.isArray(enumOptions) ? enumOptions.map((option, index) => ({ key: String(index), name: id, id: optionId(id, index), text: option.label, disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1, 'aria-describedby': ariaDescribedByIds(id), })) : []; const selectedIndex = enumOptionsIndexForValue(value, enumOptions); const uiProps = _pick(options.props || {}, allowedProps); return (_jsx(ChoiceGroup, { id: id, name: id, options: newOptions, disabled: disabled || readonly, onChange: _onChange, onFocus: _onFocus, onBlur: _onBlur, label: labelValue(label, hideLabel || !label), required: required, selectedKey: selectedIndex, ...uiProps })); } //# sourceMappingURL=RadioWidget.js.map