UNPKG

@rjsf/semantic-ui

Version:

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

33 lines 2.21 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { ariaDescribedByIds, descriptionId, getTemplate, labelValue, schemaRequiresTrueValue, } from '@rjsf/utils'; import { Form } from 'semantic-ui-react'; import { getSemanticProps } from '../util.js'; /** The `CheckBoxWidget` is a widget for rendering boolean properties. * It is typically used to represent a boolean. * * @param props - The `WidgetProps` for this component */ export default function CheckboxWidget(props) { var _a; const { id, value, disabled, readonly, label = '', hideLabel, autofocus, onChange, onBlur, options, onFocus, formContext, schema, uiSchema, rawErrors = [], registry, } = props; const semanticProps = getSemanticProps({ options, formContext, uiSchema, defaultSchemaProps: { inverted: 'false', }, }); const DescriptionFieldTemplate = getTemplate('DescriptionFieldTemplate', registry, options); // 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 _onChange = (_, data) => onChange && onChange(data.checked); const _onBlur = () => onBlur && onBlur(id, value); const _onFocus = () => onFocus && onFocus(id, value); const checked = value == 'true' || value == true; 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(Form.Checkbox, { id: id, name: id, disabled: disabled || readonly, autoFocus: autofocus, ...semanticProps, checked: typeof value === 'undefined' ? false : checked, error: rawErrors.length > 0, onChange: _onChange, onBlur: _onBlur, onFocus: _onFocus, required: required, label: labelValue(label, hideLabel, false), "aria-describedby": ariaDescribedByIds(id) })] })); } //# sourceMappingURL=CheckboxWidget.js.map