@megafon/ui-core 5.1.2 → 5.2.0

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.
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = exports.SnackbarTypes = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
+
16
+ require("core-js/modules/web.timers.js");
17
+
18
+ require("core-js/modules/es.object.values.js");
19
+
20
+ var _react = _interopRequireWildcard(require("react"));
21
+
22
+ var _uiHelpers = require("@megafon/ui-helpers");
23
+
24
+ var PropTypes = _interopRequireWildcard(require("prop-types"));
25
+
26
+ var _Button = _interopRequireDefault(require("../Button/Button"));
27
+
28
+ var _Caption = _interopRequireDefault(require("../Caption/Caption"));
29
+
30
+ var _Header = _interopRequireDefault(require("../Header/Header"));
31
+
32
+ var _Tile = _interopRequireDefault(require("../Tile/Tile"));
33
+
34
+ var _useSwipe2 = _interopRequireWildcard(require("hooks/useSwipe"));
35
+
36
+ var _SnackbarTimer = _interopRequireDefault(require("./SnackbarTimer/SnackbarTimer"));
37
+
38
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
39
+
40
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
+
42
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
43
+
44
+ var _DEFAULT_SNACKBARS;
45
+
46
+ var HeartIcon16 = function HeartIcon16(props) {
47
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
48
+ viewBox: "0 0 20 20"
49
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
50
+ d: "M13.25 3A3.78 3.78 0 0010 4.82 3.78 3.78 0 006.75 3C4.6 3 3 5.18 3 7.13a3.42 3.42 0 00.49 1.77c1.2 2 5 7.64 5.15 7.88l.15.22h2.51l.15-.22c.16-.24 4-5.83 5.1-7.92A4.14 4.14 0 0017 7.13C17 5.18 15.4 3 13.25 3zm2.41 5.4c-.94 1.81-4.16 6.53-4.89 7.59H9.32c-.73-1.09-3.92-5.87-5-7.62A2.42 2.42 0 014 7.13C4 5.71 5.23 4 6.75 4a2.73 2.73 0 012.67 2h1.15a2.73 2.73 0 012.67-2C14.77 4 16 5.71 16 7.13a3.14 3.14 0 01-.34 1.27z"
51
+ }));
52
+ };
53
+
54
+ var HeartIcon24 = function HeartIcon24(props) {
55
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
56
+ viewBox: "0 0 32 32"
57
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
58
+ d: "M20.5 6A5.55 5.55 0 0016 8.27 5.55 5.55 0 0011.5 6C8.35 6 6 9.18 6 12a5 5 0 00.73 2.61c1.67 2.77 6.92 10.59 7.14 10.93l.3.44H18l.3-.43c.23-.33 5.58-8.09 7.09-11A6 6 0 0026 12c0-2.82-2.35-6-5.5-6zm3.07 7.65c-1.25 2.42-5.5 8.65-6.66 10.35h-1.68c-1.16-1.73-5.37-8-6.79-10.4A3 3 0 018 12c0-1.82 1.56-4 3.5-4a3.47 3.47 0 013.38 2.51h2.24A3.47 3.47 0 0120.5 8c1.94 0 3.5 2.2 3.5 4a4 4 0 01-.43 1.65z"
59
+ }));
60
+ };
61
+
62
+ var AttentionIcon16 = function AttentionIcon16(props) {
63
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
64
+ viewBox: "0 0 20 20"
65
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
66
+ d: "M9 5h2v6H9V5zm1 8c-.2 0-.5.1-.7.3s-.3.4-.3.7.1.5.3.7.5.3.7.3.5-.1.7-.3.3-.4.3-.7-.1-.5-.3-.7c-.1-.2-.4-.3-.7-.3zm0 4c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7zm-8-7c0 4.4 3.6 8 8 8s8-3.6 8-8-3.6-8-8-8-8 3.6-8 8z"
67
+ }));
68
+ };
69
+
70
+ var CheckedIcon16 = function CheckedIcon16(props) {
71
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
72
+ viewBox: "0 0 20 20"
73
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
74
+ d: "M8.832 11.547L6.619 9.335l-1.414 1.413 2.462 2.462 1.445 1.446 5.932-8.486-1.638-1.148-4.574 6.525z"
75
+ }));
76
+ };
77
+
78
+ var AttentionIcon24 = function AttentionIcon24(props) {
79
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
80
+ viewBox: "0 0 32 32"
81
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
82
+ d: "M15 22h2v-2h-2v2zm0-4h2v-8h-2v8zm1 10C9.4 28 4 22.6 4 16S9.4 4 16 4s12 5.4 12 12-5.4 12-12 12zM6 16c0 5.5 4.5 10 10 10s10-4.5 10-10S21.5 6 16 6 6 10.5 6 16z"
83
+ }));
84
+ };
85
+
86
+ var CheckedIcon24 = function CheckedIcon24(props) {
87
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
88
+ viewBox: "0 0 32 32"
89
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
90
+ d: "M22.2 9l-7.8 9.4-3.6-3.7L9 16.5c3.6 3.7 5.4 5.5 5.5 5.5.1 0 3.3-3.8 9.5-11.3L22.2 9z"
91
+ }));
92
+ };
93
+
94
+ var CancelIcon = function CancelIcon(props) {
95
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
96
+ viewBox: "0 0 40 40"
97
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
98
+ d: "M20 18.586l6.364-6.364 1.414 1.414L21.414 20l6.364 6.364-1.414 1.414L20 21.414l-6.364 6.364-1.414-1.414L18.586 20l-6.364-6.364 1.414-1.414L20 18.586z"
99
+ }));
100
+ };
101
+
102
+ var DEFAULT_MAX_TIMER_SECONDS = 4;
103
+ var CLOSE_DELAY_MS = 80;
104
+ var SnackbarTypes = {
105
+ ATTENTION: 'attention',
106
+ SUCCESS: 'success',
107
+ TIMER: 'timer',
108
+ INFO: 'info'
109
+ };
110
+ exports.SnackbarTypes = SnackbarTypes;
111
+ var ATTENTION = SnackbarTypes.ATTENTION,
112
+ SUCCESS = SnackbarTypes.SUCCESS,
113
+ TIMER = SnackbarTypes.TIMER,
114
+ INFO = SnackbarTypes.INFO;
115
+ var DEFAULT_SNACKBARS = (_DEFAULT_SNACKBARS = {}, (0, _defineProperty2["default"])(_DEFAULT_SNACKBARS, ATTENTION, {
116
+ mobileIcon: /*#__PURE__*/_react["default"].createElement(AttentionIcon16, null),
117
+ desktopIcon: /*#__PURE__*/_react["default"].createElement(AttentionIcon24, null),
118
+ buttonText: 'Подробнее'
119
+ }), (0, _defineProperty2["default"])(_DEFAULT_SNACKBARS, SUCCESS, {
120
+ mobileIcon: /*#__PURE__*/_react["default"].createElement(CheckedIcon16, null),
121
+ desktopIcon: /*#__PURE__*/_react["default"].createElement(CheckedIcon24, null),
122
+ buttonText: 'Подробнее'
123
+ }), (0, _defineProperty2["default"])(_DEFAULT_SNACKBARS, TIMER, {
124
+ buttonText: 'Отмена'
125
+ }), (0, _defineProperty2["default"])(_DEFAULT_SNACKBARS, INFO, {
126
+ mobileIcon: /*#__PURE__*/_react["default"].createElement(HeartIcon16, null),
127
+ desktopIcon: /*#__PURE__*/_react["default"].createElement(HeartIcon24, null),
128
+ buttonText: 'Хорошо'
129
+ }), _DEFAULT_SNACKBARS);
130
+ var cn = (0, _uiHelpers.cnCreate)('mfui-snackbar');
131
+
132
+ var Snackbar = function Snackbar(_ref) {
133
+ var text = _ref.text,
134
+ _ref$type = _ref.type,
135
+ type = _ref$type === void 0 ? INFO : _ref$type,
136
+ icon = _ref.icon,
137
+ _ref$hasIcon = _ref.hasIcon,
138
+ hasIcon = _ref$hasIcon === void 0 ? true : _ref$hasIcon,
139
+ buttonText = _ref.buttonText,
140
+ _ref$maxTimerValue = _ref.maxTimerValue,
141
+ maxTimerValue = _ref$maxTimerValue === void 0 ? DEFAULT_MAX_TIMER_SECONDS : _ref$maxTimerValue,
142
+ _ref$hasTextButton = _ref.hasTextButton,
143
+ hasTextButton = _ref$hasTextButton === void 0 ? false : _ref$hasTextButton,
144
+ _ref$disableCloseAnim = _ref.disableCloseAnimation,
145
+ disableCloseAnimation = _ref$disableCloseAnim === void 0 ? false : _ref$disableCloseAnim,
146
+ className = _ref.className,
147
+ _ref$classes = _ref.classes,
148
+ classes = _ref$classes === void 0 ? {} : _ref$classes,
149
+ dataAttrs = _ref.dataAttrs,
150
+ onClose = _ref.onClose,
151
+ onButtonClick = _ref.onButtonClick;
152
+
153
+ var _useState = (0, _react.useState)(true),
154
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
155
+ isOpened = _useState2[0],
156
+ setIsOpened = _useState2[1];
157
+
158
+ var containerRef = (0, _react.useRef)(null);
159
+
160
+ var _useSwipe = (0, _useSwipe2["default"])(containerRef),
161
+ transform = _useSwipe.transform,
162
+ transitionStep = _useSwipe.transitionStep;
163
+
164
+ var isTransitionMoveStep = transitionStep === _useSwipe2.TransitionSteps.MOVE_STEP;
165
+ var isTransitionMoveEndStep = transitionStep === _useSwipe2.TransitionSteps.MOVE_END_STEP;
166
+ var defaultSnackbar = DEFAULT_SNACKBARS[type];
167
+ var isTimerType = type === TIMER;
168
+ var isInfoType = type === INFO;
169
+ var isHiddenIcon = isTimerType || !hasIcon && isInfoType;
170
+ var isCustomIcon = isInfoType && icon;
171
+ var currentButtonText = buttonText && !isTimerType ? buttonText : defaultSnackbar.buttonText;
172
+ var handleClose = (0, _react.useCallback)(function () {
173
+ setIsOpened(false);
174
+ }, []);
175
+ (0, _react.useEffect)(function () {
176
+ if (isOpened) {
177
+ return undefined;
178
+ }
179
+
180
+ if (disableCloseAnimation) {
181
+ onClose === null || onClose === void 0 ? void 0 : onClose();
182
+ }
183
+
184
+ var closeTimeoutId = setTimeout(function () {
185
+ onClose === null || onClose === void 0 ? void 0 : onClose();
186
+ }, CLOSE_DELAY_MS);
187
+ return function () {
188
+ clearTimeout(closeTimeoutId);
189
+ };
190
+ }, [isOpened, disableCloseAnimation, onClose]);
191
+ (0, _react.useEffect)(function () {
192
+ isTransitionMoveEndStep && handleClose();
193
+ }, [isTransitionMoveEndStep, handleClose]);
194
+ var handleTextButtonClick = (0, _react.useCallback)(function () {
195
+ onButtonClick === null || onButtonClick === void 0 ? void 0 : onButtonClick();
196
+ }, [onButtonClick]);
197
+ var renderedTimer = (0, _react.useMemo)(function () {
198
+ return /*#__PURE__*/_react["default"].createElement(_SnackbarTimer["default"], {
199
+ isTimerType: isTimerType,
200
+ maxTimerValue: maxTimerValue,
201
+ onTimerEnd: handleClose
202
+ });
203
+ }, [isTimerType, maxTimerValue, handleClose]);
204
+ var renderedIcons = (0, _react.useMemo)(function () {
205
+ return isCustomIcon ? /*#__PURE__*/_react["default"].createElement("div", {
206
+ className: cn('icon-container', [classes.icon])
207
+ }, icon) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
208
+ className: cn('icon-container', {
209
+ mobile: true
210
+ }, [classes.icon])
211
+ }, defaultSnackbar.mobileIcon), /*#__PURE__*/_react["default"].createElement("div", {
212
+ className: cn('icon-container', {
213
+ desktop: true
214
+ }, [classes.icon])
215
+ }, defaultSnackbar.desktopIcon));
216
+ }, [isCustomIcon, icon, defaultSnackbar, classes]);
217
+ return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
218
+ className: cn({
219
+ move: isTransitionMoveStep
220
+ }, [className, classes.root]),
221
+ ref: containerRef,
222
+ style: {
223
+ transform: transform
224
+ }
225
+ }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), /*#__PURE__*/_react["default"].createElement(_Tile["default"], {
226
+ className: cn('tile', {
227
+ type: type,
228
+ closed: !isOpened
229
+ }, [classes.container]),
230
+ radius: "rounded"
231
+ }, !isHiddenIcon && renderedIcons, renderedTimer, /*#__PURE__*/_react["default"].createElement(_Caption["default"], {
232
+ className: cn('text', {
233
+ mobile: true
234
+ }, [classes.text]),
235
+ variant: "medium",
236
+ color: "white",
237
+ hasMargin: false,
238
+ dataAttrs: {
239
+ root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.text
240
+ }
241
+ }, text), /*#__PURE__*/_react["default"].createElement(_Header["default"], {
242
+ as: "h5",
243
+ color: "white",
244
+ className: cn('text', {
245
+ desktop: true,
246
+ "short": !!hasTextButton
247
+ }, [classes.text]),
248
+ dataAttrs: {
249
+ root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.text
250
+ }
251
+ }, text), hasTextButton && /*#__PURE__*/_react["default"].createElement(_Button["default"], {
252
+ type: "text",
253
+ sizeAll: "small",
254
+ sizeMobile: "extra-small",
255
+ className: cn('text-button'),
256
+ dataAttrs: {
257
+ root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.textButton
258
+ },
259
+ onClick: handleTextButtonClick
260
+ }, currentButtonText), /*#__PURE__*/_react["default"].createElement("button", (0, _extends2["default"])({
261
+ type: "button",
262
+ className: cn('close-button')
263
+ }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.closeButton), {
264
+ onClick: handleClose
265
+ }), /*#__PURE__*/_react["default"].createElement(CancelIcon, {
266
+ className: cn('close-button-icon')
267
+ }))));
268
+ };
269
+
270
+ Snackbar.propTypes = {
271
+ text: PropTypes.string.isRequired,
272
+ type: PropTypes.oneOf(Object.values(SnackbarTypes)),
273
+ icon: PropTypes.element,
274
+ hasIcon: PropTypes.bool,
275
+ buttonText: PropTypes.string,
276
+ hasTextButton: PropTypes.bool,
277
+ maxTimerValue: PropTypes.number,
278
+ disableCloseAnimation: PropTypes.bool,
279
+ className: PropTypes.string,
280
+ classes: PropTypes.objectOf(PropTypes.string),
281
+ dataAttrs: PropTypes.objectOf(PropTypes.object),
282
+ onButtonClick: PropTypes.func,
283
+ onClose: PropTypes.func
284
+ };
285
+ var _default = Snackbar;
286
+ exports["default"] = _default;
@@ -0,0 +1,63 @@
1
+ h1,
2
+ h2,
3
+ h3,
4
+ h4,
5
+ h5 {
6
+ margin: 0;
7
+ }
8
+ @-webkit-keyframes snackbar-progress-bar {
9
+ 0% {
10
+ stroke-dashoffset: 100;
11
+ }
12
+ 100% {
13
+ stroke-dashoffset: 0;
14
+ }
15
+ }
16
+ @keyframes snackbar-progress-bar {
17
+ 0% {
18
+ stroke-dashoffset: 100;
19
+ }
20
+ 100% {
21
+ stroke-dashoffset: 0;
22
+ }
23
+ }
24
+ .mfui-snackbar-timer__timer {
25
+ position: relative;
26
+ display: -webkit-box;
27
+ display: -ms-flexbox;
28
+ display: flex;
29
+ -webkit-box-pack: center;
30
+ -ms-flex-pack: center;
31
+ justify-content: center;
32
+ -webkit-box-align: center;
33
+ -ms-flex-align: center;
34
+ align-items: center;
35
+ margin-right: 8px;
36
+ width: 24px;
37
+ height: 24px;
38
+ }
39
+ .mfui-snackbar-timer__timer svg {
40
+ position: absolute;
41
+ width: 24px;
42
+ height: 24px;
43
+ }
44
+ .mfui-snackbar-timer__timer-bg {
45
+ fill: none;
46
+ stroke-width: 1px;
47
+ stroke: var(--spbSky0);
48
+ }
49
+ .mfui-snackbar-timer__timer-progress {
50
+ fill: none;
51
+ stroke-width: 2px;
52
+ stroke-linecap: round;
53
+ stroke: var(--content);
54
+ stroke-dasharray: 100;
55
+ -webkit-transform: rotate(-90deg);
56
+ transform: rotate(-90deg);
57
+ -webkit-transform-origin: 50% 50%;
58
+ transform-origin: 50% 50%;
59
+ -webkit-animation-name: snackbar-progress-bar;
60
+ animation-name: snackbar-progress-bar;
61
+ -webkit-animation-timing-function: linear;
62
+ animation-timing-function: linear;
63
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import './SnackbarTimer.less';
3
+ declare type SnackbarTimerProps = {
4
+ isTimerType: boolean;
5
+ maxTimerValue: number;
6
+ onTimerEnd: () => void;
7
+ };
8
+ declare const SnackbarTimer: React.FC<SnackbarTimerProps>;
9
+ export default SnackbarTimer;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ require("core-js/modules/web.timers.js");
13
+
14
+ var _react = _interopRequireWildcard(require("react"));
15
+
16
+ var _uiHelpers = require("@megafon/ui-helpers");
17
+
18
+ var _Caption = _interopRequireDefault(require("../../Caption/Caption"));
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
+
26
+ var TIMER_END_DELAY_MS = 100;
27
+ var MS_IN_SECOND = 1000;
28
+ var cn = (0, _uiHelpers.cnCreate)('mfui-snackbar-timer');
29
+
30
+ var SnackbarTimer = function SnackbarTimer(_ref) {
31
+ var isTimerType = _ref.isTimerType,
32
+ maxTimerValue = _ref.maxTimerValue,
33
+ onTimerEnd = _ref.onTimerEnd;
34
+
35
+ var _useState = (0, _react.useState)(null),
36
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
37
+ timerValue = _useState2[0],
38
+ setTimerValue = _useState2[1];
39
+
40
+ (0, _react.useEffect)(function () {
41
+ setTimerValue(maxTimerValue);
42
+ }, [maxTimerValue]);
43
+ (0, _react.useEffect)(function () {
44
+ var timerTimeoutId;
45
+ var closeTimeoutId;
46
+
47
+ switch (timerValue) {
48
+ case null:
49
+ {
50
+ break;
51
+ }
52
+
53
+ case 0:
54
+ {
55
+ closeTimeoutId = setTimeout(function () {
56
+ setTimerValue(null);
57
+ onTimerEnd();
58
+ }, TIMER_END_DELAY_MS);
59
+ break;
60
+ }
61
+
62
+ default:
63
+ {
64
+ timerTimeoutId = setTimeout(function () {
65
+ return setTimerValue(timerValue - 1);
66
+ }, MS_IN_SECOND);
67
+ }
68
+ }
69
+
70
+ return function () {
71
+ clearTimeout(timerTimeoutId);
72
+ clearTimeout(closeTimeoutId);
73
+ };
74
+ }, [timerValue, onTimerEnd]);
75
+ return /*#__PURE__*/_react["default"].createElement("div", {
76
+ className: cn()
77
+ }, isTimerType && /*#__PURE__*/_react["default"].createElement(_Caption["default"], {
78
+ color: "white",
79
+ variant: "medium",
80
+ hasMargin: false,
81
+ className: cn('timer')
82
+ }, /*#__PURE__*/_react["default"].createElement("svg", null, /*#__PURE__*/_react["default"].createElement("circle", {
83
+ className: cn('timer-bg'),
84
+ cx: "50%",
85
+ cy: "50%",
86
+ r: "11"
87
+ }), /*#__PURE__*/_react["default"].createElement("circle", {
88
+ className: cn('timer-progress'),
89
+ style: {
90
+ animationDuration: "".concat(maxTimerValue * 1.5, "s")
91
+ },
92
+ cx: "50%",
93
+ cy: "50%",
94
+ r: "11"
95
+ })), timerValue));
96
+ };
97
+
98
+ var _default = SnackbarTimer;
99
+ exports["default"] = _default;
@@ -0,0 +1,5 @@
1
+ declare type UseResolutionReturnType = {
2
+ isMobile: boolean;
3
+ };
4
+ declare function useResolution(): UseResolutionReturnType;
5
+ export default useResolution;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var React = _interopRequireWildcard(require("react"));
13
+
14
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
+
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
+
20
+ var RESOLUTIONS;
21
+
22
+ (function (RESOLUTIONS) {
23
+ RESOLUTIONS[RESOLUTIONS["MOBILE_END"] = 767] = "MOBILE_END";
24
+ })(RESOLUTIONS || (RESOLUTIONS = {}));
25
+
26
+ var _RESOLUTIONS = RESOLUTIONS,
27
+ MOBILE_END = _RESOLUTIONS.MOBILE_END;
28
+ var MEDIA_QUERIES = {
29
+ MAX_WIDTH_MOBILE_END: "(max-width: ".concat(MOBILE_END, "px)")
30
+ };
31
+ var MAX_WIDTH_MOBILE_END = MEDIA_QUERIES.MAX_WIDTH_MOBILE_END;
32
+
33
+ function useResolution() {
34
+ var _React$useState = React.useState(window.innerWidth <= MOBILE_END),
35
+ _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
36
+ isMobile = _React$useState2[0],
37
+ setIsMobile = _React$useState2[1];
38
+
39
+ var handleMediaChange = function handleMediaChange(updateStateFn) {
40
+ return function (e) {
41
+ return updateStateFn(e.matches);
42
+ };
43
+ };
44
+
45
+ var handleMaxWidthMobileEnd = handleMediaChange(setIsMobile);
46
+ React.useEffect(function () {
47
+ window.matchMedia(MAX_WIDTH_MOBILE_END).addEventListener('change', handleMaxWidthMobileEnd);
48
+ return function () {
49
+ window.matchMedia(MAX_WIDTH_MOBILE_END).removeEventListener('change', handleMaxWidthMobileEnd);
50
+ };
51
+ }, [handleMaxWidthMobileEnd]);
52
+ return {
53
+ isMobile: isMobile
54
+ };
55
+ }
56
+
57
+ var _default = useResolution;
58
+ exports["default"] = _default;
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ export declare enum TransitionSteps {
3
+ INITIAL_STEP = "initial-step",
4
+ MOVE_STEP = "move-step",
5
+ MOVE_END_STEP = "move-end-step"
6
+ }
7
+ declare type UseSwipeReturnType = {
8
+ /** Значение для css-свойства transform управляемого элемента */
9
+ transform: string;
10
+ /** Текущий этап смахивания элемента */
11
+ transitionStep: TransitionSteps;
12
+ };
13
+ declare function useSwipe(element: React.MutableRefObject<null>): UseSwipeReturnType;
14
+ export default useSwipe;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = exports.TransitionSteps = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var React = _interopRequireWildcard(require("react"));
13
+
14
+ var _useResolution2 = _interopRequireDefault(require("./useResolution"));
15
+
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
+
22
+ var TransitionSteps;
23
+ exports.TransitionSteps = TransitionSteps;
24
+
25
+ (function (TransitionSteps) {
26
+ TransitionSteps["INITIAL_STEP"] = "initial-step";
27
+ TransitionSteps["MOVE_STEP"] = "move-step";
28
+ TransitionSteps["MOVE_END_STEP"] = "move-end-step";
29
+ })(TransitionSteps || (exports.TransitionSteps = TransitionSteps = {})); // Смахивание элемента влево или вправо на мобильном устройстве.
30
+ // Элемент закрывается на событии 'touchend', если он был смещен пользователем больше, чем на половину ширины окна.
31
+
32
+
33
+ function useSwipe(element) {
34
+ var _useResolution = (0, _useResolution2["default"])(),
35
+ isMobile = _useResolution.isMobile;
36
+
37
+ var _React$useState = React.useState(null),
38
+ _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
39
+ initialTouchPosition = _React$useState2[0],
40
+ setInitialTouchPosition = _React$useState2[1];
41
+
42
+ var _React$useState3 = React.useState(TransitionSteps.INITIAL_STEP),
43
+ _React$useState4 = (0, _slicedToArray2["default"])(_React$useState3, 2),
44
+ transitionStep = _React$useState4[0],
45
+ setTransitionStep = _React$useState4[1];
46
+
47
+ var _React$useState5 = React.useState(''),
48
+ _React$useState6 = (0, _slicedToArray2["default"])(_React$useState5, 2),
49
+ transform = _React$useState6[0],
50
+ setTransform = _React$useState6[1];
51
+
52
+ var animationFrameId = React.useRef(0);
53
+ var currentElement = element.current;
54
+ var isTransitionMoveStep = transitionStep === TransitionSteps.MOVE_STEP;
55
+ var handleWindowTouchMove = React.useCallback(function (e) {
56
+ if (animationFrameId) {
57
+ window.cancelAnimationFrame(animationFrameId.current);
58
+ }
59
+
60
+ animationFrameId.current = window.requestAnimationFrame(function () {
61
+ setTransitionStep(TransitionSteps.MOVE_STEP);
62
+
63
+ if (!currentElement) {
64
+ return;
65
+ }
66
+
67
+ if (!initialTouchPosition) {
68
+ setInitialTouchPosition(e.touches[0].clientX);
69
+ return;
70
+ }
71
+
72
+ var positionsDiff = initialTouchPosition - e.touches[0].clientX;
73
+ positionsDiff !== 0 && setTransform("translateX(".concat(-positionsDiff, "px)"));
74
+ animationFrameId.current = 0;
75
+ });
76
+ }, [currentElement, animationFrameId, initialTouchPosition]);
77
+ var handleWindowTouchEnd = React.useCallback(function (e) {
78
+ var _a;
79
+
80
+ if (!currentElement || !isTransitionMoveStep || !initialTouchPosition) {
81
+ return;
82
+ }
83
+
84
+ window.cancelAnimationFrame(animationFrameId.current);
85
+ var windowCenterPosition = window.innerWidth / 2;
86
+ var touchPosition = (_a = e.changedTouches[0]) === null || _a === void 0 ? void 0 : _a.clientX;
87
+ var isRightSwipe = touchPosition > initialTouchPosition;
88
+ var isLeftSwipe = touchPosition < initialTouchPosition;
89
+ var isMoreHalfSwiped = Math.abs(initialTouchPosition - touchPosition) > windowCenterPosition;
90
+ setInitialTouchPosition(null);
91
+
92
+ switch (true) {
93
+ case isMoreHalfSwiped && isRightSwipe:
94
+ {
95
+ setTransform('translateX(110%)');
96
+ setTransitionStep(TransitionSteps.MOVE_END_STEP);
97
+ break;
98
+ }
99
+
100
+ case isMoreHalfSwiped && isLeftSwipe:
101
+ {
102
+ setTransform('translateX(-110%)');
103
+ setTransitionStep(TransitionSteps.MOVE_END_STEP);
104
+ break;
105
+ }
106
+
107
+ default:
108
+ {
109
+ setTransform('none');
110
+ setTransitionStep(TransitionSteps.INITIAL_STEP);
111
+ }
112
+ }
113
+ }, [currentElement, isTransitionMoveStep, initialTouchPosition, animationFrameId]);
114
+ React.useEffect(function () {
115
+ if (isMobile) {
116
+ window.addEventListener('touchmove', handleWindowTouchMove);
117
+ window.addEventListener('touchend', handleWindowTouchEnd);
118
+ }
119
+
120
+ return function () {
121
+ window.removeEventListener('touchmove', handleWindowTouchMove);
122
+ window.removeEventListener('touchend', handleWindowTouchEnd);
123
+ };
124
+ }, [isMobile, handleWindowTouchMove, handleWindowTouchEnd]);
125
+ return {
126
+ transform: transform,
127
+ transitionStep: transitionStep
128
+ };
129
+ }
130
+
131
+ var _default = useSwipe;
132
+ exports["default"] = _default;