import { ChangeEvent, FocusEvent } from 'react'; import Form from 'react-bootstrap/Form'; import { ariaDescribedByIds, BaseInputTemplateProps, examplesId, FormContextType, getInputProps, RJSFSchema, StrictRJSFSchema, } from '@rjsf/utils'; export default function BaseInputTemplate< T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any >({ id, placeholder, required, readonly, disabled, type, value, onChange, onChangeOverride, onBlur, onFocus, autofocus, options, schema, rawErrors = [], children, extraProps, }: BaseInputTemplateProps) { const inputProps = { ...extraProps, ...getInputProps(schema, type, options), }; const _onChange = ({ target: { value } }: ChangeEvent) => onChange(value === '' ? options.emptyValue : value); const _onBlur = ({ target: { value } }: FocusEvent) => onBlur(id, value); const _onFocus = ({ target: { value } }: FocusEvent) => onFocus(id, value); // const classNames = [rawErrors.length > 0 ? "is-invalid" : "", type === 'file' ? 'custom-file-label': ""] return ( <> 0 ? 'is-invalid' : ''} list={schema.examples ? examplesId(id) : undefined} {...inputProps} value={value || value === 0 ? value : ''} onChange={onChangeOverride || _onChange} onBlur={_onBlur} onFocus={_onFocus} aria-describedby={ariaDescribedByIds(id, !!schema.examples)} /> {children} {Array.isArray(schema.examples) ? ( (id)}> {(schema.examples as string[]) .concat(schema.default && !schema.examples.includes(schema.default) ? ([schema.default] as string[]) : []) .map((example: any) => { return ) : null} ); }