UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

24 lines 1.66 kB
import { jsx as _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'; import { useFieldContext } from '../templates/FieldTemplate'; /** The `RangeWidget` component uses the `BaseInputTemplate` changing the type to `range` and wrapping the result * in a div, with the value along side it. * * @param props - The `WidgetProps` for this component */ export default 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((value) => onChange(value === 0 ? options.emptyValue : value), [onChange, options]); const _onBlur = useCallback((value) => onBlur(id, value), [onBlur, id]); const { description } = useFieldContext(); return (_jsx(Input.Wrapper, { label: labelValue(label, hideLabel), description: description, id: id, error: createErrors(rawErrors, hideError), required: required, className: 'armt-widget-range', children: _jsx(Slider, { disabled: disabled || readonly, autoFocus: autofocus, value: value, onChange: onChangeOverride || _onChange, onChangeEnd: _onBlur, ...inputProps, step: inputProps.step === 'any' ? undefined : inputProps.step }) })); } //# sourceMappingURL=RangeWidget.js.map