@rjsf/mui
Version:
Material UI 7 theme, fields and widgets for react-jsonschema-form
26 lines • 2.27 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import Checkbox from '@mui/material/Checkbox';
import FormControlLabel from '@mui/material/FormControlLabel';
import { ariaDescribedByIds, descriptionId, getTemplate, labelValue, schemaRequiresTrueValue, } from '@rjsf/utils';
import { getMuiProps } 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 { schema, id, htmlName, value, disabled, readonly, label = '', hideLabel, autofocus, onChange, onBlur, onFocus, registry, options, uiSchema, } = props;
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 = (_, checked) => onChange(checked);
const _onBlur = () => onBlur(id, value);
const _onFocus = () => onFocus(id, value);
const description = (_a = options.description) !== null && _a !== void 0 ? _a : schema.description;
const { rjsfSlotProps: muiSlotProps, ...otherMuiProps } = getMuiProps(options);
return (_jsxs(_Fragment, { children: [!hideLabel && description && (_jsx(DescriptionFieldTemplate, { id: descriptionId(id), description: description, schema: schema, uiSchema: uiSchema, registry: registry })), _jsx(FormControlLabel, { ...otherMuiProps, ...muiSlotProps === null || muiSlotProps === void 0 ? void 0 : muiSlotProps.formControlLabel, control: _jsx(Checkbox, { id: id, name: htmlName || id, checked: typeof value === 'undefined' ? false : Boolean(value), required: required, disabled: disabled || readonly, autoFocus: autofocus, onChange: _onChange, onBlur: _onBlur, onFocus: _onFocus, "aria-describedby": ariaDescribedByIds(id), ...muiSlotProps === null || muiSlotProps === void 0 ? void 0 : muiSlotProps.checkbox }), label: labelValue(label, hideLabel, false) })] }));
}
//# sourceMappingURL=CheckboxWidget.js.map