UNPKG

@rjsf/react-bootstrap

Version:

React Bootstrap theme, fields and widgets for react-jsonschema-form, powered by react-bootstrap

17 lines 1.72 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { ariaDescribedByIds, descriptionId, getTemplate, labelValue, schemaRequiresTrueValue, } from '@rjsf/utils'; import Form from 'react-bootstrap/Form'; export default function CheckboxWidget(props) { const { id, htmlName, value, disabled, readonly, label, hideLabel, schema, autofocus, options, onChange, onBlur, onFocus, registry, uiSchema, } = props; // Because an unchecked checkbox will cause html5 validation to fail, only add // the "required" attribute if the field value must be "true", due to the // "const" or "enum" keywords const required = schemaRequiresTrueValue(schema); const DescriptionFieldTemplate = getTemplate('DescriptionFieldTemplate', registry, options); const _onChange = ({ target: { checked } }) => onChange(checked); const _onBlur = ({ target }) => onBlur(id, target && target.checked); const _onFocus = ({ target }) => onFocus(id, target && target.checked); const description = options.description || schema.description; return (_jsxs(Form.Group, { className: disabled || readonly ? 'disabled' : '', "aria-describedby": ariaDescribedByIds(id), children: [!hideLabel && description && (_jsx(DescriptionFieldTemplate, { id: descriptionId(id), description: description, schema: schema, uiSchema: uiSchema, registry: registry })), _jsx(Form.Check, { id: id, name: htmlName || id, label: labelValue(label, hideLabel || !label), checked: typeof value === 'undefined' ? false : value, required: required, disabled: disabled || readonly, autoFocus: autofocus, onChange: _onChange, type: 'checkbox', onBlur: _onBlur, onFocus: _onFocus })] })); } //# sourceMappingURL=CheckboxWidget.js.map