UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

62 lines (59 loc) 1.59 kB
import { 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.mjs'; import { useFieldContext } from '../templates/FieldTemplate.mjs'; 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 = 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 } = useFieldContext(); return /* @__PURE__ */ jsx( Input.Wrapper, { label: labelValue(label, hideLabel), description, id, error: createErrors(rawErrors, hideError), required, className: "armt-widget-rating", children: /* @__PURE__ */ jsx( Rating, { readOnly: disabled || readonly, autoFocus: autofocus, value: ival, onChange: onChangeOverride || _onChange, count, fractions: frac, size: "xl" } ) } ); } export { RatingWidget as default }; //# sourceMappingURL=RatingWidget.mjs.map