@chobantonov/jsonforms-react-antd-renderers 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +103 -2
- package/lib/additional/LabelRenderer.d.ts +13 -0
- package/lib/additional/ListWithDetailMasterItem.d.ts +9 -0
- package/lib/additional/ListWithDetailRenderer.d.ts +8 -0
- package/lib/additional/index.d.ts +4 -0
- package/lib/additional/unwrapped.d.ts +6 -0
- package/lib/antd-controls/AntdCheckbox.d.ts +10 -0
- package/lib/antd-controls/AntdClearValueButton.d.ts +44 -0
- package/lib/antd-controls/AntdClearableInput.d.ts +19 -0
- package/lib/antd-controls/AntdDatePicker.d.ts +7 -0
- package/lib/antd-controls/AntdDateTimePicker.d.ts +7 -0
- package/lib/antd-controls/AntdFile.d.ts +7 -0
- package/lib/antd-controls/AntdInputInteger.d.ts +3 -0
- package/lib/antd-controls/AntdInputNumber.d.ts +3 -0
- package/lib/antd-controls/AntdInputNumberFormat.d.ts +6 -0
- package/lib/antd-controls/AntdInputText.d.ts +6 -0
- package/lib/antd-controls/AntdNumericInput.d.ts +9 -0
- package/lib/antd-controls/AntdOtp.d.ts +33 -0
- package/lib/antd-controls/AntdPassword.d.ts +6 -0
- package/lib/antd-controls/AntdRadioGroup.d.ts +6 -0
- package/lib/antd-controls/AntdRevealButton.d.ts +32 -0
- package/lib/antd-controls/AntdSelect.d.ts +7 -0
- package/lib/antd-controls/AntdSlider.d.ts +21 -0
- package/lib/antd-controls/AntdTimePicker.d.ts +6 -0
- package/lib/antd-controls/AntdToggle.d.ts +6 -0
- package/lib/antd-controls/FileFeedback.d.ts +6 -0
- package/lib/antd-controls/index.d.ts +18 -0
- package/lib/antd-controls/useTemporalPicker.d.ts +49 -0
- package/lib/cells/AntdCompositeCell.d.ts +8 -0
- package/lib/cells/BooleanCell.d.ts +6 -0
- package/lib/cells/BooleanToggleCell.d.ts +5 -0
- package/lib/cells/CompositeDetailDialog.d.ts +15 -0
- package/lib/cells/CustomizableCells.d.ts +9 -0
- package/lib/cells/DateCell.d.ts +6 -0
- package/lib/cells/EnumCell.d.ts +11 -0
- package/lib/cells/IntegerCell.d.ts +6 -0
- package/lib/cells/NumberCell.d.ts +10 -0
- package/lib/cells/NumberFormatCell.d.ts +10 -0
- package/lib/cells/OneOfEnumCell.d.ts +11 -0
- package/lib/cells/PasswordCell.d.ts +5 -0
- package/lib/cells/TextCell.d.ts +10 -0
- package/lib/cells/TimeCell.d.ts +6 -0
- package/lib/cells/index.d.ts +14 -0
- package/lib/complex/AdditionalProperties.d.ts +4 -0
- package/lib/complex/AnyOfRenderer.d.ts +31 -0
- package/lib/complex/ArrayControlRenderer.d.ts +8 -0
- package/lib/complex/ChipsControl.d.ts +22 -0
- package/lib/complex/CollectionPager.d.ts +5 -0
- package/lib/complex/DataCell.d.ts +16 -0
- package/lib/complex/DeleteDialog.d.ts +14 -0
- package/lib/complex/DetailModal.d.ts +6 -0
- package/lib/complex/EnumArrayRenderer.d.ts +6 -0
- package/lib/complex/ErrorFeedback.d.ts +6 -0
- package/lib/complex/MixedRenderer.d.ts +6 -0
- package/lib/complex/MultiSelectControl.d.ts +17 -0
- package/lib/complex/ObjectRenderer.d.ts +5 -0
- package/lib/complex/OneOfRenderer.d.ts +6 -0
- package/lib/complex/OneOfTabRenderer.d.ts +5 -0
- package/lib/complex/RecursiveTreeRenderer.d.ts +4 -0
- package/lib/complex/RowDetailFrame.d.ts +10 -0
- package/lib/complex/ScalarCompositionRenderer.d.ts +4 -0
- package/lib/complex/TabSwitchConfirmDialog.d.ts +9 -0
- package/lib/complex/TableControl.d.ts +9 -0
- package/lib/complex/TableToolbar.d.ts +21 -0
- package/lib/complex/TupleAdditionalItems.d.ts +13 -0
- package/lib/complex/TupleControlRenderer.d.ts +6 -0
- package/lib/complex/TupleField.d.ts +4 -0
- package/lib/complex/ValidationIcon.d.ts +8 -0
- package/lib/complex/additionalProperties/AntdAdditionalPropertyActions.d.ts +9 -0
- package/lib/complex/additionalProperties/AntdAdditionalPropertyRenameDialog.d.ts +11 -0
- package/lib/complex/index.d.ts +20 -0
- package/lib/complex/mixed/AntdJsonTypeIcon.d.ts +4 -0
- package/lib/complex/mixed/AntdMixedNavigationContext.d.ts +5 -0
- package/lib/complex/mixed/AntdMixedSplitPane.d.ts +5 -0
- package/lib/complex/mixed/AntdMixedTree.d.ts +15 -0
- package/lib/complex/mixed/AntdMixedTypeSelector.d.ts +12 -0
- package/lib/complex/mixed/AntdNestedMixedNavigation.d.ts +7 -0
- package/lib/complex/mixed/mixedTree.d.ts +2 -0
- package/lib/complex/unwrapped.d.ts +10 -0
- package/lib/controls/AnyOfStringOrEnumControl.d.ts +9 -0
- package/lib/controls/BooleanControl.d.ts +6 -0
- package/lib/controls/BooleanToggleControl.d.ts +6 -0
- package/lib/controls/ChoiceCards.d.ts +1 -0
- package/lib/controls/DateControl.d.ts +6 -0
- package/lib/controls/DateTimeControl.d.ts +6 -0
- package/lib/controls/EnumControl.d.ts +7 -0
- package/lib/controls/FileControl.d.ts +7 -0
- package/lib/controls/InputControl.d.ts +6 -0
- package/lib/controls/IntegerControl.d.ts +6 -0
- package/lib/controls/NativeControl.d.ts +6 -0
- package/lib/controls/NumberControl.d.ts +6 -0
- package/lib/controls/OneOfEnumControl.d.ts +7 -0
- package/lib/controls/OneOfRadioGroupControl.d.ts +6 -0
- package/lib/controls/PasswordControl.d.ts +18 -0
- package/lib/controls/PasswordOtpControl.d.ts +38 -0
- package/lib/controls/RadioGroup.d.ts +3 -0
- package/lib/controls/RadioGroupControl.d.ts +6 -0
- package/lib/controls/SliderControl.d.ts +6 -0
- package/lib/controls/TextControl.d.ts +6 -0
- package/lib/controls/TimeControl.d.ts +6 -0
- package/lib/controls/index.d.ts +20 -0
- package/lib/controls/unwrapped.d.ts +19 -0
- package/lib/index.d.ts +50 -0
- package/lib/jsonforms-react-antd.cjs.js +39 -0
- package/lib/jsonforms-react-antd.cjs.js.map +1 -0
- package/lib/jsonforms-react-antd.esm.js +4235 -0
- package/lib/jsonforms-react-antd.esm.js.map +1 -0
- package/lib/layouts/ArrayLayout.d.ts +5 -0
- package/lib/layouts/ArrayLayoutRenderer.d.ts +8 -0
- package/lib/layouts/ArrayPanel.d.ts +7 -0
- package/lib/layouts/ArrayToolbar.d.ts +17 -0
- package/lib/layouts/CategorizationAccordionLayout.d.ts +21 -0
- package/lib/layouts/CategorizationLayout.d.ts +14 -0
- package/lib/layouts/CategorizationStepperLayout.d.ts +10 -0
- package/lib/layouts/CategoryHeader.d.ts +39 -0
- package/lib/layouts/ContainerIndicator.d.ts +37 -0
- package/lib/layouts/GroupLayout.d.ts +6 -0
- package/lib/layouts/HorizontalLayout.d.ts +10 -0
- package/lib/layouts/ValidationIndicator.d.ts +13 -0
- package/lib/layouts/VerticalLayout.d.ts +10 -0
- package/lib/layouts/arrayTitle.d.ts +2 -0
- package/lib/layouts/index.d.ts +11 -0
- package/lib/layouts/unwrapped.d.ts +11 -0
- package/lib/locale/index.d.ts +1 -0
- package/lib/util/additionalPropertyName.d.ts +2 -0
- package/lib/util/arrayChoices.d.ts +2 -0
- package/lib/util/categoryState.d.ts +3 -0
- package/lib/util/cellFrame.d.ts +27 -0
- package/lib/util/cellMode.d.ts +29 -0
- package/lib/util/clearAffordance.d.ts +1 -0
- package/lib/util/combinators.d.ts +1 -0
- package/lib/util/compositeActions.d.ts +1 -0
- package/lib/util/compositeSummary.d.ts +1 -0
- package/lib/util/configNamespaces.d.ts +1 -0
- package/lib/util/confirmation.d.ts +2 -0
- package/lib/util/datejs.d.ts +4 -0
- package/lib/util/debounce.d.ts +1 -0
- package/lib/util/dynamicProperties.d.ts +1 -0
- package/lib/util/focus.d.ts +1 -0
- package/lib/util/groupState.d.ts +1 -0
- package/lib/util/index.d.ts +25 -0
- package/lib/util/layout.d.ts +18 -0
- package/lib/util/layoutSizing.d.ts +6 -0
- package/lib/util/literalPropertySchema.d.ts +1 -0
- package/lib/util/locale.d.ts +68 -0
- package/lib/util/numeric.d.ts +1 -0
- package/lib/util/pendingChanges.d.ts +2 -0
- package/lib/util/preTouchErrors.d.ts +2 -0
- package/lib/util/rendererLocale.d.ts +2 -0
- package/lib/util/temporalBounds.d.ts +35 -0
- package/lib/util/temporalFormats.d.ts +26 -0
- package/lib/util/theme.d.ts +9 -0
- package/lib/util/translate.d.ts +1 -0
- package/lib/util/tuple.d.ts +2 -0
- package/lib/util/useConfirmation.d.ts +7 -0
- package/lib/util/validationIndicator.d.ts +2 -0
- package/lib/util/visuallyHidden.d.ts +1 -0
- package/package.json +89 -3
- package/src/additional/LabelRenderer.tsx +21 -0
- package/src/additional/ListWithDetailMasterItem.tsx +124 -0
- package/src/additional/ListWithDetailRenderer.tsx +243 -0
- package/src/additional/index.ts +14 -0
- package/src/additional/unwrapped.ts +8 -0
- package/src/antd-controls/AntdCheckbox.tsx +56 -0
- package/src/antd-controls/AntdClearValueButton.tsx +96 -0
- package/src/antd-controls/AntdClearableInput.tsx +63 -0
- package/src/antd-controls/AntdDatePicker.tsx +26 -0
- package/src/antd-controls/AntdDateTimePicker.tsx +31 -0
- package/src/antd-controls/AntdFile.tsx +395 -0
- package/src/antd-controls/AntdInputInteger.tsx +10 -0
- package/src/antd-controls/AntdInputNumber.tsx +10 -0
- package/src/antd-controls/AntdInputNumberFormat.tsx +63 -0
- package/src/antd-controls/AntdInputText.tsx +124 -0
- package/src/antd-controls/AntdNumericInput.tsx +83 -0
- package/src/antd-controls/AntdOtp.tsx +132 -0
- package/src/antd-controls/AntdPassword.tsx +106 -0
- package/src/antd-controls/AntdRadioGroup.tsx +60 -0
- package/src/antd-controls/AntdRevealButton.tsx +74 -0
- package/src/antd-controls/AntdSelect.tsx +113 -0
- package/src/antd-controls/AntdSlider.tsx +114 -0
- package/src/antd-controls/AntdTimePicker.tsx +25 -0
- package/src/antd-controls/AntdToggle.tsx +70 -0
- package/src/antd-controls/FileFeedback.tsx +37 -0
- package/src/antd-controls/index.ts +18 -0
- package/src/antd-controls/useTemporalPicker.ts +130 -0
- package/src/cells/AntdCompositeCell.tsx +228 -0
- package/src/cells/BooleanCell.tsx +33 -0
- package/src/cells/BooleanToggleCell.tsx +38 -0
- package/src/cells/CompositeDetailDialog.tsx +100 -0
- package/src/cells/CustomizableCells.ts +9 -0
- package/src/cells/DateCell.tsx +17 -0
- package/src/cells/EnumCell.tsx +30 -0
- package/src/cells/IntegerCell.tsx +17 -0
- package/src/cells/NumberCell.tsx +20 -0
- package/src/cells/NumberFormatCell.tsx +37 -0
- package/src/cells/OneOfEnumCell.tsx +32 -0
- package/src/cells/PasswordCell.tsx +22 -0
- package/src/cells/TextCell.tsx +22 -0
- package/src/cells/TimeCell.tsx +17 -0
- package/src/cells/index.ts +40 -0
- package/src/complex/AdditionalProperties.tsx +422 -0
- package/src/complex/AnyOfRenderer.tsx +158 -0
- package/src/complex/ArrayControlRenderer.tsx +121 -0
- package/src/complex/ChipsControl.tsx +205 -0
- package/src/complex/CollectionPager.tsx +26 -0
- package/src/complex/DataCell.tsx +82 -0
- package/src/complex/DeleteDialog.tsx +44 -0
- package/src/complex/DetailModal.tsx +110 -0
- package/src/complex/EnumArrayRenderer.tsx +148 -0
- package/src/complex/ErrorFeedback.tsx +51 -0
- package/src/complex/MixedRenderer.tsx +325 -0
- package/src/complex/MultiSelectControl.tsx +205 -0
- package/src/complex/ObjectRenderer.tsx +55 -0
- package/src/complex/OneOfRenderer.tsx +299 -0
- package/src/complex/OneOfTabRenderer.tsx +123 -0
- package/src/complex/RecursiveTreeRenderer.tsx +20 -0
- package/src/complex/RowDetailFrame.tsx +99 -0
- package/src/complex/ScalarCompositionRenderer.tsx +14 -0
- package/src/complex/TabSwitchConfirmDialog.tsx +36 -0
- package/src/complex/TableControl.tsx +646 -0
- package/src/complex/TableToolbar.tsx +80 -0
- package/src/complex/TupleAdditionalItems.tsx +100 -0
- package/src/complex/TupleControlRenderer.tsx +78 -0
- package/src/complex/TupleField.tsx +44 -0
- package/src/complex/ValidationIcon.tsx +30 -0
- package/src/complex/additionalProperties/AntdAdditionalPropertyActions.tsx +56 -0
- package/src/complex/additionalProperties/AntdAdditionalPropertyRenameDialog.tsx +56 -0
- package/src/complex/index.ts +48 -0
- package/src/complex/mixed/AntdJsonTypeIcon.tsx +40 -0
- package/src/complex/mixed/AntdMixedNavigationContext.ts +8 -0
- package/src/complex/mixed/AntdMixedSplitPane.tsx +51 -0
- package/src/complex/mixed/AntdMixedTree.tsx +287 -0
- package/src/complex/mixed/AntdMixedTypeSelector.tsx +60 -0
- package/src/complex/mixed/AntdNestedMixedNavigation.tsx +39 -0
- package/src/complex/mixed/mixedTree.ts +9 -0
- package/src/complex/unwrapped.ts +15 -0
- package/src/controls/AnyOfStringOrEnumControl.tsx +123 -0
- package/src/controls/BooleanControl.tsx +17 -0
- package/src/controls/BooleanToggleControl.tsx +24 -0
- package/src/controls/ChoiceCards.tsx +13 -0
- package/src/controls/DateControl.tsx +19 -0
- package/src/controls/DateTimeControl.tsx +22 -0
- package/src/controls/EnumControl.tsx +29 -0
- package/src/controls/FileControl.tsx +44 -0
- package/src/controls/InputControl.tsx +94 -0
- package/src/controls/IntegerControl.tsx +16 -0
- package/src/controls/NativeControl.tsx +79 -0
- package/src/controls/NumberControl.tsx +18 -0
- package/src/controls/OneOfEnumControl.tsx +32 -0
- package/src/controls/OneOfRadioGroupControl.tsx +25 -0
- package/src/controls/PasswordControl.tsx +43 -0
- package/src/controls/PasswordOtpControl.tsx +61 -0
- package/src/controls/RadioGroup.tsx +8 -0
- package/src/controls/RadioGroupControl.tsx +21 -0
- package/src/controls/SliderControl.tsx +19 -0
- package/src/controls/TextControl.tsx +17 -0
- package/src/controls/TimeControl.tsx +20 -0
- package/src/controls/index.ts +69 -0
- package/src/controls/unwrapped.ts +35 -0
- package/src/index.ts +267 -0
- package/src/layouts/ArrayLayout.tsx +435 -0
- package/src/layouts/ArrayLayoutRenderer.tsx +54 -0
- package/src/layouts/ArrayPanel.tsx +51 -0
- package/src/layouts/ArrayToolbar.tsx +67 -0
- package/src/layouts/CategorizationAccordionLayout.tsx +217 -0
- package/src/layouts/CategorizationLayout.tsx +149 -0
- package/src/layouts/CategorizationStepperLayout.tsx +164 -0
- package/src/layouts/CategoryHeader.tsx +107 -0
- package/src/layouts/ContainerIndicator.tsx +83 -0
- package/src/layouts/GroupLayout.tsx +307 -0
- package/src/layouts/HorizontalLayout.tsx +50 -0
- package/src/layouts/ValidationIndicator.tsx +43 -0
- package/src/layouts/VerticalLayout.tsx +50 -0
- package/src/layouts/arrayTitle.tsx +30 -0
- package/src/layouts/index.ts +35 -0
- package/src/layouts/unwrapped.ts +17 -0
- package/src/locale/index.ts +1 -0
- package/src/util/additionalPropertyName.ts +11 -0
- package/src/util/arrayChoices.ts +21 -0
- package/src/util/categoryState.ts +17 -0
- package/src/util/cellFrame.tsx +52 -0
- package/src/util/cellMode.tsx +145 -0
- package/src/util/clearAffordance.ts +2 -0
- package/src/util/combinators.ts +6 -0
- package/src/util/compositeActions.ts +2 -0
- package/src/util/compositeSummary.ts +2 -0
- package/src/util/configNamespaces.ts +4 -0
- package/src/util/confirmation.ts +15 -0
- package/src/util/datejs.tsx +42 -0
- package/src/util/debounce.ts +2 -0
- package/src/util/dynamicProperties.ts +6 -0
- package/src/util/focus.ts +2 -0
- package/src/util/groupState.ts +8 -0
- package/src/util/index.ts +25 -0
- package/src/util/layout.tsx +121 -0
- package/src/util/layoutSizing.ts +33 -0
- package/src/util/literalPropertySchema.ts +2 -0
- package/src/util/locale.ts +222 -0
- package/src/util/numeric.ts +2 -0
- package/src/util/pendingChanges.tsx +6 -0
- package/src/util/preTouchErrors.ts +10 -0
- package/src/util/rendererLocale.ts +10 -0
- package/src/util/temporalBounds.ts +106 -0
- package/src/util/temporalFormats.ts +95 -0
- package/src/util/theme.ts +9 -0
- package/src/util/translate.ts +6 -0
- package/src/util/tuple.ts +16 -0
- package/src/util/uiSchemaCycle.tsx +2 -0
- package/src/util/useConfirmation.tsx +25 -0
- package/src/util/validationIndicator.ts +10 -0
- package/src/util/visuallyHidden.ts +2 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useMixedScalar } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedScalar';
|
|
2
|
+
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
3
|
+
import { AutoComplete, AutoCompleteProps, Input } from 'antd';
|
|
4
|
+
import every from 'lodash/every';
|
|
5
|
+
import isArray from 'lodash/isArray';
|
|
6
|
+
import isString from 'lodash/isString';
|
|
7
|
+
import merge from 'lodash/merge';
|
|
8
|
+
import React, { CSSProperties } from 'react';
|
|
9
|
+
import { useDebouncedChange, useFocus } from '../util';
|
|
10
|
+
import { AntdClearableInput } from './AntdClearableInput';
|
|
11
|
+
|
|
12
|
+
const eventToValue = (ev: any) => {
|
|
13
|
+
if (ev.target) {
|
|
14
|
+
return ev.target.value === '' ? undefined : ev.target.value;
|
|
15
|
+
}
|
|
16
|
+
return ev === '' ? undefined : ev;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type ElementType<T> = T extends (infer U)[] ? U : never;
|
|
20
|
+
type AutoCompleteOption = ElementType<AutoCompleteProps['options']>;
|
|
21
|
+
|
|
22
|
+
export const AntdInputText = React.memo(function AntdInputText(
|
|
23
|
+
props: CellProps &
|
|
24
|
+
WithClassname & {
|
|
25
|
+
inputProps?: React.ComponentProps<
|
|
26
|
+
| typeof Input
|
|
27
|
+
| typeof Input.TextArea
|
|
28
|
+
| typeof Input.Password
|
|
29
|
+
| typeof AutoComplete
|
|
30
|
+
>;
|
|
31
|
+
},
|
|
32
|
+
) {
|
|
33
|
+
const [focused, onFocus, onBlur] = useFocus();
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
data,
|
|
37
|
+
config,
|
|
38
|
+
className,
|
|
39
|
+
id,
|
|
40
|
+
enabled,
|
|
41
|
+
uischema,
|
|
42
|
+
path,
|
|
43
|
+
handleChange: originalHandleChange,
|
|
44
|
+
schema,
|
|
45
|
+
inputProps,
|
|
46
|
+
} = props;
|
|
47
|
+
const keepEmptyString = useMixedScalar(path);
|
|
48
|
+
const handleChange = React.useCallback(
|
|
49
|
+
(target: string, value: any) =>
|
|
50
|
+
originalHandleChange(
|
|
51
|
+
target,
|
|
52
|
+
keepEmptyString && value === undefined ? '' : value,
|
|
53
|
+
),
|
|
54
|
+
[originalHandleChange, keepEmptyString],
|
|
55
|
+
);
|
|
56
|
+
const maxLength = schema.maxLength;
|
|
57
|
+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
58
|
+
|
|
59
|
+
const [inputText, onChange, onClear] = useDebouncedChange(
|
|
60
|
+
handleChange,
|
|
61
|
+
'',
|
|
62
|
+
data,
|
|
63
|
+
path,
|
|
64
|
+
eventToValue,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
let InputComponent: React.ComponentType<any> = Input;
|
|
68
|
+
|
|
69
|
+
const specificProps: Record<string, any> = {};
|
|
70
|
+
|
|
71
|
+
const suggestions = appliedUiSchemaOptions?.suggestion;
|
|
72
|
+
|
|
73
|
+
if (isArray(suggestions) && every(suggestions, isString)) {
|
|
74
|
+
const options: AutoCompleteOption[] = (suggestions as string[]).map(
|
|
75
|
+
(suggestion) => ({ value: suggestion }),
|
|
76
|
+
);
|
|
77
|
+
InputComponent = AutoComplete;
|
|
78
|
+
|
|
79
|
+
(specificProps as AutoCompleteProps).options = options;
|
|
80
|
+
(specificProps as AutoCompleteProps).filterOption = true;
|
|
81
|
+
(specificProps as AutoCompleteProps).popupMatchSelectWidth = true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const inputStyle: CSSProperties = { width: '100%' };
|
|
85
|
+
|
|
86
|
+
if (appliedUiSchemaOptions.multi) {
|
|
87
|
+
inputStyle.resize = 'vertical';
|
|
88
|
+
inputStyle.overflow = 'auto';
|
|
89
|
+
InputComponent = Input.TextArea;
|
|
90
|
+
|
|
91
|
+
specificProps.rows = 5;
|
|
92
|
+
specificProps.autoSize = { minRows: 5, maxRows: 5 };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<AntdClearableInput
|
|
97
|
+
clearable={appliedUiSchemaOptions.clearable !== false}
|
|
98
|
+
data={data}
|
|
99
|
+
enabled={enabled}
|
|
100
|
+
onClear={onClear}
|
|
101
|
+
>
|
|
102
|
+
<InputComponent
|
|
103
|
+
value={inputText}
|
|
104
|
+
onChange={onChange}
|
|
105
|
+
className={className}
|
|
106
|
+
id={id}
|
|
107
|
+
disabled={!enabled}
|
|
108
|
+
autoFocus={appliedUiSchemaOptions.focus}
|
|
109
|
+
style={inputStyle}
|
|
110
|
+
maxLength={maxLength}
|
|
111
|
+
onFocus={onFocus}
|
|
112
|
+
onBlur={onBlur}
|
|
113
|
+
placeholder={appliedUiSchemaOptions.placeholder}
|
|
114
|
+
count={
|
|
115
|
+
maxLength !== undefined
|
|
116
|
+
? { max: maxLength, show: focused }
|
|
117
|
+
: undefined
|
|
118
|
+
}
|
|
119
|
+
{...specificProps}
|
|
120
|
+
{...inputProps}
|
|
121
|
+
/>
|
|
122
|
+
</AntdClearableInput>
|
|
123
|
+
);
|
|
124
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useMixedScalar } from '@chobantonov/jsonforms-react-renderer-common/mixed/mixedScalar';
|
|
3
|
+
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
4
|
+
import merge from 'lodash/merge';
|
|
5
|
+
import { InputNumber } from 'antd';
|
|
6
|
+
import { toCommittableNumber, useDebouncedChange } from '../util';
|
|
7
|
+
import { AntdClearableInput } from './AntdClearableInput';
|
|
8
|
+
import { CLEAR_OFFSET_WITH_HANDLES } from './AntdClearValueButton';
|
|
9
|
+
|
|
10
|
+
export type AntdNumericInputProps = CellProps &
|
|
11
|
+
WithClassname & {
|
|
12
|
+
inputProps?: React.ComponentProps<typeof InputNumber>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const AntdNumericInput = React.memo(function AntdNumericInput(
|
|
16
|
+
props: AntdNumericInputProps & { integerOnly?: boolean },
|
|
17
|
+
) {
|
|
18
|
+
const {
|
|
19
|
+
data,
|
|
20
|
+
className,
|
|
21
|
+
id,
|
|
22
|
+
enabled,
|
|
23
|
+
uischema,
|
|
24
|
+
path,
|
|
25
|
+
handleChange: originalHandleChange,
|
|
26
|
+
config,
|
|
27
|
+
inputProps,
|
|
28
|
+
} = props;
|
|
29
|
+
const keepSelectedType = useMixedScalar(path);
|
|
30
|
+
const handleChange = React.useCallback(
|
|
31
|
+
(target: string, value: any) =>
|
|
32
|
+
originalHandleChange(
|
|
33
|
+
target,
|
|
34
|
+
keepSelectedType && value === undefined ? 0 : value,
|
|
35
|
+
),
|
|
36
|
+
[originalHandleChange, keepSelectedType],
|
|
37
|
+
);
|
|
38
|
+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
39
|
+
const inputStyle = { width: '100%' };
|
|
40
|
+
|
|
41
|
+
const [inputValue, onChange, onClear] = useDebouncedChange(
|
|
42
|
+
handleChange,
|
|
43
|
+
keepSelectedType ? 0 : '',
|
|
44
|
+
data,
|
|
45
|
+
path,
|
|
46
|
+
toCommittableNumber,
|
|
47
|
+
);
|
|
48
|
+
return (
|
|
49
|
+
// The clear button sits over the control rather than in antd's suffix,
|
|
50
|
+
// because `Form.Item` feedback replaces that slot instead of composing with
|
|
51
|
+
// it - so an errored field would lose its clear button. The wider offset
|
|
52
|
+
// keeps it clear of the stepper handles antd reveals on hover.
|
|
53
|
+
<AntdClearableInput
|
|
54
|
+
clearable={appliedUiSchemaOptions.clearable !== false}
|
|
55
|
+
data={data}
|
|
56
|
+
enabled={enabled}
|
|
57
|
+
offset={CLEAR_OFFSET_WITH_HANDLES}
|
|
58
|
+
onClear={onClear}
|
|
59
|
+
>
|
|
60
|
+
<InputNumber
|
|
61
|
+
value={inputValue}
|
|
62
|
+
// antd reports a cleared field as null. Routing that through onClear
|
|
63
|
+
// rather than the debounced path commits it at once and cancels any
|
|
64
|
+
// queued keystroke, so an old callback cannot restore the value.
|
|
65
|
+
onChange={(value) =>
|
|
66
|
+
value === null || value === undefined
|
|
67
|
+
? onClear()
|
|
68
|
+
: !props.integerOnly || Number.isInteger(Number(value))
|
|
69
|
+
? onChange(value as never)
|
|
70
|
+
: undefined
|
|
71
|
+
}
|
|
72
|
+
className={className}
|
|
73
|
+
id={id}
|
|
74
|
+
disabled={!enabled}
|
|
75
|
+
autoFocus={appliedUiSchemaOptions.focus}
|
|
76
|
+
step={props.integerOnly ? undefined : 0.1}
|
|
77
|
+
style={inputStyle}
|
|
78
|
+
placeholder={appliedUiSchemaOptions.placeholder}
|
|
79
|
+
{...inputProps}
|
|
80
|
+
/>
|
|
81
|
+
</AntdClearableInput>
|
|
82
|
+
);
|
|
83
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { CellProps, JsonSchema, WithClassname } from '@jsonforms/core';
|
|
2
|
+
import { Flex, Input } from 'antd';
|
|
3
|
+
import merge from 'lodash/merge';
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import { AntdClearableInput } from './AntdClearableInput';
|
|
6
|
+
import { AntdRevealButton } from './AntdRevealButton';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* How many boxes a segmented code editor draws, or `undefined` when the schema
|
|
10
|
+
* does not fix a length.
|
|
11
|
+
*
|
|
12
|
+
* `maxLength` is the count, because a box the user cannot fill would be a lie
|
|
13
|
+
* about what the field accepts. `minLength` has to be present too - see
|
|
14
|
+
* `otpControlTester` - but it constrains validity rather than layout: with the
|
|
15
|
+
* two equal, which is the intended authoring, the boxes and the schema agree
|
|
16
|
+
* exactly; with `minLength` lower, the trailing boxes are optional and the
|
|
17
|
+
* floor is enforced by validation like any other `minLength`.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* The character drawn in place of each hidden one.
|
|
21
|
+
*
|
|
22
|
+
* A bullet rather than `true`: see the note on `mask` below - antd's boolean
|
|
23
|
+
* form reveals the value it is supposed to hide.
|
|
24
|
+
*/
|
|
25
|
+
export const OTP_MASK = '\u2022';
|
|
26
|
+
|
|
27
|
+
export const otpLength = (schema?: JsonSchema): number | undefined => {
|
|
28
|
+
const min = (schema as { minLength?: unknown } | undefined)?.minLength;
|
|
29
|
+
const max = (schema as { maxLength?: unknown } | undefined)?.maxLength;
|
|
30
|
+
return typeof min === 'number' && typeof max === 'number' && max > 0
|
|
31
|
+
? max
|
|
32
|
+
: undefined;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A fixed-length secret entered one character per box.
|
|
37
|
+
*
|
|
38
|
+
* Selected by `options.variant: "otp"` on a password control whose schema
|
|
39
|
+
* bounds its length. It is the same value under the same storage contract as
|
|
40
|
+
* the ordinary password field - only the editor differs - so masking, reveal
|
|
41
|
+
* and clear all behave the way section 18 requires of a password.
|
|
42
|
+
*/
|
|
43
|
+
export const AntdOtp = React.memo(function AntdOtp(
|
|
44
|
+
props: CellProps &
|
|
45
|
+
WithClassname & {
|
|
46
|
+
inputProps?: Record<string, unknown>;
|
|
47
|
+
label?: React.ReactNode;
|
|
48
|
+
},
|
|
49
|
+
) {
|
|
50
|
+
const {
|
|
51
|
+
data,
|
|
52
|
+
config,
|
|
53
|
+
className,
|
|
54
|
+
id,
|
|
55
|
+
enabled,
|
|
56
|
+
uischema,
|
|
57
|
+
path,
|
|
58
|
+
handleChange,
|
|
59
|
+
schema,
|
|
60
|
+
label,
|
|
61
|
+
} = props;
|
|
62
|
+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
63
|
+
const [revealed, setRevealed] = useState(false);
|
|
64
|
+
const length = otpLength(schema) ?? 6;
|
|
65
|
+
const value = typeof data === 'string' ? data : '';
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<AntdClearableInput
|
|
69
|
+
clearable={appliedUiSchemaOptions.clearable !== false}
|
|
70
|
+
data={data}
|
|
71
|
+
enabled={enabled}
|
|
72
|
+
onClear={() => handleChange(path, undefined)}
|
|
73
|
+
>
|
|
74
|
+
{(clear) => (
|
|
75
|
+
<Flex align='center' gap='small'>
|
|
76
|
+
<Input.OTP
|
|
77
|
+
/*
|
|
78
|
+
`onInput`, not `onChange`. antd fires `onChange` only once every
|
|
79
|
+
box is filled, so a half-typed code would leave the form data
|
|
80
|
+
holding the previous value while the screen showed something
|
|
81
|
+
else, and deleting a character would write nothing at all.
|
|
82
|
+
Section 19 requires the UI to represent the actual form data, and
|
|
83
|
+
a `minLength` error can only be reported against a value that was
|
|
84
|
+
actually stored.
|
|
85
|
+
*/
|
|
86
|
+
onInput={(cells) => handleChange(path, cells.join('') || undefined)}
|
|
87
|
+
/*
|
|
88
|
+
Reveal is the `mask` lever: antd's OTP has no toggle of its own.
|
|
89
|
+
As with the password field this changes presentation only and
|
|
90
|
+
never touches form data.
|
|
91
|
+
|
|
92
|
+
`mask` is a **character**, not `true`. antd draws the mask as an
|
|
93
|
+
overlay showing `typeof mask === 'string' ? mask : value`, over an
|
|
94
|
+
input whose own text is `color: transparent` - so `mask={true}`
|
|
95
|
+
puts the real character on screen, which is no mask at all.
|
|
96
|
+
|
|
97
|
+
`type` is set for the same reason from the other side: OTPInput
|
|
98
|
+
asks for `type: mask === true ? 'password' : 'text'` and then
|
|
99
|
+
spreads its shared props, which carry `type: undefined`, over the
|
|
100
|
+
top - so the cells come out as plain text boxes unless the type is
|
|
101
|
+
passed in explicitly. Passing it keeps each box a real password
|
|
102
|
+
input, which is what a screen reader and a browser read.
|
|
103
|
+
*/
|
|
104
|
+
mask={revealed ? false : OTP_MASK}
|
|
105
|
+
type={revealed ? 'text' : 'password'}
|
|
106
|
+
value={value}
|
|
107
|
+
length={length}
|
|
108
|
+
disabled={!enabled}
|
|
109
|
+
autoComplete='one-time-code'
|
|
110
|
+
className={className}
|
|
111
|
+
/*
|
|
112
|
+
The boxes are separate inputs, so the Form.Item label has no
|
|
113
|
+
single control to point `htmlFor` at. Naming the group is what
|
|
114
|
+
assistive technology needs to announce the field once rather than
|
|
115
|
+
announcing `length` unlabelled text boxes.
|
|
116
|
+
*/
|
|
117
|
+
role='group'
|
|
118
|
+
aria-label={typeof label === 'string' ? label : undefined}
|
|
119
|
+
id={id}
|
|
120
|
+
{...(props.inputProps as Record<string, unknown>)}
|
|
121
|
+
/>
|
|
122
|
+
<AntdRevealButton
|
|
123
|
+
revealed={revealed}
|
|
124
|
+
onToggle={() => setRevealed((shown) => !shown)}
|
|
125
|
+
disabled={!enabled}
|
|
126
|
+
/>
|
|
127
|
+
{clear}
|
|
128
|
+
</Flex>
|
|
129
|
+
)}
|
|
130
|
+
</AntdClearableInput>
|
|
131
|
+
);
|
|
132
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { CellProps, WithClassname } from '@jsonforms/core';
|
|
2
|
+
import { Input } from 'antd';
|
|
3
|
+
import merge from 'lodash/merge';
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import { useDebouncedChange } from '../util';
|
|
6
|
+
import { AntdClearableInput } from './AntdClearableInput';
|
|
7
|
+
import { AntdRevealButton } from './AntdRevealButton';
|
|
8
|
+
|
|
9
|
+
const eventToValue = (ev: any) =>
|
|
10
|
+
ev.target.value === '' ? undefined : ev.target.value;
|
|
11
|
+
|
|
12
|
+
export const AntdPassword = React.memo(function AntdPassword(
|
|
13
|
+
props: CellProps &
|
|
14
|
+
WithClassname & {
|
|
15
|
+
inputProps?: React.ComponentProps<typeof Input>;
|
|
16
|
+
},
|
|
17
|
+
) {
|
|
18
|
+
const {
|
|
19
|
+
data,
|
|
20
|
+
config,
|
|
21
|
+
className,
|
|
22
|
+
id,
|
|
23
|
+
enabled,
|
|
24
|
+
uischema,
|
|
25
|
+
path,
|
|
26
|
+
handleChange,
|
|
27
|
+
schema,
|
|
28
|
+
inputProps,
|
|
29
|
+
} = props;
|
|
30
|
+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
31
|
+
const [inputText, onChange, onClear] = useDebouncedChange(
|
|
32
|
+
handleChange,
|
|
33
|
+
'',
|
|
34
|
+
data,
|
|
35
|
+
path,
|
|
36
|
+
eventToValue,
|
|
37
|
+
);
|
|
38
|
+
/*
|
|
39
|
+
Reveal state is local runtime state. The specification is explicit that
|
|
40
|
+
toggling "must not write form data, trigger a value-change event, alter
|
|
41
|
+
validation, or mark the value dirty", and that it is "never serialized into
|
|
42
|
+
data or UI schema".
|
|
43
|
+
*/
|
|
44
|
+
const [revealed, setRevealed] = useState(false);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<AntdClearableInput
|
|
48
|
+
clearable={appliedUiSchemaOptions.clearable !== false}
|
|
49
|
+
data={data}
|
|
50
|
+
enabled={enabled}
|
|
51
|
+
onClear={onClear}
|
|
52
|
+
>
|
|
53
|
+
{/*
|
|
54
|
+
The clear and reveal controls both go in antd's `suffix` slot. An
|
|
55
|
+
overlaid clear button landed on top of the reveal icon, and the
|
|
56
|
+
`Form.Item` error icon on top of both - three icons in one corner.
|
|
57
|
+
`Input` *composes* `suffix` with the feedback icon
|
|
58
|
+
(`<>{suffix}{hasFeedback && feedbackIcon}</>`) rather than replacing it,
|
|
59
|
+
as `InputNumber` does, so the slot yields clear / reveal / error laid
|
|
60
|
+
out by antd and correct whether or not the value is currently invalid.
|
|
61
|
+
Clear comes first so its conditional appearance does not move the
|
|
62
|
+
persistent reveal control or leave a gap when hidden.
|
|
63
|
+
*/}
|
|
64
|
+
{(clear) => (
|
|
65
|
+
<Input
|
|
66
|
+
/*
|
|
67
|
+
A plain `Input` with our own toggle, not `Input.Password`.
|
|
68
|
+
|
|
69
|
+
antd 6's `Input.Password` wraps whatever `iconRender` returns in a
|
|
70
|
+
`span` that is itself `role="button"`, focusable, and labelled from
|
|
71
|
+
antd's own locale - so putting a real button inside it, which is
|
|
72
|
+
what the accessible name has to live on, nested one interactive
|
|
73
|
+
element inside another: two tab stops for one action, and two
|
|
74
|
+
different names for it ("Show" from antd, "Show password" from the
|
|
75
|
+
form's translator).
|
|
76
|
+
|
|
77
|
+
Owning the toggle keeps one control, one name, and that name coming
|
|
78
|
+
from the JSON Forms translator like every other rendered string.
|
|
79
|
+
All `Input.Password` does beyond this is swap the input type, which
|
|
80
|
+
is one line.
|
|
81
|
+
*/
|
|
82
|
+
type={revealed ? 'text' : 'password'}
|
|
83
|
+
suffix={
|
|
84
|
+
<>
|
|
85
|
+
{clear}
|
|
86
|
+
<AntdRevealButton
|
|
87
|
+
revealed={revealed}
|
|
88
|
+
onToggle={() => setRevealed((shown) => !shown)}
|
|
89
|
+
disabled={!enabled}
|
|
90
|
+
/>
|
|
91
|
+
</>
|
|
92
|
+
}
|
|
93
|
+
value={inputText}
|
|
94
|
+
onChange={onChange}
|
|
95
|
+
className={className}
|
|
96
|
+
id={id}
|
|
97
|
+
disabled={!enabled}
|
|
98
|
+
autoFocus={appliedUiSchemaOptions.focus}
|
|
99
|
+
maxLength={schema.maxLength}
|
|
100
|
+
placeholder={appliedUiSchemaOptions.placeholder}
|
|
101
|
+
{...inputProps}
|
|
102
|
+
/>
|
|
103
|
+
)}
|
|
104
|
+
</AntdClearableInput>
|
|
105
|
+
);
|
|
106
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CellProps, OwnPropsOfEnum, WithClassname } from '@jsonforms/core';
|
|
3
|
+
import { Flex, Radio } from 'antd';
|
|
4
|
+
import isEqual from 'lodash/isEqual';
|
|
5
|
+
|
|
6
|
+
export const AntdRadioGroup = React.memo(function AntdRadioGroup(
|
|
7
|
+
props: CellProps &
|
|
8
|
+
WithClassname &
|
|
9
|
+
OwnPropsOfEnum & {
|
|
10
|
+
inputProps?: React.ComponentProps<typeof Radio.Group>;
|
|
11
|
+
},
|
|
12
|
+
) {
|
|
13
|
+
const {
|
|
14
|
+
data,
|
|
15
|
+
options = [],
|
|
16
|
+
handleChange,
|
|
17
|
+
path,
|
|
18
|
+
enabled,
|
|
19
|
+
uischema,
|
|
20
|
+
inputProps,
|
|
21
|
+
} = props;
|
|
22
|
+
/*
|
|
23
|
+
`options.vertical` is the single orientation encoding for a radio group:
|
|
24
|
+
false (the default) arranges the choices in a row that may wrap, true
|
|
25
|
+
stacks them. The orientation is also announced, so assistive technology
|
|
26
|
+
describes the arrangement that is actually on screen.
|
|
27
|
+
*/
|
|
28
|
+
const vertical =
|
|
29
|
+
(uischema.options?.vertical ??
|
|
30
|
+
props.config?.jsonformsExtended?.radio?.vertical ??
|
|
31
|
+
false) === true;
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Radio.Group
|
|
35
|
+
aria-orientation={vertical ? 'vertical' : 'horizontal'}
|
|
36
|
+
disabled={!enabled}
|
|
37
|
+
value={(options || []).findIndex((option) => isEqual(option.value, data))}
|
|
38
|
+
// Guarded as well as disabled: the specification requires mutation
|
|
39
|
+
// handlers to enforce the same rules as the visible state, so that
|
|
40
|
+
// neither a keyboard path nor a caller-supplied `inputProps.disabled`
|
|
41
|
+
// override can commit a change to a read-only control.
|
|
42
|
+
onChange={(e: any) => {
|
|
43
|
+
if (!enabled) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
handleChange(path, options[e.target.value].value);
|
|
47
|
+
}}
|
|
48
|
+
{...inputProps}
|
|
49
|
+
>
|
|
50
|
+
<Flex gap={vertical ? 4 : 8} vertical={vertical} wrap={!vertical}>
|
|
51
|
+
{(options || []).map((option, index) => (
|
|
52
|
+
// UI tokens stay separate from JSON values and translated labels.
|
|
53
|
+
<Radio value={index} key={index}>
|
|
54
|
+
{option.label}
|
|
55
|
+
</Radio>
|
|
56
|
+
))}
|
|
57
|
+
</Flex>
|
|
58
|
+
</Radio.Group>
|
|
59
|
+
);
|
|
60
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import EyeInvisibleOutlined from '@ant-design/icons/EyeInvisibleOutlined';
|
|
2
|
+
import EyeOutlined from '@ant-design/icons/EyeOutlined';
|
|
3
|
+
import { Tooltip } from 'antd';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useI18n } from '../util/translate';
|
|
6
|
+
|
|
7
|
+
export interface AntdRevealButtonProps {
|
|
8
|
+
revealed: boolean;
|
|
9
|
+
/** Toggles the reveal state. */
|
|
10
|
+
onToggle: () => void;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The show/hide control for a masked value.
|
|
16
|
+
*
|
|
17
|
+
* A real button whose accessible name states the **action it will perform**
|
|
18
|
+
* rather than the current state - "Show password" while the value is hidden -
|
|
19
|
+
* which is what section 18 asks for. Enter or Space activates it natively.
|
|
20
|
+
*
|
|
21
|
+
* It carries a tooltip with the same wording, for the same reason the clear
|
|
22
|
+
* button does: the control is an icon, and an icon with no visible name is
|
|
23
|
+
* guessable at best. antd renders no tooltip on its own reveal icon - it gives
|
|
24
|
+
* the wrapper an `aria-label` and stops there - so this is ours to supply, not
|
|
25
|
+
* something the library prevents.
|
|
26
|
+
*
|
|
27
|
+
* Deliberately no `aria-pressed`. A toggle button either names its state and
|
|
28
|
+
* reports pressed, or names the action it will perform; doing both describes
|
|
29
|
+
* the control twice and contradicts itself, since "Show password" is not a
|
|
30
|
+
* thing that can be pressed or unpressed. The specification asks for the
|
|
31
|
+
* action wording, so that is what this reports.
|
|
32
|
+
*
|
|
33
|
+
* Toggling is presentation only. The specification is explicit that it "must
|
|
34
|
+
* not write form data, trigger a value-change event, alter validation, or mark
|
|
35
|
+
* the value dirty", and that reveal state is "never serialized into data or UI
|
|
36
|
+
* schema".
|
|
37
|
+
*/
|
|
38
|
+
export const AntdRevealButton = ({
|
|
39
|
+
revealed,
|
|
40
|
+
onToggle,
|
|
41
|
+
disabled = false,
|
|
42
|
+
}: AntdRevealButtonProps) => {
|
|
43
|
+
const t = useI18n();
|
|
44
|
+
const name = t(revealed ? 'password.hide' : 'password.show');
|
|
45
|
+
return (
|
|
46
|
+
<Tooltip title={name}>
|
|
47
|
+
<button
|
|
48
|
+
aria-label={name}
|
|
49
|
+
data-password-toggle
|
|
50
|
+
disabled={disabled}
|
|
51
|
+
// Keeps focus in the text field, the way antd's own icon does, so
|
|
52
|
+
// revealing does not move the caret or close the field's clear button.
|
|
53
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
54
|
+
onClick={onToggle}
|
|
55
|
+
style={{
|
|
56
|
+
background: 'none',
|
|
57
|
+
border: 0,
|
|
58
|
+
color: 'inherit',
|
|
59
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
60
|
+
display: 'inline-flex',
|
|
61
|
+
padding: 0,
|
|
62
|
+
}}
|
|
63
|
+
tabIndex={0}
|
|
64
|
+
type='button'
|
|
65
|
+
>
|
|
66
|
+
{revealed ? (
|
|
67
|
+
<EyeOutlined rev={undefined} />
|
|
68
|
+
) : (
|
|
69
|
+
<EyeInvisibleOutlined rev={undefined} />
|
|
70
|
+
)}
|
|
71
|
+
</button>
|
|
72
|
+
</Tooltip>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { EnumCellProps, WithClassname } from '@jsonforms/core';
|
|
3
|
+
|
|
4
|
+
import { Select } from 'antd';
|
|
5
|
+
import merge from 'lodash/merge';
|
|
6
|
+
import isEqual from 'lodash/isEqual';
|
|
7
|
+
import { useI18nDefault } from '../util';
|
|
8
|
+
import { TranslateProps } from '@jsonforms/react';
|
|
9
|
+
|
|
10
|
+
export const AntdSelect = (
|
|
11
|
+
props: EnumCellProps &
|
|
12
|
+
WithClassname &
|
|
13
|
+
TranslateProps & { inputProps?: React.ComponentProps<typeof Select> },
|
|
14
|
+
) => {
|
|
15
|
+
const {
|
|
16
|
+
data,
|
|
17
|
+
className,
|
|
18
|
+
id,
|
|
19
|
+
enabled,
|
|
20
|
+
schema,
|
|
21
|
+
uischema,
|
|
22
|
+
path,
|
|
23
|
+
handleChange,
|
|
24
|
+
options = [],
|
|
25
|
+
config,
|
|
26
|
+
inputProps,
|
|
27
|
+
t,
|
|
28
|
+
} = props;
|
|
29
|
+
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
30
|
+
/*
|
|
31
|
+
The default message carries the locale bundle (§6.5), so it must not be
|
|
32
|
+
read straight out of the English table.
|
|
33
|
+
*/
|
|
34
|
+
const d = useI18nDefault();
|
|
35
|
+
const noneOptionLabel = useMemo(
|
|
36
|
+
() => t('enum.none', d('enum.none'), { schema, uischema, path }),
|
|
37
|
+
[t, d, schema, uischema, path],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const selectedIndex = options.findIndex((option) =>
|
|
41
|
+
isEqual(option.value, data),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const selectStyle = { width: '100%' };
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
`options.autocomplete` is the portable encoding for searchable finite
|
|
48
|
+
choices. **This family defaults to off**, which the specification permits -
|
|
49
|
+
"preserves the renderer family's documented default. No universal default
|
|
50
|
+
is imposed" - and which differs from Material, where searching is the
|
|
51
|
+
default. See Adjustment 16.
|
|
52
|
+
|
|
53
|
+
Only `true` turns it on, so `false` and absence behave alike; the
|
|
54
|
+
distinction matters only against a global config that switched it on.
|
|
55
|
+
*/
|
|
56
|
+
const searchable = appliedUiSchemaOptions.autocomplete === true;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<Select
|
|
60
|
+
className={className}
|
|
61
|
+
id={id}
|
|
62
|
+
disabled={!enabled}
|
|
63
|
+
autoFocus={appliedUiSchemaOptions.focus}
|
|
64
|
+
value={selectedIndex < 0 ? undefined : selectedIndex}
|
|
65
|
+
onChange={(index) => {
|
|
66
|
+
if (enabled) {
|
|
67
|
+
handleChange(
|
|
68
|
+
path,
|
|
69
|
+
typeof index === 'number' ? options[index]?.value : undefined,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}}
|
|
73
|
+
style={selectStyle}
|
|
74
|
+
placeholder={appliedUiSchemaOptions.placeholder ?? noneOptionLabel}
|
|
75
|
+
allowClear={enabled}
|
|
76
|
+
/*
|
|
77
|
+
The specification requires a searchable renderer to say how the query
|
|
78
|
+
filters: here, a case-insensitive substring of the **label** - what the
|
|
79
|
+
reader can actually see, which for a constant-based `oneOf` is the
|
|
80
|
+
branch title rather than the stored constant. Matching the value would
|
|
81
|
+
mean searching for `eng` to find "Engineering".
|
|
82
|
+
|
|
83
|
+
Configured through the `showSearch` object; antd 6 deprecated the flat
|
|
84
|
+
`optionFilterProp` / `filterOption` props in favour of it.
|
|
85
|
+
*/
|
|
86
|
+
showSearch={
|
|
87
|
+
searchable
|
|
88
|
+
? {
|
|
89
|
+
optionFilterProp: 'label',
|
|
90
|
+
filterOption: (input, option) =>
|
|
91
|
+
String(option?.label ?? '')
|
|
92
|
+
.toLowerCase()
|
|
93
|
+
.includes(input.toLowerCase()),
|
|
94
|
+
}
|
|
95
|
+
: false
|
|
96
|
+
}
|
|
97
|
+
notFoundContent={
|
|
98
|
+
searchable
|
|
99
|
+
? t('enum.noMatches', d('enum.noMatches'), {
|
|
100
|
+
schema,
|
|
101
|
+
uischema,
|
|
102
|
+
path,
|
|
103
|
+
})
|
|
104
|
+
: undefined
|
|
105
|
+
}
|
|
106
|
+
// `options` rather than `<Select.Option>` children: the component form is
|
|
107
|
+
// deprecated in antd 6, and it also keyed each entry by its value, which
|
|
108
|
+
// collides when two choices share one.
|
|
109
|
+
options={options.map(({ label }, index) => ({ value: index, label }))}
|
|
110
|
+
{...inputProps}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
};
|