@shopgate/pwa-common 7.30.0-alpha.7 → 7.30.0-alpha.8
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/App.js +48 -6
- package/action-creators/app/index.js +75 -12
- package/action-creators/app/spec.js +96 -1
- package/action-creators/client/index.js +27 -5
- package/action-creators/client/spec.js +44 -1
- package/action-creators/error/index.js +15 -3
- package/action-creators/index.js +9 -1
- package/action-creators/menu/index.js +23 -4
- package/action-creators/menu/spec.js +37 -1
- package/action-creators/modal/index.js +15 -3
- package/action-creators/modal/spec.js +26 -1
- package/action-creators/page/index.js +24 -4
- package/action-creators/page/spec.js +38 -1
- package/action-creators/router/index.js +48 -7
- package/action-creators/url/index.js +24 -4
- package/action-creators/url/spec.js +45 -1
- package/action-creators/user/index.js +90 -13
- package/action-creators/user/spec.js +186 -2
- package/actions/app/handleDeepLink.js +11 -2
- package/actions/app/handleLink.js +62 -6
- package/actions/app/handlePushNotification.js +32 -4
- package/actions/app/handleUniversalLink.js +11 -2
- package/actions/app/registerLinkEvents.js +24 -3
- package/actions/client/fetchClientInformation.js +26 -2
- package/actions/menu/fetchMenu.js +23 -2
- package/actions/modal/closeModal.js +18 -2
- package/actions/modal/promiseMap.js +3 -1
- package/actions/modal/showModal.js +54 -8
- package/actions/page/fetchPageConfig.js +69 -2
- package/actions/page/getPageConfig.js +6 -2
- package/actions/page/index.js +1 -1
- package/actions/router/historyPop.js +12 -2
- package/actions/router/historyPopToRoute.js +27 -2
- package/actions/router/historyPush.js +12 -2
- package/actions/router/historyRedirect.js +21 -2
- package/actions/router/historyReplace.js +20 -3
- package/actions/router/historyReset.js +11 -2
- package/actions/router/historyResetTo.js +12 -2
- package/actions/router/index.js +17 -1
- package/actions/router/routeDidPop.js +11 -2
- package/actions/router/routeDidPush.js +13 -2
- package/actions/router/routeDidReplace.js +11 -2
- package/actions/router/routeDidReset.js +11 -2
- package/actions/router/routeDidUpdate.js +10 -2
- package/actions/router/routeWillPop.js +11 -2
- package/actions/router/routeWillPush.js +13 -2
- package/actions/router/routeWillReplace.js +11 -2
- package/actions/router/routeWillReset.js +11 -2
- package/actions/router/windowOpenOverride.js +10 -2
- package/actions/user/fetchRegisterUrl.js +36 -2
- package/actions/user/fetchUser.js +29 -3
- package/actions/user/getUser.js +6 -2
- package/actions/user/index.js +1 -1
- package/actions/user/login.js +76 -9
- package/actions/user/logout.js +30 -2
- package/collections/AuthRoutes.js +73 -14
- package/collections/Configuration.js +54 -7
- package/collections/EmbeddedMedia.js +84 -11
- package/collections/PersistedReducers.js +41 -6
- package/collections/Redirects.js +103 -17
- package/collections/index.js +5 -1
- package/collections/media-providers/MediaProvider.js +151 -26
- package/collections/media-providers/Vimeo.js +113 -19
- package/collections/media-providers/YouTube.js +74 -14
- package/collections/media-providers/index.js +3 -1
- package/collections/media-providers/style.js +52 -2
- package/components/Backdrop/index.js +95 -6
- package/components/Backdrop/spec.js +23 -1
- package/components/Backdrop/style.js +11 -2
- package/components/Button/index.js +47 -5
- package/components/Button/spec.js +36 -1
- package/components/Button/style.js +6 -1
- package/components/Checkbox/index.js +126 -32
- package/components/Checkbox/spec.js +94 -3
- package/components/Consume/helpers/buildParams.js +13 -2
- package/components/Consume/index.js +14 -2
- package/components/CountdownTimer/index.js +115 -17
- package/components/CountdownTimer/spec.js +126 -12
- package/components/Drawer/index.js +131 -16
- package/components/Drawer/spec.js +76 -1
- package/components/Drawer/style.js +37 -1
- package/components/Dropdown/index.js +65 -6
- package/components/Dropdown/style.js +4 -1
- package/components/Dropdown/transitions.js +34 -1
- package/components/Ellipsis/index.js +16 -2
- package/components/Ellipsis/spec.js +13 -1
- package/components/EmbeddedMedia/index.js +56 -6
- package/components/EmbeddedMedia/spec.js +52 -3
- package/components/ErrorBoundary/connector.js +9 -2
- package/components/ErrorBoundary/index.js +43 -7
- package/components/Grid/components/Item/index.js +40 -4
- package/components/Grid/components/Item/spec.js +23 -1
- package/components/Grid/components/Item/style.js +17 -3
- package/components/Grid/index.js +36 -4
- package/components/Grid/spec.js +23 -1
- package/components/Grid/style.js +11 -2
- package/components/HtmlSanitizer/connector.js +24 -3
- package/components/HtmlSanitizer/index.js +104 -12
- package/components/HtmlSanitizer/spec.js +207 -6
- package/components/I18n/components/FormatDate/index.js +26 -2
- package/components/I18n/components/FormatDate/spec.js +46 -1
- package/components/I18n/components/FormatNumber/index.js +34 -2
- package/components/I18n/components/FormatNumber/spec.js +41 -2
- package/components/I18n/components/FormatPrice/index.js +32 -2
- package/components/I18n/components/FormatPrice/spec.js +46 -1
- package/components/I18n/components/FormatTime/index.js +26 -2
- package/components/I18n/components/FormatTime/spec.js +43 -2
- package/components/I18n/components/I18nProvider/index.js +52 -9
- package/components/I18n/components/I18nProvider/spec.js +39 -1
- package/components/I18n/components/Placeholder/index.js +8 -2
- package/components/I18n/components/Placeholder/spec.js +30 -1
- package/components/I18n/components/Translate/index.js +68 -7
- package/components/I18n/components/Translate/spec.js +30 -1
- package/components/I18n/index.js +16 -1
- package/components/Icon/index.js +25 -2
- package/components/Icon/style.js +6 -1
- package/components/Image/Image.js +176 -19
- package/components/Image/ImageInner.js +48 -2
- package/components/Image/index.js +1 -1
- package/components/Image/style.js +29 -2
- package/components/InfiniteContainer/index.js +381 -49
- package/components/InfiniteContainer/spec.js +199 -10
- package/components/Input/components/DateInput.js +262 -6
- package/components/Input/components/MultiLineInput.js +98 -12
- package/components/Input/components/SimpleInput.js +207 -31
- package/components/Input/index.js +32 -3
- package/components/Input/spec.js +122 -1
- package/components/KeyboardConsumer/index.js +48 -7
- package/components/Link/connector.js +7 -1
- package/components/Link/index.js +96 -11
- package/components/Link/spec.js +56 -1
- package/components/Link/style.js +10 -1
- package/components/List/components/Item/index.js +35 -3
- package/components/List/components/Item/style.js +16 -1
- package/components/List/index.js +20 -2
- package/components/List/spec.js +31 -1
- package/components/Loading/index.js +6 -2
- package/components/Modal/index.js +38 -3
- package/components/Modal/style.js +36 -1
- package/components/ModalContainer/connector.js +17 -3
- package/components/ModalContainer/index.js +36 -3
- package/components/ModalContainer/spec.js +105 -5
- package/components/Picker/components/Button/index.js +34 -2
- package/components/Picker/components/Button/style.js +19 -1
- package/components/Picker/components/List/index.js +33 -2
- package/components/Picker/components/List/style.js +17 -1
- package/components/Picker/components/Modal/index.js +60 -7
- package/components/Picker/components/Modal/style.js +78 -1
- package/components/Picker/index.js +167 -21
- package/components/Picker/spec.js +83 -2
- package/components/Portal/index.js +130 -19
- package/components/ProductCharacteristics/connector.js +33 -4
- package/components/ProductCharacteristics/context.js +2 -1
- package/components/ProductCharacteristics/helpers/index.js +135 -21
- package/components/ProductCharacteristics/index.js +266 -31
- package/components/RangeSlider/components/Handle/index.js +25 -2
- package/components/RangeSlider/components/Handle/style.js +14 -1
- package/components/RangeSlider/helper.js +43 -8
- package/components/RangeSlider/index.js +228 -38
- package/components/RangeSlider/style.js +14 -1
- package/components/Route/RouteNotFound.js +46 -3
- package/components/Route/index.js +78 -10
- package/components/Router/connector.js +9 -2
- package/components/Router/index.js +237 -31
- package/components/ScannerContainer/connector.js +9 -2
- package/components/ScannerContainer/index.js +42 -6
- package/components/Select/components/Item/index.js +20 -4
- package/components/Select/components/Item/style.js +4 -1
- package/components/Select/index.js +149 -28
- package/components/Select/spec.js +86 -2
- package/components/Select/style.js +17 -1
- package/components/SelectBox/components/Item/index.js +47 -5
- package/components/SelectBox/components/Item/style.js +7 -1
- package/components/SelectBox/index.js +173 -17
- package/components/SelectBox/spec.js +59 -3
- package/components/SelectBox/style.js +18 -1
- package/components/Slider/index.js +6 -2
- package/components/SurroundPortals/index.js +26 -2
- package/components/Swiper/components/SwiperItem/index.js +28 -4
- package/components/Swiper/components/SwiperItem/spec.js +17 -1
- package/components/Swiper/components/SwiperItem/styles.js +5 -1
- package/components/Swiper/index.js +210 -18
- package/components/Swiper/styles.js +75 -7
- package/components/Toaster/index.js +10 -2
- package/components/Transition/index.js +89 -13
- package/components/Widgets/components/Widget/index.js +52 -4
- package/components/Widgets/components/Widget/spec.js +68 -3
- package/components/Widgets/components/Widget/style.js +21 -3
- package/components/Widgets/components/WidgetGrid/index.js +52 -7
- package/components/Widgets/components/WidgetGrid/spec.js +46 -2
- package/components/Widgets/components/WidgetGrid/style.js +8 -1
- package/components/Widgets/helpers/shouldShowWidget.js +44 -7
- package/components/Widgets/index.js +127 -15
- package/components/Widgets/spec.js +213 -6
- package/components/index.js +9 -1
- package/constants/ActionTypes.js +97 -19
- package/constants/Configuration.js +12 -2
- package/constants/Device.js +29 -2
- package/constants/DisplayOptions.js +8 -1
- package/constants/MenuIDs.js +2 -1
- package/constants/ModalTypes.js +1 -1
- package/constants/PageIDs.js +1 -1
- package/constants/Pipelines.js +7 -1
- package/constants/Portals.js +136 -3
- package/constants/Registration.js +3 -1
- package/constants/RoutePaths.js +13 -2
- package/constants/Tracking.js +3 -1
- package/constants/client.js +6 -1
- package/constants/ui.js +2 -1
- package/constants/user.js +6 -2
- package/context/index.js +33 -3
- package/helpers/config/index.js +139 -21
- package/helpers/config/mock.js +200 -8
- package/helpers/config/theme.js +50 -4
- package/helpers/data/index.js +204 -29
- package/helpers/data/spec.js +187 -7
- package/helpers/date/index.js +58 -6
- package/helpers/date/spec.js +92 -1
- package/helpers/dom/index.js +48 -11
- package/helpers/environment/index.js +14 -2
- package/helpers/html/decodeHTML.js +7 -1
- package/helpers/html/handleDOM.js +172 -21
- package/helpers/html/parseHTML.js +67 -12
- package/helpers/i18n/getDateFormatter.js +23 -4
- package/helpers/i18n/getNumberFormatter.js +32 -4
- package/helpers/i18n/getPriceFormatter.js +38 -4
- package/helpers/i18n/getTimeFormatter.js +23 -4
- package/helpers/i18n/getTranslator.js +62 -8
- package/helpers/i18n/index.js +5 -1
- package/helpers/i18n/mergeTranslations.js +36 -9
- package/helpers/i18n/messageCache.js +3 -1
- package/helpers/legacy/index.js +47 -9
- package/helpers/modal/withShowModal.js +13 -2
- package/helpers/portals/portalCollection.js +28 -6
- package/helpers/portals/routePortals.js +12 -1
- package/helpers/redux/compareObjects.js +7 -2
- package/helpers/redux/generateResultHash.js +36 -3
- package/helpers/redux/generateSortedHash.js +7 -2
- package/helpers/redux/hasExpired.js +10 -2
- package/helpers/redux/index.js +7 -1
- package/helpers/redux/mutable.js +143 -24
- package/helpers/redux/shouldFetchData.js +46 -10
- package/helpers/redux/shouldFetchFilters.js +17 -4
- package/helpers/router/index.js +49 -5
- package/helpers/style/index.js +43 -4
- package/helpers/style/spec.js +108 -2
- package/helpers/tracking/index.js +52 -9
- package/helpers/validation/index.js +39 -12
- package/helpers/validation/spec.js +10 -1
- package/package.json +3 -3
- package/providers/index.js +4 -1
- package/providers/loading/context.js +2 -1
- package/providers/loading/index.js +137 -22
- package/providers/toast/context.js +2 -1
- package/providers/toast/index.js +105 -11
- package/reducers/client/connectivity.js +22 -2
- package/reducers/client/index.js +7 -1
- package/reducers/client/info.js +27 -2
- package/reducers/index.js +23 -4
- package/reducers/menu/index.js +5 -1
- package/reducers/menu/menusById.js +41 -2
- package/reducers/modal/index.js +14 -2
- package/reducers/page/index.js +68 -5
- package/reducers/router/index.js +48 -2
- package/reducers/url/index.js +42 -3
- package/reducers/user/data.js +27 -2
- package/reducers/user/index.js +7 -1
- package/reducers/user/login.js +65 -2
- package/selectors/client.js +138 -21
- package/selectors/history.js +49 -11
- package/selectors/menu.js +34 -6
- package/selectors/modal.js +15 -4
- package/selectors/page.js +25 -4
- package/selectors/router.js +154 -30
- package/selectors/url.js +25 -4
- package/selectors/user.js +90 -13
- package/store/index.js +60 -6
- package/store/middelwares/logger.js +7 -1
- package/store/middelwares/streams.js +19 -2
- package/streams/app.js +60 -8
- package/streams/client.js +8 -2
- package/streams/error.js +14 -3
- package/streams/index.js +6 -1
- package/streams/interval.js +6 -2
- package/streams/main.js +27 -2
- package/streams/router.js +45 -8
- package/streams/user.js +89 -15
- package/streams/view.js +97 -25
- package/styles/reset/form.js +57 -5
- package/styles/reset/index.js +6 -1
- package/styles/reset/media.js +22 -1
- package/styles/reset/root.js +33 -1
- package/styles/reset/table.js +10 -1
- package/styles/reset/typography.js +26 -1
- package/subscriptions/app.js +148 -17
- package/subscriptions/error.js +292 -13
- package/subscriptions/helpers/buildRegisterUrl.js +25 -6
- package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
- package/subscriptions/helpers/handleLinks.js +267 -25
- package/subscriptions/helpers/pipeline.js +12 -1
- package/subscriptions/history.js +34 -6
- package/subscriptions/index.js +25 -4
- package/subscriptions/menu.js +22 -5
- package/subscriptions/mock.js +39 -7
- package/subscriptions/router.js +336 -23
- package/subscriptions/user.js +93 -3
package/components/Link/spec.js
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow, mount } from 'enzyme';
|
|
3
|
+
import { Disconnected as Link } from "./index";
|
|
4
|
+
describe('<Link />', () => {
|
|
5
|
+
const historyPush = jest.fn();
|
|
6
|
+
const historyReplace = jest.fn();
|
|
7
|
+
const pathname = '/';
|
|
8
|
+
const state = {
|
|
9
|
+
x: 5
|
|
10
|
+
};
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
jest.useFakeTimers();
|
|
13
|
+
jest.clearAllMocks();
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
jest.useRealTimers();
|
|
17
|
+
});
|
|
18
|
+
it('renders with children', () => {
|
|
19
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(Link, {
|
|
20
|
+
href: pathname,
|
|
21
|
+
historyPush: historyPush,
|
|
22
|
+
historyReplace: historyReplace
|
|
23
|
+
}, /*#__PURE__*/React.createElement("span", null)));
|
|
24
|
+
expect(wrapper).toMatchSnapshot();
|
|
25
|
+
expect(wrapper.find('span').length).toBe(1);
|
|
26
|
+
});
|
|
27
|
+
it('handles a push', () => {
|
|
28
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Link, {
|
|
29
|
+
href: pathname,
|
|
30
|
+
state: state,
|
|
31
|
+
historyPush: historyPush,
|
|
32
|
+
historyReplace: historyReplace
|
|
33
|
+
}, /*#__PURE__*/React.createElement("span", null)));
|
|
34
|
+
wrapper.find('div').simulate('click');
|
|
35
|
+
jest.runAllTimers();
|
|
36
|
+
expect(historyPush).toHaveBeenLastCalledWith({
|
|
37
|
+
pathname,
|
|
38
|
+
state
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('handles a replace', () => {
|
|
42
|
+
const wrapper = mount(/*#__PURE__*/React.createElement(Link, {
|
|
43
|
+
href: pathname,
|
|
44
|
+
historyPush: historyPush,
|
|
45
|
+
historyReplace: historyReplace,
|
|
46
|
+
state: state,
|
|
47
|
+
replace: true
|
|
48
|
+
}, /*#__PURE__*/React.createElement("span", null)));
|
|
49
|
+
wrapper.find('div').simulate('click');
|
|
50
|
+
jest.runAllTimers();
|
|
51
|
+
expect(historyReplace).toHaveBeenLastCalledWith({
|
|
52
|
+
pathname,
|
|
53
|
+
state
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
package/components/Link/style.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
export default css({
|
|
3
|
+
padding: 0,
|
|
4
|
+
margin: 0,
|
|
5
|
+
border: 'none',
|
|
6
|
+
textAlign: 'left',
|
|
7
|
+
alignItems: 'stretch',
|
|
8
|
+
width: '100%',
|
|
9
|
+
cursor: 'pointer'
|
|
10
|
+
}).toString();
|
|
@@ -1,5 +1,37 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styles from "./style";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* The ListItem component.
|
|
3
7
|
* @returns {JSX}
|
|
4
|
-
*/
|
|
5
|
-
|
|
8
|
+
*/
|
|
9
|
+
const ListItem = ({
|
|
10
|
+
children,
|
|
11
|
+
className,
|
|
12
|
+
isSelected,
|
|
13
|
+
role
|
|
14
|
+
}) => {
|
|
15
|
+
if (!React.Children.count(children)) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
let classes = styles.item;
|
|
19
|
+
if (className) {
|
|
20
|
+
classes += ` ${className}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Add selected or unselected styling.
|
|
24
|
+
classes += ` common__list__list-item ${isSelected ? styles.selected : styles.unselected}`;
|
|
25
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
26
|
+
className: classes,
|
|
27
|
+
"data-test-id": "listItem",
|
|
28
|
+
role: role
|
|
29
|
+
}, children);
|
|
30
|
+
};
|
|
31
|
+
ListItem.defaultProps = {
|
|
32
|
+
className: null,
|
|
33
|
+
children: null,
|
|
34
|
+
isSelected: false,
|
|
35
|
+
role: null
|
|
36
|
+
};
|
|
37
|
+
export default ListItem;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
const item = css({
|
|
3
|
+
display: 'block',
|
|
4
|
+
position: 'relative'
|
|
5
|
+
}).toString();
|
|
6
|
+
const unselected = css({
|
|
7
|
+
zIndex: 1
|
|
8
|
+
}).toString();
|
|
9
|
+
const selected = css({
|
|
10
|
+
zIndex: 2
|
|
11
|
+
}).toString();
|
|
12
|
+
export default {
|
|
13
|
+
item,
|
|
14
|
+
selected,
|
|
15
|
+
unselected
|
|
16
|
+
};
|
package/components/List/index.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import ListItem from "./components/Item";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* The List component.
|
|
3
7
|
* @param {Object} props The component props.
|
|
4
8
|
* @returns {JSX}
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const List = ({
|
|
11
|
+
children,
|
|
12
|
+
className,
|
|
13
|
+
role
|
|
14
|
+
}) => /*#__PURE__*/React.createElement("ul", {
|
|
15
|
+
className: `${className} common_list`,
|
|
16
|
+
role: role
|
|
17
|
+
}, children);
|
|
18
|
+
List.Item = ListItem;
|
|
19
|
+
List.defaultProps = {
|
|
20
|
+
className: '',
|
|
21
|
+
role: null
|
|
22
|
+
};
|
|
23
|
+
export default List;
|
package/components/List/spec.js
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { shallow } from 'enzyme';
|
|
4
|
+
import List from "./index";
|
|
5
|
+
console.error = jest.fn();
|
|
6
|
+
describe('<List />', () => {
|
|
7
|
+
const children = [/*#__PURE__*/React.createElement(List.Item, {
|
|
8
|
+
key: "0"
|
|
9
|
+
}), /*#__PURE__*/React.createElement(List.Item, {
|
|
10
|
+
key: "1"
|
|
11
|
+
}), /*#__PURE__*/React.createElement(List.Item, {
|
|
12
|
+
key: "2"
|
|
13
|
+
})];
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
it('renders with children', () => {
|
|
18
|
+
const numChildren = children.length;
|
|
19
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(List, null, children));
|
|
20
|
+
expect(wrapper).toMatchSnapshot();
|
|
21
|
+
expect(wrapper.find(List.Item).length).toBe(numChildren);
|
|
22
|
+
expect(console.error).not.toHaveBeenCalled();
|
|
23
|
+
});
|
|
24
|
+
it('renders without children', () => {
|
|
25
|
+
const wrapper = shallow(/*#__PURE__*/React.createElement(List, null));
|
|
26
|
+
expect(wrapper).toMatchSnapshot();
|
|
27
|
+
expect(wrapper.find(List.Item).length).toBe(0);
|
|
28
|
+
expect(console.error).toHaveBeenCalledTimes(1);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
/* eslint-enable no-console */
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import React,{Fragment}from'react'
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* @return {null}
|
|
3
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
const Loading = () => /*#__PURE__*/React.createElement(Fragment, null, null);
|
|
7
|
+
export default Loading;
|
|
@@ -1,7 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { useTrackModalState } from '@shopgate/engage/a11y/hooks';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import styles from "./style";
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* The Modal component.
|
|
3
11
|
* @param {Object} props The component props.
|
|
4
12
|
* @param {Object} props.classes The component classes.
|
|
5
13
|
* @returns {JSX.Element}
|
|
6
|
-
*/
|
|
7
|
-
|
|
14
|
+
*/
|
|
15
|
+
const Modal = /*#__PURE__*/forwardRef(({
|
|
16
|
+
children,
|
|
17
|
+
classes,
|
|
18
|
+
...props
|
|
19
|
+
}, ref) => {
|
|
20
|
+
// Track modal visibility for accessibility purposes.
|
|
21
|
+
useTrackModalState();
|
|
22
|
+
return /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement("div", _extends({
|
|
23
|
+
className: classNames(styles.container, classes?.container, 'common__modal'),
|
|
24
|
+
role: "alertdialog",
|
|
25
|
+
"aria-modal": true
|
|
26
|
+
}, props, {
|
|
27
|
+
ref: ref
|
|
28
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
className: classNames(styles.layout, classes?.layout)
|
|
30
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
31
|
+
className: classNames(styles.content, classes?.content)
|
|
32
|
+
}, children))), document.getElementById('portals'));
|
|
33
|
+
});
|
|
34
|
+
Modal.defaultProps = {
|
|
35
|
+
children: null,
|
|
36
|
+
classes: {
|
|
37
|
+
container: '',
|
|
38
|
+
layout: '',
|
|
39
|
+
content: ''
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export default Modal;
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { responsiveMediaQuery } from '@shopgate/engage/styles';
|
|
3
|
+
const container = css({
|
|
4
|
+
position: 'fixed',
|
|
5
|
+
top: 0,
|
|
6
|
+
bottom: 0,
|
|
7
|
+
left: 0,
|
|
8
|
+
right: 0,
|
|
9
|
+
overflow: 'hidden',
|
|
10
|
+
zIndex: 2000
|
|
11
|
+
}).toString();
|
|
12
|
+
const layout = css({
|
|
13
|
+
display: 'flex',
|
|
14
|
+
flexDirection: 'column',
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
height: '100%'
|
|
18
|
+
}).toString();
|
|
19
|
+
const content = css({
|
|
20
|
+
position: 'relative',
|
|
21
|
+
maxWidth: '100vw',
|
|
22
|
+
maxHeight: '100vh',
|
|
23
|
+
paddingTop: 'var(--safe-area-inset-top)',
|
|
24
|
+
paddingBottom: 'var(--safe-area-inset-bottom)',
|
|
25
|
+
overflowY: 'scroll',
|
|
26
|
+
[responsiveMediaQuery('>xs', {
|
|
27
|
+
webOnly: true
|
|
28
|
+
})]: {
|
|
29
|
+
overflowY: 'initial'
|
|
30
|
+
}
|
|
31
|
+
}).toString();
|
|
32
|
+
export default {
|
|
33
|
+
container,
|
|
34
|
+
layout,
|
|
35
|
+
content
|
|
36
|
+
};
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
import{connect}from'react-redux';
|
|
1
|
+
import { connect } from 'react-redux';
|
|
2
|
+
import closeModal from "../../actions/modal/closeModal";
|
|
3
|
+
import { getFirstModal } from "../../selectors/modal";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Maps the contents of the state to the component props.
|
|
3
7
|
* @param {Object} state The current application state.
|
|
4
8
|
* @return {Object} The extended component props.
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const mapStateToProps = state => ({
|
|
11
|
+
modal: getFirstModal(state)
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/**
|
|
6
15
|
* Connects the dispatch function to a callable function in the props.
|
|
7
16
|
* @param {Function} dispatch The redux dispatch function.
|
|
8
17
|
* @return {Object} The extended component props.
|
|
9
|
-
*/
|
|
18
|
+
*/
|
|
19
|
+
const mapDispatchToProps = dispatch => ({
|
|
20
|
+
confirm: id => dispatch(closeModal(id, true)),
|
|
21
|
+
dismiss: id => dispatch(closeModal(id, false))
|
|
22
|
+
});
|
|
23
|
+
export default connect(mapStateToProps, mapDispatchToProps);
|
|
@@ -1,7 +1,40 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import connect from "./connector";
|
|
4
|
+
export const MODAL_EVENTS = {
|
|
5
|
+
SHOW: 'Modal.show',
|
|
6
|
+
HIDE: 'Modal.hide'
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* The ModalContainer is connected to the modal state
|
|
3
11
|
* and renders the currently active modal.
|
|
4
12
|
* @param {Object} props The component props.
|
|
5
13
|
* @returns {JSX.Element}
|
|
6
|
-
*/
|
|
7
|
-
|
|
14
|
+
*/
|
|
15
|
+
const ModalContainer = ({
|
|
16
|
+
component,
|
|
17
|
+
confirm,
|
|
18
|
+
dismiss,
|
|
19
|
+
modal
|
|
20
|
+
}) => {
|
|
21
|
+
if (!modal) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const componentProps = {
|
|
25
|
+
modal,
|
|
26
|
+
// A11Y focus is handled by the modal container itself.
|
|
27
|
+
onConfirm: () => confirm(modal.id),
|
|
28
|
+
onDismiss: () => dismiss(modal.id)
|
|
29
|
+
};
|
|
30
|
+
if (/*#__PURE__*/React.isValidElement(component)) {
|
|
31
|
+
return /*#__PURE__*/React.cloneElement(component, componentProps);
|
|
32
|
+
}
|
|
33
|
+
return /*#__PURE__*/React.createElement(component, componentProps);
|
|
34
|
+
};
|
|
35
|
+
ModalContainer.defaultProps = {
|
|
36
|
+
confirm: () => {},
|
|
37
|
+
dismiss: () => {},
|
|
38
|
+
modal: null
|
|
39
|
+
};
|
|
40
|
+
export default connect(ModalContainer);
|
|
@@ -1,11 +1,111 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars */
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { mount } from 'enzyme';
|
|
4
|
+
import { Provider } from 'react-redux';
|
|
5
|
+
import { configureStore } from "../../store";
|
|
6
|
+
import modalReducer from "../../reducers/modal";
|
|
7
|
+
import showModal from "../../actions/modal/showModal";
|
|
8
|
+
import ModalContainer from "./index";
|
|
9
|
+
|
|
10
|
+
// const store = configureStore({ modal: modalReducer });
|
|
2
11
|
// Replacement for commented out configureStore()
|
|
3
|
-
|
|
12
|
+
const store = {};
|
|
13
|
+
jest.mock('redux-logger', () => ({
|
|
14
|
+
createLogger: () => () => next => action => next(action)
|
|
15
|
+
}));
|
|
16
|
+
global.requestAnimationFrame = fn => fn();
|
|
17
|
+
|
|
18
|
+
/**
|
|
4
19
|
* Some mock modal component.
|
|
5
20
|
* @param {func} onConfirm Confirm callback
|
|
6
21
|
* @param {func} onDismiss Dismiss callback
|
|
7
22
|
* @constructor
|
|
8
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
const MockModal = ({
|
|
25
|
+
onConfirm,
|
|
26
|
+
// eslint-disable-line react/prop-types
|
|
27
|
+
onDismiss // eslint-disable-line react/prop-types
|
|
28
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
className: "modal"
|
|
30
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
31
|
+
className: "confirmBtn",
|
|
32
|
+
onClick: onConfirm,
|
|
33
|
+
type: "button"
|
|
34
|
+
}), /*#__PURE__*/React.createElement("button", {
|
|
35
|
+
className: "dismissBtn",
|
|
36
|
+
onClick: onDismiss,
|
|
37
|
+
type: "button"
|
|
38
|
+
}));
|
|
39
|
+
describe.skip('<ModalContainer />', () => {
|
|
40
|
+
let renderedElement;
|
|
41
|
+
const {
|
|
42
|
+
dispatch,
|
|
43
|
+
getState
|
|
44
|
+
} = store;
|
|
45
|
+
|
|
46
|
+
/**
|
|
9
47
|
* The rendered component.
|
|
10
|
-
*/
|
|
11
|
-
|
|
48
|
+
*/
|
|
49
|
+
const renderComponent = () => {
|
|
50
|
+
renderedElement = mount(/*#__PURE__*/React.createElement(Provider, {
|
|
51
|
+
store: store
|
|
52
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
53
|
+
id: "container"
|
|
54
|
+
}, /*#__PURE__*/React.createElement(ModalContainer, {
|
|
55
|
+
component: MockModal
|
|
56
|
+
}))));
|
|
57
|
+
};
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
// Reset the modals state before each test.
|
|
60
|
+
getState().modal = [];
|
|
61
|
+
renderComponent();
|
|
62
|
+
});
|
|
63
|
+
describe('Given the component was mounted to the DOM', () => {
|
|
64
|
+
it('should match snapshot', () => {
|
|
65
|
+
expect(renderedElement).toMatchSnapshot();
|
|
66
|
+
});
|
|
67
|
+
it('should show no modal', () => {
|
|
68
|
+
expect(renderedElement.find('.modal').length).toBe(0);
|
|
69
|
+
});
|
|
70
|
+
describe('Given a modal gets dispatched', () => {
|
|
71
|
+
let modalPromise;
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
modalPromise = dispatch(showModal({
|
|
74
|
+
title: 'Title',
|
|
75
|
+
message: 'Message'
|
|
76
|
+
}));
|
|
77
|
+
renderedElement.update();
|
|
78
|
+
});
|
|
79
|
+
it('should contain a modal item in the state', () => {
|
|
80
|
+
expect(getState().modal.length).toBe(1);
|
|
81
|
+
});
|
|
82
|
+
it('should show the modal', () => {
|
|
83
|
+
expect(renderedElement.find('.modal').length).toBe(1);
|
|
84
|
+
});
|
|
85
|
+
describe('Given the modal gets confirmed', () => {
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
renderedElement.find('.confirmBtn').simulate('click');
|
|
88
|
+
});
|
|
89
|
+
it('should resolve the promise as confirmed', () => {
|
|
90
|
+
modalPromise.then(confirmed => expect(confirmed).toBe(true));
|
|
91
|
+
});
|
|
92
|
+
it('should contain no modal item in the state', () => {
|
|
93
|
+
expect(getState().modal.length).toBe(0);
|
|
94
|
+
});
|
|
95
|
+
it('should not show the modal anymore', () => {
|
|
96
|
+
expect(renderedElement.find('.modal').length).toBe(0);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('Given the modal gets dismissed', () => {
|
|
100
|
+
beforeEach(() => {
|
|
101
|
+
renderedElement.find('.dismissBtn').simulate('click');
|
|
102
|
+
});
|
|
103
|
+
it('should resolve the promise as dismissed', () => {
|
|
104
|
+
modalPromise.then(confirmed => expect(confirmed).toBe(false));
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/* eslint-enable no-unused-vars */
|
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
import React from'react';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import styles from "./style";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* The default button for the Picker component.
|
|
3
7
|
* @returns {JSX} The button component.
|
|
4
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
const PickerButton = ({
|
|
10
|
+
value,
|
|
11
|
+
label,
|
|
12
|
+
openList
|
|
13
|
+
}) => {
|
|
14
|
+
if (value !== null) {
|
|
15
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
16
|
+
className: styles.button,
|
|
17
|
+
onClick: openList,
|
|
18
|
+
type: "button"
|
|
19
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
20
|
+
className: styles.label
|
|
21
|
+
}, label), /*#__PURE__*/React.createElement("span", {
|
|
22
|
+
className: styles.value
|
|
23
|
+
}, value));
|
|
24
|
+
}
|
|
25
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
26
|
+
className: styles.button,
|
|
27
|
+
onClick: openList,
|
|
28
|
+
type: "button"
|
|
29
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
30
|
+
className: styles.label
|
|
31
|
+
}, label));
|
|
32
|
+
};
|
|
33
|
+
PickerButton.defaultProps = {
|
|
34
|
+
value: null
|
|
35
|
+
};
|
|
36
|
+
export default PickerButton;
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
const button = css({
|
|
3
|
+
display: 'block',
|
|
4
|
+
width: '100%',
|
|
5
|
+
textAlign: 'left',
|
|
6
|
+
padding: '10px 20px'
|
|
7
|
+
}).toString();
|
|
8
|
+
const label = css({
|
|
9
|
+
display: 'block'
|
|
10
|
+
}).toString();
|
|
11
|
+
const value = css({
|
|
12
|
+
display: 'block',
|
|
13
|
+
fontWeight: 'bold'
|
|
14
|
+
}).toString();
|
|
15
|
+
export default {
|
|
16
|
+
button,
|
|
17
|
+
label,
|
|
18
|
+
value
|
|
19
|
+
};
|
|
@@ -1,4 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import styles from "./style";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* The default button for the Picker component.
|
|
3
8
|
* @returns {JSX} The button component.
|
|
4
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const PickerList = ({
|
|
11
|
+
items,
|
|
12
|
+
onClose,
|
|
13
|
+
onSelect,
|
|
14
|
+
selectedIndex
|
|
15
|
+
}) => /*#__PURE__*/React.createElement("ul", {
|
|
16
|
+
className: "common__picker__list"
|
|
17
|
+
}, items.map((item, currentIndex) => /*#__PURE__*/React.createElement("li", {
|
|
18
|
+
key: item.value,
|
|
19
|
+
className: classNames({
|
|
20
|
+
[styles.active]: currentIndex === selectedIndex
|
|
21
|
+
})
|
|
22
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
23
|
+
className: styles.button,
|
|
24
|
+
disabled: item.disabled,
|
|
25
|
+
onClick: () => {
|
|
26
|
+
onSelect(item.value);
|
|
27
|
+
onClose();
|
|
28
|
+
},
|
|
29
|
+
type: "button"
|
|
30
|
+
}, item.label))));
|
|
31
|
+
PickerList.defaultProps = {
|
|
32
|
+
onClose: () => {},
|
|
33
|
+
selectedIndex: null
|
|
34
|
+
};
|
|
35
|
+
export default PickerList;
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
const button = css({
|
|
3
|
+
display: 'block',
|
|
4
|
+
width: '100%',
|
|
5
|
+
padding: '10px 20px',
|
|
6
|
+
outline: 'none',
|
|
7
|
+
textAlign: 'left'
|
|
8
|
+
}).toString();
|
|
9
|
+
const active = css({
|
|
10
|
+
button: {
|
|
11
|
+
fontWeight: 'bold'
|
|
12
|
+
}
|
|
13
|
+
}).toString();
|
|
14
|
+
export default {
|
|
15
|
+
button,
|
|
16
|
+
active
|
|
17
|
+
};
|