@aokiapp/rjsf-mantine-theme
Version:
Mantine theme, fields and widgets for react-jsonschema-form
24 lines • 1.75 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { ariaDescribedByIds, labelValue, schemaRequiresTrueValue, } from '@rjsf/utils';
import { useCallback } from 'react';
import { Checkbox } from '@mantine/core';
import { createErrors } from '../utils/createErrors';
import { useFieldContext } from '../templates/FieldTemplate';
/** 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) {
const { id, value, disabled, readonly, label = '', hideLabel, autofocus, onChange, onBlur, onFocus, schema, rawErrors, hideError, } = 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 handleChange = useCallback((event) => onChange(event.target.checked), [onChange]);
const handleBlur = useCallback((event) => onBlur(id, event.target.checked), [onBlur, id]);
const handleFocus = useCallback((event) => onFocus(id, event.target.checked), [onFocus, id]);
const { description } = useFieldContext();
return (_jsx(Checkbox, { description: description, id: id, label: labelValue(label, hideLabel), required: required, disabled: disabled || readonly, autoFocus: autofocus, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, error: createErrors(rawErrors, hideError), "aria-describedby": ariaDescribedByIds(id), checked: typeof value === 'undefined' ? false : value, className: 'armt-widget-checkbox' }));
}
//# sourceMappingURL=CheckboxWidget.js.map