import { useCallback } from 'react'; import { getWidget, getUiOptions, optionsList, hasWidget, FieldProps, FormContextType, RJSFSchema, StrictRJSFSchema, ErrorSchema, } from '@rjsf/utils'; /** The `StringField` component is used to render a schema field that represents a string type * * @param props - The `FieldProps` for this template */ function StringField( props: FieldProps, ) { const { schema, name, uiSchema, fieldPathId, formData, required, disabled = false, readonly = false, autofocus = false, onChange, onBlur, onFocus, registry, rawErrors, hideError, title, } = props; const { title: schemaTitle, format } = schema; const { widgets, schemaUtils, globalUiOptions } = registry; const enumOptions = schemaUtils.isSelect(schema) ? optionsList(schema, uiSchema) : undefined; let defaultWidget = enumOptions ? 'select' : 'text'; if (format && hasWidget(schema, format, widgets)) { defaultWidget = format; } const { widget = defaultWidget, placeholder = '', title: uiTitle, ...options } = getUiOptions(uiSchema); const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions); const label = uiTitle ?? title ?? schemaTitle ?? name; const Widget = getWidget(schema, widget, widgets); const onWidgetChange = useCallback( (value: T | undefined, errorSchema?: ErrorSchema, id?: string) => { // String field change passes an empty path array to the parent field which adds the appropriate path return onChange(value, fieldPathId.path, errorSchema, id); }, [onChange, fieldPathId], ); return ( ); } export default StringField;