@megafon/ui-core 3.3.0 → 3.5.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/es/components/Badges/components/PriceBadge/PriceBadge.css +13 -5
  3. package/dist/es/components/Badges/components/PriceBadge/PriceBadge.js +4 -2
  4. package/dist/es/components/Badges/components/PromoBadge/PromoBadge.css +4 -1
  5. package/dist/es/components/Badges/components/PromoBadge/PromoBadge.d.ts +1 -0
  6. package/dist/es/components/Badges/components/PromoBadge/PromoBadge.js +1 -0
  7. package/dist/es/components/Badges/components/TimerBadge/Timer/Timer.d.ts +13 -0
  8. package/dist/es/components/Badges/components/TimerBadge/Timer/Timer.js +96 -0
  9. package/dist/es/components/Badges/components/TimerBadge/TimerBadge.css +60 -0
  10. package/dist/es/components/Badges/components/TimerBadge/TimerBadge.d.ts +24 -0
  11. package/dist/es/components/Badges/components/TimerBadge/TimerBadge.js +110 -0
  12. package/dist/es/components/Button/Button.d.ts +1 -1
  13. package/dist/es/components/Checkbox/Checkbox.d.ts +1 -1
  14. package/dist/es/components/Collapse/Collapse.js +1 -0
  15. package/dist/es/components/Counter/Counter.d.ts +1 -1
  16. package/dist/es/components/Logo/Logo.css +5 -0
  17. package/dist/es/components/Notification/Notification.css +15 -21
  18. package/dist/es/components/RadioButton/RadioButton.d.ts +1 -1
  19. package/dist/es/components/Search/Search.d.ts +3 -1
  20. package/dist/es/components/Search/Search.js +7 -4
  21. package/dist/es/components/Select/Select.d.ts +1 -1
  22. package/dist/es/components/Switcher/Switcher.css +101 -28
  23. package/dist/es/components/Switcher/Switcher.d.ts +9 -2
  24. package/dist/es/components/Switcher/Switcher.js +39 -10
  25. package/dist/es/components/TextField/TextField.d.ts +1 -1
  26. package/dist/es/index.d.ts +2 -0
  27. package/dist/es/index.js +2 -0
  28. package/dist/lib/components/Badges/components/PriceBadge/PriceBadge.css +13 -5
  29. package/dist/lib/components/Badges/components/PriceBadge/PriceBadge.js +4 -2
  30. package/dist/lib/components/Badges/components/PromoBadge/PromoBadge.css +4 -1
  31. package/dist/lib/components/Badges/components/PromoBadge/PromoBadge.d.ts +1 -0
  32. package/dist/lib/components/Badges/components/PromoBadge/PromoBadge.js +1 -0
  33. package/dist/lib/components/Badges/components/TimerBadge/Timer/Timer.d.ts +13 -0
  34. package/dist/lib/components/Badges/components/TimerBadge/Timer/Timer.js +123 -0
  35. package/dist/lib/components/Badges/components/TimerBadge/TimerBadge.css +60 -0
  36. package/dist/lib/components/Badges/components/TimerBadge/TimerBadge.d.ts +24 -0
  37. package/dist/lib/components/Badges/components/TimerBadge/TimerBadge.js +133 -0
  38. package/dist/lib/components/Button/Button.d.ts +1 -1
  39. package/dist/lib/components/Checkbox/Checkbox.d.ts +1 -1
  40. package/dist/lib/components/Collapse/Collapse.js +1 -0
  41. package/dist/lib/components/Counter/Counter.d.ts +1 -1
  42. package/dist/lib/components/Logo/Logo.css +5 -0
  43. package/dist/lib/components/Notification/Notification.css +15 -21
  44. package/dist/lib/components/RadioButton/RadioButton.d.ts +1 -1
  45. package/dist/lib/components/Search/Search.d.ts +3 -1
  46. package/dist/lib/components/Search/Search.js +7 -4
  47. package/dist/lib/components/Select/Select.d.ts +1 -1
  48. package/dist/lib/components/Switcher/Switcher.css +101 -28
  49. package/dist/lib/components/Switcher/Switcher.d.ts +9 -2
  50. package/dist/lib/components/Switcher/Switcher.js +38 -9
  51. package/dist/lib/components/TextField/TextField.d.ts +1 -1
  52. package/dist/lib/index.d.ts +2 -0
  53. package/dist/lib/index.js +16 -0
  54. package/package.json +4 -4
@@ -1,48 +1,121 @@
1
1
  .mfui-switcher {
2
- top: 22px;
3
- right: 28px;
4
- width: 48px;
5
- height: 28px;
6
- border: 1px solid var(--stcBlack20);
7
- border-radius: 15.5px;
8
- background-color: var(--base);
9
- cursor: pointer;
10
- -webkit-transition: all 0.3s;
11
- transition: all 0.3s;
2
+ display: -webkit-box;
3
+ display: -ms-flexbox;
4
+ display: flex;
5
+ }
6
+ .mfui-switcher__content {
7
+ font-size: 15px;
8
+ line-height: 24px;
9
+ font-weight: 400;
10
+ -ms-flex-item-align: center;
11
+ align-self: center;
12
+ margin-left: 12px;
13
+ }
14
+ .mfui-switcher__content_size_small {
15
+ font-size: 12px;
16
+ line-height: 16px;
17
+ }
18
+ .mfui-switcher__content_left {
19
+ margin-right: 12px;
20
+ margin-left: 0;
21
+ }
22
+ .mfui-switcher__content_left + .mfui-switcher__input {
23
+ margin-left: auto;
12
24
  }
13
25
  .mfui-switcher__pointer {
14
26
  position: relative;
15
- top: 1px;
16
- left: 1px;
27
+ top: 2px;
28
+ left: 2px;
17
29
  width: 24px;
18
30
  height: 24px;
19
- border: 1px solid var(--stcBlack20);
20
31
  border-radius: 50%;
21
- background-color: var(--base);
22
- -webkit-box-shadow: 0 3px 3px rgba(0, 0, 0, 0.05), 0 3px 1px rgba(0, 0, 0, 0.05);
23
- box-shadow: 0 3px 3px rgba(0, 0, 0, 0.05), 0 3px 1px rgba(0, 0, 0, 0.05);
32
+ background-color: var(--stcWhite);
24
33
  -webkit-transition: all 0.3s;
25
34
  transition: all 0.3s;
26
35
  }
27
- .mfui-switcher_no-touch:hover:not(.mfui-switcher_disabled) {
36
+ .mfui-switcher__loader {
37
+ position: absolute;
38
+ top: 0;
39
+ right: 0;
40
+ bottom: 0;
41
+ left: 0;
42
+ overflow: hidden;
43
+ }
44
+ .mfui-switcher__loader:before {
45
+ content: '';
46
+ position: absolute;
47
+ top: 0;
48
+ bottom: 0;
49
+ left: 0;
50
+ width: 300%;
51
+ height: 100%;
52
+ background: -webkit-gradient(linear, left top, right top, from(var(--spbSky1)), color-stop(16%, var(--spbSky2)), color-stop(33%, var(--spbSky1)), color-stop(50%, var(--spbSky2)), color-stop(66%, var(--spbSky1)), color-stop(82%, var(--spbSky2)), to(var(--spbSky1)));
53
+ background: linear-gradient(90deg, var(--spbSky1) 0%, var(--spbSky2) 16%, var(--spbSky1) 33%, var(--spbSky2) 50%, var(--spbSky1) 66%, var(--spbSky2) 82%, var(--spbSky1) 100%);
54
+ -webkit-animation: shining 0.8s linear infinite;
55
+ animation: shining 0.8s linear infinite;
56
+ }
57
+ @-webkit-keyframes shining {
58
+ 0% {
59
+ -webkit-transform: translateX(-33%);
60
+ transform: translateX(-33%);
61
+ }
62
+ 100% {
63
+ -webkit-transform: translateX(0);
64
+ transform: translateX(0);
65
+ }
66
+ }
67
+ @keyframes shining {
68
+ 0% {
69
+ -webkit-transform: translateX(-33%);
70
+ transform: translateX(-33%);
71
+ }
72
+ 100% {
73
+ -webkit-transform: translateX(0);
74
+ transform: translateX(0);
75
+ }
76
+ }
77
+ .mfui-switcher__input {
78
+ position: relative;
79
+ -ms-flex-item-align: start;
80
+ align-self: flex-start;
81
+ width: 48px;
82
+ min-width: 48px;
83
+ height: 28px;
84
+ border-radius: 15.5px;
85
+ overflow: hidden;
86
+ background-color: var(--spbSky1);
87
+ cursor: pointer;
88
+ -webkit-transition: background-color 0.3s;
89
+ transition: background-color 0.3s;
90
+ }
91
+ .mfui-switcher__input_disabled {
28
92
  background-color: var(--spbSky1);
29
93
  }
30
- .mfui-switcher_checked {
94
+ .mfui-switcher__input_disabled,
95
+ .mfui-switcher__input_loaded {
96
+ cursor: default;
97
+ }
98
+ .mfui-switcher__input:hover:not(.mfui-switcher__input_disabled) {
99
+ background-color: var(--spbSky2);
100
+ }
101
+ .mfui-switcher__input_checked:not(.mfui-switcher__input_disabled) {
31
102
  border-color: var(--brandGreen);
32
103
  background-color: var(--brandGreen);
33
104
  }
34
- .mfui-switcher_checked .mfui-switcher__pointer {
35
- left: 21px;
36
- }
37
- .mfui-switcher_checked.mfui-switcher_no-touch:hover {
105
+ .mfui-switcher__input_checked:hover:not(.mfui-switcher__input_disabled) {
38
106
  border-color: var(--buttonHoverGreen);
39
107
  background-color: var(--buttonHoverGreen);
40
108
  }
41
- .mfui-switcher_disabled {
42
- background-color: var(--spbSky1);
43
- cursor: default;
44
- }
45
- .mfui-switcher_disabled.mfui-switcher_checked.mfui-switcher_no-touch {
46
- border-color: var(--spbSky2);
109
+ .mfui-switcher__input_disabled .mfui-switcher__pointer {
47
110
  background-color: var(--spbSky2);
48
111
  }
112
+ .mfui-switcher__input_checked .mfui-switcher__pointer {
113
+ left: 22px;
114
+ }
115
+ .mfui-switcher__input_checked .mfui-switcher__loader:before {
116
+ background: -webkit-gradient(linear, left top, right top, from(var(--brandGreen)), color-stop(16%, var(--buttonHoverGreen)), color-stop(33%, var(--brandGreen)), color-stop(50%, var(--buttonHoverGreen)), color-stop(66%, var(--brandGreen)), color-stop(82%, var(--buttonHoverGreen)), to(var(--brandGreen)));
117
+ background: linear-gradient(90deg, var(--brandGreen) 0%, var(--buttonHoverGreen) 16%, var(--brandGreen) 33%, var(--buttonHoverGreen) 50%, var(--brandGreen) 66%, var(--buttonHoverGreen) 82%, var(--brandGreen) 100%);
118
+ }
119
+ .mfui-switcher_disabled .mfui-switcher__content {
120
+ color: var(--spbSky3);
121
+ }
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { AccessibilityEventType } from '@megafon/ui-helpers';
2
3
  import './Switcher.less';
3
4
  export interface ISwitcherProps {
4
5
  /** Дополнительные data атрибуты к внутренним элементам */
@@ -9,10 +10,16 @@ export interface ISwitcherProps {
9
10
  className?: string;
10
11
  /** Управление состоянием вкл/выкл компонента */
11
12
  checked?: boolean;
12
- /** Управление возможностью взаимодействия с компонентом */
13
+ /** Отключение переключателя */
13
14
  disabled?: boolean;
15
+ /** Cостояние загрузки */
16
+ showLoader?: boolean;
17
+ /** Размер текста лейбла */
18
+ textSize?: 'small' | 'medium';
19
+ /** Позиция лейбла относительно свитчера */
20
+ textPosition?: 'left' | 'right';
14
21
  /** Обработчик изменения элемента */
15
- onChange?: (e: React.MouseEvent<HTMLDivElement>) => void;
22
+ onChange?: (e: AccessibilityEventType) => void;
16
23
  }
17
24
  declare const Switcher: React.FC<ISwitcherProps>;
18
25
  export default Switcher;
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import * as React from 'react';
3
- import { cnCreate, detectTouch, filterDataAttrs } from '@megafon/ui-helpers';
3
+ import { checkEventIsClickOrEnterPress, cnCreate, detectTouch, filterDataAttrs } from '@megafon/ui-helpers';
4
4
  import * as PropTypes from 'prop-types';
5
5
  import "./Switcher.css";
6
6
  var cn = cnCreate('mfui-switcher');
@@ -12,27 +12,53 @@ var Switcher = function Switcher(_ref) {
12
12
  checked = _ref$checked === void 0 ? false : _ref$checked,
13
13
  _ref$disabled = _ref.disabled,
14
14
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
15
+ _ref$showLoader = _ref.showLoader,
16
+ showLoader = _ref$showLoader === void 0 ? false : _ref$showLoader,
17
+ children = _ref.children,
18
+ _ref$textSize = _ref.textSize,
19
+ textSize = _ref$textSize === void 0 ? 'medium' : _ref$textSize,
20
+ _ref$textPosition = _ref.textPosition,
21
+ textPosition = _ref$textPosition === void 0 ? 'right' : _ref$textPosition,
15
22
  onChange = _ref.onChange;
16
23
  var isTouch = detectTouch();
17
-
18
- var handleChange = function handleChange(e) {
19
- if (disabled) {
24
+ var isLeftContent = !!children && textPosition === 'left';
25
+ var isRightContent = !!children && textPosition === 'right';
26
+ var isInteractiveDisabled = showLoader || disabled;
27
+ var handleChange = React.useCallback(function (e) {
28
+ if (isInteractiveDisabled || !checkEventIsClickOrEnterPress(e)) {
20
29
  return;
21
30
  }
22
31
 
23
32
  onChange === null || onChange === void 0 ? void 0 : onChange(e);
24
- };
25
-
26
- return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
33
+ }, [isInteractiveDisabled, onChange]);
34
+ return /*#__PURE__*/React.createElement("div", _extends({
27
35
  className: cn({
36
+ disabled: disabled
37
+ }, className)
38
+ }, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), isLeftContent && /*#__PURE__*/React.createElement("div", {
39
+ className: cn('content', {
40
+ size: textSize,
41
+ left: true
42
+ })
43
+ }, children), /*#__PURE__*/React.createElement("div", {
44
+ className: cn('input', {
28
45
  checked: checked,
29
46
  disabled: disabled,
47
+ loaded: showLoader,
30
48
  'no-touch': !isTouch
31
- }, className),
32
- onClick: handleChange
49
+ }),
50
+ onClick: handleChange,
51
+ onKeyDown: handleChange,
52
+ tabIndex: isInteractiveDisabled ? undefined : 0
53
+ }, showLoader && !disabled && /*#__PURE__*/React.createElement("div", {
54
+ className: cn('loader')
33
55
  }), /*#__PURE__*/React.createElement("div", {
34
56
  className: cn('pointer')
35
- }));
57
+ })), isRightContent && /*#__PURE__*/React.createElement("div", {
58
+ className: cn('content', {
59
+ size: textSize
60
+ })
61
+ }, children));
36
62
  };
37
63
 
38
64
  Switcher.propTypes = {
@@ -40,8 +66,11 @@ Switcher.propTypes = {
40
66
  root: PropTypes.objectOf(PropTypes.string.isRequired)
41
67
  }),
42
68
  className: PropTypes.string,
69
+ textSize: PropTypes.oneOf(['small', 'medium']),
70
+ textPosition: PropTypes.oneOf(['left', 'right']),
43
71
  checked: PropTypes.bool,
44
72
  disabled: PropTypes.bool,
73
+ showLoader: PropTypes.bool,
45
74
  onChange: PropTypes.func
46
75
  };
47
76
  export default Switcher;
@@ -31,7 +31,7 @@ export declare type TextFieldProps = {
31
31
  verification?: 'valid' | 'error';
32
32
  /** Подпись снизу, меняет цвет в зависимости от аргумента verification */
33
33
  noticeText?: string;
34
- /** Управление возможностью взаимодействия с компонентом */
34
+ /** Отключение поля ввода */
35
35
  disabled?: boolean;
36
36
  /** Показывает обязательность поля */
37
37
  required?: boolean;
@@ -40,5 +40,7 @@ export { default as Tabs } from './components/Tabs/Tabs';
40
40
  export { default as TextField } from './components/TextField/TextField';
41
41
  export { default as TextLink } from './components/TextLink/TextLink';
42
42
  export { default as Tile } from './components/Tile/Tile';
43
+ export { default as Timer } from './components/Badges/components/TimerBadge/Timer/Timer';
44
+ export { default as TimerBadge } from './components/Badges/components/TimerBadge/TimerBadge';
43
45
  export { default as Tooltip } from './components/Tooltip/Tooltip';
44
46
  export { default as usePagination } from './components/Pagination/usePagination';
package/dist/es/index.js CHANGED
@@ -40,5 +40,7 @@ export { default as Tabs } from "./components/Tabs/Tabs";
40
40
  export { default as TextField } from "./components/TextField/TextField";
41
41
  export { default as TextLink } from "./components/TextLink/TextLink";
42
42
  export { default as Tile } from "./components/Tile/Tile";
43
+ export { default as Timer } from "./components/Badges/components/TimerBadge/Timer/Timer";
44
+ export { default as TimerBadge } from "./components/Badges/components/TimerBadge/TimerBadge";
43
45
  export { default as Tooltip } from "./components/Tooltip/Tooltip";
44
46
  export { default as usePagination } from "./components/Pagination/usePagination";
@@ -7,20 +7,23 @@
7
7
  -webkit-box-align: center;
8
8
  -ms-flex-align: center;
9
9
  align-items: center;
10
- padding: 4px;
10
+ padding: 2px;
11
11
  padding-right: 8px;
12
12
  width: -webkit-fit-content;
13
13
  width: -moz-fit-content;
14
14
  width: fit-content;
15
- height: 24px;
15
+ height: -webkit-fit-content;
16
+ height: -moz-fit-content;
17
+ height: fit-content;
16
18
  border-radius: 8px;
17
19
  }
18
20
  @media screen and (min-width: 1024px) {
19
21
  .mfui-price-badge_adaptive {
20
22
  font-size: 15px;
21
23
  line-height: 24px;
22
- padding: 4px 8px;
23
- height: 32px;
24
+ padding: 4px;
25
+ padding-right: 8px;
26
+ min-height: 32px;
24
27
  border-radius: 12px;
25
28
  }
26
29
  }
@@ -62,7 +65,12 @@
62
65
  }
63
66
  .mfui-price-badge__text {
64
67
  font-family: inherit;
65
- margin-left: 4px;
68
+ margin-left: 2px;
69
+ }
70
+ .mfui-price-badge__icon-container {
71
+ display: -webkit-box;
72
+ display: -ms-flexbox;
73
+ display: flex;
66
74
  }
67
75
  .mfui-price-badge__icon {
68
76
  height: 20px;
@@ -113,9 +113,11 @@ var PriceBadge = function PriceBadge(_ref) {
113
113
  theme: theme,
114
114
  adaptive: isAdaptive
115
115
  }, className)
116
- }), /*#__PURE__*/React.createElement(Icon, {
116
+ }), /*#__PURE__*/React.createElement("div", {
117
+ className: cn('icon-container')
118
+ }, /*#__PURE__*/React.createElement(Icon, {
117
119
  className: cn('icon')
118
- }), /*#__PURE__*/React.createElement("span", {
120
+ })), /*#__PURE__*/React.createElement("span", {
119
121
  className: cn('text')
120
122
  }, children));
121
123
  };
@@ -10,7 +10,7 @@
10
10
  width: -moz-fit-content;
11
11
  width: fit-content;
12
12
  border-radius: 8px;
13
- color: var(--base);
13
+ color: var(--stcWhite);
14
14
  }
15
15
  .mfui-promo-badge_type_hit {
16
16
  background-color: var(--warmRedC);
@@ -18,6 +18,9 @@
18
18
  .mfui-promo-badge_type_new {
19
19
  background-color: var(--systemBlue);
20
20
  }
21
+ .mfui-promo-badge_type_vip {
22
+ background-color: var(--brandPurple);
23
+ }
21
24
  .mfui-promo-badge_type_popular {
22
25
  background-color: var(--137C);
23
26
  }
@@ -3,6 +3,7 @@ import './PromoBadge.less';
3
3
  export declare const PromoBadgeTypes: {
4
4
  readonly HIT: "hit";
5
5
  readonly NEW: "new";
6
+ readonly VIP: "vip";
6
7
  readonly POPULAR: "popular";
7
8
  readonly USER_CHOICE: "user-choice";
8
9
  };
@@ -26,6 +26,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
26
26
  var PromoBadgeTypes = {
27
27
  HIT: 'hit',
28
28
  NEW: 'new',
29
+ VIP: 'vip',
29
30
  POPULAR: 'popular',
30
31
  USER_CHOICE: 'user-choice'
31
32
  };
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ export declare const getCountdownText: (remainingTime?: number) => string;
3
+ interface ITimerProps {
4
+ actualRemainingTime: number;
5
+ expirationDate: Date;
6
+ showCountdown: boolean;
7
+ additionalText?: string;
8
+ dataAttrs?: {
9
+ root?: Record<string, string>;
10
+ };
11
+ }
12
+ declare const Timer: React.FC<ITimerProps>;
13
+ export default Timer;
@@ -0,0 +1,123 @@
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.getCountdownText = void 0;
9
+
10
+ require("core-js/modules/es.array.concat");
11
+
12
+ require("core-js/modules/es.date.to-string");
13
+
14
+ require("core-js/modules/es.math.trunc");
15
+
16
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
17
+
18
+ var React = _interopRequireWildcard(require("react"));
19
+
20
+ var _uiHelpers = require("@megafon/ui-helpers");
21
+
22
+ var _format = _interopRequireDefault(require("date-fns/format"));
23
+
24
+ var _ru = _interopRequireDefault(require("date-fns/locale/ru"));
25
+
26
+ var PropTypes = _interopRequireWildcard(require("prop-types"));
27
+
28
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
29
+
30
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
33
+
34
+ var SECONDS_IN_DAY = 86400;
35
+ var SECONDS_IN_HOUR = 3600;
36
+ var SECONDS_IN_MINUTE = 60;
37
+
38
+ var formatDate = function formatDate(date, pattern) {
39
+ return (0, _format["default"])(date, pattern, {
40
+ locale: _ru["default"]
41
+ });
42
+ };
43
+
44
+ var getCountdownText = function getCountdownText() {
45
+ var remainingTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
46
+ var isMoreHourAndLessDay = remainingTime >= SECONDS_IN_HOUR && remainingTime < SECONDS_IN_DAY;
47
+
48
+ var truncTime = function truncTime() {
49
+ var divider = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
50
+ return Math.trunc(remainingTime / divider);
51
+ };
52
+
53
+ switch (true) {
54
+ case remainingTime <= 0:
55
+ {
56
+ return '';
57
+ }
58
+
59
+ case remainingTime < SECONDS_IN_MINUTE:
60
+ {
61
+ var seconds = truncTime();
62
+ return "".concat(seconds, " \u0441\u0435\u043A");
63
+ }
64
+
65
+ case remainingTime < SECONDS_IN_HOUR:
66
+ {
67
+ var minutes = truncTime(SECONDS_IN_MINUTE);
68
+ return "".concat(minutes, " \u043C\u0438\u043D");
69
+ }
70
+
71
+ case isMoreHourAndLessDay:
72
+ {
73
+ var hours = truncTime(SECONDS_IN_HOUR);
74
+ var secondsLeft = remainingTime - hours * SECONDS_IN_HOUR;
75
+
76
+ var _minutes = Math.trunc(secondsLeft / SECONDS_IN_MINUTE);
77
+
78
+ return _minutes ? "".concat(hours, " \u0447 ").concat(_minutes, " \u043C\u0438\u043D") : "".concat(hours, " \u0447");
79
+ }
80
+
81
+ case remainingTime >= SECONDS_IN_DAY:
82
+ {
83
+ var days = truncTime(SECONDS_IN_DAY);
84
+
85
+ var _secondsLeft = remainingTime - days * SECONDS_IN_DAY;
86
+
87
+ var _hours = Math.trunc(_secondsLeft / SECONDS_IN_HOUR);
88
+
89
+ return _hours ? "".concat(days, " \u0434\u043D ").concat(_hours, " \u0447") : "".concat(days, " \u0434\u043D");
90
+ }
91
+
92
+ default:
93
+ {
94
+ return '';
95
+ }
96
+ }
97
+ };
98
+
99
+ exports.getCountdownText = getCountdownText;
100
+ var cn = (0, _uiHelpers.cnCreate)('mfui-timer');
101
+
102
+ var Timer = function Timer(_ref) {
103
+ var actualRemainingTime = _ref.actualRemainingTime,
104
+ expirationDate = _ref.expirationDate,
105
+ showCountdown = _ref.showCountdown,
106
+ additionalText = _ref.additionalText,
107
+ dataAttrs = _ref.dataAttrs;
108
+ return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
109
+ className: cn()
110
+ }, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), additionalText && /*#__PURE__*/React.createElement("span", null, additionalText, " "), /*#__PURE__*/React.createElement("span", null, showCountdown ? getCountdownText(actualRemainingTime) : formatDate(expirationDate, 'dd MMMM yyyy')));
111
+ };
112
+
113
+ Timer.propTypes = {
114
+ expirationDate: PropTypes.instanceOf(Date).isRequired,
115
+ actualRemainingTime: PropTypes.number.isRequired,
116
+ showCountdown: PropTypes.bool.isRequired,
117
+ additionalText: PropTypes.string,
118
+ dataAttrs: PropTypes.shape({
119
+ root: PropTypes.objectOf(PropTypes.string.isRequired)
120
+ })
121
+ };
122
+ var _default = Timer;
123
+ exports["default"] = _default;
@@ -0,0 +1,60 @@
1
+ .mfui-timer-badge {
2
+ display: -webkit-box;
3
+ display: -ms-flexbox;
4
+ display: flex;
5
+ -webkit-box-align: center;
6
+ -ms-flex-align: center;
7
+ align-items: center;
8
+ padding: 1px 2px;
9
+ padding-right: 8px;
10
+ width: -webkit-fit-content;
11
+ width: -moz-fit-content;
12
+ width: fit-content;
13
+ height: -webkit-fit-content;
14
+ height: -moz-fit-content;
15
+ height: fit-content;
16
+ border: 1px solid var(--spbSky1);
17
+ border-radius: 12px;
18
+ background: var(--base);
19
+ overflow: hidden;
20
+ }
21
+ .mfui-timer-badge_theme_grey .mfui-timer-badge__text {
22
+ color: var(--spbSky3);
23
+ }
24
+ .mfui-timer-badge_theme_grey .mfui-timer-badge__icon {
25
+ fill: var(--spbSky3);
26
+ }
27
+ .mfui-timer-badge_theme_red .mfui-timer-badge__text {
28
+ color: var(--fury);
29
+ }
30
+ .mfui-timer-badge_theme_red .mfui-timer-badge__icon {
31
+ fill: var(--fury);
32
+ }
33
+ .mfui-timer-badge__text {
34
+ font-size: 12px;
35
+ line-height: 16px;
36
+ font-family: inherit;
37
+ margin-left: 2px;
38
+ font-weight: 500;
39
+ }
40
+ .mfui-timer-badge__icon {
41
+ height: 20px;
42
+ width: 20px;
43
+ }
44
+ .mfui-timer-badge__icon-container {
45
+ position: relative;
46
+ display: -webkit-box;
47
+ display: -ms-flexbox;
48
+ display: flex;
49
+ }
50
+ .mfui-timer-badge__icon-container_shadow:before {
51
+ content: '';
52
+ position: absolute;
53
+ top: 2px;
54
+ left: 2px;
55
+ height: 16px;
56
+ width: 16px;
57
+ border-radius: 50%;
58
+ -webkit-box-shadow: 0px 0px 6px var(--fury);
59
+ box-shadow: 0px 0px 6px var(--fury);
60
+ }
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import './TimerBadge.less';
3
+ export interface ITimerBadgeProps {
4
+ /** Дата окончания таймера */
5
+ expirationDate: Date;
6
+ /** Граница переключения в режим обратного отсчёта, в секундах */
7
+ countdownStart?: number;
8
+ /** Отображение дополнительного текста */
9
+ hasPrefix?: boolean;
10
+ /** Текст перед таймером в режиме обратного отсчета. Появляется при hasPrefix=true. */
11
+ countdownText?: string;
12
+ /** Текст перед таймером в режиме даты. Появляется при hasPrefix=true. */
13
+ expirationDateText?: string;
14
+ /** Дополнительный класс корневого элемента */
15
+ className?: string;
16
+ /** Дополнительные data-атрибуты к внутренним элементам */
17
+ dataAttrs?: {
18
+ root?: Record<string, string>;
19
+ text?: Record<string, string>;
20
+ timer?: Record<string, string>;
21
+ };
22
+ }
23
+ declare const TimerBadge: React.FC<ITimerBadgeProps>;
24
+ export default TimerBadge;