@aokiapp/rjsf-mantine-theme
Version:
Mantine theme, fields and widgets for react-jsonschema-form
28 lines • 1.74 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { Input, Rating } from '@mantine/core';
import { 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 RatingWidget(props) {
var _a, _b, _c;
const { id, label, hideLabel, value, required, readonly, disabled, onChange, onChangeOverride, autofocus, schema, rawErrors, hideError, } = props;
if (!id) {
console.log('No id for', props);
throw new Error(`no id for props ${JSON.stringify(props)}`);
}
const mx = Math.floor((_a = schema.maximum) !== null && _a !== void 0 ? _a : 5);
const mn = Math.floor((_b = schema.minimum) !== null && _b !== void 0 ? _b : 0);
const _onChange = useCallback((value) => onChange(value - 1 + mn), [mn, onChange]);
const count = mx - mn + 1;
const frac = 1 / ((_c = schema.multipleOf) !== null && _c !== void 0 ? _c : 1);
const ival = value - mn + 1;
const { description } = useFieldContext();
return (_jsx(Input.Wrapper, { label: labelValue(label, hideLabel), description: description, id: id, error: createErrors(rawErrors, hideError), required: required, className: 'armt-widget-rating', children: _jsx(Rating, { readOnly: disabled || readonly, autoFocus: autofocus, value: ival, onChange: onChangeOverride || _onChange, count: count, fractions: frac, size: 'xl' }) }));
}
//# sourceMappingURL=RatingWidget.js.map