@rjsf/material-ui
Version:
Material UI 4 theme, fields and widgets for react-jsonschema-form
41 lines • 2.83 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import TextField from '@material-ui/core/TextField';
import { ariaDescribedByIds, examplesId, getInputProps, labelValue, } from '@rjsf/utils';
const TYPES_THAT_SHRINK_LABEL = ['date', 'datetime-local', 'file', 'time'];
/** The `BaseInputTemplate` is the template to use to render the basic `<input>` component for the `core` theme.
* It is used as the template for rendering many of the <input> 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(props) {
const { id, name, // remove this from textFieldProps
placeholder, required, readonly, disabled, type, label, hideLabel, hideError, value, onChange, onChangeOverride, onBlur, onFocus, autofocus, options, schema, uiSchema, rawErrors = [], formContext, registry, InputLabelProps, ...textFieldProps } = props;
const inputProps = getInputProps(schema, type, options);
// Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
const { step, min, max, ...rest } = inputProps;
const otherProps = {
inputProps: {
step,
min,
max,
...(schema.examples ? { list: examplesId(id) } : undefined),
},
...rest,
};
const _onChange = ({ target: { value } }) => onChange(value === '' ? options.emptyValue : value);
const _onBlur = ({ target }) => onBlur(id, target && target.value);
const _onFocus = ({ target }) => onFocus(id, target && target.value);
const DisplayInputLabelProps = TYPES_THAT_SHRINK_LABEL.includes(type)
? {
...InputLabelProps,
shrink: true,
}
: InputLabelProps;
return (_jsxs(_Fragment, { children: [_jsx(TextField, { id: id, name: id, placeholder: placeholder, label: labelValue(label || undefined, hideLabel, false), autoFocus: autofocus, required: required, disabled: disabled || readonly, ...otherProps, value: value || value === 0 ? value : '', error: rawErrors.length > 0, onChange: onChangeOverride || _onChange, onBlur: _onBlur, onFocus: _onFocus, InputLabelProps: DisplayInputLabelProps, ...textFieldProps, "aria-describedby": ariaDescribedByIds(id, !!schema.examples) }), Array.isArray(schema.examples) && (_jsx("datalist", { id: examplesId(id), children: schema.examples
.concat(schema.default && !schema.examples.includes(schema.default) ? [schema.default] : [])
.map((example) => {
return _jsx("option", { value: example }, example);
}) }))] }));
}
//# sourceMappingURL=BaseInputTemplate.js.map