@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.
- package/CHANGELOG.md +11 -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/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/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 +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.2.0](https://hq-gitlab.megafon.ru/site-portal/libraries/javascript/megafon-ui/compare/@megafon/ui-core@5.1.2...@megafon/ui-core@5.2.0) (2023-08-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **snackbar:** create component Snackbar ([ec08ff0](https://hq-gitlab.megafon.ru/site-portal/libraries/javascript/megafon-ui/commit/ec08ff067b23dcd7ad9e3f853ba871ba20fd36bd))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [5.1.2](https://hq-gitlab.megafon.ru/site-portal/libraries/javascript/megafon-ui/compare/@megafon/ui-core@5.1.0...@megafon/ui-core@5.1.2) (2023-08-21)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
h1,
|
|
2
|
+
h2,
|
|
3
|
+
h3,
|
|
4
|
+
h4,
|
|
5
|
+
h5 {
|
|
6
|
+
margin: 0;
|
|
7
|
+
}
|
|
8
|
+
.mfui-snackbar {
|
|
9
|
+
z-index: 1;
|
|
10
|
+
width: 480px;
|
|
11
|
+
-webkit-transition: -webkit-transform 300ms;
|
|
12
|
+
transition: -webkit-transform 300ms;
|
|
13
|
+
transition: transform 300ms;
|
|
14
|
+
transition: transform 300ms, -webkit-transform 300ms;
|
|
15
|
+
}
|
|
16
|
+
@-webkit-keyframes snackbar-show {
|
|
17
|
+
from {
|
|
18
|
+
-webkit-transform: scale(90%);
|
|
19
|
+
transform: scale(90%);
|
|
20
|
+
opacity: 0;
|
|
21
|
+
}
|
|
22
|
+
to {
|
|
23
|
+
-webkit-transform: scale(100%);
|
|
24
|
+
transform: scale(100%);
|
|
25
|
+
opacity: 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
@keyframes snackbar-show {
|
|
29
|
+
from {
|
|
30
|
+
-webkit-transform: scale(90%);
|
|
31
|
+
transform: scale(90%);
|
|
32
|
+
opacity: 0;
|
|
33
|
+
}
|
|
34
|
+
to {
|
|
35
|
+
-webkit-transform: scale(100%);
|
|
36
|
+
transform: scale(100%);
|
|
37
|
+
opacity: 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
@-webkit-keyframes snackbar-hide {
|
|
41
|
+
0% {
|
|
42
|
+
-webkit-transform: scale(100%);
|
|
43
|
+
transform: scale(100%);
|
|
44
|
+
opacity: 1;
|
|
45
|
+
}
|
|
46
|
+
99% {
|
|
47
|
+
-webkit-transform: scale(90%);
|
|
48
|
+
transform: scale(90%);
|
|
49
|
+
opacity: 0;
|
|
50
|
+
}
|
|
51
|
+
100% {
|
|
52
|
+
display: none;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
@keyframes snackbar-hide {
|
|
56
|
+
0% {
|
|
57
|
+
-webkit-transform: scale(100%);
|
|
58
|
+
transform: scale(100%);
|
|
59
|
+
opacity: 1;
|
|
60
|
+
}
|
|
61
|
+
99% {
|
|
62
|
+
-webkit-transform: scale(90%);
|
|
63
|
+
transform: scale(90%);
|
|
64
|
+
opacity: 0;
|
|
65
|
+
}
|
|
66
|
+
100% {
|
|
67
|
+
display: none;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
@media screen and (max-width: 767px) {
|
|
71
|
+
.mfui-snackbar {
|
|
72
|
+
width: 304px;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
.mfui-snackbar_move {
|
|
76
|
+
-webkit-transition: none;
|
|
77
|
+
transition: none;
|
|
78
|
+
}
|
|
79
|
+
.mfui-snackbar__tile {
|
|
80
|
+
display: -webkit-box;
|
|
81
|
+
display: -ms-flexbox;
|
|
82
|
+
display: flex;
|
|
83
|
+
-webkit-box-align: center;
|
|
84
|
+
-ms-flex-align: center;
|
|
85
|
+
align-items: center;
|
|
86
|
+
-webkit-box-pack: justify;
|
|
87
|
+
-ms-flex-pack: justify;
|
|
88
|
+
justify-content: space-between;
|
|
89
|
+
min-height: 64px;
|
|
90
|
+
padding: 12px 16px 12px 12px;
|
|
91
|
+
background-color: var(--content);
|
|
92
|
+
opacity: 0;
|
|
93
|
+
-webkit-animation: 200ms linear 200ms 1 forwards snackbar-show;
|
|
94
|
+
animation: 200ms linear 200ms 1 forwards snackbar-show;
|
|
95
|
+
}
|
|
96
|
+
@media screen and (max-width: 767px) {
|
|
97
|
+
.mfui-snackbar__tile {
|
|
98
|
+
min-height: 48px;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
.mfui-snackbar__tile_closed {
|
|
102
|
+
-webkit-animation: 100ms linear 1 snackbar-hide;
|
|
103
|
+
animation: 100ms linear 1 snackbar-hide;
|
|
104
|
+
}
|
|
105
|
+
.mfui-snackbar__tile_type_success .mfui-snackbar__icon-container svg {
|
|
106
|
+
fill: var(--brandGreen);
|
|
107
|
+
}
|
|
108
|
+
.mfui-snackbar__tile_type_attention .mfui-snackbar__icon-container svg {
|
|
109
|
+
fill: var(--fury80);
|
|
110
|
+
}
|
|
111
|
+
.mfui-snackbar__icon-container {
|
|
112
|
+
display: -webkit-box;
|
|
113
|
+
display: -ms-flexbox;
|
|
114
|
+
display: flex;
|
|
115
|
+
-webkit-box-align: center;
|
|
116
|
+
-ms-flex-align: center;
|
|
117
|
+
align-items: center;
|
|
118
|
+
-webkit-box-pack: center;
|
|
119
|
+
-ms-flex-pack: center;
|
|
120
|
+
justify-content: center;
|
|
121
|
+
width: 32px;
|
|
122
|
+
min-width: 32px;
|
|
123
|
+
height: 32px;
|
|
124
|
+
margin-right: 8px;
|
|
125
|
+
}
|
|
126
|
+
.mfui-snackbar__icon-container svg {
|
|
127
|
+
fill: var(--base);
|
|
128
|
+
}
|
|
129
|
+
@media screen and (max-width: 767px) {
|
|
130
|
+
.mfui-snackbar__icon-container {
|
|
131
|
+
width: 20px;
|
|
132
|
+
min-width: 20px;
|
|
133
|
+
height: 20px;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
.mfui-snackbar__icon-container_desktop {
|
|
137
|
+
display: none;
|
|
138
|
+
}
|
|
139
|
+
@media screen and (min-width: 768px) {
|
|
140
|
+
.mfui-snackbar__icon-container_desktop {
|
|
141
|
+
display: block;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
.mfui-snackbar__icon-container_mobile {
|
|
145
|
+
display: none;
|
|
146
|
+
}
|
|
147
|
+
@media screen and (max-width: 767px) {
|
|
148
|
+
.mfui-snackbar__icon-container_mobile {
|
|
149
|
+
display: block;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
.mfui-snackbar__text {
|
|
153
|
+
display: none;
|
|
154
|
+
-webkit-box-flex: 1;
|
|
155
|
+
-ms-flex-positive: 1;
|
|
156
|
+
flex-grow: 1;
|
|
157
|
+
overflow: hidden;
|
|
158
|
+
}
|
|
159
|
+
@media screen and (min-width: 768px) {
|
|
160
|
+
.mfui-snackbar__text_desktop {
|
|
161
|
+
display: block;
|
|
162
|
+
max-height: 48px;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
@media screen and (max-width: 767px) {
|
|
166
|
+
.mfui-snackbar__text_mobile {
|
|
167
|
+
display: block;
|
|
168
|
+
max-height: 36px;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
.mfui-snackbar__text_short {
|
|
172
|
+
max-width: 272px;
|
|
173
|
+
}
|
|
174
|
+
.mfui-snackbar__text-button {
|
|
175
|
+
min-width: -webkit-min-content;
|
|
176
|
+
min-width: -moz-min-content;
|
|
177
|
+
min-width: min-content;
|
|
178
|
+
margin-left: 12px;
|
|
179
|
+
}
|
|
180
|
+
.mfui-snackbar__close-button {
|
|
181
|
+
display: -webkit-box;
|
|
182
|
+
display: -ms-flexbox;
|
|
183
|
+
display: flex;
|
|
184
|
+
-webkit-box-align: center;
|
|
185
|
+
-ms-flex-align: center;
|
|
186
|
+
align-items: center;
|
|
187
|
+
-webkit-box-pack: center;
|
|
188
|
+
-ms-flex-pack: center;
|
|
189
|
+
justify-content: center;
|
|
190
|
+
-webkit-box-sizing: border-box;
|
|
191
|
+
box-sizing: border-box;
|
|
192
|
+
width: 32px;
|
|
193
|
+
height: 32px;
|
|
194
|
+
margin-left: 24px;
|
|
195
|
+
padding: 0;
|
|
196
|
+
border: none;
|
|
197
|
+
border-radius: 40px;
|
|
198
|
+
background-color: transparent;
|
|
199
|
+
cursor: pointer;
|
|
200
|
+
}
|
|
201
|
+
@media screen and (max-width: 767px) {
|
|
202
|
+
.mfui-snackbar__close-button {
|
|
203
|
+
display: none;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
.mfui-snackbar__close-button:hover {
|
|
207
|
+
background-color: #99999933;
|
|
208
|
+
}
|
|
209
|
+
.mfui-snackbar__close-button:active {
|
|
210
|
+
background-color: #99999966;
|
|
211
|
+
}
|
|
212
|
+
.mfui-snackbar__close-button-icon {
|
|
213
|
+
width: 40px;
|
|
214
|
+
min-width: 40px;
|
|
215
|
+
height: 40px;
|
|
216
|
+
fill: var(--spbSky3);
|
|
217
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './Snackbar.less';
|
|
3
|
+
export declare const SnackbarTypes: {
|
|
4
|
+
readonly ATTENTION: "attention";
|
|
5
|
+
readonly SUCCESS: "success";
|
|
6
|
+
readonly TIMER: "timer";
|
|
7
|
+
readonly INFO: "info";
|
|
8
|
+
};
|
|
9
|
+
export declare type SnackbarType = typeof SnackbarTypes[keyof typeof SnackbarTypes];
|
|
10
|
+
export interface ISnackbarProps {
|
|
11
|
+
/** Текст */
|
|
12
|
+
text: string;
|
|
13
|
+
/** Тип отображения */
|
|
14
|
+
type?: SnackbarType;
|
|
15
|
+
/** Кастомная иконка для типа 'info' */
|
|
16
|
+
icon?: JSX.Element;
|
|
17
|
+
/** Отображение иконки. Скрыть иконку можно только для типа 'info' */
|
|
18
|
+
hasIcon?: boolean;
|
|
19
|
+
/** Кастомный текст кнопки. Не работает для типа 'timer' */
|
|
20
|
+
buttonText?: string;
|
|
21
|
+
/** Максимальное значение таймера */
|
|
22
|
+
maxTimerValue?: number;
|
|
23
|
+
/** Отображение текстовой кнопки */
|
|
24
|
+
hasTextButton?: boolean;
|
|
25
|
+
/** Отключение анимации закрытия */
|
|
26
|
+
disableCloseAnimation?: boolean;
|
|
27
|
+
/** Дополнительный класс корневого элемента */
|
|
28
|
+
className?: string;
|
|
29
|
+
/** Дополнительные классы для корневого и внутренних элементов */
|
|
30
|
+
classes?: {
|
|
31
|
+
root?: string;
|
|
32
|
+
container?: string;
|
|
33
|
+
icon?: string;
|
|
34
|
+
text?: string;
|
|
35
|
+
};
|
|
36
|
+
/** Дополнительные data атрибуты к внутренним элементам */
|
|
37
|
+
dataAttrs?: {
|
|
38
|
+
root?: Record<string, string>;
|
|
39
|
+
text?: Record<string, string>;
|
|
40
|
+
closeButton?: Record<string, string>;
|
|
41
|
+
textButton?: Record<string, string>;
|
|
42
|
+
};
|
|
43
|
+
/** Обработчик клика по кнопке */
|
|
44
|
+
onButtonClick?: () => void;
|
|
45
|
+
/** Обработчик на закрытие */
|
|
46
|
+
onClose?: () => void;
|
|
47
|
+
}
|
|
48
|
+
declare const Snackbar: React.FC<ISnackbarProps>;
|
|
49
|
+
export default Snackbar;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
4
|
+
|
|
5
|
+
var _DEFAULT_SNACKBARS;
|
|
6
|
+
|
|
7
|
+
import "core-js/modules/web.timers.js";
|
|
8
|
+
import "core-js/modules/es.object.values.js";
|
|
9
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
|
+
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
|
|
11
|
+
import * as PropTypes from 'prop-types';
|
|
12
|
+
import Button from "../Button/Button";
|
|
13
|
+
import Caption from "../Caption/Caption";
|
|
14
|
+
import Header from "../Header/Header";
|
|
15
|
+
import Tile from "../Tile/Tile";
|
|
16
|
+
import useSwipe, { TransitionSteps } from 'hooks/useSwipe';
|
|
17
|
+
import SnackbarTimer from "./SnackbarTimer/SnackbarTimer";
|
|
18
|
+
import "./Snackbar.css";
|
|
19
|
+
|
|
20
|
+
var HeartIcon16 = function HeartIcon16(props) {
|
|
21
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
22
|
+
viewBox: "0 0 20 20"
|
|
23
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
24
|
+
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"
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var HeartIcon24 = function HeartIcon24(props) {
|
|
29
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
30
|
+
viewBox: "0 0 32 32"
|
|
31
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
32
|
+
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"
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var AttentionIcon16 = function AttentionIcon16(props) {
|
|
37
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
38
|
+
viewBox: "0 0 20 20"
|
|
39
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
40
|
+
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"
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var CheckedIcon16 = function CheckedIcon16(props) {
|
|
45
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
46
|
+
viewBox: "0 0 20 20"
|
|
47
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
48
|
+
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"
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var AttentionIcon24 = function AttentionIcon24(props) {
|
|
53
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
54
|
+
viewBox: "0 0 32 32"
|
|
55
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
56
|
+
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"
|
|
57
|
+
}));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
var CheckedIcon24 = function CheckedIcon24(props) {
|
|
61
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
62
|
+
viewBox: "0 0 32 32"
|
|
63
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
64
|
+
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"
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var CancelIcon = function CancelIcon(props) {
|
|
69
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
70
|
+
viewBox: "0 0 40 40"
|
|
71
|
+
}, props), /*#__PURE__*/React.createElement("path", {
|
|
72
|
+
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"
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
var DEFAULT_MAX_TIMER_SECONDS = 4;
|
|
77
|
+
var CLOSE_DELAY_MS = 80;
|
|
78
|
+
export var SnackbarTypes = {
|
|
79
|
+
ATTENTION: 'attention',
|
|
80
|
+
SUCCESS: 'success',
|
|
81
|
+
TIMER: 'timer',
|
|
82
|
+
INFO: 'info'
|
|
83
|
+
};
|
|
84
|
+
var ATTENTION = SnackbarTypes.ATTENTION,
|
|
85
|
+
SUCCESS = SnackbarTypes.SUCCESS,
|
|
86
|
+
TIMER = SnackbarTypes.TIMER,
|
|
87
|
+
INFO = SnackbarTypes.INFO;
|
|
88
|
+
var DEFAULT_SNACKBARS = (_DEFAULT_SNACKBARS = {}, _defineProperty(_DEFAULT_SNACKBARS, ATTENTION, {
|
|
89
|
+
mobileIcon: /*#__PURE__*/React.createElement(AttentionIcon16, null),
|
|
90
|
+
desktopIcon: /*#__PURE__*/React.createElement(AttentionIcon24, null),
|
|
91
|
+
buttonText: 'Подробнее'
|
|
92
|
+
}), _defineProperty(_DEFAULT_SNACKBARS, SUCCESS, {
|
|
93
|
+
mobileIcon: /*#__PURE__*/React.createElement(CheckedIcon16, null),
|
|
94
|
+
desktopIcon: /*#__PURE__*/React.createElement(CheckedIcon24, null),
|
|
95
|
+
buttonText: 'Подробнее'
|
|
96
|
+
}), _defineProperty(_DEFAULT_SNACKBARS, TIMER, {
|
|
97
|
+
buttonText: 'Отмена'
|
|
98
|
+
}), _defineProperty(_DEFAULT_SNACKBARS, INFO, {
|
|
99
|
+
mobileIcon: /*#__PURE__*/React.createElement(HeartIcon16, null),
|
|
100
|
+
desktopIcon: /*#__PURE__*/React.createElement(HeartIcon24, null),
|
|
101
|
+
buttonText: 'Хорошо'
|
|
102
|
+
}), _DEFAULT_SNACKBARS);
|
|
103
|
+
var cn = cnCreate('mfui-snackbar');
|
|
104
|
+
|
|
105
|
+
var Snackbar = function Snackbar(_ref) {
|
|
106
|
+
var text = _ref.text,
|
|
107
|
+
_ref$type = _ref.type,
|
|
108
|
+
type = _ref$type === void 0 ? INFO : _ref$type,
|
|
109
|
+
icon = _ref.icon,
|
|
110
|
+
_ref$hasIcon = _ref.hasIcon,
|
|
111
|
+
hasIcon = _ref$hasIcon === void 0 ? true : _ref$hasIcon,
|
|
112
|
+
buttonText = _ref.buttonText,
|
|
113
|
+
_ref$maxTimerValue = _ref.maxTimerValue,
|
|
114
|
+
maxTimerValue = _ref$maxTimerValue === void 0 ? DEFAULT_MAX_TIMER_SECONDS : _ref$maxTimerValue,
|
|
115
|
+
_ref$hasTextButton = _ref.hasTextButton,
|
|
116
|
+
hasTextButton = _ref$hasTextButton === void 0 ? false : _ref$hasTextButton,
|
|
117
|
+
_ref$disableCloseAnim = _ref.disableCloseAnimation,
|
|
118
|
+
disableCloseAnimation = _ref$disableCloseAnim === void 0 ? false : _ref$disableCloseAnim,
|
|
119
|
+
className = _ref.className,
|
|
120
|
+
_ref$classes = _ref.classes,
|
|
121
|
+
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
122
|
+
dataAttrs = _ref.dataAttrs,
|
|
123
|
+
onClose = _ref.onClose,
|
|
124
|
+
onButtonClick = _ref.onButtonClick;
|
|
125
|
+
|
|
126
|
+
var _useState = useState(true),
|
|
127
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
128
|
+
isOpened = _useState2[0],
|
|
129
|
+
setIsOpened = _useState2[1];
|
|
130
|
+
|
|
131
|
+
var containerRef = useRef(null);
|
|
132
|
+
|
|
133
|
+
var _useSwipe = useSwipe(containerRef),
|
|
134
|
+
transform = _useSwipe.transform,
|
|
135
|
+
transitionStep = _useSwipe.transitionStep;
|
|
136
|
+
|
|
137
|
+
var isTransitionMoveStep = transitionStep === TransitionSteps.MOVE_STEP;
|
|
138
|
+
var isTransitionMoveEndStep = transitionStep === TransitionSteps.MOVE_END_STEP;
|
|
139
|
+
var defaultSnackbar = DEFAULT_SNACKBARS[type];
|
|
140
|
+
var isTimerType = type === TIMER;
|
|
141
|
+
var isInfoType = type === INFO;
|
|
142
|
+
var isHiddenIcon = isTimerType || !hasIcon && isInfoType;
|
|
143
|
+
var isCustomIcon = isInfoType && icon;
|
|
144
|
+
var currentButtonText = buttonText && !isTimerType ? buttonText : defaultSnackbar.buttonText;
|
|
145
|
+
var handleClose = useCallback(function () {
|
|
146
|
+
setIsOpened(false);
|
|
147
|
+
}, []);
|
|
148
|
+
useEffect(function () {
|
|
149
|
+
if (isOpened) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (disableCloseAnimation) {
|
|
154
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var closeTimeoutId = setTimeout(function () {
|
|
158
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
159
|
+
}, CLOSE_DELAY_MS);
|
|
160
|
+
return function () {
|
|
161
|
+
clearTimeout(closeTimeoutId);
|
|
162
|
+
};
|
|
163
|
+
}, [isOpened, disableCloseAnimation, onClose]);
|
|
164
|
+
useEffect(function () {
|
|
165
|
+
isTransitionMoveEndStep && handleClose();
|
|
166
|
+
}, [isTransitionMoveEndStep, handleClose]);
|
|
167
|
+
var handleTextButtonClick = useCallback(function () {
|
|
168
|
+
onButtonClick === null || onButtonClick === void 0 ? void 0 : onButtonClick();
|
|
169
|
+
}, [onButtonClick]);
|
|
170
|
+
var renderedTimer = useMemo(function () {
|
|
171
|
+
return /*#__PURE__*/React.createElement(SnackbarTimer, {
|
|
172
|
+
isTimerType: isTimerType,
|
|
173
|
+
maxTimerValue: maxTimerValue,
|
|
174
|
+
onTimerEnd: handleClose
|
|
175
|
+
});
|
|
176
|
+
}, [isTimerType, maxTimerValue, handleClose]);
|
|
177
|
+
var renderedIcons = useMemo(function () {
|
|
178
|
+
return isCustomIcon ? /*#__PURE__*/React.createElement("div", {
|
|
179
|
+
className: cn('icon-container', [classes.icon])
|
|
180
|
+
}, icon) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
181
|
+
className: cn('icon-container', {
|
|
182
|
+
mobile: true
|
|
183
|
+
}, [classes.icon])
|
|
184
|
+
}, defaultSnackbar.mobileIcon), /*#__PURE__*/React.createElement("div", {
|
|
185
|
+
className: cn('icon-container', {
|
|
186
|
+
desktop: true
|
|
187
|
+
}, [classes.icon])
|
|
188
|
+
}, defaultSnackbar.desktopIcon));
|
|
189
|
+
}, [isCustomIcon, icon, defaultSnackbar, classes]);
|
|
190
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
191
|
+
className: cn({
|
|
192
|
+
move: isTransitionMoveStep
|
|
193
|
+
}, [className, classes.root]),
|
|
194
|
+
ref: containerRef,
|
|
195
|
+
style: {
|
|
196
|
+
transform: transform
|
|
197
|
+
}
|
|
198
|
+
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), /*#__PURE__*/React.createElement(Tile, {
|
|
199
|
+
className: cn('tile', {
|
|
200
|
+
type: type,
|
|
201
|
+
closed: !isOpened
|
|
202
|
+
}, [classes.container]),
|
|
203
|
+
radius: "rounded"
|
|
204
|
+
}, !isHiddenIcon && renderedIcons, renderedTimer, /*#__PURE__*/React.createElement(Caption, {
|
|
205
|
+
className: cn('text', {
|
|
206
|
+
mobile: true
|
|
207
|
+
}, [classes.text]),
|
|
208
|
+
variant: "medium",
|
|
209
|
+
color: "white",
|
|
210
|
+
hasMargin: false,
|
|
211
|
+
dataAttrs: {
|
|
212
|
+
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.text
|
|
213
|
+
}
|
|
214
|
+
}, text), /*#__PURE__*/React.createElement(Header, {
|
|
215
|
+
as: "h5",
|
|
216
|
+
color: "white",
|
|
217
|
+
className: cn('text', {
|
|
218
|
+
desktop: true,
|
|
219
|
+
"short": !!hasTextButton
|
|
220
|
+
}, [classes.text]),
|
|
221
|
+
dataAttrs: {
|
|
222
|
+
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.text
|
|
223
|
+
}
|
|
224
|
+
}, text), hasTextButton && /*#__PURE__*/React.createElement(Button, {
|
|
225
|
+
type: "text",
|
|
226
|
+
sizeAll: "small",
|
|
227
|
+
sizeMobile: "extra-small",
|
|
228
|
+
className: cn('text-button'),
|
|
229
|
+
dataAttrs: {
|
|
230
|
+
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.textButton
|
|
231
|
+
},
|
|
232
|
+
onClick: handleTextButtonClick
|
|
233
|
+
}, currentButtonText), /*#__PURE__*/React.createElement("button", _extends({
|
|
234
|
+
type: "button",
|
|
235
|
+
className: cn('close-button')
|
|
236
|
+
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.closeButton), {
|
|
237
|
+
onClick: handleClose
|
|
238
|
+
}), /*#__PURE__*/React.createElement(CancelIcon, {
|
|
239
|
+
className: cn('close-button-icon')
|
|
240
|
+
}))));
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
Snackbar.propTypes = {
|
|
244
|
+
text: PropTypes.string.isRequired,
|
|
245
|
+
type: PropTypes.oneOf(Object.values(SnackbarTypes)),
|
|
246
|
+
icon: PropTypes.element,
|
|
247
|
+
hasIcon: PropTypes.bool,
|
|
248
|
+
buttonText: PropTypes.string,
|
|
249
|
+
hasTextButton: PropTypes.bool,
|
|
250
|
+
maxTimerValue: PropTypes.number,
|
|
251
|
+
disableCloseAnimation: PropTypes.bool,
|
|
252
|
+
className: PropTypes.string,
|
|
253
|
+
classes: PropTypes.objectOf(PropTypes.string),
|
|
254
|
+
dataAttrs: PropTypes.objectOf(PropTypes.object),
|
|
255
|
+
onButtonClick: PropTypes.func,
|
|
256
|
+
onClose: PropTypes.func
|
|
257
|
+
};
|
|
258
|
+
export default Snackbar;
|
|
@@ -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,79 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import "core-js/modules/web.timers.js";
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
import { cnCreate } from '@megafon/ui-helpers';
|
|
5
|
+
import Caption from "../../Caption/Caption";
|
|
6
|
+
import "./SnackbarTimer.css";
|
|
7
|
+
var TIMER_END_DELAY_MS = 100;
|
|
8
|
+
var MS_IN_SECOND = 1000;
|
|
9
|
+
var cn = cnCreate('mfui-snackbar-timer');
|
|
10
|
+
|
|
11
|
+
var SnackbarTimer = function SnackbarTimer(_ref) {
|
|
12
|
+
var isTimerType = _ref.isTimerType,
|
|
13
|
+
maxTimerValue = _ref.maxTimerValue,
|
|
14
|
+
onTimerEnd = _ref.onTimerEnd;
|
|
15
|
+
|
|
16
|
+
var _useState = useState(null),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
timerValue = _useState2[0],
|
|
19
|
+
setTimerValue = _useState2[1];
|
|
20
|
+
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
setTimerValue(maxTimerValue);
|
|
23
|
+
}, [maxTimerValue]);
|
|
24
|
+
useEffect(function () {
|
|
25
|
+
var timerTimeoutId;
|
|
26
|
+
var closeTimeoutId;
|
|
27
|
+
|
|
28
|
+
switch (timerValue) {
|
|
29
|
+
case null:
|
|
30
|
+
{
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
case 0:
|
|
35
|
+
{
|
|
36
|
+
closeTimeoutId = setTimeout(function () {
|
|
37
|
+
setTimerValue(null);
|
|
38
|
+
onTimerEnd();
|
|
39
|
+
}, TIMER_END_DELAY_MS);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
default:
|
|
44
|
+
{
|
|
45
|
+
timerTimeoutId = setTimeout(function () {
|
|
46
|
+
return setTimerValue(timerValue - 1);
|
|
47
|
+
}, MS_IN_SECOND);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return function () {
|
|
52
|
+
clearTimeout(timerTimeoutId);
|
|
53
|
+
clearTimeout(closeTimeoutId);
|
|
54
|
+
};
|
|
55
|
+
}, [timerValue, onTimerEnd]);
|
|
56
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
57
|
+
className: cn()
|
|
58
|
+
}, isTimerType && /*#__PURE__*/React.createElement(Caption, {
|
|
59
|
+
color: "white",
|
|
60
|
+
variant: "medium",
|
|
61
|
+
hasMargin: false,
|
|
62
|
+
className: cn('timer')
|
|
63
|
+
}, /*#__PURE__*/React.createElement("svg", null, /*#__PURE__*/React.createElement("circle", {
|
|
64
|
+
className: cn('timer-bg'),
|
|
65
|
+
cx: "50%",
|
|
66
|
+
cy: "50%",
|
|
67
|
+
r: "11"
|
|
68
|
+
}), /*#__PURE__*/React.createElement("circle", {
|
|
69
|
+
className: cn('timer-progress'),
|
|
70
|
+
style: {
|
|
71
|
+
animationDuration: "".concat(maxTimerValue * 1.5, "s")
|
|
72
|
+
},
|
|
73
|
+
cx: "50%",
|
|
74
|
+
cy: "50%",
|
|
75
|
+
r: "11"
|
|
76
|
+
})), timerValue));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default SnackbarTimer;
|