import { ChangeEvent, FocusEvent } from 'react';
import Input from 'antd/lib/input';
import InputNumber from 'antd/lib/input-number';
import {
ariaDescribedByIds,
BaseInputTemplateProps,
examplesId,
getInputProps,
FormContextType,
GenericObjectType,
RJSFSchema,
StrictRJSFSchema,
} from '@rjsf/utils';
const INPUT_STYLE = {
width: '100%',
};
/** The `BaseInputTemplate` is the template to use to render the basic `` component for the `core` theme.
* It is used as the template for rendering many of the based widgets that differ by `type` and callbacks only.
* It can be customized/overridden for other themes or individual implementations as needed.
*
* @param props - The `WidgetProps` for this template
*/
export default function BaseInputTemplate<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: BaseInputTemplateProps) {
const {
disabled,
formContext,
id,
onBlur,
onChange,
onChangeOverride,
onFocus,
options,
placeholder,
readonly,
schema,
value,
type,
} = props;
const inputProps = getInputProps(schema, type, options, false);
const { readonlyAsDisabled = true } = formContext as GenericObjectType;
const handleNumberChange = (nextValue: number | null) => onChange(nextValue);
const handleTextChange = onChangeOverride
? onChangeOverride
: ({ target }: ChangeEvent) => onChange(target.value === '' ? options.emptyValue : target.value);
const handleBlur = ({ target }: FocusEvent) => onBlur(id, target.value);
const handleFocus = ({ target }: FocusEvent) => onFocus(id, target.value);
const input =
inputProps.type === 'number' || inputProps.type === 'integer' ? (
(id) : undefined}
{...inputProps}
value={value}
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
/>
) : (
(id) : undefined}
{...inputProps}
value={value}
aria-describedby={ariaDescribedByIds(id, !!schema.examples)}
/>
);
return (
<>
{input}
{Array.isArray(schema.examples) && (
)}
>
);
}