UNPKG

@aokiapp/rjsf-mantine-theme

Version:

Mantine theme, fields and widgets for react-jsonschema-form

1 lines 3.7 kB
{"version":3,"file":"CheckboxWidget.mjs","sources":["../../src/widgets/CheckboxWidget.tsx"],"sourcesContent":["import {\n ariaDescribedByIds,\n labelValue,\n schemaRequiresTrueValue,\n FormContextType,\n RJSFSchema,\n StrictRJSFSchema,\n WidgetProps,\n} from '@rjsf/utils';\nimport { ChangeEvent, FocusEvent, useCallback } from 'react';\nimport { Checkbox } from '@mantine/core';\nimport { createErrors } from '../utils/createErrors';\nimport { useFieldContext } from '../templates/FieldTemplate';\n\n/** The `CheckBoxWidget` is a widget for rendering boolean properties.\n * It is typically used to represent a boolean.\n *\n * @param props - The `WidgetProps` for this component\n */\nexport default function CheckboxWidget<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any,\n>(props: WidgetProps<T, S, F>) {\n const {\n id,\n value,\n disabled,\n readonly,\n label = '',\n hideLabel,\n autofocus,\n onChange,\n onBlur,\n onFocus,\n schema,\n rawErrors,\n hideError,\n } = props;\n\n // Because an unchecked checkbox will cause html5 validation to fail, only add\n // the \"required\" attribute if the field value must be \"true\", due to the\n // \"const\" or \"enum\" keywords\n const required = schemaRequiresTrueValue<S>(schema);\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => onChange(event.target.checked),\n [onChange],\n );\n\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLInputElement>) => onBlur(id, event.target.checked),\n [onBlur, id],\n );\n\n const handleFocus = useCallback(\n (event: FocusEvent<HTMLInputElement>) => onFocus(id, event.target.checked),\n [onFocus, id],\n );\n\n const { description } = useFieldContext();\n return (\n <Checkbox\n description={description}\n id={id}\n label={labelValue(label, hideLabel)}\n required={required}\n disabled={disabled || readonly}\n autoFocus={autofocus}\n onChange={handleChange}\n onBlur={handleBlur}\n onFocus={handleFocus}\n error={createErrors<T>(rawErrors, hideError)}\n aria-describedby={ariaDescribedByIds<T>(id)}\n checked={typ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