@transferwise/components 0.0.0-experimental-112d47a → 0.0.0-experimental-30a5fa7
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/build/accordion/AccordionItem/AccordionItem.js +3 -19
- package/build/accordion/AccordionItem/AccordionItem.js.map +1 -1
- package/build/accordion/AccordionItem/AccordionItem.mjs +3 -19
- package/build/accordion/AccordionItem/AccordionItem.mjs.map +1 -1
- package/build/actionButton/ActionButton.js +1 -19
- package/build/actionButton/ActionButton.js.map +1 -1
- package/build/actionButton/ActionButton.mjs +1 -19
- package/build/actionButton/ActionButton.mjs.map +1 -1
- package/build/actionOption/ActionOption.js +1 -19
- package/build/actionOption/ActionOption.js.map +1 -1
- package/build/actionOption/ActionOption.mjs +1 -19
- package/build/actionOption/ActionOption.mjs.map +1 -1
- package/build/alert/Alert.js +4 -20
- package/build/alert/Alert.js.map +1 -1
- package/build/alert/Alert.mjs +4 -20
- package/build/alert/Alert.mjs.map +1 -1
- package/build/alert/inlineMarkdown/InlineMarkdown.js +1 -19
- package/build/alert/inlineMarkdown/InlineMarkdown.js.map +1 -1
- package/build/alert/inlineMarkdown/InlineMarkdown.mjs +1 -19
- package/build/alert/inlineMarkdown/InlineMarkdown.mjs.map +1 -1
- package/build/avatar/Avatar.js +1 -19
- package/build/avatar/Avatar.js.map +1 -1
- package/build/avatar/Avatar.mjs +1 -19
- package/build/avatar/Avatar.mjs.map +1 -1
- package/build/avatarWrapper/AvatarWrapper.js +2 -19
- package/build/avatarWrapper/AvatarWrapper.js.map +1 -1
- package/build/avatarWrapper/AvatarWrapper.mjs +2 -19
- package/build/avatarWrapper/AvatarWrapper.mjs.map +1 -1
- package/build/badge/Badge.js +2 -19
- package/build/badge/Badge.js.map +1 -1
- package/build/badge/Badge.mjs +2 -19
- package/build/badge/Badge.mjs.map +1 -1
- package/build/button/Button.js +2 -19
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +2 -19
- package/build/button/Button.mjs.map +1 -1
- package/build/button/classMap.js +0 -18
- package/build/button/classMap.js.map +1 -1
- package/build/button/classMap.mjs +0 -18
- package/build/button/classMap.mjs.map +1 -1
- package/build/button/legacyUtils/legacyUtils.js +2 -18
- package/build/button/legacyUtils/legacyUtils.js.map +1 -1
- package/build/button/legacyUtils/legacyUtils.mjs +2 -18
- package/build/button/legacyUtils/legacyUtils.mjs.map +1 -1
- package/build/card/Card.js +2 -19
- package/build/card/Card.js.map +1 -1
- package/build/card/Card.mjs +2 -19
- package/build/card/Card.mjs.map +1 -1
- package/build/checkbox/Checkbox.js +1 -19
- package/build/checkbox/Checkbox.js.map +1 -1
- package/build/checkbox/Checkbox.mjs +1 -19
- package/build/checkbox/Checkbox.mjs.map +1 -1
- package/build/chevron/Chevron.js +1 -18
- package/build/chevron/Chevron.js.map +1 -1
- package/build/chevron/Chevron.mjs +1 -18
- package/build/chevron/Chevron.mjs.map +1 -1
- package/build/chips/Chip.js +1 -19
- package/build/chips/Chip.js.map +1 -1
- package/build/chips/Chip.mjs +1 -19
- package/build/chips/Chip.mjs.map +1 -1
- package/build/circularButton/CircularButton.js +2 -19
- package/build/circularButton/CircularButton.js.map +1 -1
- package/build/circularButton/CircularButton.mjs +2 -19
- package/build/circularButton/CircularButton.mjs.map +1 -1
- package/build/common/bottomSheet/BottomSheet.js +2 -3
- package/build/common/bottomSheet/BottomSheet.js.map +1 -1
- package/build/common/bottomSheet/BottomSheet.mjs +2 -3
- package/build/common/bottomSheet/BottomSheet.mjs.map +1 -1
- package/build/common/hooks/useHasIntersected/useHasIntersected.js +10 -10
- package/build/common/hooks/useHasIntersected/useHasIntersected.js.map +1 -1
- package/build/common/hooks/useHasIntersected/useHasIntersected.mjs +10 -10
- package/build/common/hooks/useHasIntersected/useHasIntersected.mjs.map +1 -1
- package/build/common/locale/index.js +0 -18
- package/build/common/locale/index.js.map +1 -1
- package/build/common/locale/index.mjs +0 -18
- package/build/common/locale/index.mjs.map +1 -1
- package/build/common/panel/Panel.js +1 -19
- package/build/common/panel/Panel.js.map +1 -1
- package/build/common/panel/Panel.mjs +1 -19
- package/build/common/panel/Panel.mjs.map +1 -1
- package/build/common/responsivePanel/ResponsivePanel.js +2 -22
- package/build/common/responsivePanel/ResponsivePanel.js.map +1 -1
- package/build/common/responsivePanel/ResponsivePanel.mjs +2 -22
- package/build/common/responsivePanel/ResponsivePanel.mjs.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.js +3 -19
- package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
- package/build/criticalBanner/CriticalCommsBanner.mjs +3 -19
- package/build/criticalBanner/CriticalCommsBanner.mjs.map +1 -1
- package/build/dateInput/DateInput.js +4 -19
- package/build/dateInput/DateInput.js.map +1 -1
- package/build/dateInput/DateInput.mjs +4 -19
- package/build/dateInput/DateInput.mjs.map +1 -1
- package/build/dateLookup/DateLookup.js +5 -20
- package/build/dateLookup/DateLookup.js.map +1 -1
- package/build/dateLookup/DateLookup.mjs +5 -20
- package/build/dateLookup/DateLookup.mjs.map +1 -1
- package/build/dateLookup/dateHeader/DateHeader.js +4 -23
- package/build/dateLookup/dateHeader/DateHeader.js.map +1 -1
- package/build/dateLookup/dateHeader/DateHeader.mjs +4 -23
- package/build/dateLookup/dateHeader/DateHeader.mjs.map +1 -1
- package/build/dateLookup/dateTrigger/DateTrigger.js +3 -19
- package/build/dateLookup/dateTrigger/DateTrigger.js.map +1 -1
- package/build/dateLookup/dateTrigger/DateTrigger.mjs +3 -19
- package/build/dateLookup/dateTrigger/DateTrigger.mjs.map +1 -1
- package/build/decision/Decision.js +2 -19
- package/build/decision/Decision.js.map +1 -1
- package/build/decision/Decision.mjs +2 -19
- package/build/decision/Decision.mjs.map +1 -1
- package/build/definitionList/DefinitionList.js +1 -19
- package/build/definitionList/DefinitionList.js.map +1 -1
- package/build/definitionList/DefinitionList.mjs +1 -19
- package/build/definitionList/DefinitionList.mjs.map +1 -1
- package/build/dimmer/Dimmer.js +1 -20
- package/build/dimmer/Dimmer.js.map +1 -1
- package/build/dimmer/Dimmer.mjs +1 -20
- package/build/dimmer/Dimmer.mjs.map +1 -1
- package/build/display/Display.js +1 -19
- package/build/display/Display.js.map +1 -1
- package/build/display/Display.mjs +1 -19
- package/build/display/Display.mjs.map +1 -1
- package/build/drawer/Drawer.js +4 -23
- package/build/drawer/Drawer.js.map +1 -1
- package/build/drawer/Drawer.mjs +4 -23
- package/build/drawer/Drawer.mjs.map +1 -1
- package/build/field/Field.js +1 -19
- package/build/field/Field.js.map +1 -1
- package/build/field/Field.mjs +1 -19
- package/build/field/Field.mjs.map +1 -1
- package/build/flowNavigation/FlowNavigation.js +2 -19
- package/build/flowNavigation/FlowNavigation.js.map +1 -1
- package/build/flowNavigation/FlowNavigation.mjs +2 -19
- package/build/flowNavigation/FlowNavigation.mjs.map +1 -1
- package/build/header/Header.js +1 -19
- package/build/header/Header.js.map +1 -1
- package/build/header/Header.mjs +1 -19
- package/build/header/Header.mjs.map +1 -1
- package/build/image/Image.js +1 -4
- package/build/image/Image.js.map +1 -1
- package/build/image/Image.mjs +1 -4
- package/build/image/Image.mjs.map +1 -1
- package/build/index.js +62 -64
- package/build/index.js.map +1 -1
- package/build/index.mjs +20 -22
- package/build/index.mjs.map +1 -1
- package/build/info/Info.js +2 -19
- package/build/info/Info.js.map +1 -1
- package/build/info/Info.mjs +2 -19
- package/build/info/Info.mjs.map +1 -1
- package/build/inlineAlert/InlineAlert.js +2 -19
- package/build/inlineAlert/InlineAlert.js.map +1 -1
- package/build/inlineAlert/InlineAlert.mjs +2 -19
- package/build/inlineAlert/InlineAlert.mjs.map +1 -1
- package/build/inputs/SearchInput.js +1 -19
- package/build/inputs/SearchInput.js.map +1 -1
- package/build/inputs/SearchInput.mjs +1 -19
- package/build/inputs/SearchInput.mjs.map +1 -1
- package/build/instructionsList/InstructionsList.js +1 -19
- package/build/instructionsList/InstructionsList.js.map +1 -1
- package/build/instructionsList/InstructionsList.mjs +1 -19
- package/build/instructionsList/InstructionsList.mjs.map +1 -1
- package/build/loader/Loader.js +1 -19
- package/build/loader/Loader.js.map +1 -1
- package/build/loader/Loader.mjs +1 -19
- package/build/loader/Loader.mjs.map +1 -1
- package/build/markdown/Markdown.js +2 -20
- package/build/markdown/Markdown.js.map +1 -1
- package/build/markdown/Markdown.mjs +2 -20
- package/build/markdown/Markdown.mjs.map +1 -1
- package/build/modal/Modal.js +5 -22
- package/build/modal/Modal.js.map +1 -1
- package/build/modal/Modal.mjs +5 -22
- package/build/modal/Modal.mjs.map +1 -1
- package/build/moneyInput/MoneyInput.js +2 -19
- package/build/moneyInput/MoneyInput.js.map +1 -1
- package/build/moneyInput/MoneyInput.mjs +2 -19
- package/build/moneyInput/MoneyInput.mjs.map +1 -1
- package/build/navigationOption/NavigationOption.js +1 -19
- package/build/navigationOption/NavigationOption.js.map +1 -1
- package/build/navigationOption/NavigationOption.mjs +1 -19
- package/build/navigationOption/NavigationOption.mjs.map +1 -1
- package/build/nudge/Nudge.js +1 -19
- package/build/nudge/Nudge.js.map +1 -1
- package/build/nudge/Nudge.mjs +1 -19
- package/build/nudge/Nudge.mjs.map +1 -1
- package/build/overlayHeader/OverlayHeader.js +1 -19
- package/build/overlayHeader/OverlayHeader.js.map +1 -1
- package/build/overlayHeader/OverlayHeader.mjs +1 -19
- package/build/overlayHeader/OverlayHeader.mjs.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.js +1 -19
- package/build/phoneNumberInput/PhoneNumberInput.js.map +1 -1
- package/build/phoneNumberInput/PhoneNumberInput.mjs +1 -19
- package/build/phoneNumberInput/PhoneNumberInput.mjs.map +1 -1
- package/build/popover/Popover.js +4 -21
- package/build/popover/Popover.js.map +1 -1
- package/build/popover/Popover.mjs +4 -21
- package/build/popover/Popover.mjs.map +1 -1
- package/build/processIndicator/ProcessIndicator.js +1 -19
- package/build/processIndicator/ProcessIndicator.js.map +1 -1
- package/build/processIndicator/ProcessIndicator.mjs +1 -19
- package/build/processIndicator/ProcessIndicator.mjs.map +1 -1
- package/build/progressBar/ProgressBar.js +1 -19
- package/build/progressBar/ProgressBar.js.map +1 -1
- package/build/progressBar/ProgressBar.mjs +1 -19
- package/build/progressBar/ProgressBar.mjs.map +1 -1
- package/build/promoCard/PromoCard.js +1 -19
- package/build/promoCard/PromoCard.js.map +1 -1
- package/build/promoCard/PromoCard.mjs +1 -19
- package/build/promoCard/PromoCard.mjs.map +1 -1
- package/build/promoCard/PromoCardIndicator.js +1 -19
- package/build/promoCard/PromoCardIndicator.js.map +1 -1
- package/build/promoCard/PromoCardIndicator.mjs +1 -19
- package/build/promoCard/PromoCardIndicator.mjs.map +1 -1
- package/build/provider/Provider.js +1 -20
- package/build/provider/Provider.js.map +1 -1
- package/build/provider/Provider.mjs +1 -20
- package/build/provider/Provider.mjs.map +1 -1
- package/build/radio/Radio.js +1 -19
- package/build/radio/Radio.js.map +1 -1
- package/build/radio/Radio.mjs +1 -19
- package/build/radio/Radio.mjs.map +1 -1
- package/build/segmentedControl/SegmentedControl.js +1 -19
- package/build/segmentedControl/SegmentedControl.js.map +1 -1
- package/build/segmentedControl/SegmentedControl.mjs +1 -19
- package/build/segmentedControl/SegmentedControl.mjs.map +1 -1
- package/build/select/Select.js +3 -23
- package/build/select/Select.js.map +1 -1
- package/build/select/Select.mjs +3 -23
- package/build/select/Select.mjs.map +1 -1
- package/build/select/option/Option.js +1 -19
- package/build/select/option/Option.js.map +1 -1
- package/build/select/option/Option.mjs +1 -19
- package/build/select/option/Option.mjs.map +1 -1
- package/build/selectOption/SelectOption.js +3 -20
- package/build/selectOption/SelectOption.js.map +1 -1
- package/build/selectOption/SelectOption.mjs +3 -20
- package/build/selectOption/SelectOption.mjs.map +1 -1
- package/build/stepper/Stepper.js +2 -21
- package/build/stepper/Stepper.js.map +1 -1
- package/build/stepper/Stepper.mjs +2 -21
- package/build/stepper/Stepper.mjs.map +1 -1
- package/build/sticky/Sticky.js +1 -19
- package/build/sticky/Sticky.js.map +1 -1
- package/build/sticky/Sticky.mjs +1 -19
- package/build/sticky/Sticky.mjs.map +1 -1
- package/build/summary/Summary.js +4 -19
- package/build/summary/Summary.js.map +1 -1
- package/build/summary/Summary.mjs +4 -19
- package/build/summary/Summary.mjs.map +1 -1
- package/build/tabs/Tabs.js +2 -19
- package/build/tabs/Tabs.js.map +1 -1
- package/build/tabs/Tabs.mjs +2 -19
- package/build/tabs/Tabs.mjs.map +1 -1
- package/build/tile/Tile.js +1 -19
- package/build/tile/Tile.js.map +1 -1
- package/build/tile/Tile.mjs +1 -19
- package/build/tile/Tile.mjs.map +1 -1
- package/build/title/Title.js +1 -19
- package/build/title/Title.js.map +1 -1
- package/build/title/Title.mjs +1 -19
- package/build/title/Title.mjs.map +1 -1
- package/build/tooltip/Tooltip.js +1 -19
- package/build/tooltip/Tooltip.js.map +1 -1
- package/build/tooltip/Tooltip.mjs +1 -19
- package/build/tooltip/Tooltip.mjs.map +1 -1
- package/build/typeahead/Typeahead.js +3 -20
- package/build/typeahead/Typeahead.js.map +1 -1
- package/build/typeahead/Typeahead.mjs +3 -20
- package/build/typeahead/Typeahead.mjs.map +1 -1
- package/build/types/common/hooks/index.d.ts +4 -4
- package/build/types/common/hooks/index.d.ts.map +1 -1
- package/build/types/common/hooks/useConditionalListener/index.d.ts +1 -1
- package/build/types/common/hooks/useConditionalListener/index.d.ts.map +1 -1
- package/build/types/common/hooks/useDirection/index.d.ts +1 -1
- package/build/types/common/hooks/useDirection/index.d.ts.map +1 -1
- package/build/types/common/hooks/useHasIntersected/index.d.ts +1 -1
- package/build/types/common/hooks/useHasIntersected/index.d.ts.map +1 -1
- package/build/types/common/hooks/useHasIntersected/useHasIntersected.d.ts +4 -15
- package/build/types/common/hooks/useHasIntersected/useHasIntersected.d.ts.map +1 -1
- package/build/types/common/index.d.ts +24 -24
- package/build/types/common/index.d.ts.map +1 -1
- package/build/types/common/responsivePanel/index.d.ts +1 -1
- package/build/types/common/responsivePanel/index.d.ts.map +1 -1
- package/build/types/index.d.ts +0 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/navigationOption/NavigationOption.d.ts +0 -1
- package/build/types/navigationOption/NavigationOption.d.ts.map +1 -1
- package/build/types/test-utils/style-mock.d.ts +1 -0
- package/build/types/test-utils/style-mock.d.ts.map +1 -0
- package/build/types/utilities/deprecatedProperty/deprecatedProperty.d.ts +8 -6
- package/build/types/utilities/deprecatedProperty/deprecatedProperty.d.ts.map +1 -1
- package/build/types/utilities/deprecatedProperty/index.d.ts +1 -1
- package/build/types/utilities/deprecatedProperty/index.d.ts.map +1 -1
- package/build/types/utilities/index.d.ts +2 -2
- package/build/types/utilities/index.d.ts.map +1 -1
- package/build/types/utilities/logActionRequired.d.ts +2 -2
- package/build/types/utilities/logActionRequired.d.ts.map +1 -1
- package/build/upload/Upload.js +1 -19
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.mjs +1 -19
- package/build/upload/Upload.mjs.map +1 -1
- package/build/upload/steps/processingStep/processingStep.js +2 -19
- package/build/upload/steps/processingStep/processingStep.js.map +1 -1
- package/build/upload/steps/processingStep/processingStep.mjs +2 -19
- package/build/upload/steps/processingStep/processingStep.mjs.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.js +2 -19
- package/build/upload/steps/uploadImageStep/uploadImageStep.js.map +1 -1
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs +2 -19
- package/build/upload/steps/uploadImageStep/uploadImageStep.mjs.map +1 -1
- package/build/uploadInput/UploadInput.js +2 -19
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +2 -19
- package/build/uploadInput/UploadInput.mjs.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.js +1 -19
- package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.mjs +1 -19
- package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
- package/build/uploadInput/uploadButton/defaults.js +0 -18
- package/build/uploadInput/uploadButton/defaults.js.map +1 -1
- package/build/uploadInput/uploadButton/defaults.mjs +0 -18
- package/build/uploadInput/uploadButton/defaults.mjs.map +1 -1
- package/build/uploadInput/uploadItem/UploadItem.js +3 -19
- package/build/uploadInput/uploadItem/UploadItem.js.map +1 -1
- package/build/uploadInput/uploadItem/UploadItem.mjs +3 -19
- package/build/uploadInput/uploadItem/UploadItem.mjs.map +1 -1
- package/build/utilities/logActionRequired.js.map +1 -1
- package/build/utilities/logActionRequired.mjs.map +1 -1
- package/build/withDisplayFormat/WithDisplayFormat.js +1 -20
- package/build/withDisplayFormat/WithDisplayFormat.js.map +1 -1
- package/build/withDisplayFormat/WithDisplayFormat.mjs +1 -20
- package/build/withDisplayFormat/WithDisplayFormat.mjs.map +1 -1
- package/package.json +3 -3
- package/src/common/{fakeEvents.ts → fakeEvents.js} +1 -1
- package/src/common/hooks/useHasIntersected/{useHasIntersected.ts → useHasIntersected.js} +11 -20
- package/src/common/requirements.js +440 -0
- package/src/index.ts +0 -1
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.story.tsx +78 -0
- package/src/navigationOption/{NavigationOption.story.tsx → NavigationOption.story.js} +5 -23
- package/src/navigationOption/NavigationOption.tsx +1 -1
- package/src/utilities/deprecatedProperty/{deprecatedProperty.spec.js → deprecatedProperty.spec.ts} +7 -13
- package/src/utilities/deprecatedProperty/{deprecatedProperty.js → deprecatedProperty.ts} +23 -4
- package/src/utilities/{logActionRequired.js → logActionRequired.ts} +2 -2
- package/build/types/common/fakeEvents.d.ts +0 -23
- package/build/types/common/fakeEvents.d.ts.map +0 -1
- package/src/inputWithDisplayFormat/InputWithDisplayFormat.story.js +0 -85
- /package/src/common/hooks/{index.ts → index.js} +0 -0
- /package/src/common/hooks/useConditionalListener/{index.ts → index.js} +0 -0
- /package/src/common/hooks/useDirection/{index.ts → index.js} +0 -0
- /package/src/common/hooks/useHasIntersected/{index.ts → index.js} +0 -0
- /package/src/common/{index.ts → index.js} +0 -0
- /package/src/common/responsivePanel/{index.ts → index.js} +0 -0
- /package/src/test-utils/{style-mock.js → style-mock.ts} +0 -0
- /package/src/utilities/deprecatedProperty/{index.js → index.ts} +0 -0
- /package/src/utilities/{index.js → index.ts} +0 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
|
|
4
|
+
const prepRequirements = (alternatives) => {
|
|
5
|
+
if (!alternatives || alternatives.length === 0) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const preppedAlternatives = copyOf(alternatives);
|
|
10
|
+
|
|
11
|
+
preppedAlternatives.forEach((alternative) => {
|
|
12
|
+
if (alternative.prepared) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
prepLegacyAlternatives(alternative);
|
|
17
|
+
|
|
18
|
+
alternative.properties = prepFields(alternative.properties || alternative.fields);
|
|
19
|
+
|
|
20
|
+
// If we're still treating type as a special case, move it to a hidden value
|
|
21
|
+
if (alternative.type && alternative.type !== 'object' && !alternative.types) {
|
|
22
|
+
alternative.properties.type = {
|
|
23
|
+
type: 'string',
|
|
24
|
+
enum: [alternative.type],
|
|
25
|
+
required: true,
|
|
26
|
+
hidden: true,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
alternative.type = 'object';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
alternative.prepared = true;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return preppedAlternatives;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const prepFields = (fields, model, validationMessages) => {
|
|
39
|
+
if (!fields) {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let preparedFields = copyOf(fields);
|
|
44
|
+
|
|
45
|
+
preparedFields = flattenFieldsWithGroups(preparedFields);
|
|
46
|
+
preparedFields = transformFieldArrayToMap(preparedFields);
|
|
47
|
+
preparedFields = transformNestedKeysToNestedSpecs(preparedFields);
|
|
48
|
+
|
|
49
|
+
Object.keys(preparedFields).forEach((key) => {
|
|
50
|
+
preparedFields[key] = prepField(preparedFields[key], model, validationMessages);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return preparedFields;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const prepField = (field, model, validationMessages) => {
|
|
57
|
+
const preparedField = copyOf(field);
|
|
58
|
+
|
|
59
|
+
prepLegacyProps(preparedField);
|
|
60
|
+
prepType(preparedField);
|
|
61
|
+
prepPattern(preparedField);
|
|
62
|
+
prepValidationMessages(preparedField, validationMessages);
|
|
63
|
+
|
|
64
|
+
return preparedField;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* In an older format we had an extra fieldGroup level, here we flatten that out
|
|
69
|
+
* So the inner arrays of fields within the different field groups are flattened
|
|
70
|
+
* to a single array, which is returned.
|
|
71
|
+
*
|
|
72
|
+
* @param fields
|
|
73
|
+
*/
|
|
74
|
+
const flattenFieldsWithGroups = (fields) => {
|
|
75
|
+
if (Array.isArray(fields)) {
|
|
76
|
+
let flattenedFields = [];
|
|
77
|
+
fields.forEach((field) => {
|
|
78
|
+
// If we've been given a group with nested fields, break them out.
|
|
79
|
+
if (field.fields) {
|
|
80
|
+
flattenedFields = flattenedFields.concat(flattenFieldWithGroup(field, field.fields));
|
|
81
|
+
} else if (field.group) {
|
|
82
|
+
flattenedFields = flattenedFields.concat(flattenFieldWithGroup(field, field.group));
|
|
83
|
+
} else {
|
|
84
|
+
// Otherwise it's a regular field, just add it.
|
|
85
|
+
flattenedFields.push(field);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return flattenedFields;
|
|
89
|
+
}
|
|
90
|
+
return fields;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const flattenFieldWithGroup = (field, subFields) => {
|
|
94
|
+
// If first field doesn't have a label, use the one from the group
|
|
95
|
+
if (field.name && subFields.length > 0 && !subFields[0].name) {
|
|
96
|
+
subFields[0].name = field.name;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (field.width && subFields.length > 0 && !subFields[0].width) {
|
|
100
|
+
subFields[0].width = field.width;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// If there was a tooltip at fieldGroup level move it to first field.
|
|
104
|
+
if (field.tooltip && subFields.length > 0 && !subFields[0].help) {
|
|
105
|
+
subFields[0].help = { message: field.tooltip };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (field.info && subFields.length > 0 && !subFields[0].help) {
|
|
109
|
+
subFields[0].help = { message: field.info };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// If there are two parts of this group, render them side by side
|
|
113
|
+
if (subFields.length === 2) {
|
|
114
|
+
subFields.forEach((nestedField) => {
|
|
115
|
+
nestedField.width = 'md';
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// If there are three parts, render the first two side by side
|
|
120
|
+
if (subFields.length === 3) {
|
|
121
|
+
subFields[0].width = 'md';
|
|
122
|
+
subFields[1].width = 'md';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return subFields;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* Some older requirements return an array of fields, where it should be a map
|
|
130
|
+
* from the property name to the spec. This converts arrays to maps.
|
|
131
|
+
*/
|
|
132
|
+
const transformFieldArrayToMap = (fields) => {
|
|
133
|
+
if (Array.isArray(fields)) {
|
|
134
|
+
const fieldMap = {};
|
|
135
|
+
fields.forEach((field) => {
|
|
136
|
+
const key = field.key || field.name;
|
|
137
|
+
delete field.key;
|
|
138
|
+
|
|
139
|
+
fieldMap[key] = copyOf(field);
|
|
140
|
+
});
|
|
141
|
+
return fieldMap;
|
|
142
|
+
}
|
|
143
|
+
return fields;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
* Some older format return keys like 'address.city', expecting the value of
|
|
148
|
+
* city to be nested inside an address object. This function creates a spec of
|
|
149
|
+
* type 'object', and nests such fields inside of it. When we render we pass
|
|
150
|
+
* this object spec to a nested fieldset.
|
|
151
|
+
*/
|
|
152
|
+
const transformNestedKeysToNestedSpecs = (fieldMap) => {
|
|
153
|
+
if (Array.isArray(fieldMap)) {
|
|
154
|
+
throw new TypeError('Expecting a map of fields, not an array');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const nestedFields = {};
|
|
158
|
+
Object.keys(fieldMap).forEach((key) => {
|
|
159
|
+
if (key.indexOf('.') > 0) {
|
|
160
|
+
// If the key contains a period we need to nest the fields in another object
|
|
161
|
+
const pathSections = key.split('.');
|
|
162
|
+
const nestedKey = pathSections[0];
|
|
163
|
+
|
|
164
|
+
// If this sub object doesn't exist yet, create it
|
|
165
|
+
if (!nestedFields[nestedKey]) {
|
|
166
|
+
nestedFields[nestedKey] = {
|
|
167
|
+
type: 'object',
|
|
168
|
+
properties: {},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
nestedFields[nestedKey].properties[pathSections[1]] = fieldMap[key];
|
|
172
|
+
} else {
|
|
173
|
+
nestedFields[key] = fieldMap[key];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return nestedFields;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const prepType = (field) => {
|
|
180
|
+
const type = field.type && field.type.toLowerCase && field.type.toLowerCase();
|
|
181
|
+
|
|
182
|
+
switch (type) {
|
|
183
|
+
case 'text':
|
|
184
|
+
field.type = 'string';
|
|
185
|
+
break;
|
|
186
|
+
case 'date':
|
|
187
|
+
field.type = 'string';
|
|
188
|
+
field.format = 'date';
|
|
189
|
+
break;
|
|
190
|
+
case 'password':
|
|
191
|
+
field.type = 'string';
|
|
192
|
+
field.control = 'password';
|
|
193
|
+
break;
|
|
194
|
+
case 'checkbox':
|
|
195
|
+
field.type = 'boolean';
|
|
196
|
+
break;
|
|
197
|
+
case 'select':
|
|
198
|
+
if (!field.control) {
|
|
199
|
+
field.control = 'select';
|
|
200
|
+
}
|
|
201
|
+
delete field.type;
|
|
202
|
+
break;
|
|
203
|
+
case 'radio':
|
|
204
|
+
field.control = 'radio';
|
|
205
|
+
delete field.type;
|
|
206
|
+
break;
|
|
207
|
+
case 'upload':
|
|
208
|
+
field.type = 'string';
|
|
209
|
+
field.format = 'base64url';
|
|
210
|
+
break;
|
|
211
|
+
case 'tel':
|
|
212
|
+
field.type = 'string';
|
|
213
|
+
field.format = 'phone';
|
|
214
|
+
break;
|
|
215
|
+
case 'textarea':
|
|
216
|
+
field.type = 'string';
|
|
217
|
+
field.control = 'textarea';
|
|
218
|
+
break;
|
|
219
|
+
default:
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (!field.control && field.type !== 'object') {
|
|
223
|
+
field.control = getControlType(field);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const prepLegacyAlternatives = (alternative) => {
|
|
228
|
+
if (!alternative.title && alternative.label) {
|
|
229
|
+
alternative.title = alternative.label;
|
|
230
|
+
}
|
|
231
|
+
if (!alternative.title) {
|
|
232
|
+
alternative.title = getNameFromType(alternative.type);
|
|
233
|
+
}
|
|
234
|
+
if (!alternative.type && alternative.name) {
|
|
235
|
+
alternative.type = alternative.name;
|
|
236
|
+
}
|
|
237
|
+
if (!alternative.description && alternative.tooltip) {
|
|
238
|
+
alternative.description = alternative.tooltip;
|
|
239
|
+
}
|
|
240
|
+
if (alternative.fieldGroups && !alternative.fields) {
|
|
241
|
+
alternative.fields = flattenFieldsWithGroups(alternative.fieldGroups);
|
|
242
|
+
delete alternative.fieldGroups;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const prepLegacyProps = (field) => {
|
|
247
|
+
if (field.name && !field.title) {
|
|
248
|
+
field.title = field.name;
|
|
249
|
+
delete field.name;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (field.validationRegexp) {
|
|
253
|
+
field.pattern = field.validationRegexp;
|
|
254
|
+
delete field.validationRegexp;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (field.min) {
|
|
258
|
+
field.minimum = field.min;
|
|
259
|
+
delete field.min;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (field.max) {
|
|
263
|
+
field.maximum = field.max;
|
|
264
|
+
delete field.max;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (field.example && !field.placeholder) {
|
|
268
|
+
field.placeholder = field.example;
|
|
269
|
+
delete field.example;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (field.tooltip && !field.help) {
|
|
273
|
+
field.help = { message: field.tooltip };
|
|
274
|
+
delete field.tooltip;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (field.valuesAllowed && !field.values) {
|
|
278
|
+
field.values = field.valuesAllowed;
|
|
279
|
+
delete field.valuesAllowed;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (field.values && field.values.map) {
|
|
283
|
+
field.values = prepLegacyValues(field.values);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (field.value && !field.default) {
|
|
287
|
+
field.default = field.value;
|
|
288
|
+
delete field.value;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (field.values) {
|
|
292
|
+
// In some legacy arrays the first value is a placeholder, extract it.
|
|
293
|
+
if (
|
|
294
|
+
field.values &&
|
|
295
|
+
field.values.length > 0 &&
|
|
296
|
+
field.values[0] &&
|
|
297
|
+
!field.values[0].value &&
|
|
298
|
+
field.values[0].label &&
|
|
299
|
+
!field.placeholder
|
|
300
|
+
) {
|
|
301
|
+
field.placeholder = field.values[0].label;
|
|
302
|
+
field.values = field.values.slice(1);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const prepLegacyValues = (values) => values.map(prepLegacyValue);
|
|
308
|
+
|
|
309
|
+
const prepLegacyValue = (value) => {
|
|
310
|
+
if (!value.label && value.title) {
|
|
311
|
+
value.label = value.title;
|
|
312
|
+
delete value.title;
|
|
313
|
+
}
|
|
314
|
+
if (!value.label && value.name) {
|
|
315
|
+
value.label = value.name;
|
|
316
|
+
delete value.name;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!value.value && value.code) {
|
|
320
|
+
value.value = value.code;
|
|
321
|
+
delete value.code;
|
|
322
|
+
}
|
|
323
|
+
if (!value.value && value.key) {
|
|
324
|
+
value.value = value.key;
|
|
325
|
+
delete value.key;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return value;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const prepPattern = (field) => {
|
|
332
|
+
if (field.pattern) {
|
|
333
|
+
try {
|
|
334
|
+
new RegExp(field.pattern);
|
|
335
|
+
} catch {
|
|
336
|
+
// eslint-disable-next-line no-console
|
|
337
|
+
console.warn('API regexp is invalid');
|
|
338
|
+
delete field.pattern;
|
|
339
|
+
}
|
|
340
|
+
} else {
|
|
341
|
+
delete field.pattern;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const prepValidationMessages = (field, validationMessages) => {
|
|
346
|
+
field.validationMessages = field.validationMessages
|
|
347
|
+
? field.validationMessages
|
|
348
|
+
: validationMessages;
|
|
349
|
+
|
|
350
|
+
if (!field.validationMessages) {
|
|
351
|
+
delete field.validationMessages;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (field.validationMessages.minimum) {
|
|
356
|
+
field.validationMessages.min = field.validationMessages.minimum;
|
|
357
|
+
delete field.validationMessages.minimum;
|
|
358
|
+
}
|
|
359
|
+
if (field.validationMessages.maximum) {
|
|
360
|
+
field.validationMessages.max = field.validationMessages.maximum;
|
|
361
|
+
delete field.validationMessages.maximum;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const getControlType = (field) => {
|
|
366
|
+
if (field.control) {
|
|
367
|
+
return field.control.toLowerCase();
|
|
368
|
+
}
|
|
369
|
+
if (field.hidden) {
|
|
370
|
+
return 'hidden';
|
|
371
|
+
}
|
|
372
|
+
if (field.values && field.values.length > 0) {
|
|
373
|
+
return getSelectionType(field);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
switch (field.type) {
|
|
377
|
+
case 'string':
|
|
378
|
+
return getControlForStringFormat(field.format);
|
|
379
|
+
case 'number':
|
|
380
|
+
case 'integer':
|
|
381
|
+
return 'number';
|
|
382
|
+
case 'boolean':
|
|
383
|
+
return 'checkbox';
|
|
384
|
+
default:
|
|
385
|
+
return 'text';
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
const getControlForStringFormat = (format) => {
|
|
390
|
+
switch (format) {
|
|
391
|
+
case 'date':
|
|
392
|
+
return 'date';
|
|
393
|
+
case 'base64url':
|
|
394
|
+
return 'file';
|
|
395
|
+
case 'password':
|
|
396
|
+
return 'password';
|
|
397
|
+
case 'uri':
|
|
398
|
+
return 'text'; // 'url'; - not implemented
|
|
399
|
+
case 'email':
|
|
400
|
+
return 'text'; // 'email'; - not implemented
|
|
401
|
+
case 'phone':
|
|
402
|
+
return 'tel';
|
|
403
|
+
default:
|
|
404
|
+
return 'text';
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const getSelectionType = (field) => {
|
|
409
|
+
if (field.control) {
|
|
410
|
+
return field.control;
|
|
411
|
+
}
|
|
412
|
+
if (field.type === 'select') {
|
|
413
|
+
return 'select';
|
|
414
|
+
}
|
|
415
|
+
if (field.type === 'radio') {
|
|
416
|
+
return 'radio';
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (field.values) {
|
|
420
|
+
return field.values.length > 3 ? 'select' : 'radio';
|
|
421
|
+
}
|
|
422
|
+
return 'select';
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const copyOf = (object) => JSON.parse(JSON.stringify(object));
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Some older requirments formats do not include a label for alternatives
|
|
429
|
+
*
|
|
430
|
+
* @param tabType
|
|
431
|
+
*/
|
|
432
|
+
const getNameFromType = (tabType) => {
|
|
433
|
+
if (tabType && tabType.length > 0) {
|
|
434
|
+
const tabNameWithSpaces = tabType.toLowerCase().split('_').join(' '); // String.replace method only replaces first instance
|
|
435
|
+
return tabNameWithSpaces.charAt(0).toUpperCase() + tabNameWithSpaces.slice(1);
|
|
436
|
+
}
|
|
437
|
+
return '';
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
export { prepFields, getControlType };
|
package/src/index.ts
CHANGED
|
@@ -59,7 +59,6 @@ export type {
|
|
|
59
59
|
MoneyInputProps,
|
|
60
60
|
} from './moneyInput';
|
|
61
61
|
export type { NavigationOptionListProps } from './navigationOptionsList';
|
|
62
|
-
export type { NavigationOptionProps } from './navigationOption/NavigationOption';
|
|
63
62
|
export type { OverlayHeaderProps } from './overlayHeader';
|
|
64
63
|
export type { PanelProps } from './common/panel';
|
|
65
64
|
export type { PhoneNumberInputProps } from './phoneNumberInput/PhoneNumberInput';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { userEvent, within, fn } from '@storybook/test';
|
|
2
|
+
|
|
3
|
+
import InputWithDisplayFormat, { InputWithDisplayFormatProps } from '.';
|
|
4
|
+
import { Field, FieldProps } from '../field/Field';
|
|
5
|
+
import { Meta, type StoryObj } from '@storybook/react';
|
|
6
|
+
|
|
7
|
+
type Story = StoryObj<InputWithDisplayFormatProps & { label: string }>;
|
|
8
|
+
|
|
9
|
+
const meta = {
|
|
10
|
+
title: 'Forms/InputWithDisplayFormat',
|
|
11
|
+
component: InputWithDisplayFormat,
|
|
12
|
+
render: function Render({ label, ...args }: InputWithDisplayFormatProps & FieldProps) {
|
|
13
|
+
return (
|
|
14
|
+
<Field label={label} id={args.id}>
|
|
15
|
+
<InputWithDisplayFormat id={args.id} {...args} />
|
|
16
|
+
</Field>
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
onFocus: fn(),
|
|
21
|
+
onBlur: fn(),
|
|
22
|
+
onChange: fn(),
|
|
23
|
+
},
|
|
24
|
+
} satisfies Meta<typeof InputWithDisplayFormat>;
|
|
25
|
+
export default meta;
|
|
26
|
+
|
|
27
|
+
export const Basic: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
label: 'Sort Code',
|
|
30
|
+
placeholder: '**-**-**',
|
|
31
|
+
displayPattern: '**-**-**',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const CardNumber: Story = {
|
|
36
|
+
args: {
|
|
37
|
+
label: 'Card Number',
|
|
38
|
+
placeholder: '**** **** **** **** ***',
|
|
39
|
+
displayPattern: '**** **** **** **** ***',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const CVC: Story = {
|
|
44
|
+
args: {
|
|
45
|
+
label: 'CVC',
|
|
46
|
+
placeholder: '***',
|
|
47
|
+
displayPattern: '***',
|
|
48
|
+
value: '',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const ExpiryDate: Story = {
|
|
53
|
+
args: {
|
|
54
|
+
label: 'Expiry Date',
|
|
55
|
+
placeholder: '** / **',
|
|
56
|
+
displayPattern: '** / **',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const SecurityPin: Story = {
|
|
61
|
+
args: {
|
|
62
|
+
label: 'Security Pin',
|
|
63
|
+
placeholder: '*-*-*-*-*-*',
|
|
64
|
+
displayPattern: '*-*-*-*-*-*',
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const SecurityPinPlay: Story = {
|
|
69
|
+
args: {
|
|
70
|
+
label: 'Security Pin Play',
|
|
71
|
+
placeholder: '*-*-*-*-*-*',
|
|
72
|
+
displayPattern: '*-*-*-*-*-*',
|
|
73
|
+
},
|
|
74
|
+
play: async ({ canvasElement }) => {
|
|
75
|
+
const canvas = within(canvasElement);
|
|
76
|
+
await userEvent.type(canvas.getByPlaceholderText('*-*-*-*-*-*'), '123456');
|
|
77
|
+
},
|
|
78
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
1
|
import { action } from '@storybook/addon-actions';
|
|
3
2
|
import { text, boolean } from '@storybook/addon-knobs';
|
|
4
3
|
import {
|
|
@@ -20,22 +19,8 @@ export default {
|
|
|
20
19
|
tags: ['autodocs'],
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
href
|
|
25
|
-
title?: string;
|
|
26
|
-
content?: string;
|
|
27
|
-
complex?: boolean;
|
|
28
|
-
disabled?: boolean;
|
|
29
|
-
showMediaAtAllSizes?: boolean;
|
|
30
|
-
showMediaCircle?: boolean;
|
|
31
|
-
isContainerAligned?: boolean;
|
|
32
|
-
className?: string;
|
|
33
|
-
hasTitleOnly?: boolean;
|
|
34
|
-
media?: ReactNode;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const Template = (props: TemplateTypes) => {
|
|
38
|
-
const href = text('href', props.href ?? '');
|
|
22
|
+
const Template = (props) => {
|
|
23
|
+
const href = text('href', props.href);
|
|
39
24
|
const title = text('title', props.title ?? 'Navigation option');
|
|
40
25
|
const content = text('content', props.content ?? 'Button and icon are vertically centered.');
|
|
41
26
|
const complex = boolean('complex', props.complex ?? false);
|
|
@@ -43,7 +28,7 @@ const Template = (props: TemplateTypes) => {
|
|
|
43
28
|
const showMediaAtAllSizes = boolean('showMediaAtAllSizes', props.showMediaAtAllSizes ?? false);
|
|
44
29
|
const showMediaCircle = props.showMediaCircle ?? boolean('showMediaCircle', true);
|
|
45
30
|
const isContainerAligned = boolean('isContainerAligned', false);
|
|
46
|
-
const className = text('className', props.className
|
|
31
|
+
const className = text('className', props.className);
|
|
47
32
|
|
|
48
33
|
return (
|
|
49
34
|
<NavigationOption
|
|
@@ -155,10 +140,7 @@ export const Multiple = () => (
|
|
|
155
140
|
|
|
156
141
|
export const WithIllustration = () => {
|
|
157
142
|
return (
|
|
158
|
-
<Template
|
|
159
|
-
media={<Illustration name={Assets.GLOBE} disablePadding alt="" />}
|
|
160
|
-
showMediaCircle={false}
|
|
161
|
-
/>
|
|
143
|
+
<Template media={<Illustration name={Assets.GLOBE} disablePadding />} showMediaCircle={false} />
|
|
162
144
|
);
|
|
163
145
|
};
|
|
164
146
|
|
|
@@ -184,7 +166,7 @@ export const WithContainerContent = () => (
|
|
|
184
166
|
</>
|
|
185
167
|
);
|
|
186
168
|
|
|
187
|
-
const NavigationOptionTemplate = (props
|
|
169
|
+
const NavigationOptionTemplate = (props) => {
|
|
188
170
|
const {
|
|
189
171
|
href,
|
|
190
172
|
title,
|
|
@@ -6,7 +6,7 @@ import { Position } from '../common';
|
|
|
6
6
|
import Option from '../common/Option';
|
|
7
7
|
import { OptionProps, ReferenceType } from '../common/Option/Option';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
type NavigationOptionProps = OptionProps;
|
|
10
10
|
|
|
11
11
|
const NavigationOption = forwardRef<ReferenceType, NavigationOptionProps>(
|
|
12
12
|
({ as: component = 'button', disabled = false, onClick, className, ...rest }, reference) => {
|
package/src/utilities/deprecatedProperty/{deprecatedProperty.spec.js → deprecatedProperty.spec.ts}
RENAMED
|
@@ -5,6 +5,7 @@ const props = { prop1: 'prop1', prop2: 'prop2' };
|
|
|
5
5
|
const validator = jest.fn();
|
|
6
6
|
|
|
7
7
|
describe('deprecated', () => {
|
|
8
|
+
const component = 'Test';
|
|
8
9
|
const origWarn = console.warn;
|
|
9
10
|
let mockedWarn;
|
|
10
11
|
|
|
@@ -22,11 +23,10 @@ describe('deprecated', () => {
|
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
describe('if prop has been listed as deprecated', () => {
|
|
26
|
+
const propertyName = 'prop1';
|
|
27
|
+
|
|
25
28
|
it('calls console.warn with the correct message', () => {
|
|
26
|
-
const component = 'Test';
|
|
27
29
|
const newProperty = 'newProp';
|
|
28
|
-
const propertyName = 'prop1';
|
|
29
|
-
|
|
30
30
|
const expiryDate = new Date('01-01-2000');
|
|
31
31
|
const expiryDateString = expiryDate.toLocaleString('en-GB', {
|
|
32
32
|
year: 'numeric',
|
|
@@ -42,10 +42,6 @@ describe('deprecated', () => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
it('calls console.warn with correct message if newProp is not provided', () => {
|
|
45
|
-
const component = 'Test';
|
|
46
|
-
|
|
47
|
-
const propertyName = 'prop1';
|
|
48
|
-
|
|
49
45
|
const expiryDate = new Date('01-01-2000');
|
|
50
46
|
const expiryDateString = expiryDate.toLocaleString('en-GB', {
|
|
51
47
|
year: 'numeric',
|
|
@@ -61,8 +57,6 @@ describe('deprecated', () => {
|
|
|
61
57
|
});
|
|
62
58
|
|
|
63
59
|
it('calls console.warn with correct message if message is provided', () => {
|
|
64
|
-
const component = 'Test';
|
|
65
|
-
const propertyName = 'prop1';
|
|
66
60
|
const message = 'Some custom message.';
|
|
67
61
|
|
|
68
62
|
deprecated(validator, { component, message })(props, propertyName);
|
|
@@ -74,15 +68,15 @@ describe('deprecated', () => {
|
|
|
74
68
|
});
|
|
75
69
|
|
|
76
70
|
describe('if prop has not been listed as deprecated', () => {
|
|
71
|
+
const propertyName = 'prop3';
|
|
72
|
+
|
|
77
73
|
it('calls validator with props', () => {
|
|
78
|
-
|
|
79
|
-
deprecated(validator, {})(props, propertyName);
|
|
74
|
+
deprecated(validator, { component })(props, propertyName);
|
|
80
75
|
expect(console.warn).not.toHaveBeenCalled();
|
|
81
76
|
});
|
|
82
77
|
|
|
83
78
|
it('calls validator with expected args', () => {
|
|
84
|
-
|
|
85
|
-
deprecated(validator, {})(props, propertyName);
|
|
79
|
+
deprecated(validator, { component })(props, propertyName);
|
|
86
80
|
expect(validator).toHaveBeenCalledWith({ prop1: 'prop1', prop2: 'prop2' }, 'prop3');
|
|
87
81
|
});
|
|
88
82
|
});
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { logActionRequired } from '../logActionRequired';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type DeprecatedMessageType = {
|
|
4
|
+
component: string;
|
|
5
|
+
propName: string;
|
|
6
|
+
message: string;
|
|
7
|
+
expiryDate?: Date;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type ValidatorType = (props: Record<string, any>, propName: string, ...rest: any[]) => Error | null;
|
|
11
|
+
|
|
12
|
+
type DeprecatedOptionsType = {
|
|
13
|
+
component: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
newProp?: string;
|
|
16
|
+
expiryDate?: Date;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const deprecatedMessage = ({ component, propName, message, expiryDate }: DeprecatedMessageType) => {
|
|
4
20
|
const messages = [`${component} has deprecated the use of ${propName}.`];
|
|
5
21
|
|
|
6
22
|
if (message) {
|
|
@@ -21,11 +37,14 @@ const deprecatedMessage = ({ component, propName, message, expiryDate }) => {
|
|
|
21
37
|
};
|
|
22
38
|
|
|
23
39
|
const deprecated =
|
|
24
|
-
(
|
|
25
|
-
|
|
40
|
+
(
|
|
41
|
+
validator: ValidatorType,
|
|
42
|
+
{ component, message = '', newProp: newProperty, expiryDate }: DeprecatedOptionsType,
|
|
43
|
+
) =>
|
|
44
|
+
(props: Record<string, any>, propertyName: string, ...rest: any[]) => {
|
|
26
45
|
const newPropertyMessage = newProperty ? `Please use ${newProperty} instead.` : message;
|
|
27
46
|
|
|
28
|
-
if (props[propertyName]
|
|
47
|
+
if (props[propertyName] !== null && props[propertyName] !== undefined) {
|
|
29
48
|
logActionRequired(
|
|
30
49
|
deprecatedMessage({
|
|
31
50
|
component,
|