@shopgate/pwa-common 7.30.0-alpha.8 → 7.30.0-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/App.js +28 -13
- package/actions/app/handleUniversalLink.js +0 -2
- package/collections/AuthRoutes.js +15 -13
- package/collections/Configuration.js +11 -10
- package/collections/EmbeddedMedia.js +21 -19
- package/collections/PersistedReducers.js +11 -9
- package/collections/Redirects.js +15 -13
- package/collections/media-providers/MediaProvider.js +23 -21
- package/collections/media-providers/Vimeo.js +28 -22
- package/collections/media-providers/YouTube.js +17 -10
- package/components/Backdrop/index.js +15 -13
- package/components/Backdrop/spec.js +3 -2
- package/components/Button/index.js +41 -29
- package/components/Button/spec.js +16 -10
- package/components/Checkbox/index.js +36 -28
- package/components/Checkbox/spec.js +40 -27
- package/components/Consume/index.js +4 -1
- package/components/CountdownTimer/index.js +27 -20
- package/components/CountdownTimer/spec.js +39 -38
- package/components/Drawer/index.js +31 -23
- package/components/Drawer/spec.js +7 -6
- package/components/Dropdown/index.js +27 -18
- package/components/Ellipsis/index.js +5 -3
- package/components/Ellipsis/spec.js +5 -3
- package/components/EmbeddedMedia/index.js +9 -6
- package/components/EmbeddedMedia/spec.js +11 -2
- package/components/ErrorBoundary/index.js +26 -16
- package/components/Grid/components/Item/index.js +13 -6
- package/components/Grid/components/Item/spec.js +4 -3
- package/components/Grid/index.js +13 -6
- package/components/Grid/spec.js +4 -3
- package/components/HtmlSanitizer/index.js +42 -45
- package/components/HtmlSanitizer/spec.js +31 -21
- package/components/I18n/components/FormatDate/index.js +11 -4
- package/components/I18n/components/FormatDate/spec.js +22 -14
- package/components/I18n/components/FormatNumber/index.js +8 -6
- package/components/I18n/components/FormatNumber/spec.js +10 -5
- package/components/I18n/components/FormatPrice/index.js +5 -3
- package/components/I18n/components/FormatPrice/spec.js +22 -14
- package/components/I18n/components/FormatTime/index.js +11 -4
- package/components/I18n/components/FormatTime/spec.js +22 -14
- package/components/I18n/components/I18nProvider/index.js +18 -11
- package/components/I18n/components/I18nProvider/spec.js +2 -1
- package/components/I18n/components/Placeholder/index.js +10 -3
- package/components/I18n/components/Placeholder/spec.js +12 -5
- package/components/I18n/components/Translate/index.js +12 -8
- package/components/I18n/components/Translate/spec.js +9 -6
- package/components/Icon/index.js +2 -1
- package/components/Image/Image.js +23 -21
- package/components/Image/ImageInner.js +2 -1
- package/components/InfiniteContainer/index.js +59 -53
- package/components/InfiniteContainer/spec.js +10 -5
- package/components/Input/components/MultiLineInput.js +33 -26
- package/components/Input/components/SimpleInput.js +70 -54
- package/components/Input/index.js +7 -17
- package/components/Input/spec.js +12 -11
- package/components/KeyboardConsumer/index.js +19 -13
- package/components/Link/index.js +28 -20
- package/components/Link/spec.js +13 -9
- package/components/List/components/Item/index.js +5 -3
- package/components/List/index.js +5 -3
- package/components/List/spec.js +6 -9
- package/components/Loading/index.js +1 -3
- package/components/Modal/index.js +13 -10
- package/components/ModalContainer/spec.js +24 -20
- package/components/Picker/components/Button/index.js +18 -12
- package/components/Picker/components/List/index.js +19 -16
- package/components/Picker/components/Modal/index.js +34 -25
- package/components/Picker/index.js +44 -33
- package/components/Picker/spec.js +4 -1
- package/components/Portal/index.js +26 -17
- package/components/ProductCharacteristics/index.js +65 -57
- package/components/RangeSlider/components/Handle/index.js +7 -5
- package/components/RangeSlider/index.js +98 -84
- package/components/Route/RouteNotFound.js +30 -19
- package/components/Route/index.js +31 -21
- package/components/Router/index.js +51 -34
- package/components/ScannerContainer/index.js +17 -10
- package/components/Select/components/Item/index.js +5 -3
- package/components/Select/index.js +59 -47
- package/components/Select/spec.js +7 -6
- package/components/SelectBox/components/Item/index.js +23 -13
- package/components/SelectBox/index.js +83 -80
- package/components/SelectBox/spec.js +8 -5
- package/components/SurroundPortals/index.js +15 -11
- package/components/Swiper/components/SwiperItem/index.js +6 -5
- package/components/Swiper/components/SwiperItem/spec.js +12 -4
- package/components/Swiper/index.js +23 -20
- package/components/Toaster/index.js +4 -1
- package/components/Transition/index.js +19 -12
- package/components/Widgets/components/Widget/index.js +27 -16
- package/components/Widgets/components/Widget/spec.js +6 -5
- package/components/Widgets/components/WidgetGrid/index.js +27 -19
- package/components/Widgets/components/WidgetGrid/spec.js +5 -4
- package/components/Widgets/index.js +33 -26
- package/components/Widgets/spec.js +32 -18
- package/helpers/data/index.js +1 -1
- package/helpers/portals/portalCollection.js +13 -10
- package/helpers/redux/mutable.js +2 -2
- package/package.json +5 -6
- package/providers/loading/index.js +71 -57
- package/providers/toast/index.js +39 -28
- package/reducers/modal/index.js +1 -1
- package/store/index.js +1 -1
- package/subscriptions/helpers/buildRegisterUrl.js +1 -0
- package/components/Input/components/DateInput.js +0 -273
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
2
|
import React, { Component } from 'react';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import { UIEvents } from '@shopgate/pwa-core';
|
|
@@ -6,52 +7,30 @@ import LoadingContext from "./context";
|
|
|
6
7
|
/**
|
|
7
8
|
* The LoadingProvider component.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* Adds or increases the loading counter for a path.
|
|
12
|
-
* @param {string} path The path which loads.
|
|
13
|
-
*/
|
|
14
|
-
static setLoading(path) {
|
|
15
|
-
UIEvents.emit(LoadingProvider.SET, path);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Resets the loading counter for a path.
|
|
20
|
-
* @param {string} path The path which loads.
|
|
21
|
-
*/
|
|
22
|
-
static resetLoading(path) {
|
|
23
|
-
UIEvents.emit(LoadingProvider.RESET, path);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Decreases the loading counter for a path.
|
|
28
|
-
* @param {string} path The path which loads.
|
|
29
|
-
*/
|
|
30
|
-
static unsetLoading(path) {
|
|
31
|
-
UIEvents.emit(LoadingProvider.UNSET, path);
|
|
32
|
-
}
|
|
33
|
-
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
let LoadingProvider = /*#__PURE__*/function (_Component) {
|
|
34
12
|
/**
|
|
35
13
|
* @param {Object} props The component props.
|
|
36
14
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
function LoadingProvider(props) {
|
|
16
|
+
var _this;
|
|
17
|
+
_this = _Component.call(this, props) || this;
|
|
39
18
|
/**
|
|
40
19
|
* Adds or increases the loading counter for a path.
|
|
41
20
|
* @param {string} path The path which loads.
|
|
42
21
|
*/
|
|
43
|
-
|
|
22
|
+
_this.setLoading = path => {
|
|
44
23
|
const {
|
|
45
24
|
loading
|
|
46
|
-
} =
|
|
25
|
+
} = _this;
|
|
47
26
|
const newLoading = {
|
|
48
27
|
...loading,
|
|
49
28
|
[path]: loading[path] ? loading[path] + 1 : 1
|
|
50
29
|
};
|
|
51
30
|
|
|
52
31
|
// Immediately updates state due to multiple sets before actual rerender.
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
_this.loading = newLoading;
|
|
33
|
+
_this.setState({
|
|
55
34
|
loading: newLoading
|
|
56
35
|
});
|
|
57
36
|
};
|
|
@@ -59,15 +38,15 @@ class LoadingProvider extends Component {
|
|
|
59
38
|
* Resets the loading counter for a path.
|
|
60
39
|
* @param {string} path The path which loads.
|
|
61
40
|
*/
|
|
62
|
-
|
|
41
|
+
_this.resetLoading = path => {
|
|
63
42
|
const {
|
|
64
43
|
[path]: removedPath,
|
|
65
44
|
...remaining
|
|
66
|
-
} =
|
|
45
|
+
} = _this.loading;
|
|
67
46
|
|
|
68
47
|
// Immediately updates state due to multiple sets before actual rerender.
|
|
69
|
-
|
|
70
|
-
|
|
48
|
+
_this.loading = remaining;
|
|
49
|
+
_this.setState({
|
|
71
50
|
loading: remaining
|
|
72
51
|
});
|
|
73
52
|
};
|
|
@@ -75,15 +54,15 @@ class LoadingProvider extends Component {
|
|
|
75
54
|
* Decreases the loading counter for a path.
|
|
76
55
|
* @param {string} path The path which loads.
|
|
77
56
|
*/
|
|
78
|
-
|
|
57
|
+
_this.unsetLoading = path => {
|
|
79
58
|
const {
|
|
80
59
|
loading
|
|
81
|
-
} =
|
|
60
|
+
} = _this;
|
|
82
61
|
if (typeof loading[path] === 'undefined') {
|
|
83
62
|
return;
|
|
84
63
|
}
|
|
85
64
|
if (loading[path] <= 1) {
|
|
86
|
-
|
|
65
|
+
_this.resetLoading(path);
|
|
87
66
|
return;
|
|
88
67
|
}
|
|
89
68
|
const newLoading = {
|
|
@@ -92,8 +71,8 @@ class LoadingProvider extends Component {
|
|
|
92
71
|
};
|
|
93
72
|
|
|
94
73
|
// Immediately updates state due to multiple sets before actual rerender.
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
_this.loading = newLoading;
|
|
75
|
+
_this.setState({
|
|
97
76
|
loading: newLoading
|
|
98
77
|
});
|
|
99
78
|
};
|
|
@@ -102,44 +81,79 @@ class LoadingProvider extends Component {
|
|
|
102
81
|
* @param {string} path The path it inspect.
|
|
103
82
|
* @return {boolean}
|
|
104
83
|
*/
|
|
105
|
-
|
|
84
|
+
_this.isLoading = path => {
|
|
106
85
|
const {
|
|
107
86
|
loading
|
|
108
|
-
} =
|
|
87
|
+
} = _this.state;
|
|
109
88
|
return !!loading[path];
|
|
110
89
|
};
|
|
111
|
-
|
|
112
|
-
|
|
90
|
+
_this.loading = {};
|
|
91
|
+
_this.contextValue = null;
|
|
92
|
+
_this.state = {
|
|
113
93
|
loading: {}
|
|
114
94
|
};
|
|
115
|
-
UIEvents.addListener(
|
|
116
|
-
UIEvents.addListener(
|
|
117
|
-
UIEvents.addListener(
|
|
95
|
+
UIEvents.addListener(_this.constructor.SET, _this.setLoading);
|
|
96
|
+
UIEvents.addListener(_this.constructor.RESET, _this.resetLoading);
|
|
97
|
+
UIEvents.addListener(_this.constructor.UNSET, _this.unsetLoading);
|
|
98
|
+
return _this;
|
|
118
99
|
}
|
|
119
100
|
|
|
120
101
|
/**
|
|
121
102
|
* Removes the event listeners when the component unmounts.
|
|
122
103
|
*/
|
|
123
|
-
|
|
104
|
+
_inheritsLoose(LoadingProvider, _Component);
|
|
105
|
+
/**
|
|
106
|
+
* Adds or increases the loading counter for a path.
|
|
107
|
+
* @param {string} path The path which loads.
|
|
108
|
+
*/
|
|
109
|
+
LoadingProvider.setLoading = function setLoading(path) {
|
|
110
|
+
UIEvents.emit(LoadingProvider.SET, path);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Resets the loading counter for a path.
|
|
115
|
+
* @param {string} path The path which loads.
|
|
116
|
+
*/;
|
|
117
|
+
LoadingProvider.resetLoading = function resetLoading(path) {
|
|
118
|
+
UIEvents.emit(LoadingProvider.RESET, path);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Decreases the loading counter for a path.
|
|
123
|
+
* @param {string} path The path which loads.
|
|
124
|
+
*/;
|
|
125
|
+
LoadingProvider.unsetLoading = function unsetLoading(path) {
|
|
126
|
+
UIEvents.emit(LoadingProvider.UNSET, path);
|
|
127
|
+
};
|
|
128
|
+
var _proto = LoadingProvider.prototype;
|
|
129
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
124
130
|
UIEvents.removeListener(this.constructor.SET, this.setLoading);
|
|
125
131
|
UIEvents.removeListener(this.constructor.RESET, this.resetLoading);
|
|
126
132
|
UIEvents.removeListener(this.constructor.UNSET, this.unsetLoading);
|
|
127
|
-
}
|
|
133
|
+
};
|
|
128
134
|
/**
|
|
129
135
|
* @return {JSX}
|
|
130
136
|
*/
|
|
131
|
-
render() {
|
|
132
|
-
const
|
|
133
|
-
loading
|
|
137
|
+
_proto.render = function render() {
|
|
138
|
+
const {
|
|
139
|
+
loading
|
|
140
|
+
} = this.state;
|
|
141
|
+
const nextValue = {
|
|
142
|
+
loading,
|
|
134
143
|
setLoading: this.setLoading,
|
|
135
144
|
unsetLoading: this.unsetLoading,
|
|
136
145
|
isLoading: this.isLoading
|
|
137
146
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
147
|
+
if (!this.contextValue || this.contextValue.loading !== loading) {
|
|
148
|
+
this.contextValue = nextValue;
|
|
149
|
+
}
|
|
150
|
+
return /*#__PURE__*/_jsx(LoadingContext.Provider, {
|
|
151
|
+
value: this.contextValue,
|
|
152
|
+
children: this.props.children
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
return LoadingProvider;
|
|
156
|
+
}(Component);
|
|
143
157
|
LoadingProvider.SET = 'loading_set';
|
|
144
158
|
LoadingProvider.RESET = 'loading_reset';
|
|
145
159
|
LoadingProvider.UNSET = 'loading_unset';
|
package/providers/toast/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
|
|
1
3
|
import React, { Component } from 'react';
|
|
2
4
|
import PropTypes from 'prop-types';
|
|
3
5
|
import { UIEvents } from '@shopgate/pwa-core';
|
|
4
6
|
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
5
7
|
import ToastContext from "./context";
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
9
|
const {
|
|
7
10
|
variables: {
|
|
8
11
|
toast: {
|
|
@@ -14,23 +17,24 @@ const {
|
|
|
14
17
|
/**
|
|
15
18
|
* The ToastProvider component
|
|
16
19
|
*/
|
|
17
|
-
|
|
20
|
+
let ToastProvider = /*#__PURE__*/function (_Component) {
|
|
18
21
|
/**
|
|
19
22
|
* @param {Object} props The component props.
|
|
20
23
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
function ToastProvider(props) {
|
|
25
|
+
var _this;
|
|
26
|
+
_this = _Component.call(this, props) || this;
|
|
23
27
|
/**
|
|
24
28
|
* Adds a new, unique, toast to the list.
|
|
25
29
|
* @param {Object} toast The toast object to add.
|
|
26
30
|
*/
|
|
27
|
-
|
|
31
|
+
_this.addToast = toast => {
|
|
28
32
|
if (!toast.message) {
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
35
|
const {
|
|
32
36
|
toasts
|
|
33
|
-
} =
|
|
37
|
+
} = _this.state;
|
|
34
38
|
|
|
35
39
|
// Check if the toast id already is present.
|
|
36
40
|
const found = toasts.find(({
|
|
@@ -54,56 +58,63 @@ class ToastProvider extends Component {
|
|
|
54
58
|
duration: toast.duration || duration
|
|
55
59
|
});
|
|
56
60
|
}
|
|
57
|
-
|
|
61
|
+
_this.setState({
|
|
58
62
|
toasts
|
|
59
63
|
});
|
|
60
64
|
};
|
|
61
65
|
/**
|
|
62
66
|
* Removes the first toast from the list.
|
|
63
67
|
*/
|
|
64
|
-
|
|
68
|
+
_this.removeToast = () => {
|
|
65
69
|
const {
|
|
66
70
|
toasts
|
|
67
|
-
} =
|
|
71
|
+
} = _this.state;
|
|
68
72
|
toasts.shift();
|
|
69
|
-
|
|
73
|
+
_this.setState({
|
|
70
74
|
toasts
|
|
71
75
|
});
|
|
72
76
|
};
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
77
|
+
_this.flushToasts = () => {
|
|
78
|
+
if (_this.state.toasts.length) {
|
|
79
|
+
_this.setState({
|
|
76
80
|
toasts: []
|
|
77
81
|
});
|
|
78
82
|
}
|
|
79
83
|
};
|
|
80
|
-
|
|
84
|
+
_this.state = {
|
|
81
85
|
toasts: []
|
|
82
86
|
};
|
|
83
|
-
UIEvents.addListener(
|
|
84
|
-
UIEvents.addListener(
|
|
87
|
+
UIEvents.addListener(_this.constructor.ADD, _this.addToast);
|
|
88
|
+
UIEvents.addListener(_this.constructor.FLUSH, _this.flushToasts);
|
|
89
|
+
return _this;
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
/**
|
|
88
93
|
* Returns the context value to be passed to consumers.
|
|
89
94
|
* @returns {Object}
|
|
90
95
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
addToast: this.addToast,
|
|
94
|
-
removeToast: this.removeToast,
|
|
95
|
-
toasts: this.state.toasts
|
|
96
|
-
};
|
|
97
|
-
}
|
|
96
|
+
_inheritsLoose(ToastProvider, _Component);
|
|
97
|
+
var _proto = ToastProvider.prototype;
|
|
98
98
|
/**
|
|
99
99
|
* @returns {JSX}
|
|
100
100
|
*/
|
|
101
|
-
render() {
|
|
102
|
-
return /*#__PURE__*/
|
|
103
|
-
value: this.provided
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
101
|
+
_proto.render = function render() {
|
|
102
|
+
return /*#__PURE__*/_jsx(ToastContext.Provider, {
|
|
103
|
+
value: this.provided,
|
|
104
|
+
children: this.props.children
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
return _createClass(ToastProvider, [{
|
|
108
|
+
key: "provided",
|
|
109
|
+
get: function () {
|
|
110
|
+
return {
|
|
111
|
+
addToast: this.addToast,
|
|
112
|
+
removeToast: this.removeToast,
|
|
113
|
+
toasts: this.state.toasts
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}]);
|
|
117
|
+
}(Component);
|
|
107
118
|
ToastProvider.ADD = 'toast_add';
|
|
108
119
|
ToastProvider.FLUSH = 'toast_flush';
|
|
109
120
|
export default ToastProvider;
|
package/reducers/modal/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { CREATE_MODAL, REMOVE_MODAL } from "../../constants/ActionTypes";
|
|
|
9
9
|
export default function modalReducer(state = [], action) {
|
|
10
10
|
switch (action.type) {
|
|
11
11
|
case CREATE_MODAL:
|
|
12
|
-
return [
|
|
12
|
+
return [].concat(state, [action.options]);
|
|
13
13
|
case REMOVE_MODAL:
|
|
14
14
|
return state.filter(modal => modal.id !== action.id);
|
|
15
15
|
default:
|
package/store/index.js
CHANGED
|
@@ -46,7 +46,7 @@ export function configureStore(reducers, subscribers) {
|
|
|
46
46
|
if (appConfig.benchmark) {
|
|
47
47
|
benchmarkController.startup();
|
|
48
48
|
}
|
|
49
|
-
const store = createStore(makeRootReducer(reducers), getInitialState(), composeWithDevTools(applyMiddleware(
|
|
49
|
+
const store = createStore(makeRootReducer(reducers), getInitialState(), composeWithDevTools(applyMiddleware.apply(void 0, [thunk].concat(appConfig.benchmark ? [benchmarkMiddleware] : [], [streams, logger])), persistState({
|
|
50
50
|
key: storeKey,
|
|
51
51
|
paths: persistedReducers.getAll()
|
|
52
52
|
})));
|
|
@@ -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;
|