@megafon/ui-core 5.16.0 → 5.18.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 +31 -0
- package/dist/es/components/Banner/Banner.css +43 -32
- package/dist/es/components/Banner/Banner.d.ts +8 -3
- package/dist/es/components/Banner/Banner.js +62 -44
- package/dist/es/components/Banner/BannerDot.css +9 -16
- package/dist/es/components/Banner/BannerDot.d.ts +0 -7
- package/dist/es/components/Banner/BannerDot.js +5 -14
- package/dist/es/components/Banner/slidesSettings.d.ts +5 -0
- package/dist/es/components/Banner/slidesSettings.js +13 -0
- package/dist/es/components/Button/Button.css +3 -0
- package/dist/es/components/ContentView/ContentView.d.ts +1 -0
- package/dist/es/components/ContentView/ContentView.js +9 -3
- package/dist/es/components/ListData/ListData.css +162 -0
- package/dist/es/components/ListData/ListData.d.ts +94 -0
- package/dist/es/components/ListData/ListData.js +203 -0
- package/dist/es/components/ListData/ListDataGroup.css +15 -0
- package/dist/es/components/ListData/ListDataGroup.d.ts +46 -0
- package/dist/es/components/ListData/ListDataGroup.js +195 -0
- package/dist/es/components/ListData/components/ListDataSortable.css +79 -0
- package/dist/es/components/ListData/components/ListDataSortable.d.ts +34 -0
- package/dist/es/components/ListData/components/ListDataSortable.js +102 -0
- package/dist/es/components/ListData/doc/i/img.png +0 -0
- package/dist/es/components/ListData/helpers.d.ts +6 -0
- package/dist/es/components/ListData/helpers.js +40 -0
- package/dist/es/components/Search/Search.d.ts +1 -0
- package/dist/es/components/Search/Search.js +2 -2
- package/dist/es/components/Snackbar/SnackbarTimer/SnackbarTimer.css +1 -1
- package/dist/es/index.d.ts +4 -0
- package/dist/es/index.js +4 -0
- package/dist/lib/components/Banner/Banner.css +43 -32
- package/dist/lib/components/Banner/Banner.d.ts +8 -3
- package/dist/lib/components/Banner/Banner.js +63 -44
- package/dist/lib/components/Banner/BannerDot.css +9 -16
- package/dist/lib/components/Banner/BannerDot.d.ts +0 -7
- package/dist/lib/components/Banner/BannerDot.js +6 -17
- package/dist/lib/components/Banner/slidesSettings.d.ts +5 -0
- package/dist/lib/components/Banner/slidesSettings.js +24 -0
- package/dist/lib/components/Button/Button.css +3 -0
- package/dist/lib/components/ContentView/ContentView.d.ts +1 -0
- package/dist/lib/components/ContentView/ContentView.js +8 -2
- package/dist/lib/components/ListData/ListData.css +162 -0
- package/dist/lib/components/ListData/ListData.d.ts +94 -0
- package/dist/lib/components/ListData/ListData.js +229 -0
- package/dist/lib/components/ListData/ListDataGroup.css +15 -0
- package/dist/lib/components/ListData/ListDataGroup.d.ts +46 -0
- package/dist/lib/components/ListData/ListDataGroup.js +229 -0
- package/dist/lib/components/ListData/components/ListDataSortable.css +79 -0
- package/dist/lib/components/ListData/components/ListDataSortable.d.ts +34 -0
- package/dist/lib/components/ListData/components/ListDataSortable.js +129 -0
- package/dist/lib/components/ListData/doc/i/img.png +0 -0
- package/dist/lib/components/ListData/helpers.d.ts +6 -0
- package/dist/lib/components/ListData/helpers.js +58 -0
- package/dist/lib/components/Search/Search.d.ts +1 -0
- package/dist/lib/components/Search/Search.js +2 -2
- package/dist/lib/components/Snackbar/SnackbarTimer/SnackbarTimer.css +1 -1
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/index.js +32 -0
- package/package.json +5 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as PropTypes from 'prop-types';
|
|
3
|
+
import './ListData.less';
|
|
4
|
+
declare type Target = '_self' | '_blank' | '_parent' | '_top';
|
|
5
|
+
export declare type TitlePropsType = {
|
|
6
|
+
/** Текст заголовка */
|
|
7
|
+
text: string;
|
|
8
|
+
/** Ссылка */
|
|
9
|
+
href: string;
|
|
10
|
+
/** Атрибут ссылки target */
|
|
11
|
+
target?: Target;
|
|
12
|
+
/** Атрибут ссылки rel */
|
|
13
|
+
rel?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const ValueColors: {
|
|
16
|
+
readonly DEFAULT: "default";
|
|
17
|
+
readonly GREEN: "green";
|
|
18
|
+
};
|
|
19
|
+
export declare type ValueColorsType = typeof ValueColors[keyof typeof ValueColors];
|
|
20
|
+
declare const Actions: {
|
|
21
|
+
readonly DELETE: "delete";
|
|
22
|
+
readonly CONTROL: "control";
|
|
23
|
+
};
|
|
24
|
+
export declare type ActionsType = typeof Actions[keyof typeof Actions];
|
|
25
|
+
export interface IListDataProps {
|
|
26
|
+
/** Заголовок */
|
|
27
|
+
title: string | TitlePropsType;
|
|
28
|
+
/** Подзаголовок */
|
|
29
|
+
subTitle?: string;
|
|
30
|
+
/** Значение */
|
|
31
|
+
value?: string;
|
|
32
|
+
/** Цвет */
|
|
33
|
+
valueColor?: ValueColorsType;
|
|
34
|
+
/** Дополнительное значение */
|
|
35
|
+
subValue?: string;
|
|
36
|
+
/** Иконка */
|
|
37
|
+
icon?: JSX.Element;
|
|
38
|
+
/** Фоновая заливка у иконки */
|
|
39
|
+
isIconColored?: boolean;
|
|
40
|
+
/** Аватар */
|
|
41
|
+
avatar?: JSX.Element;
|
|
42
|
+
/** Отключение компонента */
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
/** Элемент дополнительного действия */
|
|
45
|
+
actionType?: ActionsType;
|
|
46
|
+
/** Обработчик дополнительного действия */
|
|
47
|
+
onAction?: (e: React.SyntheticEvent<EventTarget>) => void;
|
|
48
|
+
/** Обработчик клика */
|
|
49
|
+
onClick?: (e: React.SyntheticEvent<EventTarget>) => void;
|
|
50
|
+
/** Дополнительный класс корневого элемента */
|
|
51
|
+
className?: string;
|
|
52
|
+
/** Дополнительные классы для внутренних элементов */
|
|
53
|
+
classes?: {
|
|
54
|
+
root?: string;
|
|
55
|
+
title?: string;
|
|
56
|
+
subtitle?: string;
|
|
57
|
+
};
|
|
58
|
+
/** Дополнительные data атрибуты к внутренним элементам */
|
|
59
|
+
dataAttrs?: {
|
|
60
|
+
root?: Record<string, string>;
|
|
61
|
+
actionIcon?: Record<string, string>;
|
|
62
|
+
};
|
|
63
|
+
/** Дочерние элементы: Button, Selector */
|
|
64
|
+
children?: React.ReactNode;
|
|
65
|
+
}
|
|
66
|
+
declare const ListData: React.FC<IListDataProps>;
|
|
67
|
+
export declare const ListDataPropType: {
|
|
68
|
+
title: PropTypes.Validator<string | PropTypes.InferProps<{
|
|
69
|
+
text: PropTypes.Validator<string>;
|
|
70
|
+
href: PropTypes.Validator<string>;
|
|
71
|
+
target: PropTypes.Requireable<string>;
|
|
72
|
+
rel: PropTypes.Requireable<string>;
|
|
73
|
+
}>>;
|
|
74
|
+
subTitle: PropTypes.Requireable<string>;
|
|
75
|
+
value: PropTypes.Requireable<string>;
|
|
76
|
+
valueColor: PropTypes.Requireable<"default" | "green">;
|
|
77
|
+
subValue: PropTypes.Requireable<string>;
|
|
78
|
+
icon: PropTypes.Requireable<PropTypes.ReactElementLike>;
|
|
79
|
+
isIconColored: PropTypes.Requireable<boolean>;
|
|
80
|
+
avatar: PropTypes.Requireable<PropTypes.ReactElementLike>;
|
|
81
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
82
|
+
actionType: PropTypes.Requireable<"delete" | "control">;
|
|
83
|
+
onAction: PropTypes.Requireable<(...args: any[]) => any>;
|
|
84
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
85
|
+
className: PropTypes.Requireable<string>;
|
|
86
|
+
classes: PropTypes.Requireable<{
|
|
87
|
+
[x: string]: string | null | undefined;
|
|
88
|
+
}>;
|
|
89
|
+
dataAttrs: PropTypes.Requireable<{
|
|
90
|
+
[x: string]: object | null | undefined;
|
|
91
|
+
}>;
|
|
92
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
93
|
+
};
|
|
94
|
+
export default ListData;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof3(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof3 = function _typeof3(obj) { return typeof obj; }; } else { _typeof3 = function _typeof3(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof3(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = exports.ListDataPropType = void 0;
|
|
9
|
+
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
14
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
15
|
+
|
|
16
|
+
require("core-js/modules/es.parse-int.js");
|
|
17
|
+
|
|
18
|
+
require("core-js/modules/es.object.values.js");
|
|
19
|
+
|
|
20
|
+
var _react = _interopRequireDefault(require("react"));
|
|
21
|
+
|
|
22
|
+
var _uiHelpers = require("@megafon/ui-helpers");
|
|
23
|
+
|
|
24
|
+
var PropTypes = _interopRequireWildcard(require("prop-types"));
|
|
25
|
+
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
+
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
+
|
|
30
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
31
|
+
|
|
32
|
+
var DeleteIcon = function DeleteIcon(props) {
|
|
33
|
+
return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
|
|
34
|
+
viewBox: "0 0 20 20"
|
|
35
|
+
}, props), /*#__PURE__*/_react["default"].createElement("path", {
|
|
36
|
+
d: "M16 4h-3.2c-.4-1.2-1.5-2-2.8-2s-2.4.8-2.8 2H4v4h1l1 10h8l1-10h1V4zM5 5h3v-.4C8.2 3.7 9.1 3 10 3s1.8.7 2 1.6V5h3v2H5V5zm8 12H7l-.9-9H14l-1 9z"
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var NothingIcon = function NothingIcon(props) {
|
|
41
|
+
return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
|
|
42
|
+
viewBox: "0 0 32 32"
|
|
43
|
+
}, props), /*#__PURE__*/_react["default"].createElement("circle", {
|
|
44
|
+
cx: 21,
|
|
45
|
+
cy: 16,
|
|
46
|
+
r: 1.5
|
|
47
|
+
}), /*#__PURE__*/_react["default"].createElement("circle", {
|
|
48
|
+
cx: 16,
|
|
49
|
+
cy: 16,
|
|
50
|
+
r: 1.5
|
|
51
|
+
}), /*#__PURE__*/_react["default"].createElement("circle", {
|
|
52
|
+
cx: 11,
|
|
53
|
+
cy: 16,
|
|
54
|
+
r: 1.5
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var LINE_COUNT = 2;
|
|
59
|
+
var ValueColors = {
|
|
60
|
+
DEFAULT: 'default',
|
|
61
|
+
GREEN: 'green'
|
|
62
|
+
};
|
|
63
|
+
var Actions = {
|
|
64
|
+
DELETE: 'delete',
|
|
65
|
+
CONTROL: 'control'
|
|
66
|
+
};
|
|
67
|
+
var cn = (0, _uiHelpers.cnCreate)('mfui-list-data');
|
|
68
|
+
|
|
69
|
+
var ListData = function ListData(_ref) {
|
|
70
|
+
var title = _ref.title,
|
|
71
|
+
subTitle = _ref.subTitle,
|
|
72
|
+
value = _ref.value,
|
|
73
|
+
valueColor = _ref.valueColor,
|
|
74
|
+
subValue = _ref.subValue,
|
|
75
|
+
icon = _ref.icon,
|
|
76
|
+
_ref$isIconColored = _ref.isIconColored,
|
|
77
|
+
isIconColored = _ref$isIconColored === void 0 ? false : _ref$isIconColored,
|
|
78
|
+
avatar = _ref.avatar,
|
|
79
|
+
_ref$disabled = _ref.disabled,
|
|
80
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
81
|
+
actionType = _ref.actionType,
|
|
82
|
+
onClick = _ref.onClick,
|
|
83
|
+
onAction = _ref.onAction,
|
|
84
|
+
className = _ref.className,
|
|
85
|
+
_ref$classes = _ref.classes,
|
|
86
|
+
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
87
|
+
dataAttrs = _ref.dataAttrs,
|
|
88
|
+
children = _ref.children;
|
|
89
|
+
|
|
90
|
+
var valueRef = _react["default"].useRef(null);
|
|
91
|
+
|
|
92
|
+
var _React$useState = _react["default"].useState('right'),
|
|
93
|
+
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
|
|
94
|
+
valueAlignment = _React$useState2[0],
|
|
95
|
+
setValueAlignment = _React$useState2[1];
|
|
96
|
+
|
|
97
|
+
var isActive = !!onClick && !((0, _typeof2["default"])(title) === 'object' && (title === null || title === void 0 ? void 0 : title.href));
|
|
98
|
+
var showActionElement = !!actionType || !!children;
|
|
99
|
+
|
|
100
|
+
var handleClick = function handleClick(e) {
|
|
101
|
+
!disabled && (onClick === null || onClick === void 0 ? void 0 : onClick(e));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var handleAction = _react["default"].useCallback(function (e) {
|
|
105
|
+
e.stopPropagation();
|
|
106
|
+
!disabled && (onAction === null || onAction === void 0 ? void 0 : onAction(e));
|
|
107
|
+
}, [disabled, onAction]);
|
|
108
|
+
|
|
109
|
+
_react["default"].useEffect(function () {
|
|
110
|
+
if (!valueRef.current) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var lineHeight = parseInt(getComputedStyle(valueRef.current).lineHeight, 10);
|
|
115
|
+
var actualHeight = valueRef.current.offsetHeight;
|
|
116
|
+
var currentLineCount = actualHeight / lineHeight;
|
|
117
|
+
setValueAlignment(currentLineCount >= LINE_COUNT ? 'left' : 'right');
|
|
118
|
+
}, [value]);
|
|
119
|
+
|
|
120
|
+
var renderedTitle = /*#__PURE__*/_react["default"].createElement("div", {
|
|
121
|
+
className: cn('title', [classes.title])
|
|
122
|
+
}, typeof title === 'string' ? title : /*#__PURE__*/_react["default"].createElement("a", {
|
|
123
|
+
className: cn('title-link'),
|
|
124
|
+
href: title.href,
|
|
125
|
+
target: title === null || title === void 0 ? void 0 : title.target,
|
|
126
|
+
rel: title === null || title === void 0 ? void 0 : title.rel
|
|
127
|
+
}, title.text));
|
|
128
|
+
|
|
129
|
+
var renderIcon = function renderIcon() {
|
|
130
|
+
if (!icon && !avatar) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
135
|
+
className: cn('icon-container', {
|
|
136
|
+
colored: isIconColored && !avatar
|
|
137
|
+
})
|
|
138
|
+
}, avatar || /*#__PURE__*/_react["default"].createElement("div", {
|
|
139
|
+
className: cn('icon')
|
|
140
|
+
}, icon));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
var renderExtraContent = function renderExtraContent() {
|
|
144
|
+
if (children) {
|
|
145
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
146
|
+
className: cn('children', {
|
|
147
|
+
'event-none': !!onClick
|
|
148
|
+
})
|
|
149
|
+
}, children);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (value) {
|
|
153
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
154
|
+
className: cn('value-container')
|
|
155
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
156
|
+
className: cn('value', {
|
|
157
|
+
color: valueColor
|
|
158
|
+
}),
|
|
159
|
+
ref: valueRef,
|
|
160
|
+
style: {
|
|
161
|
+
textAlign: valueAlignment
|
|
162
|
+
}
|
|
163
|
+
}, (0, _uiHelpers.convert)(value, _uiHelpers.textConvertConfig)), !!subValue && /*#__PURE__*/_react["default"].createElement("div", {
|
|
164
|
+
className: cn('sub-value')
|
|
165
|
+
}, subValue));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (actionType) {
|
|
169
|
+
var isDelete = actionType === Actions.DELETE;
|
|
170
|
+
var ActionIcon = isDelete ? DeleteIcon : NothingIcon;
|
|
171
|
+
return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
|
|
172
|
+
className: cn('icon', {
|
|
173
|
+
small: isDelete
|
|
174
|
+
})
|
|
175
|
+
}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.actionIcon), {
|
|
176
|
+
onClick: handleAction
|
|
177
|
+
}), /*#__PURE__*/_react["default"].createElement(ActionIcon, {
|
|
178
|
+
className: cn('action-icon', {
|
|
179
|
+
active: !disabled
|
|
180
|
+
})
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return null;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
|
|
188
|
+
className: cn({
|
|
189
|
+
active: isActive,
|
|
190
|
+
disabled: disabled
|
|
191
|
+
}, [className, classes.root]),
|
|
192
|
+
onClick: handleClick
|
|
193
|
+
}), renderIcon(), /*#__PURE__*/_react["default"].createElement("div", {
|
|
194
|
+
className: cn('header', {
|
|
195
|
+
gap: showActionElement,
|
|
196
|
+
align: !!subTitle
|
|
197
|
+
})
|
|
198
|
+
}, renderedTitle, !!subTitle && /*#__PURE__*/_react["default"].createElement("div", {
|
|
199
|
+
className: cn('sub-title', [classes.subtitle])
|
|
200
|
+
}, subTitle)), renderExtraContent());
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
var ListDataPropType = {
|
|
204
|
+
title: PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
|
|
205
|
+
text: PropTypes.string.isRequired,
|
|
206
|
+
href: PropTypes.string.isRequired,
|
|
207
|
+
target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
|
|
208
|
+
rel: PropTypes.string
|
|
209
|
+
})]).isRequired,
|
|
210
|
+
subTitle: PropTypes.string,
|
|
211
|
+
value: PropTypes.string,
|
|
212
|
+
valueColor: PropTypes.oneOf(Object.values(ValueColors)),
|
|
213
|
+
subValue: PropTypes.string,
|
|
214
|
+
icon: PropTypes.element,
|
|
215
|
+
isIconColored: PropTypes.bool,
|
|
216
|
+
avatar: PropTypes.element,
|
|
217
|
+
disabled: PropTypes.bool,
|
|
218
|
+
actionType: PropTypes.oneOf(Object.values(Actions)),
|
|
219
|
+
onAction: PropTypes.func,
|
|
220
|
+
onClick: PropTypes.func,
|
|
221
|
+
className: PropTypes.string,
|
|
222
|
+
classes: PropTypes.objectOf(PropTypes.string),
|
|
223
|
+
dataAttrs: PropTypes.objectOf(PropTypes.object),
|
|
224
|
+
children: PropTypes.node
|
|
225
|
+
};
|
|
226
|
+
exports.ListDataPropType = ListDataPropType;
|
|
227
|
+
ListData.propTypes = ListDataPropType;
|
|
228
|
+
var _default = ListData;
|
|
229
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.mfui-list-data-group {
|
|
2
|
+
display: -webkit-box;
|
|
3
|
+
display: -ms-flexbox;
|
|
4
|
+
display: flex;
|
|
5
|
+
-webkit-box-orient: vertical;
|
|
6
|
+
-webkit-box-direction: normal;
|
|
7
|
+
-ms-flex-direction: column;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
-webkit-box-sizing: border-box;
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
overflow-y: hidden;
|
|
12
|
+
}
|
|
13
|
+
.mfui-list-data-group__item_divider:not(:last-child) {
|
|
14
|
+
border-bottom: 1px solid var(--spbSky1);
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DragEndEvent, DragStartEvent } from '@dnd-kit/core';
|
|
3
|
+
import { ActivatorNodesType, GapSizesType } from './components/ListDataSortable';
|
|
4
|
+
import { IListDataProps } from './ListData';
|
|
5
|
+
import './ListDataGroup.less';
|
|
6
|
+
export declare type ListItemPropsType = IListDataProps & {
|
|
7
|
+
id: string | number;
|
|
8
|
+
};
|
|
9
|
+
declare type DragOverlayPropsType = {
|
|
10
|
+
className?: string;
|
|
11
|
+
zIndex?: number;
|
|
12
|
+
};
|
|
13
|
+
export interface IListDataGroupProps {
|
|
14
|
+
/** Массив элементов */
|
|
15
|
+
items: ListItemPropsType[];
|
|
16
|
+
/** Активатор события перетаскивания */
|
|
17
|
+
activatorNode?: ActivatorNodesType;
|
|
18
|
+
/** Отступ между элементами */
|
|
19
|
+
gap?: GapSizesType;
|
|
20
|
+
/** Показать разделитель */
|
|
21
|
+
showDivider?: boolean;
|
|
22
|
+
/** Обработчик начала процесса перетаскивания */
|
|
23
|
+
onDragStart?: (event?: DragStartEvent) => void;
|
|
24
|
+
/** Обработчик окончания процесса перетаскивания */
|
|
25
|
+
onDragEnd?: (items: ListItemPropsType[], event?: DragEndEvent) => void;
|
|
26
|
+
/** Отключить перетаскивание */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/** Параметры DragOverlay элемента */
|
|
29
|
+
dragOverlayProps?: DragOverlayPropsType;
|
|
30
|
+
/** Дополнительный класс корневого элемента */
|
|
31
|
+
className?: string;
|
|
32
|
+
/** Дополнительные классы для внутренних элементов */
|
|
33
|
+
classes?: {
|
|
34
|
+
root?: string;
|
|
35
|
+
cell?: string;
|
|
36
|
+
control?: string;
|
|
37
|
+
};
|
|
38
|
+
/** Дополнительные data атрибуты к внутренним элементам */
|
|
39
|
+
dataAttrs?: {
|
|
40
|
+
root?: Record<string, string>;
|
|
41
|
+
cell?: Record<string, string>;
|
|
42
|
+
control?: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
declare const ListDataGroup: React.FC<IListDataGroupProps>;
|
|
46
|
+
export default ListDataGroup;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
14
|
+
require("core-js/modules/es.array.index-of.js");
|
|
15
|
+
|
|
16
|
+
require("core-js/modules/es.symbol.js");
|
|
17
|
+
|
|
18
|
+
require("core-js/modules/es.array.find-index.js");
|
|
19
|
+
|
|
20
|
+
require("core-js/modules/es.array.map.js");
|
|
21
|
+
|
|
22
|
+
require("core-js/modules/es.object.values.js");
|
|
23
|
+
|
|
24
|
+
var _react = _interopRequireDefault(require("react"));
|
|
25
|
+
|
|
26
|
+
var _core = require("@dnd-kit/core");
|
|
27
|
+
|
|
28
|
+
var _sortable = require("@dnd-kit/sortable");
|
|
29
|
+
|
|
30
|
+
var _uiHelpers = require("@megafon/ui-helpers");
|
|
31
|
+
|
|
32
|
+
var PropTypes = _interopRequireWildcard(require("prop-types"));
|
|
33
|
+
|
|
34
|
+
var _ListDataSortable = _interopRequireWildcard(require("./components/ListDataSortable"));
|
|
35
|
+
|
|
36
|
+
var _helpers = require("./helpers");
|
|
37
|
+
|
|
38
|
+
var _ListData = require("./ListData");
|
|
39
|
+
|
|
40
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
41
|
+
|
|
42
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
43
|
+
|
|
44
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
45
|
+
|
|
46
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
47
|
+
var t = {};
|
|
48
|
+
|
|
49
|
+
for (var p in s) {
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var SCREEN_READER_INSTRUCTION = "\u0427\u0442\u043E\u0431\u044B \u0432\u044B\u0431\u0440\u0430\u0442\u044C \u043F\u0435\u0440\u0435\u0442\u0430\u0441\u043A\u0438\u0432\u0430\u0435\u043C\u044B\u0439 \u044D\u043B\u0435\u043C\u0435\u043D\u0442, \u043D\u0430\u0436\u043C\u0438\u0442\u0435 \u043F\u0440\u043E\u0431\u0435\u043B.\n \u041F\u0440\u0438 \u043F\u0435\u0440\u0435\u0442\u0430\u0441\u043A\u0438\u0432\u0430\u043D\u0438\u0438 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 \u043A\u043B\u0430\u0432\u0438\u0448\u0438 \u0441\u043E \u0441\u0442\u0440\u0435\u043B\u043A\u0430\u043C\u0438 \u0434\u043B\u044F \u043F\u0435\u0440\u0435\u043C\u0435\u0449\u0435\u043D\u0438\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430.\n \u0421\u043D\u043E\u0432\u0430 \u043D\u0430\u0436\u043C\u0438\u0442\u0435 \u043F\u0440\u043E\u0431\u0435\u043B, \u0447\u0442\u043E\u0431\u044B \u043F\u0435\u0440\u0435\u043C\u0435\u0441\u0442\u0438\u0442\u044C \u044D\u043B\u0435\u043C\u0435\u043D\u0442 \u0432 \u0435\u0433\u043E \u043D\u043E\u0432\u043E\u0435 \u043F\u043E\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \u0438\u043B\u0438 \u043D\u0430\u0436\u043C\u0438\u0442\u0435 escape \u0434\u043B\u044F \u043E\u0442\u043C\u0435\u043D\u044B.";
|
|
60
|
+
var cn = (0, _uiHelpers.cnCreate)('mfui-list-data-group');
|
|
61
|
+
|
|
62
|
+
var ListDataGroup = function ListDataGroup(_ref) {
|
|
63
|
+
var items = _ref.items,
|
|
64
|
+
_ref$activatorNode = _ref.activatorNode,
|
|
65
|
+
activatorNode = _ref$activatorNode === void 0 ? _ListDataSortable.ActivatorNodes.CONTROL : _ref$activatorNode,
|
|
66
|
+
_ref$gap = _ref.gap,
|
|
67
|
+
gap = _ref$gap === void 0 ? _ListDataSortable.GapSizes.NONE : _ref$gap,
|
|
68
|
+
_ref$showDivider = _ref.showDivider,
|
|
69
|
+
showDivider = _ref$showDivider === void 0 ? false : _ref$showDivider,
|
|
70
|
+
onDragStart = _ref.onDragStart,
|
|
71
|
+
onDragEnd = _ref.onDragEnd,
|
|
72
|
+
_ref$disabled = _ref.disabled,
|
|
73
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
74
|
+
dragOverlayProps = _ref.dragOverlayProps,
|
|
75
|
+
className = _ref.className,
|
|
76
|
+
_ref$classes = _ref.classes,
|
|
77
|
+
classes = _ref$classes === void 0 ? {} : _ref$classes,
|
|
78
|
+
dataAttrs = _ref.dataAttrs;
|
|
79
|
+
|
|
80
|
+
var _React$useState = _react["default"].useState(items),
|
|
81
|
+
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
|
|
82
|
+
itemsList = _React$useState2[0],
|
|
83
|
+
setItemsList = _React$useState2[1];
|
|
84
|
+
|
|
85
|
+
var _React$useState3 = _react["default"].useState(null),
|
|
86
|
+
_React$useState4 = (0, _slicedToArray2["default"])(_React$useState3, 2),
|
|
87
|
+
activeId = _React$useState4[0],
|
|
88
|
+
setActiveId = _React$useState4[1];
|
|
89
|
+
|
|
90
|
+
var _React$useState5 = _react["default"].useState(null),
|
|
91
|
+
_React$useState6 = (0, _slicedToArray2["default"])(_React$useState5, 2),
|
|
92
|
+
dragEndEvent = _React$useState6[0],
|
|
93
|
+
setDragEndEvent = _React$useState6[1];
|
|
94
|
+
|
|
95
|
+
var boundaryRef = _react["default"].useRef(null);
|
|
96
|
+
|
|
97
|
+
var sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.KeyboardSensor, {
|
|
98
|
+
coordinateGetter: _sortable.sortableKeyboardCoordinates
|
|
99
|
+
}), (0, _core.useSensor)(_core.TouchSensor, {
|
|
100
|
+
activationConstraint: {
|
|
101
|
+
delay: 250,
|
|
102
|
+
tolerance: 5
|
|
103
|
+
}
|
|
104
|
+
}), (0, _core.useSensor)(_core.MouseSensor));
|
|
105
|
+
|
|
106
|
+
var handleDragStart = _react["default"].useCallback(function (event) {
|
|
107
|
+
var active = event.active;
|
|
108
|
+
setActiveId(active.id);
|
|
109
|
+
onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart(event);
|
|
110
|
+
}, [setActiveId, onDragStart]);
|
|
111
|
+
|
|
112
|
+
var handleDragCancel = _react["default"].useCallback(function () {
|
|
113
|
+
setActiveId(null);
|
|
114
|
+
}, [setActiveId]);
|
|
115
|
+
|
|
116
|
+
var handleDragEnd = _react["default"].useCallback(function (event) {
|
|
117
|
+
var active = event.active,
|
|
118
|
+
over = event.over;
|
|
119
|
+
|
|
120
|
+
if ((over === null || over === void 0 ? void 0 : over.id) && active.id !== over.id) {
|
|
121
|
+
setItemsList(function (prevItemsList) {
|
|
122
|
+
var oldIndex = prevItemsList.findIndex(function (item) {
|
|
123
|
+
return item.id === active.id;
|
|
124
|
+
});
|
|
125
|
+
var newIndex = prevItemsList.findIndex(function (item) {
|
|
126
|
+
return item.id === over.id;
|
|
127
|
+
});
|
|
128
|
+
return (0, _sortable.arrayMove)(prevItemsList, oldIndex, newIndex);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
setActiveId(null);
|
|
133
|
+
setDragEndEvent(event);
|
|
134
|
+
}, []);
|
|
135
|
+
|
|
136
|
+
_react["default"].useEffect(function () {
|
|
137
|
+
if (dragEndEvent) {
|
|
138
|
+
onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(itemsList, dragEndEvent);
|
|
139
|
+
setDragEndEvent(null);
|
|
140
|
+
}
|
|
141
|
+
}, [itemsList, onDragEnd, dragEndEvent]);
|
|
142
|
+
|
|
143
|
+
var renderSortableItem = function renderSortableItem(_a, index, isDragOverlay) {
|
|
144
|
+
var id = _a.id,
|
|
145
|
+
item = __rest(_a, ["id"]);
|
|
146
|
+
|
|
147
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
148
|
+
key: id,
|
|
149
|
+
className: cn('item', {
|
|
150
|
+
divider: showDivider
|
|
151
|
+
})
|
|
152
|
+
}, /*#__PURE__*/_react["default"].createElement(_ListDataSortable["default"], {
|
|
153
|
+
id: id,
|
|
154
|
+
item: item,
|
|
155
|
+
activatorNode: activatorNode,
|
|
156
|
+
gap: gap,
|
|
157
|
+
disabled: disabled || (item === null || item === void 0 ? void 0 : item.disabled),
|
|
158
|
+
isDragOverlay: isDragOverlay,
|
|
159
|
+
classes: {
|
|
160
|
+
root: classes.cell,
|
|
161
|
+
control: classes.control
|
|
162
|
+
},
|
|
163
|
+
dataAttrs: {
|
|
164
|
+
root: (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.cell, index + 1)),
|
|
165
|
+
control: (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.control, index + 1))
|
|
166
|
+
}
|
|
167
|
+
}));
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
var renderDragOverlay = function renderDragOverlay() {
|
|
171
|
+
var activeIndex = itemsList.findIndex(function (item) {
|
|
172
|
+
return item.id === activeId;
|
|
173
|
+
});
|
|
174
|
+
var activeItem = itemsList[activeIndex];
|
|
175
|
+
|
|
176
|
+
if (activeItem) {
|
|
177
|
+
return renderSortableItem(activeItem, activeIndex, true);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return null;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return /*#__PURE__*/_react["default"].createElement(_core.DndContext, {
|
|
184
|
+
sensors: sensors,
|
|
185
|
+
collisionDetection: _core.closestCenter,
|
|
186
|
+
onDragStart: handleDragStart,
|
|
187
|
+
onDragEnd: handleDragEnd,
|
|
188
|
+
onDragCancel: handleDragCancel,
|
|
189
|
+
modifiers: [(0, _helpers.restrictToElement)(boundaryRef), _helpers.restrictToVerticalAxis],
|
|
190
|
+
accessibility: {
|
|
191
|
+
screenReaderInstructions: {
|
|
192
|
+
draggable: SCREEN_READER_INSTRUCTION
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, /*#__PURE__*/_react["default"].createElement(_sortable.SortableContext, {
|
|
196
|
+
items: itemsList,
|
|
197
|
+
strategy: _sortable.verticalListSortingStrategy
|
|
198
|
+
}, /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({}, (0, _uiHelpers.filterDataAttrs)(dataAttrs === null || dataAttrs === void 0 ? void 0 : dataAttrs.root), {
|
|
199
|
+
className: cn([className, classes.root]),
|
|
200
|
+
ref: boundaryRef
|
|
201
|
+
}), itemsList.map(function (item, index) {
|
|
202
|
+
return renderSortableItem(item, index);
|
|
203
|
+
}))), /*#__PURE__*/_react["default"].createElement(_core.DragOverlay, dragOverlayProps, activeId ? renderDragOverlay() : null));
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
ListDataGroup.propTypes = {
|
|
207
|
+
items: PropTypes.arrayOf(PropTypes.shape((0, _extends2["default"])({
|
|
208
|
+
id: PropTypes.string.isRequired
|
|
209
|
+
}, _ListData.ListDataPropType)).isRequired).isRequired,
|
|
210
|
+
activatorNode: PropTypes.oneOf(Object.values(_ListDataSortable.ActivatorNodes)),
|
|
211
|
+
gap: PropTypes.oneOf(Object.values(_ListDataSortable.GapSizes)),
|
|
212
|
+
showDivider: PropTypes.bool,
|
|
213
|
+
onDragStart: PropTypes.func,
|
|
214
|
+
onDragEnd: PropTypes.func,
|
|
215
|
+
disabled: PropTypes.bool,
|
|
216
|
+
dragOverlayProps: PropTypes.shape({
|
|
217
|
+
className: PropTypes.string,
|
|
218
|
+
zIndex: PropTypes.number
|
|
219
|
+
}),
|
|
220
|
+
className: PropTypes.string,
|
|
221
|
+
classes: PropTypes.shape({
|
|
222
|
+
root: PropTypes.string,
|
|
223
|
+
cell: PropTypes.string,
|
|
224
|
+
control: PropTypes.string
|
|
225
|
+
}),
|
|
226
|
+
dataAttrs: PropTypes.objectOf(PropTypes.object)
|
|
227
|
+
};
|
|
228
|
+
var _default = ListDataGroup;
|
|
229
|
+
exports["default"] = _default;
|