@aloudata/aloudata-design 2.7.1 → 2.7.3
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/Button/style/type.less +1 -0
- package/dist/Icon/components/SortAscendingOrderColor.d.ts +11 -0
- package/dist/Icon/components/SortAscendingOrderColor.js +36 -0
- package/dist/Icon/components/SortColor.d.ts +11 -0
- package/dist/Icon/components/SortColor.js +33 -0
- package/dist/Icon/components/SortDescendingOrderColor.d.ts +11 -0
- package/dist/Icon/components/SortDescendingOrderColor.js +36 -0
- package/dist/Icon/index.d.ts +3 -0
- package/dist/Icon/index.js +3 -0
- package/dist/Icon/svg/Sort-Ascending-order-Color.svg +4 -0
- package/dist/Icon/svg/Sort-Color.svg +4 -0
- package/dist/Icon/svg/Sort-Descending-order-Color.svg +4 -0
- package/dist/Modal/index.d.ts +1 -0
- package/dist/Modal/index.js +33 -4
- package/dist/Modal/style/modal.less +25 -0
- package/dist/Popconfirm/style/index.less +25 -23
- package/dist/Popover/index.d.ts +1 -1
- package/dist/Popover/index.js +6 -3
- package/dist/Popover/style/index.less +40 -0
- package/dist/Select/index.js +5 -3
- package/dist/Table/components/ExpandCell.d.ts +2 -1
- package/dist/Table/components/ExpandCell.js +26 -10
- package/dist/Table/components/Footer/index.d.ts +13 -0
- package/dist/Table/components/Footer/index.js +77 -0
- package/dist/Table/components/Header.d.ts +1 -1
- package/dist/Table/components/Header.js +50 -4
- package/dist/Table/helper.d.ts +4 -1
- package/dist/Table/helper.js +4 -2
- package/dist/Table/hooks/useExpandable.d.ts +1 -0
- package/dist/Table/hooks/useExpandable.js +4 -4
- package/dist/Table/hooks/useRowSelection.d.ts +17 -0
- package/dist/Table/hooks/useRowSelection.js +164 -0
- package/dist/Table/index.js +33 -18
- package/dist/Table/style/index.less +77 -8
- package/dist/Table/types.d.ts +21 -0
- package/dist/User/index.js +3 -1
- package/dist/User/style/index.less +11 -0
- package/dist/ald.min.css +1 -1
- package/package.json +1 -1
- package/dist/Table/components/Pagination/index.d.ts +0 -10
- package/dist/Table/components/Pagination/index.js +0 -28
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
import React, { useCallback } from 'react';
|
|
9
|
+
import { Pagination } from "../../..";
|
|
10
|
+
import TextLink from "../../../TextLink";
|
|
11
|
+
import { prefixCls } from "../../helper";
|
|
12
|
+
export default function TableFooter(props) {
|
|
13
|
+
var pagination = props.pagination,
|
|
14
|
+
_props$scroll = props.scroll,
|
|
15
|
+
scroll = _props$scroll === void 0 ? {} : _props$scroll,
|
|
16
|
+
scrollToFirstRow = props.scrollToFirstRow,
|
|
17
|
+
isShowPagination = props.isShowPagination,
|
|
18
|
+
rowSelectionInfo = props.rowSelectionInfo;
|
|
19
|
+
|
|
20
|
+
// 选择行
|
|
21
|
+
var getCheckboxAllNode = rowSelectionInfo.getCheckboxAllNode,
|
|
22
|
+
selectedRowKeys = rowSelectionInfo.selectedRowKeys,
|
|
23
|
+
items = rowSelectionInfo.items,
|
|
24
|
+
isShowRowSelectionInFooter = rowSelectionInfo.isShowRowSelectionInFooter,
|
|
25
|
+
changeSelectedRowKeys = rowSelectionInfo.onChange;
|
|
26
|
+
var btnItems = [{
|
|
27
|
+
key: '$UN_SELECT_ALL$',
|
|
28
|
+
label: '取消选择',
|
|
29
|
+
onClick: function onClick(e) {
|
|
30
|
+
return rowSelectionInfo.unSelectAll(e);
|
|
31
|
+
}
|
|
32
|
+
}].concat(_toConsumableArray(items));
|
|
33
|
+
var rowSelectionNode = isShowRowSelectionInFooter && /*#__PURE__*/React.createElement("div", {
|
|
34
|
+
className: prefixCls('footer-row-selection')
|
|
35
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
36
|
+
className: prefixCls('footer-row-selection-btn')
|
|
37
|
+
}, getCheckboxAllNode === null || getCheckboxAllNode === void 0 ? void 0 : getCheckboxAllNode('全选')), /*#__PURE__*/React.createElement("div", {
|
|
38
|
+
className: prefixCls('footer-row-selection-selected')
|
|
39
|
+
}, "\u5DF2\u9009", ' ', /*#__PURE__*/React.createElement(TextLink, {
|
|
40
|
+
className: prefixCls('footer-row-selection-selected-num')
|
|
41
|
+
}, selectedRowKeys.length), ' ', "\u4E2A"), btnItems.map(function (btnItem) {
|
|
42
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
43
|
+
key: btnItem.key,
|
|
44
|
+
className: prefixCls('footer-row-selection-item'),
|
|
45
|
+
onClick: function onClick(e) {
|
|
46
|
+
btnItem.onClick(e);
|
|
47
|
+
}
|
|
48
|
+
}, /*#__PURE__*/React.createElement(TextLink, null, btnItem.label));
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
// 翻页器
|
|
52
|
+
var onChangePage = useCallback(function (page) {
|
|
53
|
+
var _ref = pagination || {},
|
|
54
|
+
_ref$onChange = _ref.onChange,
|
|
55
|
+
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange;
|
|
56
|
+
var _scroll$scrollToFirst = scroll.scrollToFirstRowOnChange,
|
|
57
|
+
scrollToFirstRowOnChange = _scroll$scrollToFirst === void 0 ? true : _scroll$scrollToFirst;
|
|
58
|
+
if (scrollToFirstRowOnChange) {
|
|
59
|
+
scrollToFirstRow();
|
|
60
|
+
}
|
|
61
|
+
onChange(page);
|
|
62
|
+
// 翻页后,清空已选行
|
|
63
|
+
changeSelectedRowKeys([]);
|
|
64
|
+
}, [scrollToFirstRow, scroll, pagination, changeSelectedRowKeys]);
|
|
65
|
+
var pager = isShowPagination && pagination && /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
className: prefixCls('pager')
|
|
67
|
+
}, /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
68
|
+
hideOnSinglePage: true
|
|
69
|
+
}, pagination, {
|
|
70
|
+
onChange: onChangePage
|
|
71
|
+
})));
|
|
72
|
+
var isShowRowSelection = rowSelectionInfo.isRowSelectionEnabled && selectedRowKeys.length > 0;
|
|
73
|
+
var isShowFooter = isShowPagination || isShowRowSelection;
|
|
74
|
+
return isShowFooter ? /*#__PURE__*/React.createElement("div", {
|
|
75
|
+
className: prefixCls('footer')
|
|
76
|
+
}, rowSelectionNode, pager) : null;
|
|
77
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Column } from '@tanstack/react-table';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export default function Header<T>(props: IProps<T>): React.JSX.Element;
|
|
3
|
+
export default function Header<T extends object>(props: IProps<T>): React.JSX.Element;
|
|
4
4
|
export interface IProps<T> {
|
|
5
5
|
column: Column<T>;
|
|
6
6
|
}
|
|
@@ -3,17 +3,63 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
3
3
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
4
4
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
5
5
|
import classnames from 'classnames';
|
|
6
|
-
import React from 'react';
|
|
6
|
+
import React, { useCallback } from 'react';
|
|
7
|
+
import SortAscIcon from "../../Icon/components/SortAscendingOrderColor";
|
|
8
|
+
import SortIcon from "../../Icon/components/SortColor";
|
|
9
|
+
import SortDescIcon from "../../Icon/components/SortDescendingOrderColor";
|
|
7
10
|
import { prefixCls } from "../helper";
|
|
8
11
|
export default function Header(props) {
|
|
12
|
+
var _classnames;
|
|
9
13
|
var column = props.column;
|
|
10
14
|
var _ref = column.columnDef.meta,
|
|
11
15
|
title = _ref.title,
|
|
12
16
|
dataIndex = _ref.dataIndex,
|
|
13
17
|
align = _ref.align,
|
|
14
|
-
ellipsis = _ref.ellipsis
|
|
18
|
+
ellipsis = _ref.ellipsis,
|
|
19
|
+
sortOrder = _ref.sortOrder,
|
|
20
|
+
onSort = _ref.onSort;
|
|
21
|
+
var sortIcon = /*#__PURE__*/React.createElement(SortIcon, {
|
|
22
|
+
size: 20
|
|
23
|
+
});
|
|
24
|
+
if (sortOrder === 'ascend') {
|
|
25
|
+
sortIcon = /*#__PURE__*/React.createElement(SortAscIcon, {
|
|
26
|
+
size: 20
|
|
27
|
+
});
|
|
28
|
+
} else if (sortOrder === 'descend') {
|
|
29
|
+
sortIcon = /*#__PURE__*/React.createElement(SortDescIcon, {
|
|
30
|
+
size: 20
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
var onClickTh = useCallback(function (e) {
|
|
34
|
+
if (sortOrder === undefined || !dataIndex || typeof onSort !== 'function') {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
e.stopPropagation();
|
|
38
|
+
var newSortOrder;
|
|
39
|
+
if (sortOrder === 'ascend') {
|
|
40
|
+
newSortOrder = 'descend';
|
|
41
|
+
} else if (sortOrder === 'descend') {
|
|
42
|
+
newSortOrder = null;
|
|
43
|
+
} else {
|
|
44
|
+
newSortOrder = 'ascend';
|
|
45
|
+
}
|
|
46
|
+
onSort(dataIndex, newSortOrder);
|
|
47
|
+
}, [dataIndex, onSort, sortOrder]);
|
|
48
|
+
var content = title;
|
|
49
|
+
if (typeof content === 'string') {
|
|
50
|
+
if (sortOrder !== undefined) {
|
|
51
|
+
content = /*#__PURE__*/React.createElement("span", {
|
|
52
|
+
className: prefixCls('sort-th-inner')
|
|
53
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
54
|
+
className: prefixCls('sort-title')
|
|
55
|
+
}, title), /*#__PURE__*/React.createElement("span", {
|
|
56
|
+
className: prefixCls('sort-btn')
|
|
57
|
+
}, sortIcon));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
15
60
|
return typeof title === 'string' ? /*#__PURE__*/React.createElement("div", {
|
|
16
61
|
key: dataIndex,
|
|
17
|
-
className: classnames(prefixCls('th-default'), prefixCls("align-".concat(align)),
|
|
18
|
-
|
|
62
|
+
className: classnames(prefixCls('th-default'), prefixCls("align-".concat(align)), (_classnames = {}, _defineProperty(_classnames, prefixCls('td-ellipsis-content'), ellipsis), _defineProperty(_classnames, prefixCls('th-sortable'), sortOrder !== undefined), _classnames)),
|
|
63
|
+
onClick: onClickTh
|
|
64
|
+
}, content) : /*#__PURE__*/React.createElement(React.Fragment, null, title);
|
|
19
65
|
}
|
package/dist/Table/helper.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ITableColumn, ITableProps } from './types';
|
|
3
|
-
export declare function getTableColumns<TDataItem extends object>({ columns, totalWidth, onError, }: {
|
|
3
|
+
export declare function getTableColumns<TDataItem extends object>({ columns, totalWidth, onError, onSort, }: {
|
|
4
4
|
columns: ITableColumn<TDataItem>[];
|
|
5
5
|
totalWidth: number;
|
|
6
6
|
onError: ITableProps<TDataItem>['onError'];
|
|
7
|
+
onSort: ITableProps<TDataItem>['onSort'];
|
|
7
8
|
}): {
|
|
8
9
|
accessorKey: string;
|
|
9
10
|
header: (props: import("./components/Header").IProps<TDataItem>) => import("react").JSX.Element;
|
|
@@ -13,6 +14,7 @@ export declare function getTableColumns<TDataItem extends object>({ columns, tot
|
|
|
13
14
|
onError: ((errorInfo: import("./types").ITableCellErrorInfo) => void) | undefined;
|
|
14
15
|
columnWidths: number[];
|
|
15
16
|
index: number;
|
|
17
|
+
onSort: ((columnKey: string, order: "ascend" | "descend" | null) => void) | undefined;
|
|
16
18
|
title: import("react").ReactNode;
|
|
17
19
|
dataIndex?: string | undefined;
|
|
18
20
|
width?: string | number | undefined;
|
|
@@ -21,6 +23,7 @@ export declare function getTableColumns<TDataItem extends object>({ columns, tot
|
|
|
21
23
|
noPadding?: boolean | undefined;
|
|
22
24
|
align?: "left" | "center" | "right" | undefined;
|
|
23
25
|
fixed?: "left" | "right" | undefined;
|
|
26
|
+
sortOrder?: "ascend" | "descend" | null | undefined;
|
|
24
27
|
};
|
|
25
28
|
}[];
|
|
26
29
|
/**
|
package/dist/Table/helper.js
CHANGED
|
@@ -11,7 +11,8 @@ import Header from "./components/Header";
|
|
|
11
11
|
export function getTableColumns(_ref) {
|
|
12
12
|
var columns = _ref.columns,
|
|
13
13
|
totalWidth = _ref.totalWidth,
|
|
14
|
-
onError = _ref.onError
|
|
14
|
+
onError = _ref.onError,
|
|
15
|
+
onSort = _ref.onSort;
|
|
15
16
|
var columnWidths = getColumnWidths(columns, totalWidth);
|
|
16
17
|
// 根据固定列的位置重排列顺序,将 left 的列放到最前面,right 的列放到最后面
|
|
17
18
|
var leftColumns = [];
|
|
@@ -37,7 +38,8 @@ export function getTableColumns(_ref) {
|
|
|
37
38
|
meta: _objectSpread(_objectSpread({}, col), {}, {
|
|
38
39
|
onError: onError,
|
|
39
40
|
columnWidths: columnWidths,
|
|
40
|
-
index: index
|
|
41
|
+
index: index,
|
|
42
|
+
onSort: onSort
|
|
41
43
|
})
|
|
42
44
|
};
|
|
43
45
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ITableProps } from '../types';
|
|
2
2
|
export default function useExpandable<TDataItem extends object>(props: IProps<TDataItem>): IExpandableInfo<TDataItem>;
|
|
3
|
+
export declare function getExpandableConfig<TDataItem extends object>(expandable: ITableProps<TDataItem>['expandable']): import("../types").ITableExpandable<TDataItem>;
|
|
3
4
|
export interface IExpandableInfo<TDataItem extends object> {
|
|
4
5
|
expandItemMap: IExpandItemMap;
|
|
5
6
|
onExpand: (record: TDataItem, isExpanded: boolean) => void;
|
|
@@ -57,13 +57,13 @@ export default function useExpandable(props) {
|
|
|
57
57
|
if (!expandedRowKeys) {
|
|
58
58
|
setExpandedKeys(function (prev) {
|
|
59
59
|
if (isExpanded) {
|
|
60
|
+
// 展开
|
|
61
|
+
return [].concat(_toConsumableArray(prev), [key]);
|
|
62
|
+
} else {
|
|
60
63
|
// 折叠
|
|
61
64
|
return prev.filter(function (expandedKey) {
|
|
62
65
|
return expandedKey !== key;
|
|
63
66
|
});
|
|
64
|
-
} else {
|
|
65
|
-
// 展开
|
|
66
|
-
return [].concat(_toConsumableArray(prev), [key]);
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
}
|
|
@@ -121,7 +121,7 @@ function getListItemsByTree(currNode, expandedKeys, getKey, childrenColumnName)
|
|
|
121
121
|
})) || [];
|
|
122
122
|
return [curr].concat(_toConsumableArray(_.flatten(subItems)));
|
|
123
123
|
}
|
|
124
|
-
function getExpandableConfig(expandable) {
|
|
124
|
+
export function getExpandableConfig(expandable) {
|
|
125
125
|
if (typeof expandable === 'boolean') {
|
|
126
126
|
return {};
|
|
127
127
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ITableProps } from '../types';
|
|
3
|
+
export default function useRowSelection<TDataItem extends object>(props: ITableProps<TDataItem>): IRowSelectionInfo<TDataItem>;
|
|
4
|
+
export interface IRowSelectionInfo<TDataItem extends object> {
|
|
5
|
+
columns: ITableProps<TDataItem>['columns'];
|
|
6
|
+
isRowSelectionEnabled: boolean;
|
|
7
|
+
getCheckboxAllNode: ((children?: React.ReactNode) => React.ReactNode) | null;
|
|
8
|
+
selectedRowKeys: string[];
|
|
9
|
+
unSelectAll: (e: React.MouseEvent) => void;
|
|
10
|
+
isShowRowSelectionInFooter: boolean;
|
|
11
|
+
items: {
|
|
12
|
+
key: string;
|
|
13
|
+
label: string;
|
|
14
|
+
onClick: (e: React.MouseEvent) => void;
|
|
15
|
+
}[];
|
|
16
|
+
onChange: (selectedRowKeys: string[]) => void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
+
import React, { useCallback, useState } from 'react';
|
|
18
|
+
import Checkbox from "../../Checkbox";
|
|
19
|
+
import { getRowKey, prefixCls } from "../helper";
|
|
20
|
+
export default function useRowSelection(props) {
|
|
21
|
+
var _rowSelection$items;
|
|
22
|
+
var columns = props.columns,
|
|
23
|
+
rowSelection = props.rowSelection,
|
|
24
|
+
rowKey = props.rowKey,
|
|
25
|
+
data = props.data;
|
|
26
|
+
var _useState = useState((rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) || (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.defaultSelectedRowKeys) || []),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
selectedRowKeysState = _useState2[0],
|
|
29
|
+
setSelectedRowKeysState = _useState2[1];
|
|
30
|
+
var selectedRowKeys = (rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) || selectedRowKeysState;
|
|
31
|
+
var getSelectedRows = useCallback(function (rowKeys) {
|
|
32
|
+
return data.filter(function (record) {
|
|
33
|
+
return rowKeys.includes(getRowKey(record, rowKey));
|
|
34
|
+
});
|
|
35
|
+
}, [data, rowKey]);
|
|
36
|
+
var changeSelectedRowKeys = useCallback(function (newSelectedRowKeys) {
|
|
37
|
+
var _rowSelection$onChang;
|
|
38
|
+
// 过滤出存在于 data 中的 selectedRowKeys
|
|
39
|
+
var visibleSelectedRowKeys = data.map(function (record) {
|
|
40
|
+
return getRowKey(record, rowKey);
|
|
41
|
+
}).filter(function (key) {
|
|
42
|
+
return newSelectedRowKeys.includes(key);
|
|
43
|
+
});
|
|
44
|
+
setSelectedRowKeysState(visibleSelectedRowKeys);
|
|
45
|
+
var selectedRows = getSelectedRows(visibleSelectedRowKeys);
|
|
46
|
+
rowSelection === null || rowSelection === void 0 ? void 0 : (_rowSelection$onChang = rowSelection.onChange) === null || _rowSelection$onChang === void 0 ? void 0 : _rowSelection$onChang.call(rowSelection, visibleSelectedRowKeys, selectedRows);
|
|
47
|
+
}, [getSelectedRows, rowSelection, data, rowKey]);
|
|
48
|
+
var checkboxAllStatus = getCheckboxAllStatus(data, selectedRowKeys, rowKey);
|
|
49
|
+
var selectAll = useCallback(function () {
|
|
50
|
+
var newKeys = data.map(function (record) {
|
|
51
|
+
return getRowKey(record, rowKey);
|
|
52
|
+
});
|
|
53
|
+
changeSelectedRowKeys(newKeys);
|
|
54
|
+
}, [data, rowKey, changeSelectedRowKeys]);
|
|
55
|
+
var unSelectAll = useCallback(function () {
|
|
56
|
+
changeSelectedRowKeys([]);
|
|
57
|
+
}, [changeSelectedRowKeys]);
|
|
58
|
+
var onClickAllCheckbox = useCallback(function () {
|
|
59
|
+
if (rowSelection !== null && rowSelection !== void 0 && rowSelection.selectedRowKeys) {
|
|
60
|
+
// 受控情况
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (checkboxAllStatus === 'all') {
|
|
64
|
+
unSelectAll();
|
|
65
|
+
} else {
|
|
66
|
+
selectAll();
|
|
67
|
+
}
|
|
68
|
+
}, [checkboxAllStatus, unSelectAll, selectAll, rowSelection]);
|
|
69
|
+
var onClickCheckbox = useCallback(function (key, isChecked) {
|
|
70
|
+
return function () {
|
|
71
|
+
if (rowSelection !== null && rowSelection !== void 0 && rowSelection.selectedRowKeys) {
|
|
72
|
+
// 受控情况
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var newKeys = isChecked ? selectedRowKeys.filter(function (keyItem) {
|
|
76
|
+
return keyItem !== key;
|
|
77
|
+
}) : [].concat(_toConsumableArray(selectedRowKeys), [key]);
|
|
78
|
+
changeSelectedRowKeys(newKeys);
|
|
79
|
+
};
|
|
80
|
+
}, [selectedRowKeys, rowSelection, changeSelectedRowKeys]);
|
|
81
|
+
|
|
82
|
+
// 全选按钮
|
|
83
|
+
var getCheckboxAllNode = function getCheckboxAllNode(children) {
|
|
84
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
85
|
+
className: prefixCls('row-selection-all')
|
|
86
|
+
}, /*#__PURE__*/React.createElement(Checkbox, {
|
|
87
|
+
onClick: onClickAllCheckbox,
|
|
88
|
+
checked: checkboxAllStatus === 'all',
|
|
89
|
+
indeterminate: checkboxAllStatus === 'indeterminate'
|
|
90
|
+
}, children));
|
|
91
|
+
};
|
|
92
|
+
if (!rowSelection) {
|
|
93
|
+
return {
|
|
94
|
+
columns: columns,
|
|
95
|
+
isRowSelectionEnabled: false,
|
|
96
|
+
getCheckboxAllNode: getCheckboxAllNode,
|
|
97
|
+
selectedRowKeys: [],
|
|
98
|
+
unSelectAll: unSelectAll,
|
|
99
|
+
isShowRowSelectionInFooter: false,
|
|
100
|
+
items: [],
|
|
101
|
+
onChange: function onChange() {}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (!rowKey) {
|
|
105
|
+
throw new Error('rowKey is required when rowSelection is enabled');
|
|
106
|
+
}
|
|
107
|
+
var rowSelectionColumn = {
|
|
108
|
+
dataIndex: '',
|
|
109
|
+
title: getCheckboxAllNode(),
|
|
110
|
+
width: 48,
|
|
111
|
+
render: function render(text, record) {
|
|
112
|
+
var key = getRowKey(record, rowKey);
|
|
113
|
+
var isChecked = !!(selectedRowKeys !== null && selectedRowKeys !== void 0 && selectedRowKeys.includes(key));
|
|
114
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
115
|
+
className: prefixCls('row-selection-item')
|
|
116
|
+
}, /*#__PURE__*/React.createElement(Checkbox, {
|
|
117
|
+
onClick: onClickCheckbox(key, isChecked),
|
|
118
|
+
checked: isChecked
|
|
119
|
+
}));
|
|
120
|
+
},
|
|
121
|
+
fixed: rowSelection.fixed ? 'left' : undefined
|
|
122
|
+
};
|
|
123
|
+
var selectedRowKeysInCurrPage = data.map(function (record) {
|
|
124
|
+
return getRowKey(record, rowKey);
|
|
125
|
+
}).filter(function (key) {
|
|
126
|
+
return selectedRowKeys.includes(key);
|
|
127
|
+
});
|
|
128
|
+
var isShowRowSelectionInFooter = selectedRowKeysInCurrPage.length > 0;
|
|
129
|
+
var items = ((_rowSelection$items = rowSelection.items) === null || _rowSelection$items === void 0 ? void 0 : _rowSelection$items.map(function (operationItem) {
|
|
130
|
+
return _objectSpread(_objectSpread({}, operationItem), {}, {
|
|
131
|
+
onClick: function onClick(e) {
|
|
132
|
+
operationItem.onClick(selectedRowKeysInCurrPage, getSelectedRows(selectedRowKeysInCurrPage), e);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
})) || [];
|
|
136
|
+
return {
|
|
137
|
+
columns: [rowSelectionColumn].concat(_toConsumableArray(columns)),
|
|
138
|
+
isRowSelectionEnabled: true,
|
|
139
|
+
getCheckboxAllNode: getCheckboxAllNode,
|
|
140
|
+
selectedRowKeys: selectedRowKeysInCurrPage,
|
|
141
|
+
unSelectAll: unSelectAll,
|
|
142
|
+
isShowRowSelectionInFooter: isShowRowSelectionInFooter,
|
|
143
|
+
items: items,
|
|
144
|
+
onChange: changeSelectedRowKeys
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function getCheckboxAllStatus(data, selectedRowKeys, rowKey) {
|
|
148
|
+
var selectedKeysInData = data.map(function (record) {
|
|
149
|
+
var key = getRowKey(record, rowKey);
|
|
150
|
+
if (selectedRowKeys.includes(key)) {
|
|
151
|
+
return key;
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}).filter(function (key) {
|
|
155
|
+
return key !== null;
|
|
156
|
+
});
|
|
157
|
+
if (selectedKeysInData.length === 0) {
|
|
158
|
+
return 'none';
|
|
159
|
+
}
|
|
160
|
+
if (selectedKeysInData.length === data.length) {
|
|
161
|
+
return 'all';
|
|
162
|
+
}
|
|
163
|
+
return 'indeterminate';
|
|
164
|
+
}
|
package/dist/Table/index.js
CHANGED
|
@@ -17,16 +17,17 @@ import ResizeObserver from 'rc-resize-observer';
|
|
|
17
17
|
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useState } from 'react';
|
|
18
18
|
import { Empty, Spin } from '..';
|
|
19
19
|
import ExpandCell from "./components/ExpandCell";
|
|
20
|
-
import
|
|
20
|
+
import Footer from "./components/Footer";
|
|
21
21
|
import { getRowKey, getTableColumns, prefixCls } from "./helper";
|
|
22
22
|
import useExpandable from "./hooks/useExpandable";
|
|
23
23
|
import useFixed from "./hooks/useFixed";
|
|
24
|
+
import useRowSelection from "./hooks/useRowSelection";
|
|
24
25
|
import useScroll from "./hooks/useScroll";
|
|
25
26
|
var HEADER_HEIGHT = 41;
|
|
27
|
+
var FOOTER_HEIGHT = 52;
|
|
26
28
|
function Table(props, ref) {
|
|
27
29
|
var _classnames, _classnames5, _classnames6;
|
|
28
|
-
var
|
|
29
|
-
data = props.data,
|
|
30
|
+
var data = props.data,
|
|
30
31
|
rowKey = props.rowKey,
|
|
31
32
|
columnSizing = props.columnSizing,
|
|
32
33
|
sticky = props.sticky,
|
|
@@ -41,6 +42,7 @@ function Table(props, ref) {
|
|
|
41
42
|
} : _props$rowClassName,
|
|
42
43
|
onRowClick = props.onRowClick,
|
|
43
44
|
onError = props.onError,
|
|
45
|
+
onSort = props.onSort,
|
|
44
46
|
expandable = props.expandable;
|
|
45
47
|
var _useState = useState(null),
|
|
46
48
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -74,16 +76,18 @@ function Table(props, ref) {
|
|
|
74
76
|
data: data,
|
|
75
77
|
rowKey: rowKey
|
|
76
78
|
});
|
|
79
|
+
var rowSelectionInfo = useRowSelection(props);
|
|
77
80
|
var tableColumns = useMemo(function () {
|
|
78
81
|
if (!totalSize || !realWidth) {
|
|
79
82
|
return [];
|
|
80
83
|
}
|
|
81
84
|
return getTableColumns({
|
|
82
|
-
columns: columns,
|
|
85
|
+
columns: rowSelectionInfo.columns,
|
|
83
86
|
totalWidth: realWidth,
|
|
84
|
-
onError: onError
|
|
87
|
+
onError: onError,
|
|
88
|
+
onSort: onSort
|
|
85
89
|
});
|
|
86
|
-
}, [
|
|
90
|
+
}, [totalSize, realWidth, onError, onSort, rowSelectionInfo.columns]);
|
|
87
91
|
var getColumnFixedInfo = useFixed({
|
|
88
92
|
tableColumns: tableColumns,
|
|
89
93
|
y: y,
|
|
@@ -122,6 +126,8 @@ function Table(props, ref) {
|
|
|
122
126
|
}
|
|
123
127
|
}, _.map(headerGroup.headers, function (header, index) {
|
|
124
128
|
var _classnames2;
|
|
129
|
+
// 选择行的列不能拖动宽度
|
|
130
|
+
var showResizer = columnSizing && !(!!rowSelectionInfo.isRowSelectionEnabled && index === 0);
|
|
125
131
|
var _getColumnFixedInfo = getColumnFixedInfo(index, true),
|
|
126
132
|
fixedClassName = _getColumnFixedInfo.className,
|
|
127
133
|
fixedStyle = _getColumnFixedInfo.style;
|
|
@@ -131,7 +137,7 @@ function Table(props, ref) {
|
|
|
131
137
|
width: header.getSize()
|
|
132
138
|
}, fixedStyle),
|
|
133
139
|
key: header.id
|
|
134
|
-
}, flexRender(header.column.columnDef.header, header.getContext()),
|
|
140
|
+
}, flexRender(header.column.columnDef.header, header.getContext()), showResizer && /*#__PURE__*/React.createElement("div", {
|
|
135
141
|
onMouseDown: header.getResizeHandler(),
|
|
136
142
|
onTouchStart: header.getResizeHandler(),
|
|
137
143
|
className: classnames(prefixCls('resizer'), (_classnames2 = {}, _defineProperty(_classnames2, prefixCls('self-resizing'), header.column.getIsResizing()), _defineProperty(_classnames2, prefixCls('resizing'), tableInstance.getState().columnSizingInfo.isResizingColumn), _classnames2))
|
|
@@ -156,10 +162,12 @@ function Table(props, ref) {
|
|
|
156
162
|
onRowClick(rowData, rowIndex);
|
|
157
163
|
};
|
|
158
164
|
}, [onRowClick]);
|
|
159
|
-
var isShowPagination = pagination && pagination.total > pagination.pageSize;
|
|
165
|
+
var isShowPagination = !!(pagination && pagination.total > pagination.pageSize);
|
|
166
|
+
var isShowRowSelection = rowSelectionInfo.isShowRowSelectionInFooter;
|
|
167
|
+
var isShowFooter = isShowPagination || isShowRowSelection;
|
|
160
168
|
|
|
161
169
|
// 空态切换 size 的阈值
|
|
162
|
-
var EMPTY_SMALL_SIZE_HEIGHT =
|
|
170
|
+
var EMPTY_SMALL_SIZE_HEIGHT = 436;
|
|
163
171
|
var isSmallEmpty = totalSize && totalSize.height < EMPTY_SMALL_SIZE_HEIGHT;
|
|
164
172
|
var isEmpty = rows.length === 0 && !loading;
|
|
165
173
|
|
|
@@ -169,12 +177,16 @@ function Table(props, ref) {
|
|
|
169
177
|
style: {
|
|
170
178
|
width: realWidth
|
|
171
179
|
}
|
|
172
|
-
}, isEmpty ?
|
|
180
|
+
}, isEmpty ? /*#__PURE__*/React.createElement("div", {
|
|
181
|
+
style: {
|
|
182
|
+
width: totalSize === null || totalSize === void 0 ? void 0 : totalSize.width
|
|
183
|
+
}
|
|
184
|
+
}, emptyComponent || /*#__PURE__*/React.createElement("div", {
|
|
173
185
|
className: classnames(prefixCls('empty'), _defineProperty({}, prefixCls('empty-small'), isSmallEmpty))
|
|
174
186
|
}, /*#__PURE__*/React.createElement(Empty, {
|
|
175
187
|
image: isSmallEmpty ? null : Empty.PRESENTED_IMAGE_SEARCH,
|
|
176
188
|
size: isSmallEmpty ? 'small' : undefined
|
|
177
|
-
})) : _.map(rows, function (row, rowIndex) {
|
|
189
|
+
}))) : _.map(rows, function (row, rowIndex) {
|
|
178
190
|
var _classnames4;
|
|
179
191
|
return /*#__PURE__*/React.createElement("div", {
|
|
180
192
|
key: row.id,
|
|
@@ -193,6 +205,7 @@ function Table(props, ref) {
|
|
|
193
205
|
}, fixedStyle)
|
|
194
206
|
}, expandableInfo.isExpandable && colIndex === 0 ? /*#__PURE__*/React.createElement(ExpandCell, {
|
|
195
207
|
expandableInfo: expandableInfo,
|
|
208
|
+
expandable: expandable,
|
|
196
209
|
data: row.original,
|
|
197
210
|
rowKey: rowKey
|
|
198
211
|
}, tdContent) : tdContent);
|
|
@@ -204,12 +217,18 @@ function Table(props, ref) {
|
|
|
204
217
|
className: prefixCls('content')
|
|
205
218
|
}, headerContent, /*#__PURE__*/React.createElement("div", {
|
|
206
219
|
style: {
|
|
207
|
-
height: y && totalSize ? totalSize.height - HEADER_HEIGHT : 'auto'
|
|
220
|
+
height: y && totalSize ? totalSize.height - HEADER_HEIGHT - (isShowFooter ? FOOTER_HEIGHT : 0) : 'auto'
|
|
208
221
|
},
|
|
209
222
|
className: classnames(prefixCls('body-scroll'), (_classnames5 = {}, _defineProperty(_classnames5, prefixCls('scroll-y'), y !== undefined), _defineProperty(_classnames5, prefixCls('scroll-hidden'), isEmpty), _classnames5)),
|
|
210
223
|
ref: bodyRef,
|
|
211
224
|
onScroll: onBodyScroll
|
|
212
|
-
}, bodyContent)
|
|
225
|
+
}, bodyContent), isShowFooter && /*#__PURE__*/React.createElement(Footer, {
|
|
226
|
+
rowSelectionInfo: rowSelectionInfo,
|
|
227
|
+
isShowPagination: isShowPagination,
|
|
228
|
+
pagination: pagination,
|
|
229
|
+
scroll: scroll,
|
|
230
|
+
scrollToFirstRow: scrollToFirstRow
|
|
231
|
+
})));
|
|
213
232
|
var tableStyle = {};
|
|
214
233
|
if (y) {
|
|
215
234
|
tableStyle.height = y;
|
|
@@ -228,10 +247,6 @@ function Table(props, ref) {
|
|
|
228
247
|
}
|
|
229
248
|
}, /*#__PURE__*/React.createElement("div", {
|
|
230
249
|
className: classnames(prefixCls('main'), (_classnames6 = {}, _defineProperty(_classnames6, prefixCls('overflow-hidden'), !!y), _defineProperty(_classnames6, prefixCls('ping-left'), isPingLeft), _defineProperty(_classnames6, prefixCls('ping-right'), isPingRight), _classnames6))
|
|
231
|
-
}, tableContent))
|
|
232
|
-
pagination: pagination,
|
|
233
|
-
scroll: scroll,
|
|
234
|
-
scrollToFirstRow: scrollToFirstRow
|
|
235
|
-
}));
|
|
250
|
+
}, tableContent)));
|
|
236
251
|
}
|
|
237
252
|
export default /*#__PURE__*/forwardRef(Table);
|