@megafon/ui-core 2.0.0 → 2.1.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 CHANGED
@@ -3,6 +3,26 @@
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
+ # [2.1.0](https://github.com/MegafonWebLab/megafon-ui/compare/@megafon/ui-core@2.0.0...@megafon/ui-core@2.1.0) (2021-12-07)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **button:** fix rendering difference on client and server side ([323287e](https://github.com/MegafonWebLab/megafon-ui/commit/323287ea040716b9200bbaa5112f277427015598))
12
+ * **contentarea:** fix prop type ([3e4114d](https://github.com/MegafonWebLab/megafon-ui/commit/3e4114dbd2d8a446a1247528fbf5464706bb4d4a))
13
+ * **textfield:** fix rendering difference on client and server side ([4d26cac](https://github.com/MegafonWebLab/megafon-ui/commit/4d26cac90002692d7c404f9180310261e9a0e567))
14
+
15
+
16
+ ### Features
17
+
18
+ * **tabs:** add renderOnlyCurrentPanel props ([0241f6c](https://github.com/MegafonWebLab/megafon-ui/commit/0241f6c9ed4ebb5132b38204612bcff095302822))
19
+ * **ui-core:** fix mixin ([8e0f401](https://github.com/MegafonWebLab/megafon-ui/commit/8e0f401973d758821ee32ca2af1a714f3bca8b01))
20
+ * **ui-core:** fix some mixins and variables ([be0462e](https://github.com/MegafonWebLab/megafon-ui/commit/be0462ed3bdcbc1e72d83b749723cf7b896f0846))
21
+
22
+
23
+
24
+
25
+
6
26
  # [2.0.0](https://github.com/MegafonWebLab/megafon-ui/compare/@megafon/ui-core@2.0.0-beta.169...@megafon/ui-core@2.0.0) (2021-11-30)
7
27
 
8
28
 
@@ -2,6 +2,7 @@ import "core-js/modules/es.array.concat";
2
2
  import "core-js/modules/es.array.is-array";
3
3
  import "core-js/modules/es.object.values";
4
4
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
6
  import _extends from "@babel/runtime/helpers/extends";
6
7
  import React from 'react';
7
8
  import { cnCreate, detectTouch, filterDataAttrs } from '@megafon/ui-helpers';
@@ -82,9 +83,12 @@ var Button = function Button(_ref) {
82
83
  onClick = _ref.onClick,
83
84
  dataAttrs = _ref.dataAttrs,
84
85
  buttonRef = _ref.buttonRef;
85
- var isTouch = React.useMemo(function () {
86
- return detectTouch();
87
- }, []);
86
+
87
+ var _React$useState = React.useState(false),
88
+ _React$useState2 = _slicedToArray(_React$useState, 2),
89
+ isTouch = _React$useState2[0],
90
+ setTouch = _React$useState2[1];
91
+
88
92
  var ElementType = href ? 'a' : 'button';
89
93
  var handleClick = React.useCallback(function (e) {
90
94
  if (disabled) {
@@ -167,6 +171,9 @@ var Button = function Button(_ref) {
167
171
  };
168
172
 
169
173
  var classNameValue = Array.isArray(className) ? [].concat(_toConsumableArray(className), [rootClassName]) : [className, rootClassName];
174
+ React.useEffect(function () {
175
+ setTouch(detectTouch());
176
+ }, []);
170
177
  return /*#__PURE__*/React.createElement(ElementType, _extends({}, filterDataAttrs(dataAttrs), {
171
178
  className: cn({
172
179
  type: type,
@@ -183,7 +190,7 @@ var Button = function Button(_ref) {
183
190
  'content-type': contentType
184
191
  }, classNameValue),
185
192
  href: href,
186
- download: href && download,
193
+ download: !!href && download,
187
194
  target: href ? target : undefined,
188
195
  rel: setRelAttribute(),
189
196
  type: href ? undefined : actionType,
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
2
  import './ContentArea.less';
3
3
  declare const BACKGROUND_COLORS: {
4
- WHITE: string;
5
- TRANSPARENT: string;
6
- GREEN: string;
7
- PURPLE: string;
8
- SPB_SKY_0: string;
9
- SPB_SKY_1: string;
10
- SPB_SKY_2: string;
11
- FRESH_ASPHALT: string;
12
- FULL_BLACK: string;
4
+ readonly WHITE: "white";
5
+ readonly TRANSPARENT: "transparent";
6
+ readonly GREEN: "green";
7
+ readonly PURPLE: "purple";
8
+ readonly SPB_SKY_0: "spbSky0";
9
+ readonly SPB_SKY_1: "spbSky1";
10
+ readonly SPB_SKY_2: "spbSky2";
11
+ readonly FRESH_ASPHALT: "freshAsphalt";
12
+ readonly FULL_BLACK: "fullBlack";
13
13
  };
14
14
  export declare type BackgroundColorType = typeof BACKGROUND_COLORS[keyof typeof BACKGROUND_COLORS];
15
15
  declare const DisableIndents: {
@@ -7,6 +7,8 @@ export interface ITabProps extends IFilterDataAttrs {
7
7
  icon?: React.ReactNode;
8
8
  /** Ссылка */
9
9
  href?: string;
10
+ /** Дочерние элементы */
11
+ children?: React.ReactNode;
10
12
  /** Функция рендера компонента-обертки для заголовка и иконки */
11
13
  renderTabWrapper?: (tab: React.ReactNode) => React.ReactNode;
12
14
  }
@@ -39,6 +39,8 @@ export interface ITabsProps {
39
39
  currentIndex?: number;
40
40
  /** Индекс активного таба по умолчанию (не работает в режиме управления табами снаружи) */
41
41
  defaultIndex?: number;
42
+ /** Рендер содержимого только для текущего таба */
43
+ renderOnlyCurrentPanel?: boolean;
42
44
  /** Обработчика клика по табам */
43
45
  onTabClick?: (index: number) => void;
44
46
  children: Array<React.ReactElement<ITabProps>>;
@@ -64,6 +64,8 @@ var Tabs = function Tabs(_ref) {
64
64
  _ref$defaultIndex = _ref.defaultIndex,
65
65
  defaultIndex = _ref$defaultIndex === void 0 ? 0 : _ref$defaultIndex,
66
66
  outerIndex = _ref.currentIndex,
67
+ _ref$renderOnlyCurren = _ref.renderOnlyCurrentPanel,
68
+ renderOnlyCurrentPanel = _ref$renderOnlyCurren === void 0 ? false : _ref$renderOnlyCurren,
67
69
  children = _ref.children,
68
70
  onTabClick = _ref.onTabClick;
69
71
  var tabsRef = React.useRef([]);
@@ -219,11 +221,18 @@ var Tabs = function Tabs(_ref) {
219
221
  }, [renderTab, children]);
220
222
  var renderPanels = React.useCallback(function () {
221
223
  return React.Children.map(children, function (child, i) {
224
+ var panel = child.props.children;
225
+ var isCurrentPanel = currentIndex === i;
226
+
227
+ if (!panel || renderOnlyCurrentPanel && !isCurrentPanel) {
228
+ return null;
229
+ }
230
+
222
231
  return /*#__PURE__*/React.createElement("div", {
223
232
  className: cn('panel', {
224
- current: currentIndex === i
233
+ current: isCurrentPanel
225
234
  })
226
- }, child);
235
+ }, panel);
227
236
  });
228
237
  }, [children, currentIndex]);
229
238
  var handleReachBeginning = React.useCallback(function (swiper) {
@@ -371,6 +380,7 @@ Tabs.propTypes = {
371
380
  sticky: PropTypes.bool,
372
381
  currentIndex: PropTypes.number,
373
382
  defaultIndex: PropTypes.number,
383
+ renderOnlyCurrentPanel: PropTypes.bool,
374
384
  onTabClick: PropTypes.func
375
385
  };
376
386
  export default Tabs;
@@ -125,6 +125,11 @@ var TextField = function TextField(_ref) {
125
125
  isMaxLimitExceeded = _useState10[0],
126
126
  setIsMaxLimitExceeded = _useState10[1];
127
127
 
128
+ var _useState11 = useState(false),
129
+ _useState12 = _slicedToArray(_useState11, 2),
130
+ isTouch = _useState12[0],
131
+ setTouch = _useState12[1];
132
+
128
133
  var fieldNode = useRef();
129
134
  var isPasswordType = useMemo(function () {
130
135
  return type === 'password';
@@ -132,9 +137,6 @@ var TextField = function TextField(_ref) {
132
137
  var isVisiblePassword = useMemo(function () {
133
138
  return isPasswordType && !isPasswordHidden;
134
139
  }, [isPasswordHidden, isPasswordType]);
135
- var isTouch = useMemo(function () {
136
- return detectTouch();
137
- }, []);
138
140
  var checkSymbolMaxLimit = useCallback(function () {
139
141
  var textareaValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
140
142
 
@@ -148,6 +150,9 @@ var TextField = function TextField(_ref) {
148
150
  !isControlled && setInputValue(value);
149
151
  checkSymbolMaxLimit(value);
150
152
  }, [value, checkSymbolMaxLimit]);
153
+ useEffect(function () {
154
+ setTouch(detectTouch());
155
+ }, []);
151
156
  var togglePasswordHiding = useCallback(function () {
152
157
  return setPasswordHidden(function (prevPassState) {
153
158
  return !prevPassState;
@@ -15,6 +15,8 @@ require("core-js/modules/es.object.values");
15
15
 
16
16
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
17
17
 
18
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
19
+
18
20
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
19
21
 
20
22
  var _react = _interopRequireDefault(require("react"));
@@ -108,9 +110,10 @@ var Button = function Button(_ref) {
108
110
  dataAttrs = _ref.dataAttrs,
109
111
  buttonRef = _ref.buttonRef;
110
112
 
111
- var isTouch = _react["default"].useMemo(function () {
112
- return (0, _uiHelpers.detectTouch)();
113
- }, []);
113
+ var _React$useState = _react["default"].useState(false),
114
+ _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
115
+ isTouch = _React$useState2[0],
116
+ setTouch = _React$useState2[1];
114
117
 
115
118
  var ElementType = href ? 'a' : 'button';
116
119
 
@@ -201,6 +204,11 @@ var Button = function Button(_ref) {
201
204
  };
202
205
 
203
206
  var classNameValue = Array.isArray(className) ? [].concat((0, _toConsumableArray2["default"])(className), [rootClassName]) : [className, rootClassName];
207
+
208
+ _react["default"].useEffect(function () {
209
+ setTouch((0, _uiHelpers.detectTouch)());
210
+ }, []);
211
+
204
212
  return /*#__PURE__*/_react["default"].createElement(ElementType, (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs), {
205
213
  className: cn({
206
214
  type: type,
@@ -217,7 +225,7 @@ var Button = function Button(_ref) {
217
225
  'content-type': contentType
218
226
  }, classNameValue),
219
227
  href: href,
220
- download: href && download,
228
+ download: !!href && download,
221
229
  target: href ? target : undefined,
222
230
  rel: setRelAttribute(),
223
231
  type: href ? undefined : actionType,
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
2
  import './ContentArea.less';
3
3
  declare const BACKGROUND_COLORS: {
4
- WHITE: string;
5
- TRANSPARENT: string;
6
- GREEN: string;
7
- PURPLE: string;
8
- SPB_SKY_0: string;
9
- SPB_SKY_1: string;
10
- SPB_SKY_2: string;
11
- FRESH_ASPHALT: string;
12
- FULL_BLACK: string;
4
+ readonly WHITE: "white";
5
+ readonly TRANSPARENT: "transparent";
6
+ readonly GREEN: "green";
7
+ readonly PURPLE: "purple";
8
+ readonly SPB_SKY_0: "spbSky0";
9
+ readonly SPB_SKY_1: "spbSky1";
10
+ readonly SPB_SKY_2: "spbSky2";
11
+ readonly FRESH_ASPHALT: "freshAsphalt";
12
+ readonly FULL_BLACK: "fullBlack";
13
13
  };
14
14
  export declare type BackgroundColorType = typeof BACKGROUND_COLORS[keyof typeof BACKGROUND_COLORS];
15
15
  declare const DisableIndents: {
@@ -7,6 +7,8 @@ export interface ITabProps extends IFilterDataAttrs {
7
7
  icon?: React.ReactNode;
8
8
  /** Ссылка */
9
9
  href?: string;
10
+ /** Дочерние элементы */
11
+ children?: React.ReactNode;
10
12
  /** Функция рендера компонента-обертки для заголовка и иконки */
11
13
  renderTabWrapper?: (tab: React.ReactNode) => React.ReactNode;
12
14
  }
@@ -39,6 +39,8 @@ export interface ITabsProps {
39
39
  currentIndex?: number;
40
40
  /** Индекс активного таба по умолчанию (не работает в режиме управления табами снаружи) */
41
41
  defaultIndex?: number;
42
+ /** Рендер содержимого только для текущего таба */
43
+ renderOnlyCurrentPanel?: boolean;
42
44
  /** Обработчика клика по табам */
43
45
  onTabClick?: (index: number) => void;
44
46
  children: Array<React.ReactElement<ITabProps>>;
@@ -94,6 +94,8 @@ var Tabs = function Tabs(_ref) {
94
94
  _ref$defaultIndex = _ref.defaultIndex,
95
95
  defaultIndex = _ref$defaultIndex === void 0 ? 0 : _ref$defaultIndex,
96
96
  outerIndex = _ref.currentIndex,
97
+ _ref$renderOnlyCurren = _ref.renderOnlyCurrentPanel,
98
+ renderOnlyCurrentPanel = _ref$renderOnlyCurren === void 0 ? false : _ref$renderOnlyCurren,
97
99
  children = _ref.children,
98
100
  onTabClick = _ref.onTabClick;
99
101
  var tabsRef = React.useRef([]);
@@ -248,11 +250,18 @@ var Tabs = function Tabs(_ref) {
248
250
  }, [renderTab, children]);
249
251
  var renderPanels = React.useCallback(function () {
250
252
  return React.Children.map(children, function (child, i) {
253
+ var panel = child.props.children;
254
+ var isCurrentPanel = currentIndex === i;
255
+
256
+ if (!panel || renderOnlyCurrentPanel && !isCurrentPanel) {
257
+ return null;
258
+ }
259
+
251
260
  return /*#__PURE__*/React.createElement("div", {
252
261
  className: cn('panel', {
253
- current: currentIndex === i
262
+ current: isCurrentPanel
254
263
  })
255
- }, child);
264
+ }, panel);
256
265
  });
257
266
  }, [children, currentIndex]);
258
267
  var handleReachBeginning = React.useCallback(function (swiper) {
@@ -400,6 +409,7 @@ Tabs.propTypes = {
400
409
  sticky: _propTypes["default"].bool,
401
410
  currentIndex: _propTypes["default"].number,
402
411
  defaultIndex: _propTypes["default"].number,
412
+ renderOnlyCurrentPanel: _propTypes["default"].bool,
403
413
  onTabClick: _propTypes["default"].func
404
414
  };
405
415
  var _default = Tabs;
@@ -150,6 +150,11 @@ var TextField = function TextField(_ref) {
150
150
  isMaxLimitExceeded = _useState10[0],
151
151
  setIsMaxLimitExceeded = _useState10[1];
152
152
 
153
+ var _useState11 = (0, React.useState)(false),
154
+ _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
155
+ isTouch = _useState12[0],
156
+ setTouch = _useState12[1];
157
+
153
158
  var fieldNode = (0, React.useRef)();
154
159
  var isPasswordType = (0, React.useMemo)(function () {
155
160
  return type === 'password';
@@ -157,9 +162,6 @@ var TextField = function TextField(_ref) {
157
162
  var isVisiblePassword = (0, React.useMemo)(function () {
158
163
  return isPasswordType && !isPasswordHidden;
159
164
  }, [isPasswordHidden, isPasswordType]);
160
- var isTouch = (0, React.useMemo)(function () {
161
- return (0, _uiHelpers.detectTouch)();
162
- }, []);
163
165
  var checkSymbolMaxLimit = (0, React.useCallback)(function () {
164
166
  var textareaValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
165
167
 
@@ -173,6 +175,9 @@ var TextField = function TextField(_ref) {
173
175
  !isControlled && setInputValue(value);
174
176
  checkSymbolMaxLimit(value);
175
177
  }, [value, checkSymbolMaxLimit]);
178
+ (0, React.useEffect)(function () {
179
+ setTouch((0, _uiHelpers.detectTouch)());
180
+ }, []);
176
181
  var togglePasswordHiding = (0, React.useCallback)(function () {
177
182
  return setPasswordHidden(function (prevPassState) {
178
183
  return !prevPassState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megafon/ui-core",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "styles"
@@ -95,5 +95,5 @@
95
95
  "react-popper": "^2.2.3",
96
96
  "swiper": "^6.5.6"
97
97
  },
98
- "gitHead": "7f552b59c6bfc912d14a39c4564995685c18d4f5"
98
+ "gitHead": "42bd6840a217196ba9e80c6c77f92f5951881c12"
99
99
  }
package/styles/base.less CHANGED
@@ -1,5 +1,3 @@
1
- @class-prefix: 'mfui';
2
-
3
1
  // Basic Colors
4
2
  @green: #00B956;
5
3
  @purple: #731982;
@@ -107,6 +105,20 @@
107
105
  font-family: Graphik, Arial, sans-serif;
108
106
  }
109
107
 
108
+ .fontFamily() {
109
+ font-family: inherit;
110
+ }
111
+
112
+ .commonFont() {
113
+ font-size: 15px;
114
+ line-height: 24px;
115
+ }
116
+
117
+ .smallFont() {
118
+ font-size: 12px;
119
+ line-height: 16px;
120
+ }
121
+
110
122
  h1,
111
123
  h2,
112
124
  h3,
@@ -115,6 +127,26 @@ h5 {
115
127
  margin: 0;
116
128
  }
117
129
 
130
+ .h1() {
131
+ font-weight: 600;
132
+ font-size: 36px;
133
+ line-height: 30px;
134
+ letter-spacing: 0.5px;
135
+
136
+ @media @mobileB {
137
+ font-size: 36px;
138
+ line-height: 40px;
139
+ }
140
+ @media @desktop {
141
+ font-size: 44px;
142
+ line-height: 48px;
143
+ }
144
+ @media @desktopMU {
145
+ font-size: 52px;
146
+ line-height: 56px;
147
+ }
148
+ }
149
+
118
150
  .h2() {
119
151
  font-weight: 600;
120
152
  font-size: 22px;
@@ -157,7 +189,7 @@ h5 {
157
189
  font-weight: 400;
158
190
  }
159
191
 
160
- .p-indents() {
192
+ .pIndents() {
161
193
  margin-top: 0;
162
194
  margin-bottom: 16px;
163
195
 
@@ -166,7 +198,7 @@ h5 {
166
198
  }
167
199
  }
168
200
 
169
- .default-link() {
201
+ .link() {
170
202
  color: @link;
171
203
  text-decoration: none;
172
204
 
@@ -174,17 +206,3 @@ h5 {
174
206
  text-decoration: underline;
175
207
  }
176
208
  }
177
-
178
- .fontFamily() {
179
- font-family: inherit;
180
- }
181
-
182
- .commonFont() {
183
- font-size: 15px;
184
- line-height: 24px;
185
- }
186
-
187
- .smallFont() {
188
- font-size: 12px;
189
- line-height: 16px;
190
- }