@shopgate/pwa-common 7.30.0-alpha.7 → 7.30.0-alpha.9
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 +214 -7
- 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 +21 -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 +228 -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 -4
- 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
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { useMemo, useState, useEffect, useRef, useCallback, memo } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import noop from 'lodash/noop';
|
|
5
|
+
import { themeConfig } from '@shopgate/engage';
|
|
6
|
+
import { getFullImageSource } from '@shopgate/engage/core/helpers';
|
|
7
|
+
import styles from "./style";
|
|
8
|
+
import ImageInner from "./ImageInner";
|
|
9
|
+
const {
|
|
10
|
+
colors: themeColors
|
|
11
|
+
} = themeConfig;
|
|
12
|
+
|
|
13
|
+
/**
|
|
2
14
|
* Calculates the Greatest Common Divisor (GCD) of two numbers using the Euclidean algorithm.
|
|
3
15
|
*
|
|
4
16
|
* @param {number} a - The first number (must be a positive integer).
|
|
@@ -9,32 +21,177 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
9
21
|
* gcd(1920, 1080); // Returns 120
|
|
10
22
|
* gcd(10, 15); // Returns 5
|
|
11
23
|
* gcd(100, 25); // Returns 25
|
|
12
|
-
*/
|
|
24
|
+
*/
|
|
25
|
+
const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
26
|
+
|
|
27
|
+
/**
|
|
13
28
|
* The image component.
|
|
14
29
|
* @param {Object} props The components props.
|
|
15
30
|
* @returns {JSX.Element}
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
*/
|
|
32
|
+
const Image = ({
|
|
33
|
+
alt,
|
|
34
|
+
backgroundColor,
|
|
35
|
+
className,
|
|
36
|
+
classNameImg,
|
|
37
|
+
forcePlaceholder: parentRendersPlaceholder,
|
|
38
|
+
highestResolutionLoaded,
|
|
39
|
+
onError,
|
|
40
|
+
onLoad,
|
|
41
|
+
ratio,
|
|
42
|
+
resolutions,
|
|
43
|
+
src,
|
|
44
|
+
lazy,
|
|
45
|
+
unwrapped
|
|
46
|
+
}) => {
|
|
47
|
+
// Prepare two image sources - a small preview image and a large main image. The idea is to
|
|
48
|
+
// display an image as soon as possible. Small images might be also available in the cache from
|
|
49
|
+
// the previous page.
|
|
50
|
+
const sources = useMemo(() => {
|
|
51
|
+
// Create a preview source when resolutions array has more than one element
|
|
52
|
+
const preview = resolutions.length > 1 ? getFullImageSource(src, resolutions[resolutions.length - 2]) : null;
|
|
53
|
+
|
|
54
|
+
// Create a main source when resolutions array has at least one element (highest resolution)
|
|
55
|
+
const main = resolutions.length > 0 ? getFullImageSource(src, resolutions[resolutions.length - 1]) : null;
|
|
56
|
+
return {
|
|
57
|
+
// Only assign preview source if it is different from the main source. Image swap logic
|
|
58
|
+
// will not run when no preview source is available.
|
|
59
|
+
preview: preview !== main ? preview : null,
|
|
60
|
+
main
|
|
61
|
+
};
|
|
62
|
+
}, [resolutions, src]);
|
|
63
|
+
const imgRef = useRef(null);
|
|
64
|
+
const [isInView, setIsInView] = useState(!lazy);
|
|
65
|
+
|
|
66
|
+
// Effect to create an Intersection Observer to enable lazy loading of preview images
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!lazy || !sources.preview) return undefined;
|
|
69
|
+
|
|
70
|
+
// Intersection Observer to check if the image is in (or near) the viewport
|
|
71
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
72
|
+
if (entry.isIntersecting) {
|
|
73
|
+
setIsInView(true);
|
|
74
|
+
// stop observing once visible
|
|
75
|
+
observer.unobserve(entry.target);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
// load a bit earlier
|
|
79
|
+
{
|
|
80
|
+
rootMargin: '100px'
|
|
81
|
+
});
|
|
82
|
+
if (imgRef.current) {
|
|
83
|
+
// start observing the image element
|
|
84
|
+
observer.observe(imgRef.current);
|
|
85
|
+
}
|
|
86
|
+
return () => {
|
|
87
|
+
// disconnect the observer when the component is unmounted
|
|
88
|
+
observer.disconnect();
|
|
89
|
+
};
|
|
90
|
+
}, [lazy, sources.preview]);
|
|
91
|
+
|
|
92
|
+
/**
|
|
30
93
|
* Handles the onLoad event of the image.
|
|
31
|
-
*/
|
|
94
|
+
*/
|
|
95
|
+
const handleOnLoad = useCallback(e => {
|
|
96
|
+
highestResolutionLoaded();
|
|
97
|
+
onLoad(e);
|
|
98
|
+
}, [highestResolutionLoaded, onLoad]);
|
|
99
|
+
|
|
100
|
+
/**
|
|
32
101
|
* Handles the onError event of the image.
|
|
33
|
-
*/
|
|
102
|
+
*/
|
|
103
|
+
const handleOnError = useCallback(e => {
|
|
104
|
+
onError(e);
|
|
105
|
+
}, [onError]);
|
|
106
|
+
|
|
107
|
+
/**
|
|
34
108
|
* Memoized calculation of aspect ratio and CSS padding-hack ratio for responsive elements.
|
|
35
109
|
*
|
|
36
110
|
* Returns n object containing:
|
|
37
111
|
* - `aspectRatio` {string} - The aspect ratio in the format `width / height` (e.g., `16 / 9`).
|
|
38
112
|
* - `paddingHackRatio` {string} - The CSS padding-hack ratio as a percentage for older browsers
|
|
39
113
|
* (e.g., `56.250%` for a 16:9 ratio).
|
|
40
|
-
*/
|
|
114
|
+
*/
|
|
115
|
+
const {
|
|
116
|
+
aspectRatio,
|
|
117
|
+
paddingHackRatio
|
|
118
|
+
} = useMemo(() => {
|
|
119
|
+
let width;
|
|
120
|
+
let height;
|
|
121
|
+
if (ratio) {
|
|
122
|
+
[width, height] = ratio;
|
|
123
|
+
} else {
|
|
124
|
+
({
|
|
125
|
+
width,
|
|
126
|
+
height
|
|
127
|
+
} = resolutions[resolutions.length - 1]);
|
|
128
|
+
}
|
|
129
|
+
const divisor = gcd(width, height);
|
|
130
|
+
return {
|
|
131
|
+
aspectRatio: `${width / divisor} / ${height / divisor}`,
|
|
132
|
+
paddingHackRatio: `${(height / width * 100).toFixed(3)}%`
|
|
133
|
+
};
|
|
134
|
+
}, [ratio, resolutions]);
|
|
135
|
+
if (unwrapped) {
|
|
136
|
+
if (!(src && !parentRendersPlaceholder)) return null;
|
|
137
|
+
return /*#__PURE__*/React.createElement(ImageInner, {
|
|
138
|
+
ref: imgRef,
|
|
139
|
+
src: sources.main,
|
|
140
|
+
className: classNames(classNameImg),
|
|
141
|
+
style: {
|
|
142
|
+
aspectRatio,
|
|
143
|
+
...(isInView && sources.preview && {
|
|
144
|
+
backgroundImage: `url(${sources.preview})`,
|
|
145
|
+
backgroundSize: 'contain',
|
|
146
|
+
backgroundRepeat: 'no-repeat',
|
|
147
|
+
backgroundPosition: 'center'
|
|
148
|
+
})
|
|
149
|
+
},
|
|
150
|
+
alt: alt,
|
|
151
|
+
lazy: lazy,
|
|
152
|
+
onLoad: handleOnLoad,
|
|
153
|
+
onError: handleOnError
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const containerStyle = styles.container(backgroundColor, paddingHackRatio);
|
|
157
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
158
|
+
className: classNames(containerStyle, className, 'common__image__container')
|
|
159
|
+
}, src && !parentRendersPlaceholder && /*#__PURE__*/React.createElement(ImageInner, {
|
|
160
|
+
ref: imgRef,
|
|
161
|
+
src: sources.main,
|
|
162
|
+
className: classNames(classNameImg),
|
|
163
|
+
style: {
|
|
164
|
+
aspectRatio,
|
|
165
|
+
...(isInView && sources.preview && {
|
|
166
|
+
backgroundImage: `url(${sources.preview})`,
|
|
167
|
+
backgroundSize: 'contain',
|
|
168
|
+
backgroundRepeat: 'no-repeat',
|
|
169
|
+
backgroundPosition: 'center'
|
|
170
|
+
})
|
|
171
|
+
},
|
|
172
|
+
alt: alt,
|
|
173
|
+
lazy: lazy,
|
|
174
|
+
onLoad: handleOnLoad,
|
|
175
|
+
onError: handleOnError
|
|
176
|
+
}));
|
|
177
|
+
};
|
|
178
|
+
const defaultResolutions = [{
|
|
179
|
+
width: 440,
|
|
180
|
+
height: 440
|
|
181
|
+
}];
|
|
182
|
+
Image.defaultProps = {
|
|
183
|
+
alt: null,
|
|
184
|
+
backgroundColor: themeColors.placeholder,
|
|
185
|
+
className: '',
|
|
186
|
+
classNameImg: '',
|
|
187
|
+
forcePlaceholder: false,
|
|
188
|
+
highestResolutionLoaded: noop,
|
|
189
|
+
onError: noop,
|
|
190
|
+
onLoad: noop,
|
|
191
|
+
ratio: null,
|
|
192
|
+
resolutions: defaultResolutions,
|
|
193
|
+
src: null,
|
|
194
|
+
unwrapped: false,
|
|
195
|
+
lazy: true
|
|
196
|
+
};
|
|
197
|
+
export default /*#__PURE__*/memo(Image);
|
|
@@ -1,6 +1,52 @@
|
|
|
1
|
-
import React,{forwardRef}
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import noop from 'lodash/noop';
|
|
5
|
+
import styles from "./style";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* The ImageInner component renders tha actual image of the Image component.
|
|
3
9
|
* @param {Object} props The component props
|
|
4
10
|
* @param {Function} ref The component reference
|
|
5
11
|
* @returns {JSX.Element}
|
|
6
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
const ImageInner = /*#__PURE__*/forwardRef(({
|
|
14
|
+
src,
|
|
15
|
+
className,
|
|
16
|
+
alt,
|
|
17
|
+
lazy,
|
|
18
|
+
onLoad,
|
|
19
|
+
onError,
|
|
20
|
+
style
|
|
21
|
+
}, ref) => /*#__PURE__*/React.createElement("img", {
|
|
22
|
+
ref: ref,
|
|
23
|
+
loading: lazy ? 'lazy' : 'eager',
|
|
24
|
+
src: src,
|
|
25
|
+
className: classNames(className, styles.image, 'common__image'),
|
|
26
|
+
alt: alt,
|
|
27
|
+
"aria-label": alt,
|
|
28
|
+
"aria-hidden": !alt,
|
|
29
|
+
"data-test-id": "image",
|
|
30
|
+
onLoad: onLoad,
|
|
31
|
+
onError: onError,
|
|
32
|
+
style: style
|
|
33
|
+
}));
|
|
34
|
+
ImageInner.propTypes = {
|
|
35
|
+
alt: PropTypes.string,
|
|
36
|
+
className: PropTypes.string,
|
|
37
|
+
lazy: PropTypes.bool,
|
|
38
|
+
onError: PropTypes.func,
|
|
39
|
+
onLoad: PropTypes.func,
|
|
40
|
+
src: PropTypes.string,
|
|
41
|
+
style: PropTypes.shape()
|
|
42
|
+
};
|
|
43
|
+
ImageInner.defaultProps = {
|
|
44
|
+
src: null,
|
|
45
|
+
alt: null,
|
|
46
|
+
className: null,
|
|
47
|
+
lazy: false,
|
|
48
|
+
style: null,
|
|
49
|
+
onError: noop,
|
|
50
|
+
onLoad: noop
|
|
51
|
+
};
|
|
52
|
+
export default ImageInner;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{default}from"./Image";
|
|
1
|
+
export { default } from "./Image";
|
|
@@ -1,5 +1,32 @@
|
|
|
1
|
-
import{css}from'glamor';
|
|
1
|
+
import { css } from 'glamor';
|
|
2
|
+
import { themeColors } from '@shopgate/pwa-common/helpers/config';
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* @param {string} [background=themeColors.placeholder] The background color.
|
|
3
6
|
* @param {string} [paddingTop='100%'] The padding top value.
|
|
4
7
|
* @returns {string} The compiled class names.
|
|
5
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
const container = (background = themeColors.placeholder, paddingTop = '100%') => css({
|
|
10
|
+
background,
|
|
11
|
+
position: 'relative',
|
|
12
|
+
zIndex: 0,
|
|
13
|
+
':before': {
|
|
14
|
+
display: 'block',
|
|
15
|
+
content: '""',
|
|
16
|
+
width: '100%',
|
|
17
|
+
paddingTop
|
|
18
|
+
}
|
|
19
|
+
}).toString();
|
|
20
|
+
const image = css({
|
|
21
|
+
position: 'absolute',
|
|
22
|
+
top: 0,
|
|
23
|
+
left: 0,
|
|
24
|
+
width: '100%',
|
|
25
|
+
maxHeight: '100%',
|
|
26
|
+
WebkitTouchCallout: 'none',
|
|
27
|
+
fontSize: 0
|
|
28
|
+
}).toString();
|
|
29
|
+
export default {
|
|
30
|
+
container,
|
|
31
|
+
image
|
|
32
|
+
};
|