@aloudata/aloudata-design 2.6.0 → 2.6.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/Icon/components/ArrowDownLightLine.d.ts +11 -0
- package/dist/Icon/components/ArrowDownLightLine.js +35 -0
- package/dist/Icon/index.d.ts +1 -0
- package/dist/Icon/index.js +1 -0
- package/dist/Icon/svg/arrow-down-light-line.svg +5 -0
- package/dist/Radio/style/index.less +6 -3
- package/dist/Table/components/ExpandCell.d.ts +11 -0
- package/dist/Table/components/ExpandCell.js +46 -0
- package/dist/Table/components/Pagination/index.d.ts +3 -2
- package/dist/Table/components/Pagination/index.js +1 -1
- package/dist/Table/helper.d.ts +2 -1
- package/dist/Table/helper.js +10 -0
- package/dist/Table/hooks/useExpandable.d.ts +23 -0
- package/dist/Table/hooks/useExpandable.js +152 -0
- package/dist/Table/index.d.ts +1 -1
- package/dist/Table/index.js +32 -17
- package/dist/Table/style/index.less +96 -45
- package/dist/Table/types.d.ts +10 -1
- package/dist/Tabs/index.d.ts +1 -1
- package/dist/Tabs/index.js +13 -13
- package/dist/Tabs/style/index.less +1 -0
- package/dist/ald.min.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SVGProps } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
interface SVGRProps {
|
|
4
|
+
size?: number | string;
|
|
5
|
+
title?: string;
|
|
6
|
+
titleId?: string;
|
|
7
|
+
desc?: string;
|
|
8
|
+
descId?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const Memo: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<SVGProps<SVGSVGElement> & SVGRProps, "ref"> & React.RefAttributes<SVGSVGElement>>>;
|
|
11
|
+
export default Memo;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var _excluded = ["title", "titleId", "desc", "descId"];
|
|
2
|
+
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); }
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { forwardRef, memo } from 'react';
|
|
7
|
+
var ArrowDownLightLine = function ArrowDownLightLine(_ref, ref) {
|
|
8
|
+
var title = _ref.title,
|
|
9
|
+
titleId = _ref.titleId,
|
|
10
|
+
desc = _ref.desc,
|
|
11
|
+
descId = _ref.descId,
|
|
12
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
13
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
14
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
15
|
+
width: props.width || props.size || 16,
|
|
16
|
+
height: props.height || props.size || 16,
|
|
17
|
+
fill: "none",
|
|
18
|
+
viewBox: "0 0 24 24",
|
|
19
|
+
ref: ref,
|
|
20
|
+
"aria-labelledby": titleId,
|
|
21
|
+
"aria-describedby": descId
|
|
22
|
+
}, props), desc ? /*#__PURE__*/React.createElement("desc", {
|
|
23
|
+
id: descId
|
|
24
|
+
}, desc) : null, title ? /*#__PURE__*/React.createElement("title", {
|
|
25
|
+
id: titleId
|
|
26
|
+
}, title) : null, /*#__PURE__*/React.createElement("path", {
|
|
27
|
+
fill: props.color || 'currentColor',
|
|
28
|
+
fillRule: "evenodd",
|
|
29
|
+
d: "M6.47 9.47a.75.75 0 0 1 1.06 0L12 13.94l4.47-4.47a.75.75 0 1 1 1.06 1.06l-5 5a.75.75 0 0 1-1.06 0l-5-5a.75.75 0 0 1 0-1.06Z",
|
|
30
|
+
clipRule: "evenodd"
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
var ForwardRef = /*#__PURE__*/forwardRef(ArrowDownLightLine);
|
|
34
|
+
var Memo = /*#__PURE__*/memo(ForwardRef);
|
|
35
|
+
export default Memo;
|
package/dist/Icon/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { default as AlertTriangleDuotone } from './components/AlertTriangleDuotone';
|
|
2
2
|
export { default as AlertTriangleLine } from './components/AlertTriangleLine';
|
|
3
3
|
export { default as ArrowDownFill } from './components/ArrowDownFill';
|
|
4
|
+
export { default as ArrowDownLightLine } from './components/ArrowDownLightLine';
|
|
4
5
|
export { default as ArrowRightLightLine } from './components/ArrowRightLightLine';
|
|
5
6
|
export { default as AttentionCircleFill } from './components/AttentionCircleFill';
|
|
6
7
|
export { default as AttentionTriangleFill } from './components/AttentionTriangleFill';
|
package/dist/Icon/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { default as AlertTriangleDuotone } from "./components/AlertTriangleDuotone";
|
|
2
2
|
export { default as AlertTriangleLine } from "./components/AlertTriangleLine";
|
|
3
3
|
export { default as ArrowDownFill } from "./components/ArrowDownFill";
|
|
4
|
+
export { default as ArrowDownLightLine } from "./components/ArrowDownLightLine";
|
|
4
5
|
export { default as ArrowRightLightLine } from "./components/ArrowRightLightLine";
|
|
5
6
|
export { default as AttentionCircleFill } from "./components/AttentionCircleFill";
|
|
6
7
|
export { default as AttentionTriangleFill } from "./components/AttentionTriangleFill";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id=" Icon / Light / Arrow / Arrow-Down-light-line">
|
|
3
|
+
<path id="Icon" fill-rule="evenodd" clip-rule="evenodd" d="M6.46967 9.46967C6.76256 9.17678 7.23744 9.17678 7.53033 9.46967L12 13.9393L16.4697 9.46967C16.7626 9.17678 17.2374 9.17678 17.5303 9.46967C17.8232 9.76256 17.8232 10.2374 17.5303 10.5303L12.5303 15.5303C12.2374 15.8232 11.7626 15.8232 11.4697 15.5303L6.46967 10.5303C6.17678 10.2374 6.17678 9.76256 6.46967 9.46967Z" fill="black"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -300,7 +300,11 @@
|
|
|
300
300
|
// filled样式的button
|
|
301
301
|
.ald-radio-button-wrapper-filled,
|
|
302
302
|
.ald-radio-button-wrapper-filter {
|
|
303
|
-
padding: 0 @radio-button-padding;
|
|
303
|
+
padding: 0 @radio-button-padding - 1;
|
|
304
|
+
|
|
305
|
+
&:not(.ald-radio-wrapper-checked) {
|
|
306
|
+
padding: 0 @radio-button-padding;
|
|
307
|
+
}
|
|
304
308
|
}
|
|
305
309
|
|
|
306
310
|
.ald-radio-button-wrapper-filled,
|
|
@@ -314,7 +318,6 @@
|
|
|
314
318
|
height: calc(100% - 4px);
|
|
315
319
|
background-color: var(--alias-colors-bg-skeleton-strong, #f3f4f6);
|
|
316
320
|
cursor: pointer;
|
|
317
|
-
border: 1px solid transparent;
|
|
318
321
|
|
|
319
322
|
// 选中样式
|
|
320
323
|
&.ald-radio-wrapper-checked {
|
|
@@ -602,7 +605,7 @@
|
|
|
602
605
|
width: min-content;
|
|
603
606
|
|
|
604
607
|
.ald-radio-label:not(.ald-radio-wrapper-disabled) {
|
|
605
|
-
&:hover {
|
|
608
|
+
&:not(.ald-radio-wrapper-checked):hover {
|
|
606
609
|
background: var(--alias-colors-bg-interaction-hover, rgba(0, 0, 0, 0.05));
|
|
607
610
|
}
|
|
608
611
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IExpandableInfo } from '../hooks/useExpandable';
|
|
3
|
+
import { TRowKey } from '../types';
|
|
4
|
+
export default function ExpandCell<TDataItem extends object>(props: IProps<TDataItem>): React.JSX.Element;
|
|
5
|
+
interface IProps<TDataItem extends object> {
|
|
6
|
+
expandableInfo: IExpandableInfo<TDataItem>;
|
|
7
|
+
data: TDataItem;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
rowKey?: TRowKey<TDataItem>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ArrowDownLightLine, ArrowRightLightLine } from "../../Icon";
|
|
4
|
+
import { getRowKey, prefixCls } from "../helper";
|
|
5
|
+
export default function ExpandCell(props) {
|
|
6
|
+
var children = props.children,
|
|
7
|
+
expandableInfo = props.expandableInfo,
|
|
8
|
+
data = props.data,
|
|
9
|
+
rowKey = props.rowKey;
|
|
10
|
+
if (!expandableInfo.isExpandable || !rowKey) {
|
|
11
|
+
// 配置了折叠展开时,会在前面的流程中强制检查 rowKey 字段是否存在
|
|
12
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
13
|
+
}
|
|
14
|
+
var expandItemMap = expandableInfo.expandItemMap,
|
|
15
|
+
onExpand = expandableInfo.onExpand;
|
|
16
|
+
var key = getRowKey(data, rowKey);
|
|
17
|
+
var expandItem = expandItemMap[key];
|
|
18
|
+
if (!expandItem) {
|
|
19
|
+
console.error('expandItem in not found', key, expandItemMap);
|
|
20
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
21
|
+
}
|
|
22
|
+
var level = expandItem.level,
|
|
23
|
+
isExpanded = expandItem.isExpanded,
|
|
24
|
+
isLeaf = expandItem.isLeaf;
|
|
25
|
+
var expandBtn = isLeaf ? null : isExpanded ? /*#__PURE__*/React.createElement(ArrowDownLightLine, null) : /*#__PURE__*/React.createElement(ArrowRightLightLine, null);
|
|
26
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
27
|
+
className: prefixCls('expandable-td')
|
|
28
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
29
|
+
className: prefixCls('indent-list')
|
|
30
|
+
}, _.map(_.range(level), function (i) {
|
|
31
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
className: prefixCls('indent-item'),
|
|
33
|
+
key: i
|
|
34
|
+
});
|
|
35
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
36
|
+
className: prefixCls('expand-btn'),
|
|
37
|
+
onClick: function onClick() {
|
|
38
|
+
if (isLeaf) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
onExpand(data, !!isExpanded);
|
|
42
|
+
}
|
|
43
|
+
}, expandBtn), /*#__PURE__*/React.createElement("div", {
|
|
44
|
+
className: prefixCls('expand-content')
|
|
45
|
+
}, children));
|
|
46
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { IPaginationProps } from '../../../Pagination/types';
|
|
2
3
|
import { ITableProps } from '../../types';
|
|
3
|
-
export default function TablePagination<TDataItem extends object>(props: IProps<TDataItem>): React.JSX.Element
|
|
4
|
+
export default function TablePagination<TDataItem extends object>(props: IProps<TDataItem>): React.JSX.Element;
|
|
4
5
|
interface IProps<TDataItem extends object> {
|
|
5
|
-
pagination
|
|
6
|
+
pagination: IPaginationProps;
|
|
6
7
|
scroll?: ITableProps<TDataItem>['scroll'];
|
|
7
8
|
scrollToFirstRow: () => void;
|
|
8
9
|
}
|
|
@@ -18,7 +18,7 @@ export default function TablePagination(props) {
|
|
|
18
18
|
}
|
|
19
19
|
onChange(page);
|
|
20
20
|
}, [scrollToFirstRow, scroll, pagination]);
|
|
21
|
-
return
|
|
21
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
22
22
|
className: prefixCls('pagination')
|
|
23
23
|
}, /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
24
24
|
hideOnSinglePage: true
|
package/dist/Table/helper.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare function getTableColumns<TDataItem extends object>({ columns, tot
|
|
|
19
19
|
render?: ((text: any, record: TDataItem, rowIndex: number) => import("react").ReactNode) | undefined;
|
|
20
20
|
ellipsis?: boolean | undefined;
|
|
21
21
|
noPadding?: boolean | undefined;
|
|
22
|
-
align?: "
|
|
22
|
+
align?: "center" | "left" | "right" | undefined;
|
|
23
23
|
fixed?: "left" | "right" | undefined;
|
|
24
24
|
};
|
|
25
25
|
}[];
|
|
@@ -39,3 +39,4 @@ export declare function getNumberFromPercentageStr(str: string): number;
|
|
|
39
39
|
*/
|
|
40
40
|
export declare function isPercentage(str: string): boolean;
|
|
41
41
|
export declare function prefixCls(className: string): string;
|
|
42
|
+
export declare function getRowKey<TDataItem extends object>(row: TDataItem, rowKey: ITableProps<TDataItem>['rowKey'], defaultKey?: string | number): string;
|
package/dist/Table/helper.js
CHANGED
|
@@ -5,6 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
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
7
|
import _ from 'lodash';
|
|
8
|
+
import { getUUID } from "../_utils/hooks/useId";
|
|
8
9
|
import Cell from "./components/Cell";
|
|
9
10
|
import Header from "./components/Header";
|
|
10
11
|
export function getTableColumns(_ref) {
|
|
@@ -142,4 +143,13 @@ export function isPercentage(str) {
|
|
|
142
143
|
var ALD_PREFIX = 'ald-table';
|
|
143
144
|
export function prefixCls(className) {
|
|
144
145
|
return "".concat(ALD_PREFIX, "-").concat(className);
|
|
146
|
+
}
|
|
147
|
+
export function getRowKey(row, rowKey, defaultKey) {
|
|
148
|
+
var rowKeyStr = defaultKey || getUUID();
|
|
149
|
+
if (typeof rowKey === 'function') {
|
|
150
|
+
rowKeyStr = rowKey(row);
|
|
151
|
+
} else if (rowKey !== undefined) {
|
|
152
|
+
rowKeyStr = _.get(row, rowKey);
|
|
153
|
+
}
|
|
154
|
+
return _.toString(rowKeyStr);
|
|
145
155
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ITableProps } from '../types';
|
|
2
|
+
export default function useExpandable<TDataItem extends object>(props: IProps<TDataItem>): IExpandableInfo<TDataItem>;
|
|
3
|
+
export interface IExpandableInfo<TDataItem extends object> {
|
|
4
|
+
expandItemMap: IExpandItemMap;
|
|
5
|
+
onExpand: (record: TDataItem, isExpanded: boolean) => void;
|
|
6
|
+
isExpandable: boolean;
|
|
7
|
+
data: TDataItem[];
|
|
8
|
+
}
|
|
9
|
+
export interface IExpandItem {
|
|
10
|
+
isLeaf: boolean;
|
|
11
|
+
isExpanded?: boolean;
|
|
12
|
+
level: number;
|
|
13
|
+
rowKey: string;
|
|
14
|
+
}
|
|
15
|
+
interface IExpandItemMap {
|
|
16
|
+
[key: string]: IExpandItem;
|
|
17
|
+
}
|
|
18
|
+
interface IProps<TDataItem extends object> {
|
|
19
|
+
expandable: ITableProps<TDataItem>['expandable'];
|
|
20
|
+
data: ITableProps<TDataItem>['data'];
|
|
21
|
+
rowKey: ITableProps<TDataItem>['rowKey'];
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
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; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import _ from 'lodash';
|
|
12
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
13
|
+
import { getRowKey } from "../helper";
|
|
14
|
+
export default function useExpandable(props) {
|
|
15
|
+
var propsExpandable = props.expandable,
|
|
16
|
+
data = props.data,
|
|
17
|
+
rowKey = props.rowKey;
|
|
18
|
+
var expandable = getExpandableConfig(propsExpandable);
|
|
19
|
+
if (!!propsExpandable && !rowKey) {
|
|
20
|
+
throw new Error('rowKey is necessary when expandable is enabled, but is missing');
|
|
21
|
+
}
|
|
22
|
+
var expandedRowKeys = expandable.expandedRowKeys,
|
|
23
|
+
propsOnExpand = expandable.onExpand,
|
|
24
|
+
_expandable$defaultEx = expandable.defaultExpandAllRows,
|
|
25
|
+
defaultExpandAllRows = _expandable$defaultEx === void 0 ? true : _expandable$defaultEx,
|
|
26
|
+
defaultExpandedRowKeys = expandable.defaultExpandedRowKeys,
|
|
27
|
+
childrenColumnName = expandable.childrenColumnName;
|
|
28
|
+
var columnName = getChildrenColumnName(childrenColumnName);
|
|
29
|
+
var flattenList = useMemo(function () {
|
|
30
|
+
return flattenChildren(data, columnName);
|
|
31
|
+
}, [columnName, data]);
|
|
32
|
+
var allCategoryRowKeys = useMemo(function () {
|
|
33
|
+
return getAllExpandRowKeys(flattenList, columnName, defaultExpandAllRows, rowKey);
|
|
34
|
+
}, [columnName, flattenList, defaultExpandAllRows, rowKey]);
|
|
35
|
+
|
|
36
|
+
// 考虑 defaultExpandAllRows 的情况
|
|
37
|
+
var _useState = useState(expandedRowKeys || defaultExpandedRowKeys || allCategoryRowKeys || []),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
expandedKeys = _useState2[0],
|
|
40
|
+
setExpandedKeys = _useState2[1];
|
|
41
|
+
var expandItemMap = useMemo(function () {
|
|
42
|
+
var listData = data.map(function (dataItem) {
|
|
43
|
+
return getListItemsByTree(dataItem, expandedKeys, rowKey, childrenColumnName);
|
|
44
|
+
}).flat();
|
|
45
|
+
return _.keyBy(listData, function (dataItem) {
|
|
46
|
+
return dataItem.rowKey;
|
|
47
|
+
});
|
|
48
|
+
}, [childrenColumnName, data, expandedKeys, rowKey]);
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
if (expandedRowKeys) {
|
|
51
|
+
// 展开收起完全受控的情况
|
|
52
|
+
setExpandedKeys(expandedRowKeys);
|
|
53
|
+
}
|
|
54
|
+
}, [expandedRowKeys]);
|
|
55
|
+
var onExpand = useCallback(function (dataItem, isExpanded) {
|
|
56
|
+
var key = getRowKey(dataItem, rowKey);
|
|
57
|
+
if (!expandedRowKeys) {
|
|
58
|
+
setExpandedKeys(function (prev) {
|
|
59
|
+
if (isExpanded) {
|
|
60
|
+
// 折叠
|
|
61
|
+
return prev.filter(function (expandedKey) {
|
|
62
|
+
return expandedKey !== key;
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
// 展开
|
|
66
|
+
return [].concat(_toConsumableArray(prev), [key]);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
propsOnExpand === null || propsOnExpand === void 0 ? void 0 : propsOnExpand(dataItem, isExpanded);
|
|
71
|
+
}, [propsOnExpand, rowKey, expandedRowKeys]);
|
|
72
|
+
var visibleList = useMemo(function () {
|
|
73
|
+
return flattenList.filter(function (dataItem) {
|
|
74
|
+
var key = getRowKey(dataItem, rowKey);
|
|
75
|
+
// 不在 Map 中的行,即表示被折叠了
|
|
76
|
+
return !!expandItemMap[key];
|
|
77
|
+
});
|
|
78
|
+
}, [expandItemMap, flattenList, rowKey]);
|
|
79
|
+
if (!propsExpandable) {
|
|
80
|
+
return {
|
|
81
|
+
expandItemMap: {},
|
|
82
|
+
onExpand: function onExpand() {},
|
|
83
|
+
isExpandable: false,
|
|
84
|
+
data: data
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
expandItemMap: expandItemMap,
|
|
89
|
+
onExpand: onExpand,
|
|
90
|
+
isExpandable: true,
|
|
91
|
+
data: visibleList
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function getListItemsByTree(currNode, expandedKeys, getKey, childrenColumnName) {
|
|
95
|
+
var level = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
96
|
+
var subNodes = _.get(currNode, getChildrenColumnName(childrenColumnName));
|
|
97
|
+
var isLeaf = !subNodes;
|
|
98
|
+
var rowKey = getRowKey(currNode, getKey);
|
|
99
|
+
if (isLeaf) {
|
|
100
|
+
return [{
|
|
101
|
+
isLeaf: true,
|
|
102
|
+
level: level,
|
|
103
|
+
rowKey: rowKey
|
|
104
|
+
}];
|
|
105
|
+
}
|
|
106
|
+
// 是目录的情况
|
|
107
|
+
var isExpanded = expandedKeys.includes(rowKey);
|
|
108
|
+
var curr = {
|
|
109
|
+
isLeaf: false,
|
|
110
|
+
level: level,
|
|
111
|
+
rowKey: rowKey
|
|
112
|
+
};
|
|
113
|
+
if (!isExpanded) {
|
|
114
|
+
curr.isExpanded = false;
|
|
115
|
+
return [curr];
|
|
116
|
+
}
|
|
117
|
+
curr.isExpanded = true;
|
|
118
|
+
// 子目录是展开的情况
|
|
119
|
+
var subItems = (subNodes === null || subNodes === void 0 ? void 0 : subNodes.map(function (child) {
|
|
120
|
+
return getListItemsByTree(child, expandedKeys, getKey, childrenColumnName, level + 1);
|
|
121
|
+
})) || [];
|
|
122
|
+
return [curr].concat(_toConsumableArray(_.flatten(subItems)));
|
|
123
|
+
}
|
|
124
|
+
function getExpandableConfig(expandable) {
|
|
125
|
+
if (typeof expandable === 'boolean') {
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
return expandable || {};
|
|
129
|
+
}
|
|
130
|
+
function getAllExpandRowKeys(list, childrenColumnName, defaultExpandAllRows, rowKey) {
|
|
131
|
+
if (!defaultExpandAllRows) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
var itemsWithChildrenProp = list.filter(function (item) {
|
|
135
|
+
return !!_.get(item, childrenColumnName);
|
|
136
|
+
});
|
|
137
|
+
return itemsWithChildrenProp.map(function (item) {
|
|
138
|
+
return getRowKey(item, rowKey);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function flattenChildren(nodes, childKey) {
|
|
142
|
+
return _.flatMapDeep(nodes, function (node) {
|
|
143
|
+
var children = node[childKey];
|
|
144
|
+
if (children && children.length > 0) {
|
|
145
|
+
return [node].concat(_toConsumableArray(flattenChildren(children, childKey)));
|
|
146
|
+
}
|
|
147
|
+
return [node];
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function getChildrenColumnName(childrenColumnName) {
|
|
151
|
+
return childrenColumnName || 'children';
|
|
152
|
+
}
|
package/dist/Table/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import React, { ForwardedRef } from 'react';
|
|
|
2
2
|
import { ITableProps, ITableRef } from './types';
|
|
3
3
|
declare function Table<TDataItem extends object>(props: ITableProps<TDataItem>, ref: ForwardedRef<ITableRef>): React.JSX.Element;
|
|
4
4
|
declare const _default: <TDataItem extends object>(props: ITableProps<TDataItem> & {
|
|
5
|
-
ref?: React.ForwardedRef<
|
|
5
|
+
ref?: React.ForwardedRef<ITableRef> | undefined;
|
|
6
6
|
}) => ReturnType<typeof Table>;
|
|
7
7
|
export default _default;
|
package/dist/Table/index.js
CHANGED
|
@@ -16,13 +16,15 @@ import _ from 'lodash';
|
|
|
16
16
|
import ResizeObserver from 'rc-resize-observer';
|
|
17
17
|
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useState } from 'react';
|
|
18
18
|
import { Empty, Spin } from '..';
|
|
19
|
+
import ExpandCell from "./components/ExpandCell";
|
|
19
20
|
import Pagination from "./components/Pagination";
|
|
20
|
-
import { getTableColumns, prefixCls } from "./helper";
|
|
21
|
+
import { getRowKey, getTableColumns, prefixCls } from "./helper";
|
|
22
|
+
import useExpandable from "./hooks/useExpandable";
|
|
21
23
|
import useFixed from "./hooks/useFixed";
|
|
22
24
|
import useScroll from "./hooks/useScroll";
|
|
23
25
|
var HEADER_HEIGHT = 41;
|
|
24
26
|
function Table(props, ref) {
|
|
25
|
-
var _classnames,
|
|
27
|
+
var _classnames, _classnames6;
|
|
26
28
|
var columns = props.columns,
|
|
27
29
|
data = props.data,
|
|
28
30
|
rowKey = props.rowKey,
|
|
@@ -38,7 +40,8 @@ function Table(props, ref) {
|
|
|
38
40
|
return '';
|
|
39
41
|
} : _props$rowClassName,
|
|
40
42
|
onRowClick = props.onRowClick,
|
|
41
|
-
onError = props.onError
|
|
43
|
+
onError = props.onError,
|
|
44
|
+
expandable = props.expandable;
|
|
42
45
|
var _useState = useState(null),
|
|
43
46
|
_useState2 = _slicedToArray(_useState, 2),
|
|
44
47
|
totalSize = _useState2[0],
|
|
@@ -66,6 +69,11 @@ function Table(props, ref) {
|
|
|
66
69
|
scrollToFirstRow: scrollToFirstRow
|
|
67
70
|
};
|
|
68
71
|
});
|
|
72
|
+
var expandableInfo = useExpandable({
|
|
73
|
+
expandable: expandable,
|
|
74
|
+
data: data,
|
|
75
|
+
rowKey: rowKey
|
|
76
|
+
});
|
|
69
77
|
var tableColumns = useMemo(function () {
|
|
70
78
|
if (!totalSize || !realWidth) {
|
|
71
79
|
return [];
|
|
@@ -83,16 +91,11 @@ function Table(props, ref) {
|
|
|
83
91
|
});
|
|
84
92
|
var tableInstance = useReactTable({
|
|
85
93
|
columns: tableColumns,
|
|
86
|
-
|
|
94
|
+
// 排除掉被折叠的行
|
|
95
|
+
data: expandableInfo.data,
|
|
87
96
|
getCoreRowModel: getCoreRowModel(),
|
|
88
97
|
getRowId: function getRowId(row, index) {
|
|
89
|
-
|
|
90
|
-
if (typeof rowKey === 'function') {
|
|
91
|
-
rowKeyStr = rowKey(row);
|
|
92
|
-
} else if (rowKey !== undefined) {
|
|
93
|
-
rowKeyStr = _.get(row, rowKey, index);
|
|
94
|
-
}
|
|
95
|
-
return _.toString(rowKeyStr);
|
|
98
|
+
return getRowKey(row, rowKey, index);
|
|
96
99
|
},
|
|
97
100
|
columnResizeMode: 'onChange'
|
|
98
101
|
});
|
|
@@ -153,6 +156,11 @@ function Table(props, ref) {
|
|
|
153
156
|
onRowClick(rowData, rowIndex);
|
|
154
157
|
};
|
|
155
158
|
}, [onRowClick]);
|
|
159
|
+
var isShowPagination = pagination && pagination.total > pagination.pageSize;
|
|
160
|
+
|
|
161
|
+
// 空态切换 size 的阈值
|
|
162
|
+
var EMPTY_SMALL_SIZE_HEIGHT = 288;
|
|
163
|
+
var isSmallEmpty = totalSize && totalSize.height < EMPTY_SMALL_SIZE_HEIGHT;
|
|
156
164
|
|
|
157
165
|
// 渲染 body
|
|
158
166
|
var bodyContent = /*#__PURE__*/React.createElement("div", {
|
|
@@ -161,25 +169,32 @@ function Table(props, ref) {
|
|
|
161
169
|
width: realWidth
|
|
162
170
|
}
|
|
163
171
|
}, rows.length === 0 && !loading ? emptyComponent || /*#__PURE__*/React.createElement("div", {
|
|
164
|
-
className: prefixCls('empty')
|
|
172
|
+
className: classnames(prefixCls('empty'), _defineProperty({}, prefixCls('empty-small'), isSmallEmpty))
|
|
165
173
|
}, /*#__PURE__*/React.createElement(Empty, {
|
|
166
|
-
image: Empty.PRESENTED_IMAGE_SEARCH
|
|
174
|
+
image: isSmallEmpty ? null : Empty.PRESENTED_IMAGE_SEARCH,
|
|
175
|
+
size: isSmallEmpty ? 'small' : undefined
|
|
167
176
|
})) : _.map(rows, function (row, rowIndex) {
|
|
177
|
+
var _classnames4;
|
|
168
178
|
return /*#__PURE__*/React.createElement("div", {
|
|
169
179
|
key: row.id,
|
|
170
|
-
className: classnames(prefixCls('tr'),
|
|
180
|
+
className: classnames(prefixCls('tr'), (_classnames4 = {}, _defineProperty(_classnames4, prefixCls('row-hover'), typeof onRowClick === 'function'), _defineProperty(_classnames4, prefixCls('no-border-tr'), isShowPagination && rowIndex === rows.length - 1), _classnames4), rowClassName(row.original, rowIndex)),
|
|
171
181
|
onClick: onClickRow(row.original, rowIndex)
|
|
172
182
|
}, _.map(row.getVisibleCells(), function (cell, colIndex) {
|
|
173
183
|
var _getColumnFixedInfo2 = getColumnFixedInfo(colIndex),
|
|
174
184
|
fixedClassName = _getColumnFixedInfo2.className,
|
|
175
185
|
fixedStyle = _getColumnFixedInfo2.style;
|
|
186
|
+
var tdContent = flexRender(cell.column.columnDef.cell, cell.getContext());
|
|
176
187
|
return /*#__PURE__*/React.createElement("div", {
|
|
177
188
|
className: classnames(prefixCls('td'), fixedClassName),
|
|
178
189
|
key: cell.id,
|
|
179
190
|
style: _objectSpread({
|
|
180
191
|
width: cell.column.getSize()
|
|
181
192
|
}, fixedStyle)
|
|
182
|
-
},
|
|
193
|
+
}, colIndex === 0 ? /*#__PURE__*/React.createElement(ExpandCell, {
|
|
194
|
+
expandableInfo: expandableInfo,
|
|
195
|
+
data: row.original,
|
|
196
|
+
rowKey: rowKey
|
|
197
|
+
}, tdContent) : tdContent);
|
|
183
198
|
}));
|
|
184
199
|
}));
|
|
185
200
|
var tableContent = /*#__PURE__*/React.createElement(Spin, {
|
|
@@ -211,8 +226,8 @@ function Table(props, ref) {
|
|
|
211
226
|
});
|
|
212
227
|
}
|
|
213
228
|
}, /*#__PURE__*/React.createElement("div", {
|
|
214
|
-
className: classnames(prefixCls('main'), (
|
|
215
|
-
}, tableContent)), /*#__PURE__*/React.createElement(Pagination, {
|
|
229
|
+
className: classnames(prefixCls('main'), (_classnames6 = {}, _defineProperty(_classnames6, prefixCls('overflow-hidden'), !!y), _defineProperty(_classnames6, prefixCls('ping-left'), isPingLeft), _defineProperty(_classnames6, prefixCls('ping-right'), isPingRight), _classnames6))
|
|
230
|
+
}, tableContent)), isShowPagination && /*#__PURE__*/React.createElement(Pagination, {
|
|
216
231
|
pagination: pagination,
|
|
217
232
|
scroll: scroll,
|
|
218
233
|
scrollToFirstRow: scrollToFirstRow
|