import React, { useCallback } from 'react'; import { StrictRJSFSchema, RJSFSchema, FormContextType, WidgetProps, labelValue, ariaDescribedByIds, } from '@rjsf/utils'; import { Checkbox } from '@mantine/core'; import { cleanupOptions } from '../utils'; export default function CheckboxWidget< T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any >(props: WidgetProps): React.ReactElement { const { id, name, value = false, required, disabled, readonly, autofocus, label, hideLabel, rawErrors, options, onChange, onBlur, onFocus, } = props; const themeProps = cleanupOptions(options); const handleCheckboxChange = useCallback( (e: React.ChangeEvent) => { if (!disabled && !readonly && onChange) { onChange(e.currentTarget.checked); } }, [onChange, disabled, readonly] ); const handleBlur = useCallback( ({ target }: React.FocusEvent) => { if (onBlur) { onBlur(id, target.checked); } }, [onBlur, id] ); const handleFocus = useCallback( ({ target }: React.FocusEvent) => { if (onFocus) { onFocus(id, target.checked); } }, [onFocus, id] ); return ( 0 ? rawErrors.join('\n') : undefined} aria-describedby={ariaDescribedByIds(id)} {...themeProps} /> ); }