import { FocusEvent } from 'react'; import { ariaDescribedByIds, descriptionId, getTemplate, labelValue, WidgetProps, schemaRequiresTrueValue, StrictRJSFSchema, RJSFSchema, FormContextType, } from '@rjsf/utils'; import Form from 'react-bootstrap/Form'; export default function CheckboxWidget< T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any >(props: WidgetProps) { 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', T, S, F>( 'DescriptionFieldTemplate', registry, options ); const _onChange = ({ target: { checked } }: FocusEvent) => onChange(checked); const _onBlur = ({ target: { checked } }: FocusEvent) => onBlur(id, checked); const _onFocus = ({ target: { checked } }: FocusEvent) => onFocus(id, checked); const description = options.description || schema.description; return ( (id)} > {!hideLabel && !!description && ( (id)} description={description} schema={schema} uiSchema={uiSchema} registry={registry} /> )} ); }