@megafon/ui-core 5.1.1 → 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.
- package/CHANGELOG.md +25 -0
- package/dist/es/components/Snackbar/Snackbar.css +217 -0
- package/dist/es/components/Snackbar/Snackbar.d.ts +49 -0
- package/dist/es/components/Snackbar/Snackbar.js +258 -0
- package/dist/es/components/Snackbar/SnackbarTimer/SnackbarTimer.css +63 -0
- package/dist/es/components/Snackbar/SnackbarTimer/SnackbarTimer.d.ts +9 -0
- package/dist/es/components/Snackbar/SnackbarTimer/SnackbarTimer.js +79 -0
- package/dist/es/components/Tabs/Tabs.js +8 -1
- package/dist/es/hooks/useResolution.d.ts +5 -0
- package/dist/es/hooks/useResolution.js +40 -0
- package/dist/es/hooks/useSwipe.d.ts +14 -0
- package/dist/es/hooks/useSwipe.js +112 -0
- package/dist/es/index.d.ts +2 -0
- package/dist/es/index.js +2 -0
- package/dist/lib/components/Snackbar/Snackbar.css +217 -0
- package/dist/lib/components/Snackbar/Snackbar.d.ts +49 -0
- package/dist/lib/components/Snackbar/Snackbar.js +286 -0
- package/dist/lib/components/Snackbar/SnackbarTimer/SnackbarTimer.css +63 -0
- package/dist/lib/components/Snackbar/SnackbarTimer/SnackbarTimer.d.ts +9 -0
- package/dist/lib/components/Snackbar/SnackbarTimer/SnackbarTimer.js +99 -0
- package/dist/lib/components/Tabs/Tabs.js +8 -1
- package/dist/lib/hooks/useResolution.d.ts +5 -0
- package/dist/lib/hooks/useResolution.js +58 -0
- package/dist/lib/hooks/useSwipe.d.ts +14 -0
- package/dist/lib/hooks/useSwipe.js +132 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +16 -0
- package/package.json +4 -4
|
@@ -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;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export { default as RadioButton } from './components/RadioButton/RadioButton';
|
|
|
36
36
|
export { default as Search } from './components/Search/Search';
|
|
37
37
|
export { default as Select } from './components/Select/Select';
|
|
38
38
|
export { default as selectReducer } from './components/Select/reducer/selectReducer';
|
|
39
|
+
export { default as Snackbar } from './components/Snackbar/Snackbar';
|
|
40
|
+
export { default as SnackbarTimer } from './components/Snackbar/SnackbarTimer/SnackbarTimer';
|
|
39
41
|
export { default as Switcher } from './components/Switcher/Switcher';
|
|
40
42
|
export { default as Tab } from './components/Tabs/Tab';
|
|
41
43
|
export { default as Tabs } from './components/Tabs/Tabs';
|
package/dist/lib/index.js
CHANGED
|
@@ -231,6 +231,18 @@ Object.defineProperty(exports, "selectReducer", {
|
|
|
231
231
|
return _selectReducer["default"];
|
|
232
232
|
}
|
|
233
233
|
});
|
|
234
|
+
Object.defineProperty(exports, "Snackbar", {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
get: function get() {
|
|
237
|
+
return _Snackbar["default"];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(exports, "SnackbarTimer", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get: function get() {
|
|
243
|
+
return _SnackbarTimer["default"];
|
|
244
|
+
}
|
|
245
|
+
});
|
|
234
246
|
Object.defineProperty(exports, "Switcher", {
|
|
235
247
|
enumerable: true,
|
|
236
248
|
get: function get() {
|
|
@@ -374,6 +386,10 @@ var _Select = _interopRequireDefault(require("./components/Select/Select"));
|
|
|
374
386
|
|
|
375
387
|
var _selectReducer = _interopRequireDefault(require("./components/Select/reducer/selectReducer"));
|
|
376
388
|
|
|
389
|
+
var _Snackbar = _interopRequireDefault(require("./components/Snackbar/Snackbar"));
|
|
390
|
+
|
|
391
|
+
var _SnackbarTimer = _interopRequireDefault(require("./components/Snackbar/SnackbarTimer/SnackbarTimer"));
|
|
392
|
+
|
|
377
393
|
var _Switcher = _interopRequireDefault(require("./components/Switcher/Switcher"));
|
|
378
394
|
|
|
379
395
|
var _Tab = _interopRequireDefault(require("./components/Tabs/Tab"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@megafon/ui-core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"styles"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@babel/preset-env": "^7.8.6",
|
|
51
51
|
"@babel/preset-react": "^7.8.3",
|
|
52
52
|
"@babel/preset-typescript": "^7.8.3",
|
|
53
|
-
"@megafon/ui-icons": "^2.
|
|
53
|
+
"@megafon/ui-icons": "^2.14.0",
|
|
54
54
|
"@svgr/core": "^2.4.1",
|
|
55
55
|
"@testing-library/jest-dom": "5.16.2",
|
|
56
56
|
"@testing-library/react": "12.1.2",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@babel/runtime": "^7.8.4",
|
|
87
87
|
"@datepicker-react/hooks": "^2.7.0",
|
|
88
|
-
"@megafon/ui-helpers": "^2.5.
|
|
88
|
+
"@megafon/ui-helpers": "^2.5.2",
|
|
89
89
|
"@popperjs/core": "^2.5.3",
|
|
90
90
|
"core-js": "^3.6.4",
|
|
91
91
|
"date-fns": "^2.16.1",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"react-popper": "^2.2.3",
|
|
97
97
|
"swiper": "^6.5.6"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "dcc83f03d9aa2088d55b98deecafe819051cda0d"
|
|
100
100
|
}
|