UNPKG

@aokiapp/rjsf-mantine-theme

Version:

Mantine theme, fields and widgets for react-jsonschema-form

65 lines (62 loc) 1.68 kB
import { jsx } from 'react/jsx-runtime'; import { Input, Slider } from '@mantine/core'; import { getInputProps, labelValue } from '@rjsf/utils'; import { useCallback } from 'react'; import { createErrors } from '../utils/createErrors.mjs'; import { useFieldContext } from '../templates/FieldTemplate.mjs'; function RangeWidget(props) { const { id, label, hideLabel, value, required, readonly, disabled, onChange, onChangeOverride, onBlur, autofocus, options, schema, type, rawErrors, hideError } = props; if (!id) { console.log("No id for", props); throw new Error(`no id for props ${JSON.stringify(props)}`); } const inputProps = getInputProps(schema, type, options); const _onChange = useCallback( (value2) => onChange(value2 === 0 ? options.emptyValue : value2), [onChange, options] ); const _onBlur = useCallback((value2) => onBlur(id, value2), [onBlur, id]); const { description } = useFieldContext(); return /* @__PURE__ */ jsx( Input.Wrapper, { label: labelValue(label, hideLabel), description, id, error: createErrors(rawErrors, hideError), required, className: "armt-widget-range", children: /* @__PURE__ */ jsx( Slider, { disabled: disabled || readonly, autoFocus: autofocus, value, onChange: onChangeOverride || _onChange, onChangeEnd: _onBlur, ...inputProps, step: inputProps.step === "any" ? void 0 : inputProps.step } ) } ); } export { RangeWidget as default }; //# sourceMappingURL=RangeWidget.mjs.map