@megafon/ui-shared 4.21.2 → 5.0.1
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 +35 -0
- package/dist/es/components/Card/Card.css +226 -83
- package/dist/es/components/Card/Card.d.ts +30 -62
- package/dist/es/components/Card/Card.js +237 -157
- package/dist/es/components/Card/types.d.ts +71 -0
- package/dist/es/components/Card/types.js +0 -0
- package/dist/es/components/CardsBox/CardsBox.d.ts +4 -7
- package/dist/es/components/CardsBox/CardsBox.js +21 -67
- package/dist/es/components/CardsBox/helpers.d.ts +10 -0
- package/dist/es/components/CardsBox/helpers.js +25 -0
- package/dist/es/components/CarouselBox/CarouselBox.d.ts +6 -1
- package/dist/es/components/CarouselBox/CarouselBox.js +30 -3
- package/dist/es/components/Property/Property.js +2 -2
- package/dist/es/components/Property/types.d.ts +1 -1
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +1 -0
- package/dist/lib/components/Card/Card.css +226 -83
- package/dist/lib/components/Card/Card.d.ts +30 -62
- package/dist/lib/components/Card/Card.js +233 -160
- package/dist/lib/components/Card/types.d.ts +71 -0
- package/dist/lib/components/Card/types.js +1 -0
- package/dist/lib/components/CardsBox/CardsBox.d.ts +4 -7
- package/dist/lib/components/CardsBox/CardsBox.js +19 -67
- package/dist/lib/components/CardsBox/helpers.d.ts +10 -0
- package/dist/lib/components/CardsBox/helpers.js +35 -0
- package/dist/lib/components/CarouselBox/CarouselBox.d.ts +6 -1
- package/dist/lib/components/CarouselBox/CarouselBox.js +32 -2
- package/dist/lib/components/Property/Property.js +2 -2
- package/dist/lib/components/Property/types.d.ts +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +8 -0
- package/package.json +2 -2
@@ -1,198 +1,278 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import "core-js/modules/es.string.link.js";
|
3
|
-
import "core-js/modules/es.
|
3
|
+
import "core-js/modules/es.array.map.js";
|
4
4
|
import React from 'react';
|
5
|
-
import
|
6
|
-
import {
|
7
|
-
import { cnCreate, filterDataAttrs, convert, titleConvertConfig, textConvertConfig } from '@megafon/ui-helpers';
|
5
|
+
import { Button, Header } from '@megafon/ui-core';
|
6
|
+
import { cnCreate, convert, filterDataAttrs } from '@megafon/ui-helpers';
|
8
7
|
import PropTypes from 'prop-types';
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
import "./Card.css";
|
9
|
+
var textsConvertConfig = {
|
10
|
+
b: {
|
11
|
+
component: function component(_ref) {
|
12
|
+
var children = _ref.children;
|
13
|
+
return /*#__PURE__*/React.createElement("b", null, children);
|
14
|
+
}
|
15
|
+
},
|
16
|
+
ul: {
|
17
|
+
component: function component(_ref2) {
|
18
|
+
var children = _ref2.children;
|
19
|
+
return /*#__PURE__*/React.createElement("ul", null, children);
|
20
|
+
}
|
21
|
+
},
|
22
|
+
ol: {
|
23
|
+
component: function component(_ref3) {
|
24
|
+
var children = _ref3.children;
|
25
|
+
return /*#__PURE__*/React.createElement("ol", null, children);
|
26
|
+
}
|
27
|
+
},
|
28
|
+
li: {
|
29
|
+
component: function component(_ref4) {
|
30
|
+
var children = _ref4.children;
|
31
|
+
return /*#__PURE__*/React.createElement("li", null, children);
|
32
|
+
}
|
33
|
+
}
|
16
34
|
};
|
17
|
-
var cn = cnCreate('mfui-card
|
18
|
-
|
19
|
-
var Card = function Card(
|
20
|
-
var dataAttrs =
|
21
|
-
className =
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
var
|
43
|
-
|
44
|
-
|
45
|
-
var renderImage = React.useCallback(function () {
|
46
|
-
switch (true) {
|
47
|
-
case !!imageSrc:
|
48
|
-
{
|
49
|
-
return /*#__PURE__*/React.createElement("div", {
|
50
|
-
className: cn('pic-wrapper', {
|
51
|
-
'object-fit': objectFit
|
52
|
-
})
|
53
|
-
}, /*#__PURE__*/React.createElement("img", {
|
54
|
-
className: cn('img'),
|
55
|
-
src: imageSrc,
|
56
|
-
alt: imageAlt
|
57
|
-
}));
|
58
|
-
}
|
59
|
-
|
60
|
-
case !!svgSrc:
|
61
|
-
{
|
62
|
-
return /*#__PURE__*/React.createElement("div", {
|
63
|
-
className: cn('svg-wrapper')
|
64
|
-
}, svgSrc);
|
65
|
-
}
|
66
|
-
|
67
|
-
default:
|
68
|
-
return null;
|
35
|
+
var cn = cnCreate('mfui-card');
|
36
|
+
|
37
|
+
var Card = function Card(_ref5) {
|
38
|
+
var dataAttrs = _ref5.dataAttrs,
|
39
|
+
className = _ref5.className,
|
40
|
+
_ref5$isFullHeight = _ref5.isFullHeight,
|
41
|
+
isFullHeight = _ref5$isFullHeight === void 0 ? false : _ref5$isFullHeight,
|
42
|
+
link = _ref5.link,
|
43
|
+
_ref5$view = _ref5.view,
|
44
|
+
view = _ref5$view === void 0 ? 'shadow' : _ref5$view,
|
45
|
+
image = _ref5.image,
|
46
|
+
icon = _ref5.icon,
|
47
|
+
title = _ref5.title,
|
48
|
+
textsList = _ref5.textsList,
|
49
|
+
featuresList = _ref5.featuresList,
|
50
|
+
iconsList = _ref5.iconsList,
|
51
|
+
price = _ref5.price,
|
52
|
+
button = _ref5.button,
|
53
|
+
extraButton = _ref5.extraButton,
|
54
|
+
onClick = _ref5.onClick;
|
55
|
+
var isOnlyTitle = !image && !icon && !textsList && !featuresList && !iconsList && !price && !button && !extraButton;
|
56
|
+
var isLink = (link === null || link === void 0 ? void 0 : link.href) && !button && !extraButton;
|
57
|
+
var isBottomImage = (image === null || image === void 0 ? void 0 : image.position) === 'bottom';
|
58
|
+
var ElementType = isLink ? 'a' : 'div';
|
59
|
+
|
60
|
+
var renderImage = function renderImage() {
|
61
|
+
if (!image) {
|
62
|
+
return null;
|
69
63
|
}
|
70
|
-
|
71
|
-
|
72
|
-
|
64
|
+
|
65
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.imgBox), {
|
66
|
+
className: cn('img-box', {
|
67
|
+
position: image.position
|
68
|
+
})
|
69
|
+
}), /*#__PURE__*/React.createElement("img", {
|
70
|
+
className: cn('img'),
|
71
|
+
src: image.src,
|
72
|
+
alt: image.alt
|
73
|
+
}));
|
74
|
+
};
|
75
|
+
|
76
|
+
var renderIcon = function renderIcon() {
|
77
|
+
if (!icon) {
|
73
78
|
return null;
|
74
79
|
}
|
75
80
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
linkRel = link.rel;
|
81
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.icon), {
|
82
|
+
className: cn('icon')
|
83
|
+
}), icon);
|
84
|
+
};
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
var renderContent = function renderContent() {
|
87
|
+
if (textsList) {
|
88
|
+
return /*#__PURE__*/React.createElement("div", {
|
89
|
+
className: cn('texts')
|
90
|
+
}, textsList.map(function (item, i) {
|
91
|
+
return /*#__PURE__*/React.createElement("div", {
|
92
|
+
className: cn('texts-item'),
|
93
|
+
key: i
|
94
|
+
}, !!item.title && /*#__PURE__*/React.createElement("div", {
|
95
|
+
className: cn('texts-title')
|
96
|
+
}, convert(item.title, textsConvertConfig)), /*#__PURE__*/React.createElement("div", {
|
97
|
+
className: cn('texts-desc')
|
98
|
+
}, convert(item.desc, textsConvertConfig)));
|
99
|
+
}));
|
86
100
|
}
|
87
101
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
102
|
+
if (featuresList) {
|
103
|
+
return /*#__PURE__*/React.createElement("div", {
|
104
|
+
className: cn('features')
|
105
|
+
}, /*#__PURE__*/React.createElement("div", {
|
106
|
+
className: cn('features-list')
|
107
|
+
}, featuresList.items.map(function (item, i) {
|
108
|
+
return /*#__PURE__*/React.createElement("div", {
|
109
|
+
className: cn('features-item'),
|
110
|
+
key: i
|
111
|
+
}, /*#__PURE__*/React.createElement("div", {
|
112
|
+
className: cn('features-item-title')
|
113
|
+
}, item.title), /*#__PURE__*/React.createElement("div", {
|
114
|
+
className: cn('features-item-separator')
|
115
|
+
}), /*#__PURE__*/React.createElement("div", {
|
116
|
+
className: cn('features-item-value')
|
117
|
+
}, item.value));
|
118
|
+
})), featuresList.desc);
|
119
|
+
}
|
120
|
+
|
121
|
+
if (iconsList) {
|
122
|
+
return /*#__PURE__*/React.createElement("div", {
|
123
|
+
className: cn('icons')
|
124
|
+
}, !!iconsList.desc && /*#__PURE__*/React.createElement("div", {
|
125
|
+
className: cn('icons-desc')
|
126
|
+
}, iconsList.desc), /*#__PURE__*/React.createElement("div", {
|
127
|
+
className: cn('icons-list')
|
128
|
+
}, iconsList.items.map(function (item, i) {
|
129
|
+
return /*#__PURE__*/React.createElement("div", {
|
130
|
+
className: cn('icons-item'),
|
131
|
+
key: i
|
132
|
+
}, /*#__PURE__*/React.createElement("div", {
|
133
|
+
className: cn('icons-item-icon')
|
134
|
+
}, item.icon), /*#__PURE__*/React.createElement("div", {
|
135
|
+
className: cn('icons-item-text')
|
136
|
+
}, item.text));
|
137
|
+
})));
|
138
|
+
}
|
139
|
+
|
140
|
+
return null;
|
141
|
+
};
|
142
|
+
|
143
|
+
var renderPrice = function renderPrice() {
|
144
|
+
if (!price) {
|
101
145
|
return null;
|
102
146
|
}
|
103
147
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
148
|
+
return /*#__PURE__*/React.createElement("div", {
|
149
|
+
className: cn('price')
|
150
|
+
}, !!price.oldValue && /*#__PURE__*/React.createElement("div", {
|
151
|
+
className: cn('price-old-value')
|
152
|
+
}, price.oldValue), /*#__PURE__*/React.createElement("div", {
|
153
|
+
className: cn('price-value')
|
154
|
+
}, price.value), !!price.period && /*#__PURE__*/React.createElement("div", {
|
155
|
+
className: cn('price-period')
|
156
|
+
}, price.period));
|
157
|
+
};
|
158
|
+
|
159
|
+
var renderButtons = function renderButtons() {
|
160
|
+
if (!button && !extraButton) {
|
161
|
+
return null;
|
162
|
+
}
|
163
|
+
|
164
|
+
return /*#__PURE__*/React.createElement("div", {
|
165
|
+
className: cn('buttons', {
|
166
|
+
centered: (button === null || button === void 0 ? void 0 : button.isCentered) || (extraButton === null || extraButton === void 0 ? void 0 : extraButton.isCentered)
|
167
|
+
})
|
168
|
+
}, !!button && /*#__PURE__*/React.createElement(Button, {
|
111
169
|
dataAttrs: {
|
112
170
|
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.button
|
113
171
|
},
|
114
|
-
className: cn('button'
|
115
|
-
href:
|
116
|
-
target:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
172
|
+
className: cn('button'),
|
173
|
+
href: button.href,
|
174
|
+
target: button.target,
|
175
|
+
onClick: button === null || button === void 0 ? void 0 : button.onClick
|
176
|
+
}, button.title), !!extraButton && /*#__PURE__*/React.createElement(Button, {
|
177
|
+
dataAttrs: {
|
178
|
+
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.extraButton
|
179
|
+
},
|
180
|
+
className: cn('button'),
|
181
|
+
href: extraButton.href,
|
182
|
+
target: extraButton.target,
|
183
|
+
type: "outline",
|
184
|
+
onClick: extraButton === null || extraButton === void 0 ? void 0 : extraButton.onClick
|
185
|
+
}, extraButton.title));
|
186
|
+
};
|
187
|
+
|
188
|
+
var renderFooter = function renderFooter() {
|
189
|
+
if (!price && !button && !extraButton && !image) {
|
127
190
|
return null;
|
128
191
|
}
|
129
192
|
|
130
193
|
return /*#__PURE__*/React.createElement("div", {
|
131
|
-
className: cn('
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
'
|
141
|
-
}, [className
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
className: cn('
|
147
|
-
}, /*#__PURE__*/React.createElement(React.Fragment, null, renderImage(), /*#__PURE__*/React.createElement(Header, {
|
194
|
+
className: cn('footer')
|
195
|
+
}, isBottomImage && renderImage(), renderPrice(), renderButtons());
|
196
|
+
};
|
197
|
+
|
198
|
+
return /*#__PURE__*/React.createElement(ElementType, _extends({}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
|
199
|
+
className: cn({
|
200
|
+
'only-title': isOnlyTitle,
|
201
|
+
view: view,
|
202
|
+
link: isLink,
|
203
|
+
'full-height': isFullHeight
|
204
|
+
}, [className]),
|
205
|
+
href: isLink ? link === null || link === void 0 ? void 0 : link.href : undefined,
|
206
|
+
target: isLink ? link === null || link === void 0 ? void 0 : link.target : undefined,
|
207
|
+
onClick: isLink ? onClick : undefined
|
208
|
+
}), renderIcon(), !isBottomImage && renderImage(), /*#__PURE__*/React.createElement(Header, {
|
209
|
+
className: cn('title'),
|
148
210
|
as: "h3",
|
149
|
-
|
150
|
-
},
|
151
|
-
className: cn('text')
|
152
|
-
}, typeof text === 'string' ? convert(text, textConvertConfig) : text), renderBtnsWrapper())));
|
211
|
+
align: title.align
|
212
|
+
}, title.text), renderContent(), renderFooter());
|
153
213
|
};
|
154
214
|
|
155
215
|
Card.propTypes = {
|
156
216
|
dataAttrs: PropTypes.shape({
|
157
217
|
root: PropTypes.objectOf(PropTypes.string.isRequired),
|
158
|
-
|
159
|
-
|
218
|
+
icon: PropTypes.objectOf(PropTypes.string.isRequired),
|
219
|
+
imgBox: PropTypes.objectOf(PropTypes.string.isRequired),
|
220
|
+
button: PropTypes.objectOf(PropTypes.string.isRequired),
|
221
|
+
extraButton: PropTypes.objectOf(PropTypes.string.isRequired)
|
160
222
|
}),
|
161
223
|
className: PropTypes.string,
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
224
|
+
view: PropTypes.oneOf(['shadow', 'background']),
|
225
|
+
link: PropTypes.shape({
|
226
|
+
href: PropTypes.string,
|
227
|
+
target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top'])
|
228
|
+
}),
|
229
|
+
image: PropTypes.shape({
|
230
|
+
src: PropTypes.string.isRequired,
|
231
|
+
alt: PropTypes.string,
|
232
|
+
position: PropTypes.oneOf(['top', 'bottom'])
|
233
|
+
}),
|
234
|
+
icon: PropTypes.node,
|
235
|
+
title: PropTypes.shape({
|
236
|
+
text: PropTypes.string.isRequired,
|
237
|
+
align: PropTypes.oneOf(['left', 'center'])
|
238
|
+
}).isRequired,
|
239
|
+
textsList: PropTypes.arrayOf(PropTypes.shape({
|
240
|
+
title: PropTypes.string,
|
241
|
+
desc: PropTypes.string.isRequired
|
242
|
+
}).isRequired),
|
243
|
+
featuresList: PropTypes.shape({
|
244
|
+
desc: PropTypes.string,
|
245
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
246
|
+
title: PropTypes.string.isRequired,
|
247
|
+
value: PropTypes.string.isRequired
|
248
|
+
}).isRequired).isRequired
|
249
|
+
}),
|
250
|
+
iconsList: PropTypes.shape({
|
251
|
+
desc: PropTypes.string,
|
252
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
253
|
+
icon: PropTypes.node.isRequired,
|
254
|
+
text: PropTypes.string.isRequired
|
255
|
+
}).isRequired).isRequired
|
256
|
+
}),
|
257
|
+
price: PropTypes.shape({
|
258
|
+
oldValue: PropTypes.string,
|
259
|
+
value: PropTypes.string.isRequired,
|
260
|
+
period: PropTypes.string
|
167
261
|
}),
|
168
|
-
rootRef: PropTypes.oneOfType([PropTypes.func, PropTypes.oneOfType([PropTypes.shape({
|
169
|
-
current: PropTypes.elementType
|
170
|
-
}), PropTypes.any])]),
|
171
|
-
imageSrc: PropTypes.string,
|
172
|
-
imageAlt: PropTypes.string,
|
173
|
-
svgSrc: PropTypes.node,
|
174
|
-
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.arrayOf(PropTypes.node)]).isRequired,
|
175
|
-
text: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
|
176
262
|
button: PropTypes.shape({
|
177
263
|
title: PropTypes.string.isRequired,
|
178
264
|
href: PropTypes.string,
|
179
|
-
target: PropTypes.oneOf(
|
180
|
-
|
181
|
-
rel: PropTypes.string,
|
265
|
+
target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
|
266
|
+
isCentered: PropTypes.bool,
|
182
267
|
onClick: PropTypes.func
|
183
268
|
}),
|
184
|
-
|
269
|
+
extraButton: PropTypes.shape({
|
185
270
|
title: PropTypes.string.isRequired,
|
186
271
|
href: PropTypes.string,
|
187
|
-
target: PropTypes.oneOf(
|
188
|
-
|
189
|
-
|
272
|
+
target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
|
273
|
+
isCentered: PropTypes.bool,
|
274
|
+
onClick: PropTypes.func
|
190
275
|
}),
|
191
|
-
|
192
|
-
isLeftHAlign: PropTypes.bool,
|
193
|
-
isFullHeight: PropTypes.bool,
|
194
|
-
href: PropTypes.string,
|
195
|
-
target: PropTypes.oneOf(Object.values(Target)),
|
196
|
-
objectFit: PropTypes.oneOf(Object.values(ObjectFit))
|
276
|
+
onClick: PropTypes.func
|
197
277
|
};
|
198
278
|
export default Card;
|
@@ -0,0 +1,71 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
declare type Target = '_self' | '_blank' | '_parent' | '_top';
|
3
|
+
export declare type Link = {
|
4
|
+
/** Ссылка */
|
5
|
+
href?: string;
|
6
|
+
/** Target свойство ссылки */
|
7
|
+
target?: Target;
|
8
|
+
};
|
9
|
+
export declare type Image = {
|
10
|
+
/** Ссылка на изображение */
|
11
|
+
src: string;
|
12
|
+
/** Значение тега alt для изображения */
|
13
|
+
alt?: string;
|
14
|
+
/** Позиция изображения */
|
15
|
+
position?: 'top' | 'bottom';
|
16
|
+
};
|
17
|
+
export declare type Title = {
|
18
|
+
/** Текст */
|
19
|
+
text: string;
|
20
|
+
/** Выравнивание */
|
21
|
+
align?: 'left' | 'center';
|
22
|
+
};
|
23
|
+
export declare type TextsList = {
|
24
|
+
/** Заголовок */
|
25
|
+
title?: string;
|
26
|
+
/** Описание */
|
27
|
+
desc: string;
|
28
|
+
}[];
|
29
|
+
export declare type FeaturesList = {
|
30
|
+
/** Список */
|
31
|
+
items: {
|
32
|
+
/** Заголовок */
|
33
|
+
title: string;
|
34
|
+
/** Значение */
|
35
|
+
value: string;
|
36
|
+
}[];
|
37
|
+
/** Описание */
|
38
|
+
desc?: string;
|
39
|
+
};
|
40
|
+
export declare type IconsList = {
|
41
|
+
/** Список */
|
42
|
+
items: {
|
43
|
+
/** Иконка */
|
44
|
+
icon: React.ReactNode;
|
45
|
+
/** Текст */
|
46
|
+
text: string;
|
47
|
+
}[];
|
48
|
+
/** Описание */
|
49
|
+
desc?: string;
|
50
|
+
};
|
51
|
+
export declare type Price = {
|
52
|
+
/** Старая цена */
|
53
|
+
oldValue?: string;
|
54
|
+
/** Текущая цена */
|
55
|
+
value: string;
|
56
|
+
/** Период */
|
57
|
+
period?: string;
|
58
|
+
};
|
59
|
+
export declare type ButtonType = {
|
60
|
+
/** Название */
|
61
|
+
title: string;
|
62
|
+
/** Ссылка */
|
63
|
+
href?: string;
|
64
|
+
/** Target свойство кнопки */
|
65
|
+
target?: Target;
|
66
|
+
/** Центрировать кнопку */
|
67
|
+
isCentered?: boolean;
|
68
|
+
/** Обработчик клика по кнопке */
|
69
|
+
onClick?: () => void;
|
70
|
+
};
|
71
|
+
export {};
|
File without changes
|
@@ -1,16 +1,13 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { ICard } from '../Card/Card';
|
3
3
|
interface ICardsBoxProps {
|
4
|
-
/**
|
5
|
-
|
6
|
-
/** Ссылка на корневой элемент */
|
7
|
-
rootRef?: React.Ref<HTMLDivElement>;
|
4
|
+
/** Выводить по две колонки в ряду для 2 или 4 карточек */
|
5
|
+
renderTwoColumnsInRow?: boolean;
|
8
6
|
/** Дата атрибуты для корневого элемента */
|
9
7
|
dataAttrs?: {
|
10
|
-
|
8
|
+
root?: Record<string, string>;
|
9
|
+
column?: Record<string, string>;
|
11
10
|
};
|
12
|
-
/** Обработчик смены слайда (должен быть обернут в useCallback) */
|
13
|
-
onChange?: (currentIndex: number, previousIndex: number, slidesPerView?: number | 'auto') => void;
|
14
11
|
children: Array<React.ReactElement<ICard>> | React.ReactElement<ICard>;
|
15
12
|
}
|
16
13
|
declare const CardsBox: React.FC<ICardsBoxProps>;
|
@@ -1,83 +1,37 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
4
|
-
|
5
|
-
var _SlidesSettings;
|
6
|
-
|
7
2
|
import "core-js/modules/es.array.map.js";
|
8
3
|
import * as React from 'react';
|
9
|
-
import { Grid, GridColumn
|
10
|
-
import {
|
11
|
-
import throttle from 'lodash.throttle';
|
4
|
+
import { Grid, GridColumn } from '@megafon/ui-core';
|
5
|
+
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
|
12
6
|
import * as PropTypes from 'prop-types';
|
13
|
-
import
|
14
|
-
var MAX_CARDS_COUNT_IN_GRID_ON_MOBILE = 2;
|
15
|
-
var SlidesSettings = (_SlidesSettings = {}, _defineProperty(_SlidesSettings, breakpoints.MOBILE_SMALL_START, {
|
16
|
-
slidesPerView: 1,
|
17
|
-
spaceBetween: 16
|
18
|
-
}), _defineProperty(_SlidesSettings, breakpoints.MOBILE_BIG_START, {
|
19
|
-
slidesPerView: 2,
|
20
|
-
spaceBetween: 20
|
21
|
-
}), _SlidesSettings);
|
7
|
+
import getColumnConfig from "./helpers";
|
22
8
|
var cn = cnCreate('mfui-cards-box');
|
23
9
|
|
24
10
|
var CardsBox = function CardsBox(_ref) {
|
25
|
-
var
|
26
|
-
|
11
|
+
var _ref$renderTwoColumns = _ref.renderTwoColumnsInRow,
|
12
|
+
renderTwoColumnsInRow = _ref$renderTwoColumns === void 0 ? false : _ref$renderTwoColumns,
|
27
13
|
dataAttrs = _ref.dataAttrs,
|
28
|
-
onChange = _ref.onChange,
|
29
14
|
children = _ref.children;
|
30
|
-
|
31
|
-
var _React$useState = React.useState(false),
|
32
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
33
|
-
isMobile = _React$useState2[0],
|
34
|
-
setIsMobile = _React$useState2[1];
|
35
|
-
|
36
|
-
var itemsCount = React.Children.count(children);
|
37
|
-
var isRenderCarousel = isMobile && itemsCount > MAX_CARDS_COUNT_IN_GRID_ON_MOBILE;
|
38
|
-
var renderGrid = React.useCallback(function () {
|
39
|
-
return /*#__PURE__*/React.createElement(Grid, {
|
40
|
-
guttersBottom: "medium",
|
41
|
-
guttersLeft: "medium",
|
42
|
-
hAlign: gridHAlign
|
43
|
-
}, React.Children.map(children, function (child) {
|
44
|
-
return /*#__PURE__*/React.createElement(GridColumn, {
|
45
|
-
all: "4",
|
46
|
-
mobile: "12"
|
47
|
-
}, child);
|
48
|
-
}));
|
49
|
-
}, [children, gridHAlign]);
|
50
|
-
var renderCarousel = React.useCallback(function () {
|
51
|
-
return /*#__PURE__*/React.createElement(Carousel, {
|
52
|
-
slidesSettings: SlidesSettings,
|
53
|
-
onChange: onChange
|
54
|
-
}, children);
|
55
|
-
}, [children, onChange]);
|
56
|
-
React.useEffect(function () {
|
57
|
-
var resizeHandler = function resizeHandler() {
|
58
|
-
return window.innerWidth <= breakpoints.MOBILE_BIG_END ? setIsMobile(true) : setIsMobile(false);
|
59
|
-
};
|
60
|
-
|
61
|
-
var resizeHandlerThrottled = throttle(resizeHandler, throttleTime.resize);
|
62
|
-
resizeHandler();
|
63
|
-
window.addEventListener('resize', resizeHandlerThrottled);
|
64
|
-
return function () {
|
65
|
-
window.removeEventListener('resize', resizeHandlerThrottled);
|
66
|
-
};
|
67
|
-
}, []);
|
68
15
|
return /*#__PURE__*/React.createElement("div", _extends({
|
69
|
-
className: cn()
|
70
|
-
|
71
|
-
|
16
|
+
className: cn()
|
17
|
+
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), /*#__PURE__*/React.createElement(Grid, {
|
18
|
+
guttersBottom: "medium",
|
19
|
+
guttersLeft: "medium"
|
20
|
+
}, React.Children.map(children, function (child, i) {
|
21
|
+
return /*#__PURE__*/React.createElement(GridColumn, _extends({
|
22
|
+
dataAttrs: {
|
23
|
+
root: dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.column
|
24
|
+
}
|
25
|
+
}, getColumnConfig(React.Children.count(children), i, renderTwoColumnsInRow)), child);
|
26
|
+
})));
|
72
27
|
};
|
73
28
|
|
74
29
|
CardsBox.propTypes = {
|
75
|
-
|
76
|
-
rootRef: PropTypes.oneOfType([PropTypes.func, PropTypes.oneOfType([PropTypes.shape({
|
77
|
-
current: PropTypes.elementType
|
78
|
-
}), PropTypes.any])]),
|
30
|
+
renderTwoColumnsInRow: PropTypes.bool,
|
79
31
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element.isRequired), PropTypes.element]).isRequired,
|
80
|
-
dataAttrs: PropTypes.
|
81
|
-
|
32
|
+
dataAttrs: PropTypes.shape({
|
33
|
+
root: PropTypes.objectOf(PropTypes.string.isRequired),
|
34
|
+
column: PropTypes.objectOf(PropTypes.string.isRequired)
|
35
|
+
})
|
82
36
|
};
|
83
37
|
export default CardsBox;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
declare type TGridSizeValues = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12';
|
2
|
+
declare type GridConfig = {
|
3
|
+
all?: TGridSizeValues;
|
4
|
+
tablet?: TGridSizeValues;
|
5
|
+
mobile?: TGridSizeValues;
|
6
|
+
leftOffsetWide?: TGridSizeValues;
|
7
|
+
leftOffsetDesktop?: TGridSizeValues;
|
8
|
+
};
|
9
|
+
declare const getColumnConfig: (count: number, index: number, renderTwoColumnsInRow: boolean) => GridConfig;
|
10
|
+
export default getColumnConfig;
|