UNPKG

@aokiapp/rjsf-mantine-theme

Version:

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

1 lines 4.52 kB
{"version":3,"file":"RadioWidget.mjs","sources":["../../src/widgets/RadioWidget.tsx"],"sourcesContent":["import {\n ariaDescribedByIds,\n enumOptionsValueForIndex,\n optionId,\n FormContextType,\n RJSFSchema,\n StrictRJSFSchema,\n WidgetProps,\n enumOptionsIndexForValue,\n labelValue,\n} from '@rjsf/utils';\n\nimport { Flex, Radio } from '@mantine/core';\nimport { createErrors } from '../utils/createErrors';\n\n/** The `RadioWidget` is a widget for rendering a radio group.\n * It is typically used with a string property constrained with enum options.\n *\n * @param props - The `WidgetProps` for this component\n */\nexport default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(\n props: WidgetProps<T, S, F>,\n) {\n const {\n id,\n value,\n required,\n disabled,\n readonly,\n hideLabel,\n label,\n onChange,\n onBlur,\n onFocus,\n options,\n rawErrors,\n hideError,\n schema,\n } = props;\n const { enumOptions, enumDisabled, emptyValue, inline } = options;\n const _onChange = (nextValue: any) => {\n onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));\n };\n\n const _onBlur = () => onBlur(id, value);\n const _onFocus = () => onFocus(id, value);\n\n const description = options.description || schema.description;\n return (\n <Radio.Group\n name={id}\n label={labelValue(label || undefined, hideLabel, false)}\n description={description}\n required={required}\n value={enumOptionsIndexForValue<S>(value, enumOptions, false) as string | undefined} // since I set multiple to false, this should not be an array, so I need to cast and suppress the error\n onChange={_onChange}\n onBlur={_onBlur}\n onFocus={_onFocus}\n error={createErrors<T>(rawErrors, hideError)}\n className='armt-widget-radio'\n >\n <Flex direction={inline ? 'row' : 'column'} m='xs' gap='sm'>\n {enumOptions?.map((option, index) => {\n const itemDisabled = enumDisabled && enumDisabled.indexOf(option.value) !== -1;\n return (\n <Radio\n id={optionId(id, index)}\n name={id}\n label={option.label}\n value={enumOptionsIndexForValue<S>(option.value, enumOptions, false) as string}\n key={index}\n disabled={disabled || itemDisabled || readonly}\n aria-describedby={ariaDescribedByIds<T>(id)}\n description={option.schema?.description}\n />\n );\n })}\n </Flex>\n </Radio.Group>\n );\n}\n"],"names":[],"mappings":";;;;;AAWe,SAAS,WAAW,CAAC,KAAK,EAAE;AAC3C,EAAE,MAAM;AACR,IAAI,EAAE;AACN,IAAI,KAAK;AACT,IAAI,QAAQ;AACZ,IAAI,QAAQ;AACZ,IAAI,QAAQ;AACZ,IAAI,SAAS;AACb,IAAI,KAAK;AACT,IAAI,QAAQ;AACZ,IAAI,MAAM;AACV,IAAI,OAAO;AACX,IAAI,OAAO;AACX,IAAI,SAAS;AACb,IAAI,SAAS;AACb,IAAI,MAAM;AACV,GAAG,GAAG,KAAK,CAAC;AACZ,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;AACpE,EAAE,MAAM,SAAS,GAAG,CAAC,SAAS,KAAK;AACnC,IAAI,QAAQ,CAAC,wBAAwB,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;AAC3E,GAAG,CAAC;AACJ,EAAE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAC1C,EAAE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;AAC5C,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC;AAChE,EAAE,uBAAuB,GAAG;AAC5B,IAAI,KAAK,CAAC,KAAK;AACf,IAAI;AACJ,MAAM,IAAI,EAAE,EAAE;AACd,MAAM,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC;AAC1D,MAAM,WAAW;AACjB,MAAM,QAAQ;AACd,MAAM,KAAK,EAAE,wBAAwB,CAAC,KAAK,EAAE,WAAW,EAA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