@aokiapp/rjsf-mantine-theme
Version:
Mantine theme, fields and widgets for react-jsonschema-form
75 lines (72 loc) • 1.99 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import { NumberInput } from '@mantine/core';
import { labelValue, ariaDescribedByIds } from '@rjsf/utils';
import { useCallback } from 'react';
import { createErrors } from '../utils/createErrors.mjs';
import { useFieldContext } from '../templates/FieldTemplate.mjs';
function UpDownWidget(props) {
const {
id,
placeholder,
label,
hideLabel,
value,
required,
readonly,
disabled,
onChange,
onChangeOverride,
onBlur,
onFocus,
autofocus,
options,
schema,
rawErrors,
className,
hideError
} = props;
if (!id) {
console.log("No id for", props);
throw new Error(`no id for props ${JSON.stringify(props)}`);
}
const overrideProps = typeof options["props"] === "object" ? options["props"] : {};
const _onChange = useCallback(
(e) => {
const callTarget = onChangeOverride || onChange;
callTarget(e);
},
[onChangeOverride, onChange]
);
const _onBlur = useCallback(({ target: { value: value2 } }) => onBlur(id, value2), [onBlur, id]);
const _onFocus = useCallback(
({ target: { value: value2 } }) => onFocus(id, value2),
[onFocus, id]
);
const { description } = useFieldContext();
const inputValue = value || value === 0 ? value : "";
return /* @__PURE__ */ jsx(
NumberInput,
{
id,
placeholder,
description,
max: schema.maximum,
min: schema.minimum,
label: labelValue(label, hideLabel, void 0),
required,
autoFocus: autofocus,
disabled: disabled || readonly,
value: inputValue,
error: createErrors(rawErrors, hideError),
onChange: _onChange,
onBlur: _onBlur,
onFocus: _onFocus,
"aria-describedby": ariaDescribedByIds(id, !!schema.examples),
className: `armt-widget-updown ${className || ""}`,
...overrideProps
},
id
);
}
export { UpDownWidget as default };
//# sourceMappingURL=UpDownWidget.mjs.map