@boomerang-io/carbon-addons-boomerang-react 4.6.14-beta.9 → 4.6.15-beta.1
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/README.md +162 -162
- package/dist/cjs/components/AboutPlatform/AboutPlatform.js +50 -50
- package/dist/cjs/components/AdvantageSideNav/AdvantageSideNav.js +221 -221
- package/dist/cjs/components/AutoSuggest/AutoSuggest.js +101 -101
- package/dist/cjs/components/Avatar/Avatar.js +18 -18
- package/dist/cjs/components/CheckboxList/CheckboxList.js +34 -34
- package/dist/cjs/components/ComboBox/ComboBox.js +103 -103
- package/dist/cjs/components/ComboBoxMultiSelect/ComboBoxMultiSelect.js +32 -32
- package/dist/cjs/components/ComboBoxMultiSelect/MultiSelect.js +208 -208
- package/dist/cjs/components/ComposedModal/ComposedModal.js +80 -80
- package/dist/cjs/components/ConfirmModal/ConfirmModal.js +43 -43
- package/dist/cjs/components/Creatable/Creatable.js +137 -137
- package/dist/cjs/components/DataDrivenInput/DataDrivenInput.js +226 -226
- package/dist/cjs/components/DateInput/DateInput.js +35 -35
- package/dist/cjs/components/DecisionButtons/DecisionButtons.js +61 -61
- package/dist/cjs/components/DelayedRender/DelayedRender.js +17 -17
- package/dist/cjs/components/DynamicFormik/DynamicFormik.js +578 -578
- package/dist/cjs/components/Error403/Error403.js +13 -13
- package/dist/cjs/components/Error403/ForbiddenErrorBackground.js +113 -113
- package/dist/cjs/components/Error403/GraphicWrangler/GraphicWrangler.js +62 -62
- package/dist/cjs/components/Error404/Error404.js +13 -13
- package/dist/cjs/components/Error404/GraphicLoch/GraphicLoch.js +17 -17
- package/dist/cjs/components/Error404/NotFoundErrorBackground.js +129 -129
- package/dist/cjs/components/ErrorBoundary/ErrorBoundary.js +32 -32
- package/dist/cjs/components/ErrorDragon/ErrorDragon.js +13 -13
- package/dist/cjs/components/ErrorDragon/assets/ErrorGraphic.js +35 -35
- package/dist/cjs/components/ErrorFullPage/ErrorFullPage.js +10 -10
- package/dist/cjs/components/ErrorMessage/ErrorMessage.js +22 -22
- package/dist/cjs/components/ErrorPage/ErrorPage.js +11 -11
- package/dist/cjs/components/ErrorPageCore/ErrorPageCore.js +15 -15
- package/dist/cjs/components/ErrorPageCore/GenericErrorBackground.js +124 -124
- package/dist/cjs/components/FeatureHeader/FeatureHeader.js +29 -29
- package/dist/cjs/components/FeatureNavTab/FeatureNavTab.js +12 -12
- package/dist/cjs/components/FeatureNavTabs/FeatureNavTabs.js +12 -12
- package/dist/cjs/components/FeatureSideNav/FeatureSideNav.js +12 -12
- package/dist/cjs/components/FeatureSideNav/FeatureSideNavFooter.js +8 -8
- package/dist/cjs/components/FeatureSideNav/FeatureSideNavHeader.js +8 -8
- package/dist/cjs/components/FeatureSideNav/FeatureSideNavLinks.js +14 -14
- package/dist/cjs/components/FeatureSideNavLink/FeatureSideNavLink.js +12 -12
- package/dist/cjs/components/Feedback/Feedback.js +38 -38
- package/dist/cjs/components/FlowModal/FlowModal.js +141 -141
- package/dist/cjs/components/FlowModal/FlowModalForm.js +12 -12
- package/dist/cjs/components/Header/Header.js +187 -187
- package/dist/cjs/components/Header/HeaderAppSwitcher.js +94 -94
- package/dist/cjs/components/Header/HeaderMenu.js +7 -7
- package/dist/cjs/components/Header/HeaderMenuItem.js +51 -51
- package/dist/cjs/components/Header/HeaderTeamSwitcher.js +329 -332
- package/dist/cjs/components/Header/UserRequests.js +29 -29
- package/dist/cjs/components/ImageModal/ImageModal.js +17 -17
- package/dist/cjs/components/Loading/Loading.js +8 -8
- package/dist/cjs/components/MemberBar/MemberBar.js +20 -20
- package/dist/cjs/components/Modal/Modal.js +20 -20
- package/dist/cjs/components/ModalConfirmEdit/ModalConfirmArray.js +14 -14
- package/dist/cjs/components/ModalConfirmEdit/ModalConfirmDetails.js +11 -11
- package/dist/cjs/components/ModalConfirmEdit/ModalConfirmEdit.js +17 -17
- package/dist/cjs/components/ModalForm/ModalForm.js +9 -9
- package/dist/cjs/components/Notifications/NotificationsContainer.js +22 -22
- package/dist/cjs/components/Notifications/ToastNotification.js +21 -21
- package/dist/cjs/components/Notifications/notify.js +17 -17
- package/dist/cjs/components/PlatformBanner/PlatformBanner.js +8 -8
- package/dist/cjs/components/PlatformNotifications/PlatformNotification.js +17 -17
- package/dist/cjs/components/PlatformNotifications/PlatformNotificationsContainer.js +136 -136
- package/dist/cjs/components/Portal/Portal.js +14 -14
- package/dist/cjs/components/PrivacyRedirect/PrivacyRedirect.js +30 -30
- package/dist/cjs/components/PrivacyStatement/PrivacyStatement.js +90 -90
- package/dist/cjs/components/ProfileSettings/ProfileSettings.js +124 -142
- package/dist/cjs/components/ProtectedRoute/ProtectedRoute.js +13 -13
- package/dist/cjs/components/RadioGroup/RadioGroup.js +33 -33
- package/dist/cjs/components/RichTextArea/RichTextArea.js +142 -142
- package/dist/cjs/components/SignOut/SignOut.js +27 -27
- package/dist/cjs/components/SupportCenter/SupportCenter.js +65 -65
- package/dist/cjs/components/TextArea/TextArea.js +16 -16
- package/dist/cjs/components/TextInput/TextInput.js +13 -13
- package/dist/cjs/components/Toggle/Toggle.js +22 -22
- package/dist/cjs/components/TooltipHover/TooltipHover.js +39 -39
- package/dist/cjs/components/UIShell/UIShell.js +95 -95
- package/dist/cjs/config/servicesConfig.js +22 -22
- package/dist/cjs/constants/DataDrivenInputTypes.js +74 -74
- package/dist/cjs/constants/UserType.js +13 -13
- package/dist/cjs/hooks/useHeaderMenu.js +49 -49
- package/dist/cjs/hooks/usePortal.js +74 -74
- package/dist/cjs/hooks/useWindowSize.js +33 -33
- package/dist/cjs/internal/ListBox/ListBox.js +41 -41
- package/dist/cjs/internal/ListBox/ListBoxField.js +19 -19
- package/dist/cjs/internal/ListBox/ListBoxMenu.js +19 -19
- package/dist/cjs/internal/ListBox/ListBoxMenuIcon.js +31 -31
- package/dist/cjs/internal/ListBox/ListBoxMenuItem.js +38 -38
- package/dist/cjs/internal/ListBox/ListBoxSelection.js +64 -64
- package/dist/cjs/internal/ListBox/index.js +10 -10
- package/dist/cjs/internal/keyboard/keys.js +16 -16
- package/dist/cjs/internal/keyboard/match.js +67 -67
- package/dist/cjs/internal/settings.js +5 -5
- package/dist/cjs/tools/accessibility.js +13 -13
- package/dist/cjs/tools/createPropAdapter.js +44 -44
- package/dist/cjs/tools/isUrl.js +39 -39
- package/dist/cjs/tools/setupGetInstanceId.js +20 -20
- package/dist/cjs/tools/useSetState.js +12 -12
- package/dist/cjs/tools/yupAst/astGenerator.js +212 -212
- package/dist/cjs/tools/yupAst/customValidators.js +17 -17
- package/dist/esm/components/AboutPlatform/AboutPlatform.js +50 -50
- package/dist/esm/components/AdvantageSideNav/AdvantageSideNav.js +221 -221
- package/dist/esm/components/AutoSuggest/AutoSuggest.js +101 -101
- package/dist/esm/components/Avatar/Avatar.js +18 -18
- package/dist/esm/components/CheckboxList/CheckboxList.js +34 -34
- package/dist/esm/components/ComboBox/ComboBox.js +103 -103
- package/dist/esm/components/ComboBoxMultiSelect/ComboBoxMultiSelect.js +32 -32
- package/dist/esm/components/ComboBoxMultiSelect/MultiSelect.js +208 -208
- package/dist/esm/components/ComposedModal/ComposedModal.js +80 -80
- package/dist/esm/components/ConfirmModal/ConfirmModal.js +43 -43
- package/dist/esm/components/Creatable/Creatable.js +137 -137
- package/dist/esm/components/DataDrivenInput/DataDrivenInput.js +226 -226
- package/dist/esm/components/DateInput/DateInput.js +35 -35
- package/dist/esm/components/DecisionButtons/DecisionButtons.js +61 -61
- package/dist/esm/components/DelayedRender/DelayedRender.js +17 -17
- package/dist/esm/components/DynamicFormik/DynamicFormik.js +578 -578
- package/dist/esm/components/Error403/Error403.js +13 -13
- package/dist/esm/components/Error403/ForbiddenErrorBackground.js +113 -113
- package/dist/esm/components/Error403/GraphicWrangler/GraphicWrangler.js +62 -62
- package/dist/esm/components/Error404/Error404.js +13 -13
- package/dist/esm/components/Error404/GraphicLoch/GraphicLoch.js +17 -17
- package/dist/esm/components/Error404/NotFoundErrorBackground.js +129 -129
- package/dist/esm/components/ErrorBoundary/ErrorBoundary.js +32 -32
- package/dist/esm/components/ErrorDragon/ErrorDragon.js +13 -13
- package/dist/esm/components/ErrorDragon/assets/ErrorGraphic.js +35 -35
- package/dist/esm/components/ErrorFullPage/ErrorFullPage.js +10 -10
- package/dist/esm/components/ErrorMessage/ErrorMessage.js +22 -22
- package/dist/esm/components/ErrorPage/ErrorPage.js +11 -11
- package/dist/esm/components/ErrorPageCore/ErrorPageCore.js +15 -15
- package/dist/esm/components/ErrorPageCore/GenericErrorBackground.js +124 -124
- package/dist/esm/components/FeatureHeader/FeatureHeader.js +29 -29
- package/dist/esm/components/FeatureNavTab/FeatureNavTab.js +12 -12
- package/dist/esm/components/FeatureNavTabs/FeatureNavTabs.js +12 -12
- package/dist/esm/components/FeatureSideNav/FeatureSideNav.js +12 -12
- package/dist/esm/components/FeatureSideNav/FeatureSideNavFooter.js +8 -8
- package/dist/esm/components/FeatureSideNav/FeatureSideNavHeader.js +8 -8
- package/dist/esm/components/FeatureSideNav/FeatureSideNavLinks.js +14 -14
- package/dist/esm/components/FeatureSideNavLink/FeatureSideNavLink.js +12 -12
- package/dist/esm/components/Feedback/Feedback.js +38 -38
- package/dist/esm/components/FlowModal/FlowModal.js +141 -141
- package/dist/esm/components/FlowModal/FlowModalForm.js +12 -12
- package/dist/esm/components/Header/Header.js +187 -187
- package/dist/esm/components/Header/HeaderAppSwitcher.js +94 -94
- package/dist/esm/components/Header/HeaderMenu.js +7 -7
- package/dist/esm/components/Header/HeaderMenuItem.js +51 -51
- package/dist/esm/components/Header/HeaderTeamSwitcher.js +329 -332
- package/dist/esm/components/Header/UserRequests.js +29 -29
- package/dist/esm/components/ImageModal/ImageModal.js +17 -17
- package/dist/esm/components/Loading/Loading.js +8 -8
- package/dist/esm/components/MemberBar/MemberBar.js +20 -20
- package/dist/esm/components/Modal/Modal.js +20 -20
- package/dist/esm/components/ModalConfirmEdit/ModalConfirmArray.js +14 -14
- package/dist/esm/components/ModalConfirmEdit/ModalConfirmDetails.js +11 -11
- package/dist/esm/components/ModalConfirmEdit/ModalConfirmEdit.js +17 -17
- package/dist/esm/components/ModalForm/ModalForm.js +9 -9
- package/dist/esm/components/Notifications/NotificationsContainer.js +22 -22
- package/dist/esm/components/Notifications/ToastNotification.js +21 -21
- package/dist/esm/components/Notifications/notify.js +17 -17
- package/dist/esm/components/PlatformBanner/PlatformBanner.js +8 -8
- package/dist/esm/components/PlatformNotifications/PlatformNotification.js +17 -17
- package/dist/esm/components/PlatformNotifications/PlatformNotificationsContainer.js +136 -136
- package/dist/esm/components/Portal/Portal.js +14 -14
- package/dist/esm/components/PrivacyRedirect/PrivacyRedirect.js +30 -30
- package/dist/esm/components/PrivacyStatement/PrivacyStatement.js +90 -90
- package/dist/esm/components/ProfileSettings/ProfileSettings.js +124 -142
- package/dist/esm/components/ProtectedRoute/ProtectedRoute.js +13 -13
- package/dist/esm/components/RadioGroup/RadioGroup.js +33 -33
- package/dist/esm/components/RichTextArea/RichTextArea.js +142 -142
- package/dist/esm/components/SignOut/SignOut.js +27 -27
- package/dist/esm/components/SupportCenter/SupportCenter.js +65 -65
- package/dist/esm/components/TextArea/TextArea.js +16 -16
- package/dist/esm/components/TextInput/TextInput.js +13 -13
- package/dist/esm/components/Toggle/Toggle.js +22 -22
- package/dist/esm/components/TooltipHover/TooltipHover.js +39 -39
- package/dist/esm/components/UIShell/UIShell.js +95 -95
- package/dist/esm/config/servicesConfig.js +22 -22
- package/dist/esm/constants/DataDrivenInputTypes.js +74 -74
- package/dist/esm/constants/UserType.js +13 -13
- package/dist/esm/hooks/useHeaderMenu.js +49 -49
- package/dist/esm/hooks/usePortal.js +74 -74
- package/dist/esm/hooks/useWindowSize.js +33 -33
- package/dist/esm/internal/ListBox/ListBox.js +41 -41
- package/dist/esm/internal/ListBox/ListBoxField.js +19 -19
- package/dist/esm/internal/ListBox/ListBoxMenu.js +19 -19
- package/dist/esm/internal/ListBox/ListBoxMenuIcon.js +31 -31
- package/dist/esm/internal/ListBox/ListBoxMenuItem.js +38 -38
- package/dist/esm/internal/ListBox/ListBoxSelection.js +64 -64
- package/dist/esm/internal/ListBox/index.js +10 -10
- package/dist/esm/internal/keyboard/keys.js +16 -16
- package/dist/esm/internal/keyboard/match.js +67 -67
- package/dist/esm/internal/settings.js +5 -5
- package/dist/esm/tools/accessibility.js +13 -13
- package/dist/esm/tools/createPropAdapter.js +44 -44
- package/dist/esm/tools/isUrl.js +39 -39
- package/dist/esm/tools/setupGetInstanceId.js +20 -20
- package/dist/esm/tools/useSetState.js +12 -12
- package/dist/esm/tools/yupAst/astGenerator.js +212 -212
- package/dist/esm/tools/yupAst/customValidators.js +17 -17
- package/dist/types/index.d.ts +1359 -1360
- package/package.json +167 -167
- package/scss/components/AboutPlatform/_aboutPlatform.scss +139 -139
- package/scss/components/AdvantageSideNav/_advantageSideNav.scss +272 -272
- package/scss/components/AutoSuggest/_autoSuggest.scss +62 -62
- package/scss/components/Avatar/_avatar.scss +32 -32
- package/scss/components/CheckboxList/_checkboxList.scss +26 -26
- package/scss/components/ComboBox/_combobox.scss +23 -23
- package/scss/components/ComboBoxMultiSelect/_comboBoxMultiSelect.scss +53 -53
- package/scss/components/ConfirmModal/_confirmModal.scss +12 -12
- package/scss/components/Creatable/_creatable.scss +48 -48
- package/scss/components/DateInput/_dateInput.scss +36 -36
- package/scss/components/DecisionButtons/_decisionButtons.scss +132 -132
- package/scss/components/DynamicFormik/_dynamicFormik.scss +17 -17
- package/scss/components/ErrorBoundary/_errorBoundary.scss +12 -12
- package/scss/components/ErrorDragon/_errorDragon.scss +55 -55
- package/scss/components/ErrorMessage/_errorMessage.scss +43 -43
- package/scss/components/ErrorPage/_errorPage.scss +66 -66
- package/scss/components/ErrorPageCore/_errorPageCore.scss +73 -73
- package/scss/components/FeatureHeader/_featureHeader.scss +67 -67
- package/scss/components/FeatureNavTab/_featureNavTab.scss +27 -27
- package/scss/components/FeatureSideNav/_featureSideNav.scss +76 -76
- package/scss/components/FeatureSideNavLink/_featureSideNavLink.scss +49 -49
- package/scss/components/Feedback/_feedback.scss +50 -50
- package/scss/components/Header/_header.scss +179 -179
- package/scss/components/Header/_headerAppSwitcher.scss +117 -117
- package/scss/components/Header/_headerMenu.scss +30 -30
- package/scss/components/Header/_headerMenuItem.scss +65 -65
- package/scss/components/Header/_headerTeamSwitcher.scss +222 -222
- package/scss/components/Header/_userRequests.scss +36 -36
- package/scss/components/ImageModal/_imageModal.scss +51 -51
- package/scss/components/MemberBar/_memberBar.scss +99 -99
- package/scss/components/Modal/_modal.scss +163 -163
- package/scss/components/ModalConfirmEdit/_modalConfirmEdit.scss +113 -113
- package/scss/components/Notifications/_notifications.scss +57 -57
- package/scss/components/PlatformBanner/_platformBanner.scss +30 -30
- package/scss/components/PlatformNotifications/_platformNotifications.scss +230 -230
- package/scss/components/PrivacyRedirect/_privacyRedirect.scss +43 -43
- package/scss/components/PrivacyStatement/_privacyStatement.scss +137 -137
- package/scss/components/ProfileSettings/_profileSettings.scss +117 -117
- package/scss/components/ProtectedRoute/_protectedRoute.scss +32 -32
- package/scss/components/RadioGroup/_radioGroup.scss +46 -46
- package/scss/components/RichTextArea/_richTextArea.scss +82 -82
- package/scss/components/SignOut/_signOut.scss +51 -51
- package/scss/components/SupportCenter/_supportCenter.scss +16 -16
- package/scss/components/TextArea/_textArea.scss +19 -19
- package/scss/components/TextInput/_textInput.scss +26 -26
- package/scss/components/Toggle/_toggle.scss +80 -80
- package/scss/components/TooltipHover/_tooltip.scss +48 -48
- package/scss/global/_config.scss +14 -14
- package/scss/global/_tippy.scss +49 -49
- package/scss/global/index.scss +401 -401
- package/scss/global/themes/_boomerang.scss +184 -184
- package/scss/global/themes/_default.scss +79 -79
- package/scss/global/themes/_shell-tokens.scss +42 -42
- package/scss/global/utils/_animations.scss +15 -15
- package/scss/global/utils/_mixins.scss +67 -67
- package/scss/global/utils/index.scss +10 -10
|
@@ -10,214 +10,214 @@ import { mapDownshiftProps } from '../../tools/createPropAdapter.js';
|
|
|
10
10
|
import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
|
|
11
11
|
import { prefix } from '../../internal/settings.js';
|
|
12
12
|
|
|
13
|
-
/*
|
|
14
|
-
IBM Confidential
|
|
15
|
-
694970X, 69497O0
|
|
16
|
-
© Copyright IBM Corp. 2022, 2024
|
|
17
|
-
*/
|
|
18
|
-
const defaultItemToString = (item) => {
|
|
19
|
-
if (typeof item === "string") {
|
|
20
|
-
return item;
|
|
21
|
-
}
|
|
22
|
-
return item && item.label;
|
|
23
|
-
};
|
|
24
|
-
const defaultShouldFilterItem = ({ item, selectedItems, itemToString, inputValue }) => {
|
|
25
|
-
let keepItem = true;
|
|
26
|
-
const itemString = itemToString(item);
|
|
27
|
-
if (selectedItems.some((selectedItem) => itemString === itemToString(selectedItem)) ||
|
|
28
|
-
!itemString.toLowerCase().includes(inputValue.toLowerCase())) {
|
|
29
|
-
keepItem = false;
|
|
30
|
-
}
|
|
31
|
-
return keepItem;
|
|
32
|
-
};
|
|
33
|
-
const getInputValue = (state) => {
|
|
34
|
-
return state.inputValue || "";
|
|
35
|
-
};
|
|
36
|
-
const getInstanceId = setupGetInstanceId();
|
|
37
|
-
class MultiSelectComboBox extends React.Component {
|
|
38
|
-
static defaultProps = {
|
|
39
|
-
itemToString: defaultItemToString,
|
|
40
|
-
};
|
|
41
|
-
comboBoxInstanceId;
|
|
42
|
-
inputNode;
|
|
43
|
-
textInput;
|
|
44
|
-
constructor(props) {
|
|
45
|
-
super(props);
|
|
46
|
-
this.textInput = React.createRef();
|
|
47
|
-
this.comboBoxInstanceId = getInstanceId();
|
|
48
|
-
this.state = {
|
|
49
|
-
inputValue: getInputValue({}),
|
|
50
|
-
isOpen: props.open ?? false,
|
|
51
|
-
stateSelectedItems: props.initialSelectedItems || props.selectedItems || [],
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
//eslint disable-next-line
|
|
55
|
-
static getDerivedStateFromProps(nextProps, state) {
|
|
56
|
-
/**
|
|
57
|
-
* programmatically control this `open` prop
|
|
58
|
-
*/
|
|
59
|
-
const { open } = nextProps;
|
|
60
|
-
const { prevOpen } = state;
|
|
61
|
-
return prevOpen === open
|
|
62
|
-
? { inputValue: getInputValue(state) }
|
|
63
|
-
: {
|
|
64
|
-
isOpen: open,
|
|
65
|
-
prevOpen: open,
|
|
66
|
-
inputValue: getInputValue(state),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
filterItems = (items, selectedItems, itemToString, inputValue) => {
|
|
70
|
-
const { shouldFilterItem = defaultShouldFilterItem } = this.props;
|
|
71
|
-
return shouldFilterItem
|
|
72
|
-
? items.filter((item) => shouldFilterItem({
|
|
73
|
-
item,
|
|
74
|
-
selectedItems,
|
|
75
|
-
itemToString,
|
|
76
|
-
inputValue,
|
|
77
|
-
}))
|
|
78
|
-
: items;
|
|
79
|
-
};
|
|
80
|
-
handleOnInputKeyDown = (event) => {
|
|
81
|
-
event.stopPropagation();
|
|
82
|
-
};
|
|
83
|
-
handleOnInputValueChange = (inputValue) => {
|
|
84
|
-
const { onInputChange } = this.props;
|
|
85
|
-
this.setState(() => ({
|
|
86
|
-
// Default to empty string if we have a false-y `inputValue`
|
|
87
|
-
inputValue: inputValue || "",
|
|
88
|
-
}), () => {
|
|
89
|
-
if (onInputChange) {
|
|
90
|
-
onInputChange(inputValue);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
handleOnChange = (item) => {
|
|
95
|
-
if (!item) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const selectedItems = [...this.state.stateSelectedItems];
|
|
99
|
-
let selectedIndex;
|
|
100
|
-
selectedItems.forEach((selectedItem, index) => {
|
|
101
|
-
if (isEqual(selectedItem, item)) {
|
|
102
|
-
selectedIndex = index;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
if (selectedIndex === undefined) {
|
|
106
|
-
selectedItems.push(item);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
selectedItems.splice(selectedIndex, 1);
|
|
110
|
-
}
|
|
111
|
-
this.setState({ stateSelectedItems: selectedItems });
|
|
112
|
-
if (typeof this.props.onChange === "function") {
|
|
113
|
-
this.props.onChange({ selectedItems });
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
onToggleClick = (isOpen) => (event) => {
|
|
117
|
-
if (this.props.onToggleClick) {
|
|
118
|
-
this.props.onToggleClick(event);
|
|
119
|
-
}
|
|
120
|
-
if (event.target === this.textInput.current && isOpen) {
|
|
121
|
-
event.preventDownshiftDefault = true;
|
|
122
|
-
event.persist();
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
openMenu = () => {
|
|
126
|
-
this.setState({ isOpen: true });
|
|
127
|
-
};
|
|
128
|
-
closeMenu = () => {
|
|
129
|
-
this.setState({ isOpen: false });
|
|
130
|
-
};
|
|
131
|
-
handleClearSelection = () => {
|
|
132
|
-
this.setState({ stateSelectedItems: [] });
|
|
133
|
-
if (typeof this.props.onChange === "function") {
|
|
134
|
-
this.props.onChange({ selectedItems: [] });
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
handleInputBlur = (e) => {
|
|
138
|
-
this.props.onInputBlur && this.props.onInputBlur(e);
|
|
139
|
-
this.closeMenu();
|
|
140
|
-
};
|
|
141
|
-
handleOnStateChange = (changes) => {
|
|
142
|
-
const { type } = changes;
|
|
143
|
-
switch (type) {
|
|
144
|
-
case Downshift.stateChangeTypes.keyDownEscape:
|
|
145
|
-
case Downshift.stateChangeTypes.mouseUp:
|
|
146
|
-
this.setState({ isOpen: false });
|
|
147
|
-
break;
|
|
148
|
-
// Opt-in to some cases where we should be toggling the menu based on
|
|
149
|
-
// a given key press or mouse handler
|
|
150
|
-
// Reference: https://github.com/paypal/downshift/issues/206
|
|
151
|
-
case Downshift.stateChangeTypes.clickButton:
|
|
152
|
-
case Downshift.stateChangeTypes.keyDownSpaceButton:
|
|
153
|
-
this.setState(() => {
|
|
154
|
-
let nextIsOpen = changes.isOpen || false;
|
|
155
|
-
if (changes.isOpen === false) {
|
|
156
|
-
// If Downshift is trying to close the menu, but we know the input
|
|
157
|
-
// is the active element in the document, then keep the menu open
|
|
158
|
-
if (this.inputNode === document.activeElement) {
|
|
159
|
-
nextIsOpen = true;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
isOpen: nextIsOpen,
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
render() {
|
|
170
|
-
const { ariaLabel = "Choose an item", className: containerClassName, disabled = false, direction, downshiftProps, id, invalid, invalidText, items, itemToString = defaultItemToString, itemToElement, initialSelectedItems, titleText, helperText, placeholder, onChange, onInputBlur, onInputChange, light = false, selectedItems: propsSelectedItems, size,
|
|
171
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
172
|
-
shouldFilterItem = defaultShouldFilterItem, tagProps, translateWithId, type = "default", ...rest } = this.props;
|
|
173
|
-
const { stateSelectedItems, isOpen } = this.state;
|
|
174
|
-
const { ListBox, ListBoxField: Field, ListBoxSelection: Selection, ListBoxMenu: Menu, ListBoxMenuItem: MenuItem, ListBoxMenuIcon: MenuIcon, } = index;
|
|
175
|
-
// externally controlled if selectedItems props exist
|
|
176
|
-
const selectedItems = propsSelectedItems || stateSelectedItems;
|
|
177
|
-
const className = cx(`${prefix}--combo-box`, containerClassName, {
|
|
178
|
-
[`${prefix}--list-box--up`]: direction === "top",
|
|
179
|
-
});
|
|
180
|
-
const titleClasses = cx(`${prefix}--label`, {
|
|
181
|
-
[`${prefix}--label--disabled`]: disabled,
|
|
182
|
-
});
|
|
183
|
-
const comboBoxHelperId = !helperText ? undefined : `combobox-helper-text-${this.comboBoxInstanceId}`;
|
|
184
|
-
const helperClasses = cx(`${prefix}--form__helper-text`, {
|
|
185
|
-
[`${prefix}--form__helper-text--disabled`]: disabled,
|
|
186
|
-
});
|
|
187
|
-
const wrapperClasses = cx(`${prefix}--list-box__wrapper`);
|
|
188
|
-
const inputClasses = cx(`${prefix}--text-input`, {
|
|
189
|
-
[`${prefix}--text-input--empty`]: !this.state.inputValue,
|
|
190
|
-
});
|
|
191
|
-
const ItemToElement = itemToElement;
|
|
192
|
-
return (React.createElement(Downshift, { ...mapDownshiftProps(downshiftProps), onChange: this.handleOnChange, onInputValueChange: this.handleOnInputValueChange, inputValue: this.state.inputValue || "", isOpen: isOpen, itemToString: itemToString, onStateChange: this.handleOnStateChange, onOuterClick: this.closeMenu, selectedItem: selectedItems }, ({ getInputProps, getItemProps, getLabelProps, getMenuProps, getToggleButtonProps, isOpen, inputValue, selectedItem, highlightedIndex, clearSelection, }) => (React.createElement("div", { className: wrapperClasses },
|
|
193
|
-
titleText && (React.createElement("label", { htmlFor: id, className: titleClasses, ...getLabelProps() }, titleText)),
|
|
194
|
-
React.createElement(ListBox, { className: className, disabled: disabled, invalid: invalid, "aria-label": ariaLabel, invalidText: invalidText, isOpen: isOpen, light: light, type: type, size: size },
|
|
195
|
-
React.createElement("div", { className: `${prefix}--bmrg-multi-select-selected` }, Array.isArray(selectedItems) &&
|
|
196
|
-
selectedItems.map((item, index) => {
|
|
197
|
-
const itemString = itemToString(item);
|
|
198
|
-
return (React.createElement(Tag, { key: `${itemString}-${index}`, disabled: disabled, type: "teal", onClick: () => this.handleOnChange(item), onKeyDown: (e) => isAccessibleKeyDownEvent(e) && this.handleOnChange(item), filter: true, ...tagProps }, itemString));
|
|
199
|
-
})),
|
|
200
|
-
React.createElement(Field, { id: id, disabled: disabled, ...getToggleButtonProps({
|
|
201
|
-
disabled,
|
|
202
|
-
onClick: this.onToggleClick(isOpen),
|
|
203
|
-
}) },
|
|
204
|
-
React.createElement("input", { className: inputClasses, "aria-label": ariaLabel, "aria-controls": `${id}__menu`, "aria-autocomplete": "list", tabIndex: 0, ref: this.textInput, ...rest, ...getInputProps({
|
|
205
|
-
disabled,
|
|
206
|
-
id,
|
|
207
|
-
placeholder,
|
|
208
|
-
onKeyDown: this.handleOnInputKeyDown,
|
|
209
|
-
onFocus: this.openMenu,
|
|
210
|
-
onBlur: this.handleInputBlur,
|
|
211
|
-
}) }),
|
|
212
|
-
invalid && React.createElement(WarningFilled, { size: 16, className: `${prefix}--list-box__invalid-icon` }),
|
|
213
|
-
(inputValue || selectedItems.length > 0) && (React.createElement(Selection, { clearSelection: clearSelection, onClearSelection: this.handleClearSelection, disabled: disabled, translateWithId: translateWithId })),
|
|
214
|
-
React.createElement(MenuIcon, { isOpen: isOpen, translateWithId: translateWithId })),
|
|
215
|
-
isOpen && (React.createElement(Menu, { id: id, ...getMenuProps({ "aria-label": ariaLabel }) }, this.filterItems(items, selectedItem, itemToString, inputValue).map((item, index) => {
|
|
216
|
-
const itemProps = getItemProps({ item, index });
|
|
217
|
-
return (React.createElement(MenuItem, { key: itemProps.id, isHighlighted: highlightedIndex === index, title: itemToElement ? item.text : itemToString(item), ...itemProps }, typeof ItemToElement !== "undefined" ? (React.createElement(ItemToElement, { key: itemToString(item), ...item })) : (itemToString(item))));
|
|
218
|
-
})))),
|
|
219
|
-
helperText && !invalid && (React.createElement("div", { id: comboBoxHelperId, className: helperClasses }, helperText))))));
|
|
220
|
-
}
|
|
13
|
+
/*
|
|
14
|
+
IBM Confidential
|
|
15
|
+
694970X, 69497O0
|
|
16
|
+
© Copyright IBM Corp. 2022, 2024
|
|
17
|
+
*/
|
|
18
|
+
const defaultItemToString = (item) => {
|
|
19
|
+
if (typeof item === "string") {
|
|
20
|
+
return item;
|
|
21
|
+
}
|
|
22
|
+
return item && item.label;
|
|
23
|
+
};
|
|
24
|
+
const defaultShouldFilterItem = ({ item, selectedItems, itemToString, inputValue }) => {
|
|
25
|
+
let keepItem = true;
|
|
26
|
+
const itemString = itemToString(item);
|
|
27
|
+
if (selectedItems.some((selectedItem) => itemString === itemToString(selectedItem)) ||
|
|
28
|
+
!itemString.toLowerCase().includes(inputValue.toLowerCase())) {
|
|
29
|
+
keepItem = false;
|
|
30
|
+
}
|
|
31
|
+
return keepItem;
|
|
32
|
+
};
|
|
33
|
+
const getInputValue = (state) => {
|
|
34
|
+
return state.inputValue || "";
|
|
35
|
+
};
|
|
36
|
+
const getInstanceId = setupGetInstanceId();
|
|
37
|
+
class MultiSelectComboBox extends React.Component {
|
|
38
|
+
static defaultProps = {
|
|
39
|
+
itemToString: defaultItemToString,
|
|
40
|
+
};
|
|
41
|
+
comboBoxInstanceId;
|
|
42
|
+
inputNode;
|
|
43
|
+
textInput;
|
|
44
|
+
constructor(props) {
|
|
45
|
+
super(props);
|
|
46
|
+
this.textInput = React.createRef();
|
|
47
|
+
this.comboBoxInstanceId = getInstanceId();
|
|
48
|
+
this.state = {
|
|
49
|
+
inputValue: getInputValue({}),
|
|
50
|
+
isOpen: props.open ?? false,
|
|
51
|
+
stateSelectedItems: props.initialSelectedItems || props.selectedItems || [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//eslint disable-next-line
|
|
55
|
+
static getDerivedStateFromProps(nextProps, state) {
|
|
56
|
+
/**
|
|
57
|
+
* programmatically control this `open` prop
|
|
58
|
+
*/
|
|
59
|
+
const { open } = nextProps;
|
|
60
|
+
const { prevOpen } = state;
|
|
61
|
+
return prevOpen === open
|
|
62
|
+
? { inputValue: getInputValue(state) }
|
|
63
|
+
: {
|
|
64
|
+
isOpen: open,
|
|
65
|
+
prevOpen: open,
|
|
66
|
+
inputValue: getInputValue(state),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
filterItems = (items, selectedItems, itemToString, inputValue) => {
|
|
70
|
+
const { shouldFilterItem = defaultShouldFilterItem } = this.props;
|
|
71
|
+
return shouldFilterItem
|
|
72
|
+
? items.filter((item) => shouldFilterItem({
|
|
73
|
+
item,
|
|
74
|
+
selectedItems,
|
|
75
|
+
itemToString,
|
|
76
|
+
inputValue,
|
|
77
|
+
}))
|
|
78
|
+
: items;
|
|
79
|
+
};
|
|
80
|
+
handleOnInputKeyDown = (event) => {
|
|
81
|
+
event.stopPropagation();
|
|
82
|
+
};
|
|
83
|
+
handleOnInputValueChange = (inputValue) => {
|
|
84
|
+
const { onInputChange } = this.props;
|
|
85
|
+
this.setState(() => ({
|
|
86
|
+
// Default to empty string if we have a false-y `inputValue`
|
|
87
|
+
inputValue: inputValue || "",
|
|
88
|
+
}), () => {
|
|
89
|
+
if (onInputChange) {
|
|
90
|
+
onInputChange(inputValue);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
handleOnChange = (item) => {
|
|
95
|
+
if (!item) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const selectedItems = [...this.state.stateSelectedItems];
|
|
99
|
+
let selectedIndex;
|
|
100
|
+
selectedItems.forEach((selectedItem, index) => {
|
|
101
|
+
if (isEqual(selectedItem, item)) {
|
|
102
|
+
selectedIndex = index;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (selectedIndex === undefined) {
|
|
106
|
+
selectedItems.push(item);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
selectedItems.splice(selectedIndex, 1);
|
|
110
|
+
}
|
|
111
|
+
this.setState({ stateSelectedItems: selectedItems });
|
|
112
|
+
if (typeof this.props.onChange === "function") {
|
|
113
|
+
this.props.onChange({ selectedItems });
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
onToggleClick = (isOpen) => (event) => {
|
|
117
|
+
if (this.props.onToggleClick) {
|
|
118
|
+
this.props.onToggleClick(event);
|
|
119
|
+
}
|
|
120
|
+
if (event.target === this.textInput.current && isOpen) {
|
|
121
|
+
event.preventDownshiftDefault = true;
|
|
122
|
+
event.persist();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
openMenu = () => {
|
|
126
|
+
this.setState({ isOpen: true });
|
|
127
|
+
};
|
|
128
|
+
closeMenu = () => {
|
|
129
|
+
this.setState({ isOpen: false });
|
|
130
|
+
};
|
|
131
|
+
handleClearSelection = () => {
|
|
132
|
+
this.setState({ stateSelectedItems: [] });
|
|
133
|
+
if (typeof this.props.onChange === "function") {
|
|
134
|
+
this.props.onChange({ selectedItems: [] });
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
handleInputBlur = (e) => {
|
|
138
|
+
this.props.onInputBlur && this.props.onInputBlur(e);
|
|
139
|
+
this.closeMenu();
|
|
140
|
+
};
|
|
141
|
+
handleOnStateChange = (changes) => {
|
|
142
|
+
const { type } = changes;
|
|
143
|
+
switch (type) {
|
|
144
|
+
case Downshift.stateChangeTypes.keyDownEscape:
|
|
145
|
+
case Downshift.stateChangeTypes.mouseUp:
|
|
146
|
+
this.setState({ isOpen: false });
|
|
147
|
+
break;
|
|
148
|
+
// Opt-in to some cases where we should be toggling the menu based on
|
|
149
|
+
// a given key press or mouse handler
|
|
150
|
+
// Reference: https://github.com/paypal/downshift/issues/206
|
|
151
|
+
case Downshift.stateChangeTypes.clickButton:
|
|
152
|
+
case Downshift.stateChangeTypes.keyDownSpaceButton:
|
|
153
|
+
this.setState(() => {
|
|
154
|
+
let nextIsOpen = changes.isOpen || false;
|
|
155
|
+
if (changes.isOpen === false) {
|
|
156
|
+
// If Downshift is trying to close the menu, but we know the input
|
|
157
|
+
// is the active element in the document, then keep the menu open
|
|
158
|
+
if (this.inputNode === document.activeElement) {
|
|
159
|
+
nextIsOpen = true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
isOpen: nextIsOpen,
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
render() {
|
|
170
|
+
const { ariaLabel = "Choose an item", className: containerClassName, disabled = false, direction, downshiftProps, id, invalid, invalidText, items, itemToString = defaultItemToString, itemToElement, initialSelectedItems, titleText, helperText, placeholder, onChange, onInputBlur, onInputChange, light = false, selectedItems: propsSelectedItems, size,
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
172
|
+
shouldFilterItem = defaultShouldFilterItem, tagProps, translateWithId, type = "default", ...rest } = this.props;
|
|
173
|
+
const { stateSelectedItems, isOpen } = this.state;
|
|
174
|
+
const { ListBox, ListBoxField: Field, ListBoxSelection: Selection, ListBoxMenu: Menu, ListBoxMenuItem: MenuItem, ListBoxMenuIcon: MenuIcon, } = index;
|
|
175
|
+
// externally controlled if selectedItems props exist
|
|
176
|
+
const selectedItems = propsSelectedItems || stateSelectedItems;
|
|
177
|
+
const className = cx(`${prefix}--combo-box`, containerClassName, {
|
|
178
|
+
[`${prefix}--list-box--up`]: direction === "top",
|
|
179
|
+
});
|
|
180
|
+
const titleClasses = cx(`${prefix}--label`, {
|
|
181
|
+
[`${prefix}--label--disabled`]: disabled,
|
|
182
|
+
});
|
|
183
|
+
const comboBoxHelperId = !helperText ? undefined : `combobox-helper-text-${this.comboBoxInstanceId}`;
|
|
184
|
+
const helperClasses = cx(`${prefix}--form__helper-text`, {
|
|
185
|
+
[`${prefix}--form__helper-text--disabled`]: disabled,
|
|
186
|
+
});
|
|
187
|
+
const wrapperClasses = cx(`${prefix}--list-box__wrapper`);
|
|
188
|
+
const inputClasses = cx(`${prefix}--text-input`, {
|
|
189
|
+
[`${prefix}--text-input--empty`]: !this.state.inputValue,
|
|
190
|
+
});
|
|
191
|
+
const ItemToElement = itemToElement;
|
|
192
|
+
return (React.createElement(Downshift, { ...mapDownshiftProps(downshiftProps), onChange: this.handleOnChange, onInputValueChange: this.handleOnInputValueChange, inputValue: this.state.inputValue || "", isOpen: isOpen, itemToString: itemToString, onStateChange: this.handleOnStateChange, onOuterClick: this.closeMenu, selectedItem: selectedItems }, ({ getInputProps, getItemProps, getLabelProps, getMenuProps, getToggleButtonProps, isOpen, inputValue, selectedItem, highlightedIndex, clearSelection, }) => (React.createElement("div", { className: wrapperClasses },
|
|
193
|
+
titleText && (React.createElement("label", { htmlFor: id, className: titleClasses, ...getLabelProps() }, titleText)),
|
|
194
|
+
React.createElement(ListBox, { className: className, disabled: disabled, invalid: invalid, "aria-label": ariaLabel, invalidText: invalidText, isOpen: isOpen, light: light, type: type, size: size },
|
|
195
|
+
React.createElement("div", { className: `${prefix}--bmrg-multi-select-selected` }, Array.isArray(selectedItems) &&
|
|
196
|
+
selectedItems.map((item, index) => {
|
|
197
|
+
const itemString = itemToString(item);
|
|
198
|
+
return (React.createElement(Tag, { key: `${itemString}-${index}`, disabled: disabled, type: "teal", onClick: () => this.handleOnChange(item), onKeyDown: (e) => isAccessibleKeyDownEvent(e) && this.handleOnChange(item), filter: true, ...tagProps }, itemString));
|
|
199
|
+
})),
|
|
200
|
+
React.createElement(Field, { id: id, disabled: disabled, ...getToggleButtonProps({
|
|
201
|
+
disabled,
|
|
202
|
+
onClick: this.onToggleClick(isOpen),
|
|
203
|
+
}) },
|
|
204
|
+
React.createElement("input", { className: inputClasses, "aria-label": ariaLabel, "aria-controls": `${id}__menu`, "aria-autocomplete": "list", tabIndex: 0, ref: this.textInput, ...rest, ...getInputProps({
|
|
205
|
+
disabled,
|
|
206
|
+
id,
|
|
207
|
+
placeholder,
|
|
208
|
+
onKeyDown: this.handleOnInputKeyDown,
|
|
209
|
+
onFocus: this.openMenu,
|
|
210
|
+
onBlur: this.handleInputBlur,
|
|
211
|
+
}) }),
|
|
212
|
+
invalid && React.createElement(WarningFilled, { size: 16, className: `${prefix}--list-box__invalid-icon` }),
|
|
213
|
+
(inputValue || selectedItems.length > 0) && (React.createElement(Selection, { clearSelection: clearSelection, onClearSelection: this.handleClearSelection, disabled: disabled, translateWithId: translateWithId })),
|
|
214
|
+
React.createElement(MenuIcon, { isOpen: isOpen, translateWithId: translateWithId })),
|
|
215
|
+
isOpen && (React.createElement(Menu, { id: id, ...getMenuProps({ "aria-label": ariaLabel }) }, this.filterItems(items, selectedItem, itemToString, inputValue).map((item, index) => {
|
|
216
|
+
const itemProps = getItemProps({ item, index });
|
|
217
|
+
return (React.createElement(MenuItem, { key: itemProps.id, isHighlighted: highlightedIndex === index, title: itemToElement ? item.text : itemToString(item), ...itemProps }, typeof ItemToElement !== "undefined" ? (React.createElement(ItemToElement, { key: itemToString(item), ...item })) : (itemToString(item))));
|
|
218
|
+
})))),
|
|
219
|
+
helperText && !invalid && (React.createElement("div", { id: comboBoxHelperId, className: helperClasses }, helperText))))));
|
|
220
|
+
}
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
export { MultiSelectComboBox as default };
|
|
@@ -6,86 +6,86 @@ import ConfirmModal from '../ConfirmModal/ConfirmModal.js';
|
|
|
6
6
|
import { prefix } from '../../internal/settings.js';
|
|
7
7
|
import useSetState from '../../tools/useSetState.js';
|
|
8
8
|
|
|
9
|
-
/*
|
|
10
|
-
IBM Confidential
|
|
11
|
-
694970X, 69497O0
|
|
12
|
-
© Copyright IBM Corp. 2022, 2024
|
|
13
|
-
*/
|
|
14
|
-
function ComposedModal(props) {
|
|
15
|
-
const { appElement = "#app", composedModalProps = {}, isOpen = false, modalHeaderProps = {} } = props;
|
|
16
|
-
const [state, setState] = useSetState({
|
|
17
|
-
isConfirmModalOpen: false,
|
|
18
|
-
isOpen: isOpen,
|
|
19
|
-
shouldConfirmModalClose: false,
|
|
20
|
-
step: 0,
|
|
21
|
-
...props.initialState,
|
|
22
|
-
});
|
|
23
|
-
// Let it be externally controlled
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
setState({ isOpen });
|
|
26
|
-
// eslint-disable-next-line
|
|
27
|
-
}, [isOpen]);
|
|
28
|
-
/**
|
|
29
|
-
* Reset to initial state
|
|
30
|
-
* and let parent know
|
|
31
|
-
*/
|
|
32
|
-
const resetInitialState = (stateUpdate) => {
|
|
33
|
-
setState({
|
|
34
|
-
isConfirmModalOpen: false,
|
|
35
|
-
shouldConfirmModalClose: false,
|
|
36
|
-
...props.initialState,
|
|
37
|
-
...stateUpdate,
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
const handleOpenModal = () => {
|
|
41
|
-
setState({ isOpen: true });
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Close modal and call event function for parent if provided
|
|
45
|
-
*/
|
|
46
|
-
const handleCloseModal = () => {
|
|
47
|
-
resetInitialState({ isOpen: false });
|
|
48
|
-
if (typeof props.onCloseModal === "function") {
|
|
49
|
-
props.onCloseModal();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Check if should confirm exit with confirm modal or just exit modal flow
|
|
54
|
-
*/
|
|
55
|
-
const handleShouldCloseModal = () => {
|
|
56
|
-
if (state.shouldConfirmModalClose) {
|
|
57
|
-
setState({ isConfirmModalOpen: true });
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
handleCloseModal();
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
const closeConfirmModal = () => {
|
|
64
|
-
setState({ isConfirmModalOpen: false });
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* Method passed to children components and they determine if should confirm exit of modal
|
|
68
|
-
* @param {bool} shouldConfirmModalClose - boolean of current component
|
|
69
|
-
*/
|
|
70
|
-
const handleSetShouldConfirmModalClose = (shouldConfirmModalClose) => {
|
|
71
|
-
setState({ shouldConfirmModalClose });
|
|
72
|
-
};
|
|
73
|
-
const { containerClassName, ...restComposedModalProps } = composedModalProps;
|
|
74
|
-
const { subtitle, ...restModalHeaderProps } = modalHeaderProps;
|
|
75
|
-
return (React.createElement(React.Fragment, null,
|
|
76
|
-
props.modalTrigger && props.modalTrigger({ openModal: handleOpenModal }),
|
|
77
|
-
React.createElement(Modal, { appElement: appElement, containerClassName: cx(`${prefix}--bmrg-modal-composed-container`, `${prefix}--modal-container`, props.size ? `${prefix}--modal-container--${props.size}` : "modal-container-fix-width", containerClassName), isOpen: state.isOpen, onRequestClose: handleShouldCloseModal, shouldCloseOnOverlayClick: false, ...restComposedModalProps },
|
|
78
|
-
React.createElement(ModalHeader, { closeModal: handleShouldCloseModal, ...restModalHeaderProps }, subtitle && React.createElement("p", { className: `${prefix}--bmrg-modal-composed-subtitle` }, subtitle)),
|
|
79
|
-
state.isOpen &&
|
|
80
|
-
typeof props.children === "function" &&
|
|
81
|
-
props.children({
|
|
82
|
-
closeModal: handleShouldCloseModal,
|
|
83
|
-
forceCloseModal: handleCloseModal,
|
|
84
|
-
resetInitialState: resetInitialState,
|
|
85
|
-
setShouldConfirmModalClose: handleSetShouldConfirmModalClose,
|
|
86
|
-
shouldConfirmModalClose: state.shouldConfirmModalClose,
|
|
87
|
-
}),
|
|
88
|
-
React.createElement(ConfirmModal, { affirmativeAction: handleCloseModal, appElement: appElement, negativeAction: closeConfirmModal, isOpen: state.isConfirmModalOpen, onCloseModal: closeConfirmModal, ...props.confirmModalProps }))));
|
|
9
|
+
/*
|
|
10
|
+
IBM Confidential
|
|
11
|
+
694970X, 69497O0
|
|
12
|
+
© Copyright IBM Corp. 2022, 2024
|
|
13
|
+
*/
|
|
14
|
+
function ComposedModal(props) {
|
|
15
|
+
const { appElement = "#app", composedModalProps = {}, isOpen = false, modalHeaderProps = {} } = props;
|
|
16
|
+
const [state, setState] = useSetState({
|
|
17
|
+
isConfirmModalOpen: false,
|
|
18
|
+
isOpen: isOpen,
|
|
19
|
+
shouldConfirmModalClose: false,
|
|
20
|
+
step: 0,
|
|
21
|
+
...props.initialState,
|
|
22
|
+
});
|
|
23
|
+
// Let it be externally controlled
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setState({ isOpen });
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
}, [isOpen]);
|
|
28
|
+
/**
|
|
29
|
+
* Reset to initial state
|
|
30
|
+
* and let parent know
|
|
31
|
+
*/
|
|
32
|
+
const resetInitialState = (stateUpdate) => {
|
|
33
|
+
setState({
|
|
34
|
+
isConfirmModalOpen: false,
|
|
35
|
+
shouldConfirmModalClose: false,
|
|
36
|
+
...props.initialState,
|
|
37
|
+
...stateUpdate,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const handleOpenModal = () => {
|
|
41
|
+
setState({ isOpen: true });
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Close modal and call event function for parent if provided
|
|
45
|
+
*/
|
|
46
|
+
const handleCloseModal = () => {
|
|
47
|
+
resetInitialState({ isOpen: false });
|
|
48
|
+
if (typeof props.onCloseModal === "function") {
|
|
49
|
+
props.onCloseModal();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Check if should confirm exit with confirm modal or just exit modal flow
|
|
54
|
+
*/
|
|
55
|
+
const handleShouldCloseModal = () => {
|
|
56
|
+
if (state.shouldConfirmModalClose) {
|
|
57
|
+
setState({ isConfirmModalOpen: true });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
handleCloseModal();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const closeConfirmModal = () => {
|
|
64
|
+
setState({ isConfirmModalOpen: false });
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Method passed to children components and they determine if should confirm exit of modal
|
|
68
|
+
* @param {bool} shouldConfirmModalClose - boolean of current component
|
|
69
|
+
*/
|
|
70
|
+
const handleSetShouldConfirmModalClose = (shouldConfirmModalClose) => {
|
|
71
|
+
setState({ shouldConfirmModalClose });
|
|
72
|
+
};
|
|
73
|
+
const { containerClassName, ...restComposedModalProps } = composedModalProps;
|
|
74
|
+
const { subtitle, ...restModalHeaderProps } = modalHeaderProps;
|
|
75
|
+
return (React.createElement(React.Fragment, null,
|
|
76
|
+
props.modalTrigger && props.modalTrigger({ openModal: handleOpenModal }),
|
|
77
|
+
React.createElement(Modal, { appElement: appElement, containerClassName: cx(`${prefix}--bmrg-modal-composed-container`, `${prefix}--modal-container`, props.size ? `${prefix}--modal-container--${props.size}` : "modal-container-fix-width", containerClassName), isOpen: state.isOpen, onRequestClose: handleShouldCloseModal, shouldCloseOnOverlayClick: false, ...restComposedModalProps },
|
|
78
|
+
React.createElement(ModalHeader, { closeModal: handleShouldCloseModal, ...restModalHeaderProps }, subtitle && React.createElement("p", { className: `${prefix}--bmrg-modal-composed-subtitle` }, subtitle)),
|
|
79
|
+
state.isOpen &&
|
|
80
|
+
typeof props.children === "function" &&
|
|
81
|
+
props.children({
|
|
82
|
+
closeModal: handleShouldCloseModal,
|
|
83
|
+
forceCloseModal: handleCloseModal,
|
|
84
|
+
resetInitialState: resetInitialState,
|
|
85
|
+
setShouldConfirmModalClose: handleSetShouldConfirmModalClose,
|
|
86
|
+
shouldConfirmModalClose: state.shouldConfirmModalClose,
|
|
87
|
+
}),
|
|
88
|
+
React.createElement(ConfirmModal, { affirmativeAction: handleCloseModal, appElement: appElement, negativeAction: closeConfirmModal, isOpen: state.isConfirmModalOpen, onCloseModal: closeConfirmModal, ...props.confirmModalProps }))));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
export { ComposedModal, ComposedModal as default };
|