@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
17 lines • 1.71 kB
JavaScript
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, 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: { checked } }) => onBlur(id, checked);
const _onFocus = ({ target: { checked } }) => onFocus(id, checked);
const description = options.description || schema.description;
return (_jsxs(Form.Group, { className: `checkbox ${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: 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