@shopgate/pwa-common 7.30.0-alpha.9 → 7.30.0-beta.2

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.
Files changed (106) hide show
  1. package/App.js +28 -13
  2. package/actions/app/handleUniversalLink.js +0 -2
  3. package/collections/AuthRoutes.js +15 -13
  4. package/collections/Configuration.js +11 -10
  5. package/collections/EmbeddedMedia.js +21 -19
  6. package/collections/PersistedReducers.js +11 -9
  7. package/collections/Redirects.js +15 -13
  8. package/collections/media-providers/MediaProvider.js +23 -21
  9. package/collections/media-providers/Vimeo.js +28 -22
  10. package/collections/media-providers/YouTube.js +17 -10
  11. package/components/Backdrop/index.js +15 -13
  12. package/components/Backdrop/spec.js +3 -2
  13. package/components/Button/index.js +41 -29
  14. package/components/Button/spec.js +16 -10
  15. package/components/Checkbox/index.js +36 -28
  16. package/components/Checkbox/spec.js +40 -27
  17. package/components/Consume/index.js +4 -1
  18. package/components/CountdownTimer/index.js +27 -20
  19. package/components/CountdownTimer/spec.js +2 -1
  20. package/components/Drawer/index.js +31 -23
  21. package/components/Drawer/spec.js +7 -6
  22. package/components/Dropdown/index.js +27 -18
  23. package/components/Ellipsis/index.js +5 -3
  24. package/components/Ellipsis/spec.js +5 -3
  25. package/components/EmbeddedMedia/index.js +9 -6
  26. package/components/EmbeddedMedia/spec.js +11 -2
  27. package/components/ErrorBoundary/index.js +26 -16
  28. package/components/Grid/components/Item/index.js +13 -6
  29. package/components/Grid/components/Item/spec.js +4 -3
  30. package/components/Grid/index.js +13 -6
  31. package/components/Grid/spec.js +4 -3
  32. package/components/HtmlSanitizer/index.js +42 -45
  33. package/components/HtmlSanitizer/spec.js +16 -12
  34. package/components/I18n/components/FormatDate/index.js +11 -4
  35. package/components/I18n/components/FormatDate/spec.js +22 -14
  36. package/components/I18n/components/FormatNumber/index.js +8 -6
  37. package/components/I18n/components/FormatNumber/spec.js +10 -5
  38. package/components/I18n/components/FormatPrice/index.js +5 -3
  39. package/components/I18n/components/FormatPrice/spec.js +22 -14
  40. package/components/I18n/components/FormatTime/index.js +11 -4
  41. package/components/I18n/components/FormatTime/spec.js +22 -14
  42. package/components/I18n/components/I18nProvider/index.js +18 -11
  43. package/components/I18n/components/I18nProvider/spec.js +2 -1
  44. package/components/I18n/components/Placeholder/index.js +10 -3
  45. package/components/I18n/components/Placeholder/spec.js +12 -5
  46. package/components/I18n/components/Translate/index.js +12 -8
  47. package/components/I18n/components/Translate/spec.js +9 -6
  48. package/components/Icon/index.js +2 -1
  49. package/components/Image/Image.js +23 -21
  50. package/components/Image/ImageInner.js +2 -1
  51. package/components/InfiniteContainer/index.js +59 -53
  52. package/components/InfiniteContainer/spec.js +10 -5
  53. package/components/Input/components/MultiLineInput.js +33 -26
  54. package/components/Input/components/SimpleInput.js +70 -54
  55. package/components/Input/index.js +7 -17
  56. package/components/Input/spec.js +12 -11
  57. package/components/KeyboardConsumer/index.js +19 -13
  58. package/components/Link/index.js +28 -20
  59. package/components/Link/spec.js +13 -9
  60. package/components/List/components/Item/index.js +5 -3
  61. package/components/List/index.js +5 -3
  62. package/components/List/spec.js +6 -9
  63. package/components/Loading/index.js +1 -3
  64. package/components/Modal/index.js +13 -10
  65. package/components/ModalContainer/spec.js +24 -20
  66. package/components/Picker/components/Button/index.js +18 -12
  67. package/components/Picker/components/List/index.js +19 -16
  68. package/components/Picker/components/Modal/index.js +34 -25
  69. package/components/Picker/index.js +44 -33
  70. package/components/Picker/spec.js +4 -1
  71. package/components/Portal/index.js +26 -17
  72. package/components/ProductCharacteristics/index.js +65 -57
  73. package/components/RangeSlider/components/Handle/index.js +7 -5
  74. package/components/RangeSlider/index.js +98 -84
  75. package/components/Route/RouteNotFound.js +30 -19
  76. package/components/Route/index.js +31 -21
  77. package/components/Router/index.js +51 -34
  78. package/components/ScannerContainer/index.js +17 -10
  79. package/components/Select/components/Item/index.js +5 -3
  80. package/components/Select/index.js +59 -47
  81. package/components/Select/spec.js +7 -6
  82. package/components/SelectBox/components/Item/index.js +23 -13
  83. package/components/SelectBox/index.js +83 -80
  84. package/components/SelectBox/spec.js +8 -5
  85. package/components/SurroundPortals/index.js +15 -11
  86. package/components/Swiper/components/SwiperItem/index.js +6 -5
  87. package/components/Swiper/components/SwiperItem/spec.js +8 -4
  88. package/components/Swiper/index.js +23 -20
  89. package/components/Toaster/index.js +4 -1
  90. package/components/Transition/index.js +19 -12
  91. package/components/Widgets/components/Widget/index.js +27 -16
  92. package/components/Widgets/components/Widget/spec.js +5 -4
  93. package/components/Widgets/components/WidgetGrid/index.js +27 -19
  94. package/components/Widgets/components/WidgetGrid/spec.js +4 -3
  95. package/components/Widgets/index.js +33 -26
  96. package/components/Widgets/spec.js +12 -13
  97. package/helpers/data/index.js +1 -1
  98. package/helpers/portals/portalCollection.js +13 -10
  99. package/helpers/redux/mutable.js +2 -2
  100. package/package.json +5 -5
  101. package/providers/loading/index.js +71 -57
  102. package/providers/toast/index.js +39 -28
  103. package/reducers/modal/index.js +1 -1
  104. package/store/index.js +1 -1
  105. package/subscriptions/helpers/buildRegisterUrl.js +1 -0
  106. package/components/Input/components/DateInput.js +0 -273
@@ -1,273 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import React, { useCallback, useState, useEffect, useRef } from 'react';
3
- import PropTypes from 'prop-types';
4
- import DayPicker from 'react-day-picker';
5
- import MomentLocaleUtils from 'react-day-picker/moment';
6
- import 'react-day-picker/lib/style.css';
7
- import { css } from 'glamor';
8
- import classNames from 'classnames';
9
- import moment from 'moment';
10
- import CalendarIcon from '@shopgate/pwa-ui-shared/icons/CalendarIcon';
11
- import appConfig, { themeConfig } from '@shopgate/pwa-common/helpers/config';
12
- import Backdrop from '@shopgate/pwa-common/components/Backdrop';
13
- import { i18n } from '@shopgate/engage/core/helpers';
14
- import SimpleInput from "./SimpleInput";
15
- const {
16
- variables
17
- } = themeConfig;
18
- const locale = appConfig.language.substring(0, 2);
19
-
20
- /**
21
- * @param {Object|string} date The input date
22
- * @returns {string}
23
- */
24
- const getDateFromISO = date => {
25
- const result = moment(date);
26
- if (!result.isValid()) {
27
- return null;
28
- }
29
- return result.toDate();
30
- };
31
-
32
- /**
33
- * @param {Object|string} date The input date
34
- * @param {boolean} validate Should the date be validated
35
- * @returns {string}
36
- */
37
- const getISOFormattedDate = (date, validate = true) => {
38
- const result = moment(date, 'L', locale);
39
- if (validate && !result.isValid()) {
40
- return '';
41
- }
42
- return result.format(moment.HTML5_FMT.DATE);
43
- };
44
-
45
- /**
46
- * @param {Object|string} date The input date
47
- * @returns {string}
48
- */
49
- const getLocaleFormattedDate = date => {
50
- const result = moment(date);
51
- if (!result.isValid()) {
52
- return '';
53
- }
54
- return result.format('L');
55
- };
56
- const styles = {
57
- selectBox: css({
58
- WebkitAppearance: 'none',
59
- border: '1px solid var(--color-text-low-emphasis)',
60
- padding: '2px 16px 2px 6px',
61
- marginRight: 7,
62
- backgroundImage: 'url(data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgNDA1LjQ1NiA0MDUuNDU2IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA0MDUuNDU2IDQwNS40NTY7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4Ij4NCjxnPg0KCTxwYXRoIGQ9Ik03NC4xMzQsNjQuMTQ3Yy00Ljk4NSwwLjA3OC05LjkxMSwyLjE2My0xMy40MzgsNS42ODhsLTU1LDU1QzIuMDk2LDEyOC40MzIsMCwxMzMuNDkyLDAsMTM4LjU4MyAgIHMyLjA5NiwxMC4xNTEsNS42OTcsMTMuNzVsMTgzLjI4MSwxODMuMjgxYzMuNTk5LDMuNjAxLDguNjU5LDUuNjk3LDEzLjc1LDUuNjk3czEwLjE1MS0yLjA5NiwxMy43NS01LjY5N2wxODMuMjgxLTE4My4yODEgICBjMy42MDEtMy41OTksNS42OTctOC42NTksNS42OTctMTMuNzVzLTIuMDk2LTEwLjE1MS01LjY5Ny0xMy43NWwtNTUtNTVjLTMuNTk4LTMuNTkxLTguNjUxLTUuNjgxLTEzLjczNC01LjY4MSAgIGMtNS4wODMsMC0xMC4xMzYsMi4wOS0xMy43MzQsNS42ODFMMjAyLjcyOCwxODQuMzk3TDg4LjE2Niw2OS44MzNDODQuNDk5LDY2LjE2OSw3OS4zMTgsNjQuMDcsNzQuMTM0LDY0LjE0N0w3NC4xMzQsNjQuMTQ3eiIgZmlsbD0iIzk2OTY5NiIvPg0KPC9nPg0KPC9zdmc+DQo=)',
63
- backgroundPosition: 'right 4px top 50%',
64
- backgroundRepeat: 'no-repeat',
65
- backgroundSize: 10,
66
- borderRadius: 0,
67
- outline: 0,
68
- cursor: 'pointer'
69
- }).toString(),
70
- iconWrapper: css({
71
- position: 'absolute',
72
- right: variables.gap.small,
73
- top: '50%',
74
- cursor: 'pointer',
75
- color: 'var(--color-text-high-emphasis)'
76
- }).toString(),
77
- pickerWrapper: css({
78
- position: 'relative',
79
- zIndex: 12
80
- }).toString(),
81
- picker: css({
82
- left: 'inherit !important',
83
- right: 5,
84
- ' .DayPicker-Day': {
85
- padding: '3px !important'
86
- },
87
- ' .DayPicker-Day--selected': {
88
- backgroundColor: 'var(--color-primary) !important'
89
- },
90
- ' .DayPicker-Footer': {
91
- textAlign: 'center'
92
- },
93
- ' .DayPicker-TodayButton': {
94
- color: 'var(--color-primary) !important'
95
- },
96
- ' .DayPicker-TodayButton:hover': {
97
- backgroundColor: 'var(--color-primary) !important',
98
- color: '#fff !important'
99
- },
100
- ' .DayPicker-Caption': {
101
- padding: '0 !important'
102
- },
103
- ' .DayPicker-NavButton': {
104
- right: '.5em !important'
105
- }
106
- }).toString(),
107
- pickerTop: css({
108
- bottom: 30
109
- }).toString(),
110
- hidden: css({
111
- display: 'none'
112
- }).toString()
113
- };
114
- const currentYear = new Date().getFullYear();
115
- const fromMonth = new Date(currentYear - 100, 11);
116
- const toMonth = new Date(currentYear + 10, 11);
117
-
118
- /**
119
- * @param {Object} props The components props
120
- * @returns {JSX}
121
- */
122
- const Caption = ({
123
- date,
124
- localeUtils,
125
- onChange
126
- }) => {
127
- const months = localeUtils.getMonths(locale);
128
- const years = [];
129
- for (let i = fromMonth.getFullYear(); i <= toMonth.getFullYear(); i += 1) {
130
- years.push(i);
131
- }
132
- const handleChange = function handleChange(e) {
133
- const {
134
- year,
135
- month
136
- } = e.target.form;
137
- onChange(new Date(year.value, month.value));
138
- };
139
- return /*#__PURE__*/React.createElement("div", {
140
- className: "DayPicker-Caption"
141
- }, /*#__PURE__*/React.createElement("select", {
142
- name: "month",
143
- onChange: handleChange,
144
- value: date.getMonth(),
145
- className: styles.selectBox
146
- }, months.map((month, i) => /*#__PURE__*/React.createElement("option", {
147
- key: month,
148
- value: i
149
- }, month))), /*#__PURE__*/React.createElement("select", {
150
- name: "year",
151
- onChange: handleChange,
152
- value: date.getFullYear(),
153
- className: styles.selectBox
154
- }, years.map(year => /*#__PURE__*/React.createElement("option", {
155
- key: year,
156
- value: year
157
- }, year))));
158
- };
159
- /**
160
- * @param {Object} props The components props
161
- * @returns {JSX}
162
- */
163
- const DateInput = ({
164
- onFocusChange,
165
- onChange,
166
- type,
167
- value,
168
- ...rest
169
- }) => {
170
- const wrapperRef = useRef(null);
171
- const [inputValue, setInputValue] = useState(getLocaleFormattedDate(value));
172
- const [pickerValue, setPickerValue] = useState(getDateFromISO(value));
173
- const [isFocused, setIsFocused] = useState(false);
174
- const [pickerVisible, setPickerVisible] = useState(false);
175
- useEffect(() => {
176
- const updated = getLocaleFormattedDate(value);
177
- if (updated) {
178
- setInputValue(updated);
179
- setPickerValue(getDateFromISO(value));
180
- }
181
- }, [value]);
182
- const needsPositionTop = useCallback(() => {
183
- const element = wrapperRef.current;
184
- if (!element) {
185
- return false;
186
- }
187
- const {
188
- top,
189
- height
190
- } = element.getBoundingClientRect();
191
- const distToBottom = document.body.offsetHeight - (top + height);
192
- return distToBottom <= 300;
193
- }, [wrapperRef]);
194
- const handleInputValueChange = useCallback(val => {
195
- setInputValue(val);
196
- }, []);
197
- const handleFocusChange = useCallback((focused, e) => {
198
- if (!focused) {
199
- setPickerValue(getDateFromISO(getISOFormattedDate(inputValue)));
200
- onChange(inputValue.length !== 0 ? getISOFormattedDate(inputValue, false) : null);
201
- }
202
- setIsFocused(focused);
203
- onFocusChange(focused, e);
204
- }, [inputValue, onChange, onFocusChange]);
205
- const handlePickerChange = useCallback(date => {
206
- setPickerVisible(false);
207
- setPickerValue(date);
208
- setInputValue(getLocaleFormattedDate(date));
209
- onChange(getISOFormattedDate(date));
210
- }, [onChange]);
211
- const handleMonthChange = useCallback(date => {
212
- setPickerValue(date);
213
- }, []);
214
- const handleIconClick = useCallback(() => {
215
- setPickerVisible(!pickerVisible);
216
- }, [pickerVisible]);
217
- const handleBackdropClick = useCallback(() => {
218
- setPickerVisible(false);
219
- }, []);
220
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
221
- ref: wrapperRef
222
- }, /*#__PURE__*/React.createElement(SimpleInput, _extends({}, rest, {
223
- attributes: {
224
- placeholder: isFocused ? i18n.text('formats.date.pattern') : null
225
- },
226
- value: inputValue,
227
- type: "text",
228
- onFocusChange: handleFocusChange,
229
- onChange: handleInputValueChange
230
- })), /*#__PURE__*/React.createElement("div", {
231
- className: styles.iconWrapper,
232
- onClick: handleIconClick,
233
- role: "button",
234
- tabIndex: "0",
235
- onKeyDown: handleIconClick
236
- }, /*#__PURE__*/React.createElement(CalendarIcon, null))), /*#__PURE__*/React.createElement("div", {
237
- className: classNames(styles.pickerWrapper, {
238
- [styles.hidden]: !pickerVisible
239
- })
240
- }, /*#__PURE__*/React.createElement(DayPicker, {
241
- className: classNames('DayPickerInput-Overlay', styles.picker, {
242
- [styles.pickerTop]: needsPositionTop()
243
- }),
244
- onDayClick: handlePickerChange,
245
- selectedDays: pickerValue,
246
- localeUtils: MomentLocaleUtils,
247
- locale: locale,
248
- todayButton: i18n.text('locations.your_current_timeslot.today'),
249
- onTodayButtonClick: handlePickerChange,
250
- month: pickerValue,
251
- showOutsideDays: true,
252
- captionElement: ({
253
- date,
254
- localeUtils
255
- }) => /*#__PURE__*/React.createElement(Caption, {
256
- date: date,
257
- localeUtils: localeUtils,
258
- onChange: handleMonthChange
259
- })
260
- })), pickerVisible && /*#__PURE__*/React.createElement(Backdrop, {
261
- isVisible: true,
262
- level: 11,
263
- opacity: 0,
264
- onClick: handleBackdropClick
265
- }));
266
- };
267
- DateInput.defaultProps = {
268
- onFocusChange: () => {},
269
- onChange: () => {},
270
- type: null,
271
- value: null
272
- };
273
- export default DateInput;