@megafon/ui-core 8.4.0 → 8.5.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/dist/es/components/Chips/Chip.css +1 -1
- package/dist/es/components/Chips/Chip.d.ts +3 -0
- package/dist/es/components/Chips/Chip.js +4 -2
- package/dist/es/components/Chips/Chips.css +1 -1
- package/dist/es/components/Chips/Chips.d.ts +16 -2
- package/dist/es/components/Chips/Chips.js +62 -20
- package/dist/{lib/components/Chips/components → es/components/Chips/components/ChipsDropdown}/ChipsDropdown.d.ts +2 -2
- package/dist/es/components/Chips/components/{ChipsDropdown.js → ChipsDropdown/ChipsDropdown.js} +7 -4
- package/dist/es/components/Chips/components/ChipsScrollPanel/ChipsScrollPanel.css +1 -0
- package/dist/es/components/Chips/components/ChipsScrollPanel/ChipsScrollPanel.d.ts +11 -0
- package/dist/es/components/Chips/components/ChipsScrollPanel/ChipsScrollPanel.js +83 -0
- package/dist/es/index.d.ts +2 -1
- package/dist/es/index.js +2 -1
- package/dist/lib/components/Chips/Chip.css +1 -1
- package/dist/lib/components/Chips/Chip.d.ts +3 -0
- package/dist/lib/components/Chips/Chip.js +4 -2
- package/dist/lib/components/Chips/Chips.css +1 -1
- package/dist/lib/components/Chips/Chips.d.ts +16 -2
- package/dist/lib/components/Chips/Chips.js +61 -19
- package/dist/{es/components/Chips/components → lib/components/Chips/components/ChipsDropdown}/ChipsDropdown.d.ts +2 -2
- package/dist/lib/components/Chips/components/{ChipsDropdown.js → ChipsDropdown/ChipsDropdown.js} +7 -4
- package/dist/lib/components/Chips/components/ChipsScrollPanel/ChipsScrollPanel.css +1 -0
- package/dist/lib/components/Chips/components/ChipsScrollPanel/ChipsScrollPanel.d.ts +11 -0
- package/dist/lib/components/Chips/components/ChipsScrollPanel/ChipsScrollPanel.js +92 -0
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +8 -1
- package/package.json +3 -3
- /package/dist/es/components/Chips/components/{ChipsDropdown.css → ChipsDropdown/ChipsDropdown.css} +0 -0
- /package/dist/lib/components/Chips/components/{ChipsDropdown.css → ChipsDropdown/ChipsDropdown.css} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
h1,h2,h3,h4,h5{margin:0}.mfui-chip{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;font-family:inherit;font-size:15px;font-weight:500;line-height:24px;-webkit-box-align:center;-ms-flex-align:center;align-items:center
|
|
1
|
+
h1,h2,h3,h4,h5{margin:0}.mfui-chip{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;font-family:inherit;font-size:15px;font-weight:500;line-height:24px;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:var(--spbSky0);border:none;border-radius:20px;-webkit-box-sizing:border-box;box-sizing:border-box;color:var(--content);overflow:hidden;padding:8px 20px;text-align:center;text-decoration:none;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-appearance:none;-moz-appearance:none;appearance:none;cursor:pointer;outline:none;-webkit-transition:background-color .3s,color .3s;transition:background-color .3s,color .3s}.mfui-chip svg{-webkit-transition:fill .3s;transition:fill .3s;fill:var(--content)}@media screen and (max-width:767px){.mfui-chip{padding:4px 12px}}.mfui-chip:hover{background-color:var(--spbSky1)}.mfui-chip__inner{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mfui-chip__counter{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:var(--spbSky3);margin-left:6px}@media screen and (max-width:767px){.mfui-chip__counter{margin-left:4px}}.mfui-chip__icon,.mfui-chip__icon-arrow{display:block;max-height:20px;min-width:20px;width:20px}.mfui-chip__icon svg,.mfui-chip__icon-arrow svg{display:block;height:100%;width:100%}.mfui-chip__icon{margin-right:6px}@media screen and (max-width:767px){.mfui-chip__icon{margin-right:4px}}.mfui-chip_disabled,.mfui-chip_disabled:hover{background-color:var(--spbSky0);color:var(--spbSky3);cursor:default;pointer-events:none}.mfui-chip_disabled svg,.mfui-chip_disabled:hover svg{fill:var(--spbSky3)}.mfui-chip_disabled .mfui-chip__counter,.mfui-chip_disabled:hover .mfui-chip__counter{color:var(--spbSky2)}.mfui-chip_checked,.mfui-chip_checked:hover{background-color:var(--night);color:var(--stcWhite)}.mfui-chip_checked svg,.mfui-chip_checked:hover svg{fill:var(--stcWhite)}.mfui-chip_checked .mfui-chip__counter,.mfui-chip_checked:hover .mfui-chip__counter{color:var(--stcWhite)}.mfui-chip_checked.mfui-chip_color_black,.mfui-chip_checked.mfui-chip_color_black:hover{background-color:var(--content);color:var(--base)}.mfui-chip_checked.mfui-chip_color_black svg,.mfui-chip_checked.mfui-chip_color_black:hover svg{fill:var(--base)}.mfui-chip_checked.mfui-chip_color_black .mfui-chip__counter,.mfui-chip_checked.mfui-chip_color_black:hover .mfui-chip__counter{color:var(--base)}.mfui-chip_with-icon{padding-left:16px}@media screen and (max-width:767px){.mfui-chip_with-icon{padding-left:8px}}
|
|
@@ -14,6 +14,8 @@ export type ChipArrowType = (typeof ChipArrow)[keyof typeof ChipArrow];
|
|
|
14
14
|
export interface IChipProps {
|
|
15
15
|
/** Идентификатор */
|
|
16
16
|
id: ChipIdType;
|
|
17
|
+
/** Заголовок */
|
|
18
|
+
title?: string;
|
|
17
19
|
/** Набор цветов для компонента */
|
|
18
20
|
color?: ChipColorsType;
|
|
19
21
|
/** Отображение в отмеченном (зажатом) состоянии */
|
|
@@ -35,6 +37,7 @@ export interface IChipProps {
|
|
|
35
37
|
/** Дополнительные классы для внутренних элементов */
|
|
36
38
|
classes?: {
|
|
37
39
|
root?: string;
|
|
40
|
+
checked?: string;
|
|
38
41
|
inner?: string;
|
|
39
42
|
icon?: string;
|
|
40
43
|
counter?: string;
|
|
@@ -31,6 +31,7 @@ export var ChipArrow = {
|
|
|
31
31
|
var cn = cnCreate('mfui-chip');
|
|
32
32
|
var Chip = function Chip(_ref) {
|
|
33
33
|
var id = _ref.id,
|
|
34
|
+
title = _ref.title,
|
|
34
35
|
_ref$color = _ref.color,
|
|
35
36
|
color = _ref$color === void 0 ? 'default' : _ref$color,
|
|
36
37
|
_ref$checked = _ref.checked,
|
|
@@ -47,6 +48,7 @@ var Chip = function Chip(_ref) {
|
|
|
47
48
|
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
48
49
|
dataAttrs = _ref.dataAttrs,
|
|
49
50
|
rootRef = _ref.rootRef;
|
|
51
|
+
var checkedClass = checked ? classes.checked : undefined;
|
|
50
52
|
var handleClick = React.useCallback(function (e) {
|
|
51
53
|
onClick === null || onClick === void 0 ? void 0 : onClick(e, id);
|
|
52
54
|
}, [onClick, id]);
|
|
@@ -57,7 +59,7 @@ var Chip = function Chip(_ref) {
|
|
|
57
59
|
checked: checked,
|
|
58
60
|
disabled: disabled,
|
|
59
61
|
'with-icon': !!icon
|
|
60
|
-
}, [className, classes.root])
|
|
62
|
+
}, [className, classes.root, checkedClass])
|
|
61
63
|
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
|
|
62
64
|
disabled: disabled,
|
|
63
65
|
onClick: handleClick,
|
|
@@ -66,7 +68,7 @@ var Chip = function Chip(_ref) {
|
|
|
66
68
|
className: cn('icon', [classes.icon])
|
|
67
69
|
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.icon)), icon), /*#__PURE__*/React.createElement("span", _extends({
|
|
68
70
|
className: cn('inner', [classes.inner])
|
|
69
|
-
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.inner)), children), !!counterValue && /*#__PURE__*/React.createElement("span", _extends({
|
|
71
|
+
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.inner)), children || title), !!counterValue && /*#__PURE__*/React.createElement("span", _extends({
|
|
70
72
|
className: cn('counter', [classes.counter])
|
|
71
73
|
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.counter)), counterValue), !!arrow && /*#__PURE__*/React.createElement("div", _extends({
|
|
72
74
|
className: cn('icon-arrow')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
h1,h2,h3,h4,h5{margin:0}.mfui-chips{display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:12px;width:100%}@media screen and (max-width:767px){.mfui-chips{gap:8px}}.mfui-chips_hidden{display:grid;grid-template-columns:repeat(auto-fit,minMax(0,-webkit-min-content));grid-template-columns:repeat(auto-fit,minMax(0,min-content))}
|
|
1
|
+
h1,h2,h3,h4,h5{margin:0}.mfui-chips{display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:12px;width:100%}@media screen and (max-width:767px){.mfui-chips{gap:8px}}.mfui-chips_hidden{display:grid;grid-template-columns:repeat(auto-fit,minMax(0,-webkit-min-content));grid-template-columns:repeat(auto-fit,minMax(0,min-content))}.mfui-chips_align_center{-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}
|
|
@@ -4,10 +4,16 @@ import './Chips.scss';
|
|
|
4
4
|
export interface IChipsProps {
|
|
5
5
|
/** Массив элементов */
|
|
6
6
|
items: IChipProps[];
|
|
7
|
-
/** Значение */
|
|
8
|
-
value
|
|
7
|
+
/** Значение (идентификатор активного элемента). Начальное значение в неконтролируемом состоянии */
|
|
8
|
+
value?: ChipIdType;
|
|
9
9
|
/** Цвет активного элемента */
|
|
10
10
|
color?: ChipColorsType;
|
|
11
|
+
/** Горизонтальное выравнивание */
|
|
12
|
+
align?: 'left' | 'center';
|
|
13
|
+
/** Переводит компонент в контролируемое состояние */
|
|
14
|
+
isControlled?: boolean;
|
|
15
|
+
/** Горизонтальный скролл (отключается на разрешениях, для которых задан лимит отображаемых элементов) */
|
|
16
|
+
isScrollable?: boolean;
|
|
11
17
|
/** Количество отображаемых элементов на всех разрешениях экрана */
|
|
12
18
|
visibleItemsCountAll?: number;
|
|
13
19
|
/** Количество отображаемых элементов на разрешении 768 - 1023 */
|
|
@@ -22,6 +28,14 @@ export interface IChipsProps {
|
|
|
22
28
|
onChange?: (id: ChipIdType, e?: React.SyntheticEvent<EventTarget>) => void;
|
|
23
29
|
/** Дополнительный класс корневого элемента */
|
|
24
30
|
className?: string;
|
|
31
|
+
/** Дополнительные классы для внутренних элементов */
|
|
32
|
+
classes?: {
|
|
33
|
+
root?: string;
|
|
34
|
+
};
|
|
35
|
+
/** Дополнительные data атрибуты к внутренним элементам */
|
|
36
|
+
dataAttrs?: {
|
|
37
|
+
root?: Record<string, string>;
|
|
38
|
+
};
|
|
25
39
|
}
|
|
26
40
|
declare const Chips: React.FC<IChipsProps>;
|
|
27
41
|
export default Chips;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import "core-js/modules/es.symbol.js";
|
|
4
|
+
import "core-js/modules/es.array.index-of.js";
|
|
3
5
|
import "core-js/modules/es.array.map.js";
|
|
4
6
|
import "core-js/modules/es.array.slice.js";
|
|
7
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
8
|
+
var t = {};
|
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
10
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
12
|
+
}
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
5
15
|
import * as React from 'react';
|
|
6
|
-
import { breakpoints, cnCreate } from '@megafon/ui-helpers';
|
|
16
|
+
import { breakpoints, cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
|
|
7
17
|
import throttle from 'lodash.throttle';
|
|
8
18
|
import throttleTime from "../../constants/throttleTime";
|
|
9
19
|
import Chip from "./Chip";
|
|
10
|
-
import ChipsDropdown from "./components/ChipsDropdown";
|
|
20
|
+
import ChipsDropdown from "./components/ChipsDropdown/ChipsDropdown";
|
|
21
|
+
import ChipsScrollPanel from "./components/ChipsScrollPanel/ChipsScrollPanel";
|
|
11
22
|
import "./Chips.css";
|
|
12
23
|
var DESKTOP_SMALL_START = breakpoints.DESKTOP_SMALL_START,
|
|
13
24
|
DESKTOP_MIDDLE_START = breakpoints.DESKTOP_MIDDLE_START,
|
|
@@ -24,12 +35,20 @@ var Chips = function Chips(_ref) {
|
|
|
24
35
|
visibleItemsCountTablet = _ref.visibleItemsCountTablet,
|
|
25
36
|
visibleItemsCountDesktop = _ref.visibleItemsCountDesktop,
|
|
26
37
|
visibleItemsCountWide = _ref.visibleItemsCountWide,
|
|
38
|
+
_ref$isScrollable = _ref.isScrollable,
|
|
39
|
+
isScrollable = _ref$isScrollable === void 0 ? false : _ref$isScrollable,
|
|
40
|
+
_ref$isControlled = _ref.isControlled,
|
|
41
|
+
isControlled = _ref$isControlled === void 0 ? false : _ref$isControlled,
|
|
42
|
+
align = _ref.align,
|
|
27
43
|
onChange = _ref.onChange,
|
|
28
|
-
className = _ref.className
|
|
44
|
+
className = _ref.className,
|
|
45
|
+
_ref$classes = _ref.classes,
|
|
46
|
+
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
47
|
+
dataAttrs = _ref.dataAttrs;
|
|
29
48
|
var _React$useState = React.useState(value),
|
|
30
49
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
31
|
-
|
|
32
|
-
|
|
50
|
+
innerSelectedId = _React$useState2[0],
|
|
51
|
+
setInnerSelectedId = _React$useState2[1];
|
|
33
52
|
var _React$useState3 = React.useState(visibleItemsCountAll),
|
|
34
53
|
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
35
54
|
visibleItemsCount = _React$useState4[0],
|
|
@@ -42,13 +61,40 @@ var Chips = function Chips(_ref) {
|
|
|
42
61
|
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
43
62
|
hiddenItems = _React$useState8[0],
|
|
44
63
|
setHiddenItems = _React$useState8[1];
|
|
64
|
+
var _React$useState9 = React.useState(isScrollable && !visibleItemsCount),
|
|
65
|
+
_React$useState10 = _slicedToArray(_React$useState9, 2),
|
|
66
|
+
isScrollableMode = _React$useState10[0],
|
|
67
|
+
setIsScrollableMode = _React$useState10[1];
|
|
68
|
+
var selectedId = isControlled ? value : innerSelectedId;
|
|
45
69
|
var handleClick = React.useCallback(function (e, id) {
|
|
46
70
|
e.persist();
|
|
47
|
-
if (id) {
|
|
48
|
-
|
|
71
|
+
if (id && id !== selectedId) {
|
|
72
|
+
!isControlled && setInnerSelectedId(id);
|
|
49
73
|
onChange === null || onChange === void 0 ? void 0 : onChange(id, e);
|
|
50
74
|
}
|
|
51
|
-
}, [onChange]);
|
|
75
|
+
}, [isControlled, onChange, selectedId]);
|
|
76
|
+
var renderItems = function renderItems() {
|
|
77
|
+
if (isScrollableMode) {
|
|
78
|
+
return /*#__PURE__*/React.createElement(ChipsScrollPanel, {
|
|
79
|
+
value: selectedId,
|
|
80
|
+
items: visibleItems,
|
|
81
|
+
color: color,
|
|
82
|
+
onClick: handleClick
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return visibleItems.map(function (_a) {
|
|
86
|
+
var id = _a.id,
|
|
87
|
+
children = _a.children,
|
|
88
|
+
rest = __rest(_a, ["id", "children"]);
|
|
89
|
+
return /*#__PURE__*/React.createElement(Chip, _extends({
|
|
90
|
+
key: id,
|
|
91
|
+
id: id,
|
|
92
|
+
checked: id === selectedId,
|
|
93
|
+
color: color,
|
|
94
|
+
onClick: handleClick
|
|
95
|
+
}, rest), !!children && children);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
52
98
|
React.useEffect(function () {
|
|
53
99
|
var resizeHandler = function resizeHandler() {
|
|
54
100
|
var windowWidth = window.innerWidth;
|
|
@@ -82,19 +128,15 @@ var Chips = function Chips(_ref) {
|
|
|
82
128
|
setHiddenItems(null);
|
|
83
129
|
}
|
|
84
130
|
}, [items, visibleItemsCount]);
|
|
85
|
-
|
|
131
|
+
React.useEffect(function () {
|
|
132
|
+
setIsScrollableMode(isScrollable && !visibleItemsCount);
|
|
133
|
+
}, [isScrollable, visibleItemsCount]);
|
|
134
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
86
135
|
className: cn({
|
|
87
|
-
hidden: !!hiddenItems
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
key: item.id
|
|
92
|
-
}, item, {
|
|
93
|
-
checked: item.id === selectedId,
|
|
94
|
-
color: color,
|
|
95
|
-
onClick: handleClick
|
|
96
|
-
}), !!(item === null || item === void 0 ? void 0 : item.children) && item.children);
|
|
97
|
-
}), !!hiddenItems && /*#__PURE__*/React.createElement(ChipsDropdown, {
|
|
136
|
+
hidden: !!hiddenItems,
|
|
137
|
+
align: align
|
|
138
|
+
}, [className, classes.root])
|
|
139
|
+
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), renderItems(), !!hiddenItems && /*#__PURE__*/React.createElement(ChipsDropdown, {
|
|
98
140
|
value: selectedId,
|
|
99
141
|
items: hiddenItems,
|
|
100
142
|
moreTitle: moreTitle,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ChipColorsType, ChipIdType, IChipProps } from '
|
|
2
|
+
import { ChipColorsType, ChipIdType, IChipProps } from '../../Chip';
|
|
3
3
|
import './ChipsDropdown.scss';
|
|
4
4
|
export interface IChipsDropdownProps {
|
|
5
5
|
moreTitle: string;
|
|
6
|
-
value
|
|
6
|
+
value?: ChipIdType;
|
|
7
7
|
items: IChipProps[];
|
|
8
8
|
color: ChipColorsType;
|
|
9
9
|
onClick: (e: React.SyntheticEvent<EventTarget>, id: ChipIdType) => void;
|
package/dist/es/components/Chips/components/{ChipsDropdown.js → ChipsDropdown/ChipsDropdown.js}
RENAMED
|
@@ -5,7 +5,7 @@ import "core-js/modules/es.array.map.js";
|
|
|
5
5
|
import "core-js/modules/es.object.to-string.js";
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
|
|
8
|
-
import Chip from "
|
|
8
|
+
import Chip from "../../Chip";
|
|
9
9
|
import "./ChipsDropdown.css";
|
|
10
10
|
var cn = cnCreate('mfui-chips-dropdown');
|
|
11
11
|
var ChipsDropdown = function ChipsDropdown(_ref) {
|
|
@@ -71,16 +71,19 @@ var ChipsDropdown = function ChipsDropdown(_ref) {
|
|
|
71
71
|
}, filterDataAttrs(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.list)), /*#__PURE__*/React.createElement("div", {
|
|
72
72
|
className: cn('list-inner')
|
|
73
73
|
}, items.map(function (item, key) {
|
|
74
|
+
var children = item.children,
|
|
75
|
+
title = item.title,
|
|
76
|
+
icon = item.icon;
|
|
74
77
|
return /*#__PURE__*/React.createElement("div", {
|
|
75
78
|
key: key,
|
|
76
79
|
className: cn('list-item', {
|
|
77
|
-
'with-icon': !!
|
|
80
|
+
'with-icon': !!icon
|
|
78
81
|
}),
|
|
79
82
|
onClick: handleItemClick(item),
|
|
80
83
|
onKeyDown: handleItemClick(item)
|
|
81
|
-
}, !!
|
|
84
|
+
}, !!icon && /*#__PURE__*/React.createElement("span", {
|
|
82
85
|
className: cn('icon')
|
|
83
|
-
},
|
|
86
|
+
}, icon), children || title);
|
|
84
87
|
}))));
|
|
85
88
|
};
|
|
86
89
|
export default ChipsDropdown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
h1,h2,h3,h4,h5{margin:0}.mfui-chips-scroll-panel{display:-webkit-box;display:-ms-flexbox;display:flex;height:100%;overflow-x:auto;overflow-y:hidden;position:relative;-ms-overflow-style:none;scrollbar-width:none}.mfui-chips-scroll-panel::-webkit-scrollbar{display:none}.mfui-chips-scroll-panel__inner{display:-webkit-box;display:-ms-flexbox;display:flex;gap:12px;height:100%}@media screen and (max-width:767px){.mfui-chips-scroll-panel__inner{gap:8px}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChipColorsType, ChipIdType, IChipProps } from '../../Chip';
|
|
3
|
+
import './ChipsScrollPanel.scss';
|
|
4
|
+
export interface IChipsScrollPanelProps {
|
|
5
|
+
value?: ChipIdType;
|
|
6
|
+
items: IChipProps[];
|
|
7
|
+
color: ChipColorsType;
|
|
8
|
+
onClick: (e: React.SyntheticEvent<EventTarget>, id?: ChipIdType) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const ChipsScrollPanel: React.FC<IChipsScrollPanelProps>;
|
|
11
|
+
export default ChipsScrollPanel;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import "core-js/modules/es.symbol.js";
|
|
4
|
+
import "core-js/modules/es.array.index-of.js";
|
|
5
|
+
import "core-js/modules/es.array.map.js";
|
|
6
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
7
|
+
var t = {};
|
|
8
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
9
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
10
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
import * as React from 'react';
|
|
15
|
+
import { cnCreate } from '@megafon/ui-helpers';
|
|
16
|
+
import Chip from "../../Chip";
|
|
17
|
+
import "./ChipsScrollPanel.css";
|
|
18
|
+
var HALF_DIVIDER = 2;
|
|
19
|
+
var cn = cnCreate('mfui-chips-scroll-panel');
|
|
20
|
+
var ChipsScrollPanel = function ChipsScrollPanel(_ref) {
|
|
21
|
+
var value = _ref.value,
|
|
22
|
+
items = _ref.items,
|
|
23
|
+
color = _ref.color,
|
|
24
|
+
onClick = _ref.onClick;
|
|
25
|
+
var _React$useState = React.useState(),
|
|
26
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
27
|
+
currentValue = _React$useState2[0],
|
|
28
|
+
setCurrentValue = _React$useState2[1];
|
|
29
|
+
var containerRef = React.useRef(null);
|
|
30
|
+
var checkedItemRef = React.useRef(null);
|
|
31
|
+
var scrollToActiveItem = React.useCallback(function () {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
if (!containerRef.current || !checkedItemRef.current) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var activeItemElement = checkedItemRef.current;
|
|
37
|
+
var _activeItemElement$ge = activeItemElement.getBoundingClientRect(),
|
|
38
|
+
itemWidth = _activeItemElement$ge.width;
|
|
39
|
+
var itemOffsetLeft = activeItemElement.offsetLeft;
|
|
40
|
+
var panelCenter = containerRef.current.getBoundingClientRect().width / HALF_DIVIDER;
|
|
41
|
+
var itemCenter = itemWidth / HALF_DIVIDER;
|
|
42
|
+
var activeItemPosition = itemOffsetLeft - panelCenter + itemCenter;
|
|
43
|
+
(_b = (_a = containerRef.current).scrollTo) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
44
|
+
left: activeItemPosition,
|
|
45
|
+
behavior: 'smooth'
|
|
46
|
+
});
|
|
47
|
+
}, []);
|
|
48
|
+
var handleClick = React.useCallback(function (e, id) {
|
|
49
|
+
onClick(e, id);
|
|
50
|
+
scrollToActiveItem();
|
|
51
|
+
}, [onClick, scrollToActiveItem]);
|
|
52
|
+
React.useEffect(function () {
|
|
53
|
+
var isCurrentValueActual = currentValue === value;
|
|
54
|
+
if (isCurrentValueActual) {
|
|
55
|
+
scrollToActiveItem();
|
|
56
|
+
} else {
|
|
57
|
+
setCurrentValue(value);
|
|
58
|
+
}
|
|
59
|
+
}, [value, currentValue, scrollToActiveItem]);
|
|
60
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
61
|
+
className: cn(),
|
|
62
|
+
ref: containerRef
|
|
63
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
64
|
+
className: cn('inner'),
|
|
65
|
+
tabIndex: -1
|
|
66
|
+
}, items.map(function (_a) {
|
|
67
|
+
var id = _a.id,
|
|
68
|
+
children = _a.children,
|
|
69
|
+
rest = __rest(_a, ["id", "children"]);
|
|
70
|
+
var checked = id === value;
|
|
71
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
key: id,
|
|
73
|
+
className: cn('slide')
|
|
74
|
+
}, /*#__PURE__*/React.createElement(Chip, _extends({}, rest, {
|
|
75
|
+
id: id,
|
|
76
|
+
checked: checked,
|
|
77
|
+
color: color,
|
|
78
|
+
onClick: handleClick,
|
|
79
|
+
rootRef: checked ? checkedItemRef : null
|
|
80
|
+
}), children));
|
|
81
|
+
})));
|
|
82
|
+
};
|
|
83
|
+
export default ChipsScrollPanel;
|
package/dist/es/index.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export { default as Checkbox } from './components/Checkbox/Checkbox';
|
|
|
10
10
|
export { default as checkBreakpointsPropTypes } from './components/Carousel/checkBreakpointsPropTypes';
|
|
11
11
|
export { default as Chip } from './components/Chips/Chip';
|
|
12
12
|
export { default as Chips } from './components/Chips/Chips';
|
|
13
|
-
export { default as ChipsDropdown } from './components/Chips/components/ChipsDropdown';
|
|
13
|
+
export { default as ChipsDropdown } from './components/Chips/components/ChipsDropdown/ChipsDropdown';
|
|
14
|
+
export { default as ChipsScrollPanel } from './components/Chips/components/ChipsScrollPanel/ChipsScrollPanel';
|
|
14
15
|
export { default as Collapse } from './components/_Collapse/Collapse';
|
|
15
16
|
export { default as ContentArea } from './components/ContentArea/ContentArea';
|
|
16
17
|
export { default as ContentView } from './components/ContentView/ContentView';
|
package/dist/es/index.js
CHANGED
|
@@ -10,7 +10,8 @@ export { default as Checkbox } from "./components/Checkbox/Checkbox";
|
|
|
10
10
|
export { default as checkBreakpointsPropTypes } from "./components/Carousel/checkBreakpointsPropTypes";
|
|
11
11
|
export { default as Chip } from "./components/Chips/Chip";
|
|
12
12
|
export { default as Chips } from "./components/Chips/Chips";
|
|
13
|
-
export { default as ChipsDropdown } from "./components/Chips/components/ChipsDropdown";
|
|
13
|
+
export { default as ChipsDropdown } from "./components/Chips/components/ChipsDropdown/ChipsDropdown";
|
|
14
|
+
export { default as ChipsScrollPanel } from "./components/Chips/components/ChipsScrollPanel/ChipsScrollPanel";
|
|
14
15
|
export { default as Collapse } from "./components/_Collapse/Collapse";
|
|
15
16
|
export { default as ContentArea } from "./components/ContentArea/ContentArea";
|
|
16
17
|
export { default as ContentView } from "./components/ContentView/ContentView";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
h1,h2,h3,h4,h5{margin:0}.mfui-chip{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;font-family:inherit;font-size:15px;font-weight:500;line-height:24px;-webkit-box-align:center;-ms-flex-align:center;align-items:center
|
|
1
|
+
h1,h2,h3,h4,h5{margin:0}.mfui-chip{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;font-family:inherit;font-size:15px;font-weight:500;line-height:24px;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:var(--spbSky0);border:none;border-radius:20px;-webkit-box-sizing:border-box;box-sizing:border-box;color:var(--content);overflow:hidden;padding:8px 20px;text-align:center;text-decoration:none;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-appearance:none;-moz-appearance:none;appearance:none;cursor:pointer;outline:none;-webkit-transition:background-color .3s,color .3s;transition:background-color .3s,color .3s}.mfui-chip svg{-webkit-transition:fill .3s;transition:fill .3s;fill:var(--content)}@media screen and (max-width:767px){.mfui-chip{padding:4px 12px}}.mfui-chip:hover{background-color:var(--spbSky1)}.mfui-chip__inner{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.mfui-chip__counter{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:var(--spbSky3);margin-left:6px}@media screen and (max-width:767px){.mfui-chip__counter{margin-left:4px}}.mfui-chip__icon,.mfui-chip__icon-arrow{display:block;max-height:20px;min-width:20px;width:20px}.mfui-chip__icon svg,.mfui-chip__icon-arrow svg{display:block;height:100%;width:100%}.mfui-chip__icon{margin-right:6px}@media screen and (max-width:767px){.mfui-chip__icon{margin-right:4px}}.mfui-chip_disabled,.mfui-chip_disabled:hover{background-color:var(--spbSky0);color:var(--spbSky3);cursor:default;pointer-events:none}.mfui-chip_disabled svg,.mfui-chip_disabled:hover svg{fill:var(--spbSky3)}.mfui-chip_disabled .mfui-chip__counter,.mfui-chip_disabled:hover .mfui-chip__counter{color:var(--spbSky2)}.mfui-chip_checked,.mfui-chip_checked:hover{background-color:var(--night);color:var(--stcWhite)}.mfui-chip_checked svg,.mfui-chip_checked:hover svg{fill:var(--stcWhite)}.mfui-chip_checked .mfui-chip__counter,.mfui-chip_checked:hover .mfui-chip__counter{color:var(--stcWhite)}.mfui-chip_checked.mfui-chip_color_black,.mfui-chip_checked.mfui-chip_color_black:hover{background-color:var(--content);color:var(--base)}.mfui-chip_checked.mfui-chip_color_black svg,.mfui-chip_checked.mfui-chip_color_black:hover svg{fill:var(--base)}.mfui-chip_checked.mfui-chip_color_black .mfui-chip__counter,.mfui-chip_checked.mfui-chip_color_black:hover .mfui-chip__counter{color:var(--base)}.mfui-chip_with-icon{padding-left:16px}@media screen and (max-width:767px){.mfui-chip_with-icon{padding-left:8px}}
|
|
@@ -14,6 +14,8 @@ export type ChipArrowType = (typeof ChipArrow)[keyof typeof ChipArrow];
|
|
|
14
14
|
export interface IChipProps {
|
|
15
15
|
/** Идентификатор */
|
|
16
16
|
id: ChipIdType;
|
|
17
|
+
/** Заголовок */
|
|
18
|
+
title?: string;
|
|
17
19
|
/** Набор цветов для компонента */
|
|
18
20
|
color?: ChipColorsType;
|
|
19
21
|
/** Отображение в отмеченном (зажатом) состоянии */
|
|
@@ -35,6 +37,7 @@ export interface IChipProps {
|
|
|
35
37
|
/** Дополнительные классы для внутренних элементов */
|
|
36
38
|
classes?: {
|
|
37
39
|
root?: string;
|
|
40
|
+
checked?: string;
|
|
38
41
|
inner?: string;
|
|
39
42
|
icon?: string;
|
|
40
43
|
counter?: string;
|
|
@@ -40,6 +40,7 @@ var ChipArrow = exports.ChipArrow = {
|
|
|
40
40
|
var cn = (0, _uiHelpers.cnCreate)('mfui-chip');
|
|
41
41
|
var Chip = function Chip(_ref) {
|
|
42
42
|
var id = _ref.id,
|
|
43
|
+
title = _ref.title,
|
|
43
44
|
_ref$color = _ref.color,
|
|
44
45
|
color = _ref$color === void 0 ? 'default' : _ref$color,
|
|
45
46
|
_ref$checked = _ref.checked,
|
|
@@ -56,6 +57,7 @@ var Chip = function Chip(_ref) {
|
|
|
56
57
|
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
57
58
|
dataAttrs = _ref.dataAttrs,
|
|
58
59
|
rootRef = _ref.rootRef;
|
|
60
|
+
var checkedClass = checked ? classes.checked : undefined;
|
|
59
61
|
var handleClick = React.useCallback(function (e) {
|
|
60
62
|
onClick === null || onClick === void 0 ? void 0 : onClick(e, id);
|
|
61
63
|
}, [onClick, id]);
|
|
@@ -66,7 +68,7 @@ var Chip = function Chip(_ref) {
|
|
|
66
68
|
checked: checked,
|
|
67
69
|
disabled: disabled,
|
|
68
70
|
'with-icon': !!icon
|
|
69
|
-
}, [className, classes.root])
|
|
71
|
+
}, [className, classes.root, checkedClass])
|
|
70
72
|
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
|
|
71
73
|
disabled: disabled,
|
|
72
74
|
onClick: handleClick,
|
|
@@ -75,7 +77,7 @@ var Chip = function Chip(_ref) {
|
|
|
75
77
|
className: cn('icon', [classes.icon])
|
|
76
78
|
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.icon)), icon), /*#__PURE__*/React.createElement("span", (0, _extends2["default"])({
|
|
77
79
|
className: cn('inner', [classes.inner])
|
|
78
|
-
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.inner)), children), !!counterValue && /*#__PURE__*/React.createElement("span", (0, _extends2["default"])({
|
|
80
|
+
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.inner)), children || title), !!counterValue && /*#__PURE__*/React.createElement("span", (0, _extends2["default"])({
|
|
79
81
|
className: cn('counter', [classes.counter])
|
|
80
82
|
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.counter)), counterValue), !!arrow && /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
|
|
81
83
|
className: cn('icon-arrow')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
h1,h2,h3,h4,h5{margin:0}.mfui-chips{display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:12px;width:100%}@media screen and (max-width:767px){.mfui-chips{gap:8px}}.mfui-chips_hidden{display:grid;grid-template-columns:repeat(auto-fit,minMax(0,-webkit-min-content));grid-template-columns:repeat(auto-fit,minMax(0,min-content))}
|
|
1
|
+
h1,h2,h3,h4,h5{margin:0}.mfui-chips{display:-webkit-box;display:-ms-flexbox;display:flex;-ms-flex-wrap:wrap;flex-wrap:wrap;gap:12px;width:100%}@media screen and (max-width:767px){.mfui-chips{gap:8px}}.mfui-chips_hidden{display:grid;grid-template-columns:repeat(auto-fit,minMax(0,-webkit-min-content));grid-template-columns:repeat(auto-fit,minMax(0,min-content))}.mfui-chips_align_center{-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}
|
|
@@ -4,10 +4,16 @@ import './Chips.scss';
|
|
|
4
4
|
export interface IChipsProps {
|
|
5
5
|
/** Массив элементов */
|
|
6
6
|
items: IChipProps[];
|
|
7
|
-
/** Значение */
|
|
8
|
-
value
|
|
7
|
+
/** Значение (идентификатор активного элемента). Начальное значение в неконтролируемом состоянии */
|
|
8
|
+
value?: ChipIdType;
|
|
9
9
|
/** Цвет активного элемента */
|
|
10
10
|
color?: ChipColorsType;
|
|
11
|
+
/** Горизонтальное выравнивание */
|
|
12
|
+
align?: 'left' | 'center';
|
|
13
|
+
/** Переводит компонент в контролируемое состояние */
|
|
14
|
+
isControlled?: boolean;
|
|
15
|
+
/** Горизонтальный скролл (отключается на разрешениях, для которых задан лимит отображаемых элементов) */
|
|
16
|
+
isScrollable?: boolean;
|
|
11
17
|
/** Количество отображаемых элементов на всех разрешениях экрана */
|
|
12
18
|
visibleItemsCountAll?: number;
|
|
13
19
|
/** Количество отображаемых элементов на разрешении 768 - 1023 */
|
|
@@ -22,6 +28,14 @@ export interface IChipsProps {
|
|
|
22
28
|
onChange?: (id: ChipIdType, e?: React.SyntheticEvent<EventTarget>) => void;
|
|
23
29
|
/** Дополнительный класс корневого элемента */
|
|
24
30
|
className?: string;
|
|
31
|
+
/** Дополнительные классы для внутренних элементов */
|
|
32
|
+
classes?: {
|
|
33
|
+
root?: string;
|
|
34
|
+
};
|
|
35
|
+
/** Дополнительные data атрибуты к внутренним элементам */
|
|
36
|
+
dataAttrs?: {
|
|
37
|
+
root?: Record<string, string>;
|
|
38
|
+
};
|
|
25
39
|
}
|
|
26
40
|
declare const Chips: React.FC<IChipsProps>;
|
|
27
41
|
export default Chips;
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
require("core-js/modules/es.symbol.js");
|
|
11
|
+
require("core-js/modules/es.array.index-of.js");
|
|
10
12
|
require("core-js/modules/es.array.map.js");
|
|
11
13
|
require("core-js/modules/es.array.slice.js");
|
|
12
14
|
var React = _interopRequireWildcard(require("react"));
|
|
@@ -14,10 +16,19 @@ var _uiHelpers = require("@megafon/ui-helpers");
|
|
|
14
16
|
var _lodash = _interopRequireDefault(require("lodash.throttle"));
|
|
15
17
|
var _throttleTime = _interopRequireDefault(require("../../constants/throttleTime"));
|
|
16
18
|
var _Chip = _interopRequireDefault(require("./Chip"));
|
|
17
|
-
var _ChipsDropdown = _interopRequireDefault(require("./components/ChipsDropdown"));
|
|
19
|
+
var _ChipsDropdown = _interopRequireDefault(require("./components/ChipsDropdown/ChipsDropdown"));
|
|
20
|
+
var _ChipsScrollPanel = _interopRequireDefault(require("./components/ChipsScrollPanel/ChipsScrollPanel"));
|
|
18
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
19
22
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
20
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
24
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
25
|
+
var t = {};
|
|
26
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
27
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
28
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
};
|
|
21
32
|
var DESKTOP_SMALL_START = _uiHelpers.breakpoints.DESKTOP_SMALL_START,
|
|
22
33
|
DESKTOP_MIDDLE_START = _uiHelpers.breakpoints.DESKTOP_MIDDLE_START,
|
|
23
34
|
MOBILE_BIG_START = _uiHelpers.breakpoints.MOBILE_BIG_START;
|
|
@@ -33,12 +44,20 @@ var Chips = function Chips(_ref) {
|
|
|
33
44
|
visibleItemsCountTablet = _ref.visibleItemsCountTablet,
|
|
34
45
|
visibleItemsCountDesktop = _ref.visibleItemsCountDesktop,
|
|
35
46
|
visibleItemsCountWide = _ref.visibleItemsCountWide,
|
|
47
|
+
_ref$isScrollable = _ref.isScrollable,
|
|
48
|
+
isScrollable = _ref$isScrollable === void 0 ? false : _ref$isScrollable,
|
|
49
|
+
_ref$isControlled = _ref.isControlled,
|
|
50
|
+
isControlled = _ref$isControlled === void 0 ? false : _ref$isControlled,
|
|
51
|
+
align = _ref.align,
|
|
36
52
|
onChange = _ref.onChange,
|
|
37
|
-
className = _ref.className
|
|
53
|
+
className = _ref.className,
|
|
54
|
+
_ref$classes = _ref.classes,
|
|
55
|
+
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
56
|
+
dataAttrs = _ref.dataAttrs;
|
|
38
57
|
var _React$useState = React.useState(value),
|
|
39
58
|
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
|
|
40
|
-
|
|
41
|
-
|
|
59
|
+
innerSelectedId = _React$useState2[0],
|
|
60
|
+
setInnerSelectedId = _React$useState2[1];
|
|
42
61
|
var _React$useState3 = React.useState(visibleItemsCountAll),
|
|
43
62
|
_React$useState4 = (0, _slicedToArray2["default"])(_React$useState3, 2),
|
|
44
63
|
visibleItemsCount = _React$useState4[0],
|
|
@@ -51,13 +70,40 @@ var Chips = function Chips(_ref) {
|
|
|
51
70
|
_React$useState8 = (0, _slicedToArray2["default"])(_React$useState7, 2),
|
|
52
71
|
hiddenItems = _React$useState8[0],
|
|
53
72
|
setHiddenItems = _React$useState8[1];
|
|
73
|
+
var _React$useState9 = React.useState(isScrollable && !visibleItemsCount),
|
|
74
|
+
_React$useState10 = (0, _slicedToArray2["default"])(_React$useState9, 2),
|
|
75
|
+
isScrollableMode = _React$useState10[0],
|
|
76
|
+
setIsScrollableMode = _React$useState10[1];
|
|
77
|
+
var selectedId = isControlled ? value : innerSelectedId;
|
|
54
78
|
var handleClick = React.useCallback(function (e, id) {
|
|
55
79
|
e.persist();
|
|
56
|
-
if (id) {
|
|
57
|
-
|
|
80
|
+
if (id && id !== selectedId) {
|
|
81
|
+
!isControlled && setInnerSelectedId(id);
|
|
58
82
|
onChange === null || onChange === void 0 ? void 0 : onChange(id, e);
|
|
59
83
|
}
|
|
60
|
-
}, [onChange]);
|
|
84
|
+
}, [isControlled, onChange, selectedId]);
|
|
85
|
+
var renderItems = function renderItems() {
|
|
86
|
+
if (isScrollableMode) {
|
|
87
|
+
return /*#__PURE__*/React.createElement(_ChipsScrollPanel["default"], {
|
|
88
|
+
value: selectedId,
|
|
89
|
+
items: visibleItems,
|
|
90
|
+
color: color,
|
|
91
|
+
onClick: handleClick
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return visibleItems.map(function (_a) {
|
|
95
|
+
var id = _a.id,
|
|
96
|
+
children = _a.children,
|
|
97
|
+
rest = __rest(_a, ["id", "children"]);
|
|
98
|
+
return /*#__PURE__*/React.createElement(_Chip["default"], (0, _extends2["default"])({
|
|
99
|
+
key: id,
|
|
100
|
+
id: id,
|
|
101
|
+
checked: id === selectedId,
|
|
102
|
+
color: color,
|
|
103
|
+
onClick: handleClick
|
|
104
|
+
}, rest), !!children && children);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
61
107
|
React.useEffect(function () {
|
|
62
108
|
var resizeHandler = function resizeHandler() {
|
|
63
109
|
var windowWidth = window.innerWidth;
|
|
@@ -91,19 +137,15 @@ var Chips = function Chips(_ref) {
|
|
|
91
137
|
setHiddenItems(null);
|
|
92
138
|
}
|
|
93
139
|
}, [items, visibleItemsCount]);
|
|
94
|
-
|
|
140
|
+
React.useEffect(function () {
|
|
141
|
+
setIsScrollableMode(isScrollable && !visibleItemsCount);
|
|
142
|
+
}, [isScrollable, visibleItemsCount]);
|
|
143
|
+
return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
|
|
95
144
|
className: cn({
|
|
96
|
-
hidden: !!hiddenItems
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
key: item.id
|
|
101
|
-
}, item, {
|
|
102
|
-
checked: item.id === selectedId,
|
|
103
|
-
color: color,
|
|
104
|
-
onClick: handleClick
|
|
105
|
-
}), !!(item === null || item === void 0 ? void 0 : item.children) && item.children);
|
|
106
|
-
}), !!hiddenItems && /*#__PURE__*/React.createElement(_ChipsDropdown["default"], {
|
|
145
|
+
hidden: !!hiddenItems,
|
|
146
|
+
align: align
|
|
147
|
+
}, [className, classes.root])
|
|
148
|
+
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root)), renderItems(), !!hiddenItems && /*#__PURE__*/React.createElement(_ChipsDropdown["default"], {
|
|
107
149
|
value: selectedId,
|
|
108
150
|
items: hiddenItems,
|
|
109
151
|
moreTitle: moreTitle,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ChipColorsType, ChipIdType, IChipProps } from '
|
|
2
|
+
import { ChipColorsType, ChipIdType, IChipProps } from '../../Chip';
|
|
3
3
|
import './ChipsDropdown.scss';
|
|
4
4
|
export interface IChipsDropdownProps {
|
|
5
5
|
moreTitle: string;
|
|
6
|
-
value
|
|
6
|
+
value?: ChipIdType;
|
|
7
7
|
items: IChipProps[];
|
|
8
8
|
color: ChipColorsType;
|
|
9
9
|
onClick: (e: React.SyntheticEvent<EventTarget>, id: ChipIdType) => void;
|
package/dist/lib/components/Chips/components/{ChipsDropdown.js → ChipsDropdown/ChipsDropdown.js}
RENAMED
|
@@ -12,7 +12,7 @@ require("core-js/modules/es.array.map.js");
|
|
|
12
12
|
require("core-js/modules/es.object.to-string.js");
|
|
13
13
|
var React = _interopRequireWildcard(require("react"));
|
|
14
14
|
var _uiHelpers = require("@megafon/ui-helpers");
|
|
15
|
-
var _Chip = _interopRequireDefault(require("
|
|
15
|
+
var _Chip = _interopRequireDefault(require("../../Chip"));
|
|
16
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
@@ -80,16 +80,19 @@ var ChipsDropdown = function ChipsDropdown(_ref) {
|
|
|
80
80
|
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.list)), /*#__PURE__*/React.createElement("div", {
|
|
81
81
|
className: cn('list-inner')
|
|
82
82
|
}, items.map(function (item, key) {
|
|
83
|
+
var children = item.children,
|
|
84
|
+
title = item.title,
|
|
85
|
+
icon = item.icon;
|
|
83
86
|
return /*#__PURE__*/React.createElement("div", {
|
|
84
87
|
key: key,
|
|
85
88
|
className: cn('list-item', {
|
|
86
|
-
'with-icon': !!
|
|
89
|
+
'with-icon': !!icon
|
|
87
90
|
}),
|
|
88
91
|
onClick: handleItemClick(item),
|
|
89
92
|
onKeyDown: handleItemClick(item)
|
|
90
|
-
}, !!
|
|
93
|
+
}, !!icon && /*#__PURE__*/React.createElement("span", {
|
|
91
94
|
className: cn('icon')
|
|
92
|
-
},
|
|
95
|
+
}, icon), children || title);
|
|
93
96
|
}))));
|
|
94
97
|
};
|
|
95
98
|
var _default = exports["default"] = ChipsDropdown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
h1,h2,h3,h4,h5{margin:0}.mfui-chips-scroll-panel{display:-webkit-box;display:-ms-flexbox;display:flex;height:100%;overflow-x:auto;overflow-y:hidden;position:relative;-ms-overflow-style:none;scrollbar-width:none}.mfui-chips-scroll-panel::-webkit-scrollbar{display:none}.mfui-chips-scroll-panel__inner{display:-webkit-box;display:-ms-flexbox;display:flex;gap:12px;height:100%}@media screen and (max-width:767px){.mfui-chips-scroll-panel__inner{gap:8px}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChipColorsType, ChipIdType, IChipProps } from '../../Chip';
|
|
3
|
+
import './ChipsScrollPanel.scss';
|
|
4
|
+
export interface IChipsScrollPanelProps {
|
|
5
|
+
value?: ChipIdType;
|
|
6
|
+
items: IChipProps[];
|
|
7
|
+
color: ChipColorsType;
|
|
8
|
+
onClick: (e: React.SyntheticEvent<EventTarget>, id?: ChipIdType) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const ChipsScrollPanel: React.FC<IChipsScrollPanelProps>;
|
|
11
|
+
export default ChipsScrollPanel;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
require("core-js/modules/es.symbol.js");
|
|
11
|
+
require("core-js/modules/es.array.index-of.js");
|
|
12
|
+
require("core-js/modules/es.array.map.js");
|
|
13
|
+
var React = _interopRequireWildcard(require("react"));
|
|
14
|
+
var _uiHelpers = require("@megafon/ui-helpers");
|
|
15
|
+
var _Chip = _interopRequireDefault(require("../../Chip"));
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
18
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
19
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
20
|
+
var t = {};
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
22
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
};
|
|
27
|
+
var HALF_DIVIDER = 2;
|
|
28
|
+
var cn = (0, _uiHelpers.cnCreate)('mfui-chips-scroll-panel');
|
|
29
|
+
var ChipsScrollPanel = function ChipsScrollPanel(_ref) {
|
|
30
|
+
var value = _ref.value,
|
|
31
|
+
items = _ref.items,
|
|
32
|
+
color = _ref.color,
|
|
33
|
+
onClick = _ref.onClick;
|
|
34
|
+
var _React$useState = React.useState(),
|
|
35
|
+
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
|
|
36
|
+
currentValue = _React$useState2[0],
|
|
37
|
+
setCurrentValue = _React$useState2[1];
|
|
38
|
+
var containerRef = React.useRef(null);
|
|
39
|
+
var checkedItemRef = React.useRef(null);
|
|
40
|
+
var scrollToActiveItem = React.useCallback(function () {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
if (!containerRef.current || !checkedItemRef.current) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var activeItemElement = checkedItemRef.current;
|
|
46
|
+
var _activeItemElement$ge = activeItemElement.getBoundingClientRect(),
|
|
47
|
+
itemWidth = _activeItemElement$ge.width;
|
|
48
|
+
var itemOffsetLeft = activeItemElement.offsetLeft;
|
|
49
|
+
var panelCenter = containerRef.current.getBoundingClientRect().width / HALF_DIVIDER;
|
|
50
|
+
var itemCenter = itemWidth / HALF_DIVIDER;
|
|
51
|
+
var activeItemPosition = itemOffsetLeft - panelCenter + itemCenter;
|
|
52
|
+
(_b = (_a = containerRef.current).scrollTo) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
53
|
+
left: activeItemPosition,
|
|
54
|
+
behavior: 'smooth'
|
|
55
|
+
});
|
|
56
|
+
}, []);
|
|
57
|
+
var handleClick = React.useCallback(function (e, id) {
|
|
58
|
+
onClick(e, id);
|
|
59
|
+
scrollToActiveItem();
|
|
60
|
+
}, [onClick, scrollToActiveItem]);
|
|
61
|
+
React.useEffect(function () {
|
|
62
|
+
var isCurrentValueActual = currentValue === value;
|
|
63
|
+
if (isCurrentValueActual) {
|
|
64
|
+
scrollToActiveItem();
|
|
65
|
+
} else {
|
|
66
|
+
setCurrentValue(value);
|
|
67
|
+
}
|
|
68
|
+
}, [value, currentValue, scrollToActiveItem]);
|
|
69
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
className: cn(),
|
|
71
|
+
ref: containerRef
|
|
72
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
73
|
+
className: cn('inner'),
|
|
74
|
+
tabIndex: -1
|
|
75
|
+
}, items.map(function (_a) {
|
|
76
|
+
var id = _a.id,
|
|
77
|
+
children = _a.children,
|
|
78
|
+
rest = __rest(_a, ["id", "children"]);
|
|
79
|
+
var checked = id === value;
|
|
80
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
81
|
+
key: id,
|
|
82
|
+
className: cn('slide')
|
|
83
|
+
}, /*#__PURE__*/React.createElement(_Chip["default"], (0, _extends2["default"])({}, rest, {
|
|
84
|
+
id: id,
|
|
85
|
+
checked: checked,
|
|
86
|
+
color: color,
|
|
87
|
+
onClick: handleClick,
|
|
88
|
+
rootRef: checked ? checkedItemRef : null
|
|
89
|
+
}), children));
|
|
90
|
+
})));
|
|
91
|
+
};
|
|
92
|
+
var _default = exports["default"] = ChipsScrollPanel;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export { default as Checkbox } from './components/Checkbox/Checkbox';
|
|
|
10
10
|
export { default as checkBreakpointsPropTypes } from './components/Carousel/checkBreakpointsPropTypes';
|
|
11
11
|
export { default as Chip } from './components/Chips/Chip';
|
|
12
12
|
export { default as Chips } from './components/Chips/Chips';
|
|
13
|
-
export { default as ChipsDropdown } from './components/Chips/components/ChipsDropdown';
|
|
13
|
+
export { default as ChipsDropdown } from './components/Chips/components/ChipsDropdown/ChipsDropdown';
|
|
14
|
+
export { default as ChipsScrollPanel } from './components/Chips/components/ChipsScrollPanel/ChipsScrollPanel';
|
|
14
15
|
export { default as Collapse } from './components/_Collapse/Collapse';
|
|
15
16
|
export { default as ContentArea } from './components/ContentArea/ContentArea';
|
|
16
17
|
export { default as ContentView } from './components/ContentView/ContentView';
|
package/dist/lib/index.js
CHANGED
|
@@ -75,6 +75,12 @@ Object.defineProperty(exports, "ChipsDropdown", {
|
|
|
75
75
|
return _ChipsDropdown["default"];
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
+
Object.defineProperty(exports, "ChipsScrollPanel", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function get() {
|
|
81
|
+
return _ChipsScrollPanel["default"];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
Object.defineProperty(exports, "Collapse", {
|
|
79
85
|
enumerable: true,
|
|
80
86
|
get: function get() {
|
|
@@ -513,7 +519,8 @@ var _Checkbox = _interopRequireDefault(require("./components/Checkbox/Checkbox")
|
|
|
513
519
|
var _checkBreakpointsPropTypes = _interopRequireDefault(require("./components/Carousel/checkBreakpointsPropTypes"));
|
|
514
520
|
var _Chip = _interopRequireDefault(require("./components/Chips/Chip"));
|
|
515
521
|
var _Chips = _interopRequireDefault(require("./components/Chips/Chips"));
|
|
516
|
-
var _ChipsDropdown = _interopRequireDefault(require("./components/Chips/components/ChipsDropdown"));
|
|
522
|
+
var _ChipsDropdown = _interopRequireDefault(require("./components/Chips/components/ChipsDropdown/ChipsDropdown"));
|
|
523
|
+
var _ChipsScrollPanel = _interopRequireDefault(require("./components/Chips/components/ChipsScrollPanel/ChipsScrollPanel"));
|
|
517
524
|
var _Collapse = _interopRequireDefault(require("./components/_Collapse/Collapse"));
|
|
518
525
|
var _ContentArea = _interopRequireDefault(require("./components/ContentArea/ContentArea"));
|
|
519
526
|
var _ContentView = _interopRequireDefault(require("./components/ContentView/ContentView"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@megafon/ui-core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"styles"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@babel/preset-env": "^7.8.6",
|
|
51
51
|
"@babel/preset-react": "^7.8.3",
|
|
52
52
|
"@babel/preset-typescript": "^7.8.3",
|
|
53
|
-
"@megafon/ui-icons": "^3.
|
|
53
|
+
"@megafon/ui-icons": "^3.10.0",
|
|
54
54
|
"@svgr/core": "^2.4.1",
|
|
55
55
|
"@testing-library/jest-dom": "^6.5.0",
|
|
56
56
|
"@testing-library/react": "^16.0.1",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"simplebar-react": "^3.2.5",
|
|
105
105
|
"swiper": "^11.1.1"
|
|
106
106
|
},
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "443402b98607c898eda4e767dd06b15d10ca705b"
|
|
108
108
|
}
|
/package/dist/es/components/Chips/components/{ChipsDropdown.css → ChipsDropdown/ChipsDropdown.css}
RENAMED
|
File without changes
|
/package/dist/lib/components/Chips/components/{ChipsDropdown.css → ChipsDropdown/ChipsDropdown.css}
RENAMED
|
File without changes
|