UNPKG

@rjsf/fluent-ui

Version:

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

53 lines 2.35 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useCallback } from 'react'; import { Checkbox } from '@fluentui/react'; import { ariaDescribedByIds, descriptionId, getTemplate, labelValue, } from '@rjsf/utils'; import _pick from 'lodash/pick'; // Keys of ICheckboxProps from @fluentui/react export const allowedProps = [ 'ariaDescribedBy', 'ariaLabel', 'ariaPositionInSet', 'ariaSetSize', 'boxSide', 'checked', 'checkmarkIconProps', 'className', 'componentRef', 'defaultChecked', 'defaultIndeterminate', 'disabled', 'indeterminate', 'inputProps', /* Backward compatibility with fluentui v7 */ 'keytipProps', 'label', 'onChange', 'onRenderLabel', 'styles', 'theme', ]; export default function CheckboxWidget(props) { var _a; const { id, value, // required, disabled, readonly, label, hideLabel, schema, autofocus, onChange, onBlur, onFocus, options, registry, uiSchema, } = props; const DescriptionFieldTemplate = getTemplate('DescriptionFieldTemplate', registry, options); const _onChange = useCallback((_, checked) => { onChange(checked); }, [onChange]); const _onBlur = ({ target }) => onBlur(id, target && target.value); const _onFocus = ({ target }) => onFocus(id, target && target.value); const uiProps = _pick(options.props || {}, allowedProps); const description = (_a = options.description) !== null && _a !== void 0 ? _a : schema.description; return (_jsxs(_Fragment, { children: [!hideLabel && !!description && (_jsx(DescriptionFieldTemplate, { id: descriptionId(id), description: description, schema: schema, uiSchema: uiSchema, registry: registry })), _jsx(Checkbox, { id: id, name: id, label: labelValue(label || undefined, hideLabel), disabled: disabled || readonly, inputProps: { autoFocus: autofocus, onBlur: _onBlur, onFocus: _onFocus, }, checked: typeof value === 'undefined' ? false : value, onChange: _onChange, ...uiProps, "aria-describedby": ariaDescribedByIds(id), ...{ autoFocus: autofocus, onBlur: _onBlur, onFocus: _onFocus, } })] })); } //# sourceMappingURL=CheckboxWidget.js.map