@aokiapp/rjsf-mantine-theme
Version:
Mantine theme, fields and widgets for react-jsonschema-form
1 lines • 3.57 kB
Source Map (JSON)
{"version":3,"file":"RatingWidget.mjs","sources":["../../src/widgets/RatingWidget.tsx"],"sourcesContent":["import { Input, Rating } from '@mantine/core';\nimport { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps, labelValue } from '@rjsf/utils';\nimport { useCallback } from 'react';\nimport { createErrors } from '../utils/createErrors';\nimport { useFieldContext } from '../templates/FieldTemplate';\n\n/** The `RangeWidget` component uses the `BaseInputTemplate` changing the type to `range` and wrapping the result\n * in a div, with the value along side it.\n *\n * @param props - The `WidgetProps` for this component\n */\nexport default function RatingWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(\n props: WidgetProps<T, S, F>,\n) {\n const {\n id,\n label,\n hideLabel,\n value,\n required,\n readonly,\n disabled,\n onChange,\n onChangeOverride,\n autofocus,\n schema,\n rawErrors,\n hideError,\n } = props;\n\n if (!id) {\n console.log('No id for', props);\n throw new Error(`no id for props ${JSON.stringify(props)}`);\n }\n\n const mx = Math.floor(schema.maximum ?? 5);\n const mn = Math.floor(schema.minimum ?? 0);\n\n const _onChange = useCallback((value: number) => onChange(value - 1 + mn), [mn, onChange]);\n\n const count = mx - mn + 1;\n const frac = 1 / (schema.multipleOf ?? 1);\n\n const ival = value - mn + 1;\n\n const { description } = useFieldContext();\n return (\n <Input.Wrapper\n label={labelValue(label, hideLabel)}\n description={description}\n id={id}\n error={createErrors<T>(rawErrors, hideError)}\n required={required}\n className='armt-widget-rating'\n >\n <Rating\n readOnly={disabled || readonly}\n autoFocus={autofocus}\n value={ival}\n onChange={onChangeOverride || _onChange}\n count={count}\n fractions={frac}\n size='xl'\n />\n </Input.Wrapper>\n );\n}\n"],"names":[],"mappings":";;;;;;;AAOe,SAAS,YAAY,CAAC,KAAK,EAAE;AAC5C,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,SAAS;AAC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