UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

66 lines (61 loc) 1.72 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var core = require('@mantine/core'); var utils = require('@rjsf/utils'); var react = require('react'); var createErrors = require('../utils/createErrors.cjs'); var FieldTemplate = require('../templates/FieldTemplate.cjs'); function RatingWidget(props) { 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(schema.maximum ?? 5); const mn = Math.floor(schema.minimum ?? 0); const _onChange = react.useCallback((value2) => onChange(value2 - 1 + mn), [mn, onChange]); const count = mx - mn + 1; const frac = 1 / (schema.multipleOf ?? 1); const ival = value - mn + 1; const { description } = FieldTemplate.useFieldContext(); return /* @__PURE__ */ jsxRuntime.jsx( core.Input.Wrapper, { label: utils.labelValue(label, hideLabel), description, id, error: createErrors.createErrors(rawErrors, hideError), required, className: "armt-widget-rating", children: /* @__PURE__ */ jsxRuntime.jsx( core.Rating, { readOnly: disabled || readonly, autoFocus: autofocus, value: ival, onChange: onChangeOverride || _onChange, count, fractions: frac, size: "xl" } ) } ); } exports.default = RatingWidget; //# sourceMappingURL=RatingWidget.cjs.map