@teknim/rjsf-mantine
Version:
Mantine theme, fields and widgets for react-jsonschema-form
22 lines • 2.81 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { ariaDescribedByIds, examplesId, getInputProps, labelValue, } from '@rjsf/utils';
import { TextInput, NumberInput } from '@mantine/core';
import { cleanupOptions } from '../utils';
export default function BaseInputTemplate(props) {
const { id, type, schema, value, placeholder, required, disabled, readonly, autofocus, label, hideLabel, onChange, onChangeOverride, onBlur, onFocus, options, rawErrors, } = props;
const inputProps = getInputProps(schema, type, options, false);
const themeProps = cleanupOptions(options);
const handleNumberChange = (value) => onChange(value);
const handleChange = onChangeOverride
? onChangeOverride
: (e) => { var _a; return onChange(e.target.value === '' ? (_a = options.emptyValue) !== null && _a !== void 0 ? _a : '' : e.target.value); };
const handleBlur = (e) => onBlur(id, e.target && e.target.value);
const handleFocus = (e) => onFocus(id, e.target && e.target.value);
const input = inputProps.type === 'number' || inputProps.type === 'integer' ? (_jsx(NumberInput, { id: id, name: id, label: labelValue(label || undefined, hideLabel, false), required: required, autoFocus: autofocus, disabled: disabled || readonly, onBlur: !readonly ? handleBlur : undefined, onChange: !readonly ? handleNumberChange : undefined, onFocus: !readonly ? handleFocus : undefined, placeholder: placeholder, error: rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined, list: schema.examples ? examplesId(id) : undefined, ...inputProps, ...themeProps, step: typeof inputProps.step === 'number' ? inputProps.step : 1, type: 'text', value: value, "aria-describedby": ariaDescribedByIds(id, !!schema.examples) })) : (_jsx(TextInput, { id: id, name: id, label: labelValue(label || undefined, hideLabel, false), required: required, autoFocus: autofocus, disabled: disabled || readonly, onBlur: !readonly ? handleBlur : undefined, onChange: !readonly ? handleChange : undefined, onFocus: !readonly ? handleFocus : undefined, placeholder: placeholder, error: rawErrors && rawErrors.length > 0 ? rawErrors.join('\n') : undefined, list: schema.examples ? examplesId(id) : undefined, ...inputProps, ...themeProps, value: value, "aria-describedby": ariaDescribedByIds(id, !!schema.examples) }));
return (_jsxs(_Fragment, { children: [input, 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