@autobest-ui/components 1.1.1 → 1.2.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/README.md +10 -10
- package/esm/accordion/__stories__/style.scss +58 -58
- package/esm/affix/__stories__/style.scss +13 -13
- package/esm/affix/style/index.scss +34 -34
- package/esm/base.scss +42 -42
- package/esm/carousel/__stories__/style.scss +41 -41
- package/esm/carousel/index.d.ts +21 -13
- package/esm/carousel/index.js +77 -44
- package/esm/carousel/style/index.css +1 -1
- package/esm/carousel/style/index.scss +43 -37
- package/esm/checkbox/style/index.scss +117 -117
- package/esm/collapse/__stories__/style.scss +18 -18
- package/esm/collapse/style/index.scss +42 -42
- package/esm/confirm/style/index.scss +44 -44
- package/esm/date-picker/calendar/grid/index.scss +85 -85
- package/esm/date-picker/calendar/index.scss +57 -57
- package/esm/date-picker/style/index.scss +18 -18
- package/esm/drawer/style/index.scss +44 -44
- package/esm/ellipsis/style/index.scss +35 -35
- package/esm/guide/__stories__/style.scss +13 -13
- package/esm/guide/style/index.scss +17 -17
- package/esm/icon/__stories__/style.scss +39 -39
- package/esm/icon/style/index.scss +6 -6
- package/esm/index.d.ts +1 -1
- package/esm/input-number/style/index.scss +86 -86
- package/esm/lazy-image/__stories__/style.scss +9 -9
- package/esm/lazy-image/style/index.scss +24 -24
- package/esm/link-list/style/index.scss +125 -125
- package/esm/loading/style/index.scss +30 -30
- package/esm/loading-bar/style/index.scss +62 -62
- package/esm/loading-container/__stories__/style.scss +5 -5
- package/esm/loading-container/style/index.scss +27 -27
- package/esm/loading-icon/style/index.scss +23 -23
- package/esm/mask/style/index.scss +34 -34
- package/esm/message/style/index.scss +70 -70
- package/esm/modal/style/index.scss +112 -112
- package/esm/move/__stories__/style.scss +6 -6
- package/esm/move/style/index.scss +7 -7
- package/esm/popover/__stories__/style.scss +15 -15
- package/esm/popover/style/index.scss +59 -59
- package/esm/select/__stories__/style.scss +8 -8
- package/esm/select/style/index.scss +126 -126
- package/esm/show-more/style/index.scss +22 -22
- package/esm/skeleton/__stories__/style.scss +2 -2
- package/esm/skeleton/style/index.scss +26 -26
- package/esm/style.css +15 -15
- package/esm/table/__stories__/style.css +1 -1
- package/esm/table/__stories__/style.scss +33 -2
- package/esm/table/body/BodyRow.d.ts +13 -0
- package/esm/table/body/BodyRow.js +94 -0
- package/esm/table/body/CheckIcon.d.ts +16 -0
- package/esm/table/body/CheckIcon.js +35 -0
- package/esm/table/body/index.d.ts +24 -0
- package/esm/table/body/index.js +61 -0
- package/esm/table/header/CheckIcon.d.ts +13 -0
- package/esm/table/header/CheckIcon.js +37 -0
- package/esm/table/header/HeaderCell.d.ts +18 -0
- package/esm/table/{HeaderCell.js → header/HeaderCell.js} +11 -4
- package/esm/table/header/HeaderRow.d.ts +16 -0
- package/esm/table/header/HeaderRow.js +76 -0
- package/esm/table/index.d.ts +52 -27
- package/esm/table/index.js +178 -155
- package/esm/table/interface.d.ts +16 -3
- package/esm/table/style/index.css +1 -1
- package/esm/table/style/index.scss +51 -70
- package/esm/tabs/__stories__/style.scss +8 -8
- package/esm/tabs/style/index.css +1 -1
- package/esm/tabs/style/index.scss +62 -62
- package/esm/tooltip/style/index.scss +61 -61
- package/esm/trigger/style/index.scss +79 -79
- package/lib/accordion/__stories__/style.scss +58 -58
- package/lib/affix/__stories__/style.scss +13 -13
- package/lib/affix/style/index.scss +34 -34
- package/lib/base.scss +42 -42
- package/lib/carousel/__stories__/style.scss +41 -41
- package/lib/carousel/index.d.ts +21 -13
- package/lib/carousel/index.js +80 -45
- package/lib/carousel/style/index.css +1 -1
- package/lib/carousel/style/index.scss +43 -37
- package/lib/checkbox/style/index.scss +117 -117
- package/lib/collapse/__stories__/style.scss +18 -18
- package/lib/collapse/style/index.scss +42 -42
- package/lib/confirm/style/index.scss +44 -44
- package/lib/date-picker/calendar/grid/index.scss +85 -85
- package/lib/date-picker/calendar/index.scss +57 -57
- package/lib/date-picker/style/index.scss +18 -18
- package/lib/drawer/style/index.scss +44 -44
- package/lib/ellipsis/style/index.scss +35 -35
- package/lib/guide/__stories__/style.scss +13 -13
- package/lib/guide/style/index.scss +17 -17
- package/lib/icon/__stories__/style.scss +39 -39
- package/lib/icon/style/index.scss +6 -6
- package/lib/index.d.ts +1 -1
- package/lib/input-number/style/index.scss +86 -86
- package/lib/lazy-image/__stories__/style.scss +9 -9
- package/lib/lazy-image/style/index.scss +24 -24
- package/lib/link-list/style/index.scss +125 -125
- package/lib/loading/style/index.scss +30 -30
- package/lib/loading-bar/style/index.scss +62 -62
- package/lib/loading-container/__stories__/style.scss +5 -5
- package/lib/loading-container/style/index.scss +27 -27
- package/lib/loading-icon/style/index.scss +23 -23
- package/lib/mask/style/index.scss +34 -34
- package/lib/message/style/index.scss +70 -70
- package/lib/modal/style/index.scss +112 -112
- package/lib/move/__stories__/style.scss +6 -6
- package/lib/move/style/index.scss +7 -7
- package/lib/popover/__stories__/style.scss +15 -15
- package/lib/popover/style/index.scss +59 -59
- package/lib/select/__stories__/style.scss +8 -8
- package/lib/select/style/index.scss +126 -126
- package/lib/show-more/style/index.scss +22 -22
- package/lib/skeleton/__stories__/style.scss +2 -2
- package/lib/skeleton/style/index.scss +26 -26
- package/lib/style.css +15 -15
- package/lib/table/__stories__/style.css +1 -1
- package/lib/table/__stories__/style.scss +33 -2
- package/lib/table/body/BodyRow.d.ts +13 -0
- package/lib/table/body/BodyRow.js +108 -0
- package/lib/table/body/CheckIcon.d.ts +16 -0
- package/lib/table/body/CheckIcon.js +47 -0
- package/lib/table/body/index.d.ts +24 -0
- package/lib/table/body/index.js +73 -0
- package/lib/table/header/CheckIcon.d.ts +13 -0
- package/lib/table/header/CheckIcon.js +49 -0
- package/lib/table/header/HeaderCell.d.ts +18 -0
- package/lib/table/{HeaderCell.js → header/HeaderCell.js} +11 -4
- package/lib/table/header/HeaderRow.d.ts +16 -0
- package/lib/table/header/HeaderRow.js +89 -0
- package/lib/table/index.d.ts +52 -27
- package/lib/table/index.js +177 -155
- package/lib/table/interface.d.ts +16 -3
- package/lib/table/style/index.css +1 -1
- package/lib/table/style/index.scss +51 -70
- package/lib/tabs/__stories__/style.scss +8 -8
- package/lib/tabs/style/index.css +1 -1
- package/lib/tabs/style/index.scss +62 -62
- package/lib/tooltip/style/index.scss +61 -61
- package/lib/trigger/style/index.scss +79 -79
- package/package.json +2 -2
- package/esm/table/BodyCell.d.ts +0 -6
- package/esm/table/BodyCell.js +0 -12
- package/esm/table/HeaderCell.d.ts +0 -13
- package/lib/table/BodyCell.d.ts +0 -6
- package/lib/table/BodyCell.js +0 -22
- package/lib/table/HeaderCell.d.ts +0 -13
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __assign = this && this.__assign || function () {
|
|
2
|
+
__assign = Object.assign || function (t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
|
|
6
|
+
for (var p in s) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import HeaderCell from './HeaderCell';
|
|
19
|
+
import HeaderCheckIcon from './CheckIcon';
|
|
20
|
+
|
|
21
|
+
function parseHeaderRows(columns) {
|
|
22
|
+
var rows = [];
|
|
23
|
+
columns.forEach(function (col) {
|
|
24
|
+
if ('colSpan' in col && col.colSpan === 0) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
rows.push(__assign(__assign({}, col), {
|
|
29
|
+
colSpan: col.colSpan ? col.colSpan : 1
|
|
30
|
+
}));
|
|
31
|
+
});
|
|
32
|
+
return rows;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function HeaderRow(_a) {
|
|
36
|
+
var cls = _a.prefixCls,
|
|
37
|
+
columns = _a.columns,
|
|
38
|
+
rowSelection = _a.rowSelection,
|
|
39
|
+
sortName = _a.sortName,
|
|
40
|
+
isSortedDescending = _a.isSortedDescending,
|
|
41
|
+
onSortChange = _a.onSortChange,
|
|
42
|
+
sortIcon = _a.sortIcon;
|
|
43
|
+
/**
|
|
44
|
+
* 点击某一列的表头,触发排序
|
|
45
|
+
* @param name
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
var onSort = function onSort(name) {
|
|
49
|
+
if (!onSortChange) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var isSortedDesc = sortName === name ? !isSortedDescending : true;
|
|
54
|
+
onSortChange(isSortedDesc, name);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var rows = React.useMemo(function () {
|
|
58
|
+
return parseHeaderRows(columns);
|
|
59
|
+
}, [columns]);
|
|
60
|
+
return React.createElement("tr", null, React.createElement(HeaderCheckIcon, {
|
|
61
|
+
prefixCls: cls,
|
|
62
|
+
rowSelection: rowSelection
|
|
63
|
+
}), rows.map(function (item) {
|
|
64
|
+
return React.createElement(HeaderCell, __assign({
|
|
65
|
+
key: item.key
|
|
66
|
+
}, item, {
|
|
67
|
+
prefixCls: cls,
|
|
68
|
+
isSort: sortName && sortName === item.sortName,
|
|
69
|
+
isSortedDescending: isSortedDescending,
|
|
70
|
+
onSort: onSort,
|
|
71
|
+
sortIcon: sortIcon
|
|
72
|
+
}));
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default HeaderRow;
|
package/esm/table/index.d.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ReactText } from 'react';
|
|
2
2
|
import { AddListenerEventHandler } from '@autobest-ui/utils';
|
|
3
3
|
import { Column } from './interface';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { HeaderRowProps } from './header/HeaderRow';
|
|
5
|
+
import { BodyProps } from './body';
|
|
6
|
+
import { HeaderRowSelectionInfo } from './header/CheckIcon';
|
|
7
|
+
import { BodyRowSelectionInfo } from './body/CheckIcon';
|
|
8
|
+
export interface RowSelectionInfo<T> extends Partial<Pick<HeaderRowSelectionInfo, 'selectAllVisible' | 'onSelectAll'>>, Partial<Pick<BodyRowSelectionInfo<T>, 'checkIcon'>> {
|
|
9
|
+
defaultSelectedRowKeys?: ReactText[];
|
|
10
|
+
getDisabled?: (dataRow: any, selectedRowKeys: ReactText[], selectedRows: T[]) => boolean;
|
|
11
|
+
onSelect?: (checked: boolean, rowData: T, selectedRows: T[]) => void;
|
|
12
|
+
onSelectedRowChange?: (selectedRowKeys: ReactText[], selectedRows: T[]) => void;
|
|
13
|
+
}
|
|
14
|
+
declare type StateRowSelectionInfo<T> = Pick<HeaderRowSelectionInfo, 'selectAllVisible' | 'selectAllChecked' | 'onSelectAll'> & Pick<BodyRowSelectionInfo<T>, 'checkIcon' | 'getDisabled' | 'onSelect'>;
|
|
15
|
+
export interface TableProps<T> extends Pick<HeaderRowProps<T>, 'sortName' | 'sortIcon' | 'onSortChange' | 'isSortedDescending'>, Pick<BodyProps<T>, 'dataSource' | 'expandable'> {
|
|
9
16
|
/**
|
|
10
|
-
*
|
|
17
|
+
* 样式名
|
|
11
18
|
*/
|
|
12
|
-
|
|
19
|
+
className?: string;
|
|
13
20
|
/**
|
|
14
|
-
*
|
|
21
|
+
* 定义每一列数据的格式
|
|
22
|
+
* 具体类型见Column
|
|
15
23
|
*/
|
|
16
|
-
|
|
24
|
+
columns: Column<T>[];
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
26
|
+
* 获取单条记录的唯一主键; 若是string类型,则取当前行数据中对应名称的属性值; 若是函数,则传入当前行数据,获取rowKey值;这也是勾选功能匹配时所用的key值
|
|
19
27
|
*/
|
|
20
|
-
|
|
28
|
+
rowKey?: string | ((rowData: T) => ReactText);
|
|
21
29
|
/**
|
|
22
30
|
* 是否固定表头
|
|
23
31
|
*/
|
|
@@ -26,7 +34,14 @@ export interface TableProps {
|
|
|
26
34
|
* 最大高度,fixedHeader为true时生效
|
|
27
35
|
*/
|
|
28
36
|
maxHeight?: string;
|
|
37
|
+
/**
|
|
38
|
+
* 为true时,Table会显示loading样式
|
|
39
|
+
*/
|
|
29
40
|
loading?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* 表格行是否可勾选,详见RowSelection
|
|
43
|
+
*/
|
|
44
|
+
rowSelection?: RowSelectionInfo<T>;
|
|
30
45
|
/**
|
|
31
46
|
* 默认勾选项数组, 以primaryKey取值
|
|
32
47
|
*/
|
|
@@ -48,43 +63,53 @@ export interface TableProps {
|
|
|
48
63
|
*/
|
|
49
64
|
isSortedDescending?: boolean;
|
|
50
65
|
}
|
|
51
|
-
interface TableState {
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
interface TableState<T> {
|
|
67
|
+
selectedRowKeys: ReactText[];
|
|
68
|
+
selectedRows: T[];
|
|
69
|
+
rowSelection: StateRowSelectionInfo<T>;
|
|
54
70
|
}
|
|
55
|
-
declare class Table extends React.Component<TableProps
|
|
71
|
+
declare class Table<RowDataType> extends React.Component<TableProps<RowDataType>, TableState<RowDataType>> {
|
|
56
72
|
prefixCls: string;
|
|
57
73
|
headerRef: React.RefObject<HTMLDivElement>;
|
|
58
74
|
bodyRef: React.RefObject<HTMLDivElement>;
|
|
59
75
|
scrollHandler: AddListenerEventHandler;
|
|
76
|
+
getRowKey: (rowData: RowDataType) => ReactText;
|
|
60
77
|
static defaultProps: {
|
|
61
78
|
fixedHeader: boolean;
|
|
62
79
|
loading: boolean;
|
|
80
|
+
rowKey: string;
|
|
63
81
|
};
|
|
64
|
-
|
|
82
|
+
readonly defaultRowSelection: Pick<StateRowSelectionInfo<RowDataType>, 'selectAllVisible' | 'selectAllChecked' | 'getDisabled'>;
|
|
83
|
+
constructor(props: TableProps<RowDataType>);
|
|
65
84
|
/**
|
|
66
85
|
* 清空选项
|
|
67
86
|
*/
|
|
68
87
|
clearSelection: () => void;
|
|
69
88
|
componentDidMount(): void;
|
|
70
|
-
componentDidUpdate(): void;
|
|
71
89
|
componentWillUnmount(): void;
|
|
72
90
|
addScrollListener: () => void;
|
|
91
|
+
getSelectedRows: (selectedKeys: any) => any;
|
|
73
92
|
/**
|
|
74
93
|
* 点击表头的checkbox,全选或全不选
|
|
75
94
|
*/
|
|
76
|
-
onSelectAll: () => void;
|
|
95
|
+
onSelectAll: (checked: any) => void;
|
|
77
96
|
/**
|
|
78
97
|
* 点击某一行的checkbook
|
|
79
98
|
* @param visible
|
|
80
|
-
* @param
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
* @param rowData
|
|
100
|
+
*/
|
|
101
|
+
onSelect: (visible: boolean, rowData: RowDataType) => void;
|
|
102
|
+
getDisabled: (rowData: any) => boolean;
|
|
103
|
+
getRowSelection: () => {
|
|
104
|
+
onSelect: (visible: boolean, rowData: RowDataType) => void;
|
|
105
|
+
onSelectAll: (checked: any) => void;
|
|
106
|
+
getDisabled: (rowData: any) => boolean;
|
|
107
|
+
defaultSelectedRowKeys?: (string | number)[];
|
|
108
|
+
onSelectedRowChange?: (selectedRowKeys: (string | number)[], selectedRows: RowDataType[]) => void;
|
|
109
|
+
selectAllVisible?: boolean;
|
|
110
|
+
checkIcon?: (checked: boolean, rowData: RowDataType, index: number) => React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)>) | (new (props: any) => React.Component<any, any, any>)>;
|
|
111
|
+
selectAllChecked: boolean;
|
|
112
|
+
};
|
|
88
113
|
/**
|
|
89
114
|
* 用colgroup设置每一列的宽度
|
|
90
115
|
*/
|
package/esm/table/index.js
CHANGED
|
@@ -40,27 +40,12 @@ var __assign = this && this.__assign || function () {
|
|
|
40
40
|
return __assign.apply(this, arguments);
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
var __spreadArrays = this && this.__spreadArrays || function () {
|
|
44
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
|
|
45
|
-
s += arguments[i].length;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++) {
|
|
49
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
|
|
50
|
-
r[k] = a[j];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return r;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
43
|
import React from 'react';
|
|
58
44
|
import classNames from 'classnames';
|
|
59
|
-
import {
|
|
45
|
+
import { addEventListener, isEmptyArray, throttleWithRAF } from '@autobest-ui/utils';
|
|
60
46
|
import LoadingContainer from '../loading-container';
|
|
61
|
-
import
|
|
62
|
-
import
|
|
63
|
-
import BodyCell from './BodyCell';
|
|
47
|
+
import HeaderRow from './header/HeaderRow';
|
|
48
|
+
import Body from './body';
|
|
64
49
|
|
|
65
50
|
var Table =
|
|
66
51
|
/** @class */
|
|
@@ -73,14 +58,26 @@ function (_super) {
|
|
|
73
58
|
_this.prefixCls = 'ab-table';
|
|
74
59
|
_this.headerRef = React.createRef();
|
|
75
60
|
_this.bodyRef = React.createRef();
|
|
61
|
+
_this.defaultRowSelection = {
|
|
62
|
+
selectAllVisible: true,
|
|
63
|
+
selectAllChecked: false,
|
|
64
|
+
getDisabled: function getDisabled() {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
76
68
|
/**
|
|
77
69
|
* 清空选项
|
|
78
70
|
*/
|
|
79
71
|
|
|
80
72
|
_this.clearSelection = function () {
|
|
81
|
-
_this.setState({
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
_this.setState(function (prevState) {
|
|
74
|
+
return {
|
|
75
|
+
selectedRowKeys: [],
|
|
76
|
+
selectedRows: [],
|
|
77
|
+
rowSelection: __assign(__assign({}, prevState.rowSelection), {
|
|
78
|
+
selectAllChecked: false
|
|
79
|
+
})
|
|
80
|
+
};
|
|
84
81
|
});
|
|
85
82
|
};
|
|
86
83
|
|
|
@@ -95,102 +92,167 @@ function (_super) {
|
|
|
95
92
|
}));
|
|
96
93
|
}
|
|
97
94
|
};
|
|
95
|
+
|
|
96
|
+
_this.getSelectedRows = function (selectedKeys) {
|
|
97
|
+
if (isEmptyArray(selectedKeys)) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var getRowKey = _this.getRowKey;
|
|
102
|
+
var dataSource = _this.props.dataSource;
|
|
103
|
+
return selectedKeys.map(function (key) {
|
|
104
|
+
return dataSource.find(function (item) {
|
|
105
|
+
return getRowKey(item) === key;
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
98
109
|
/**
|
|
99
110
|
* 点击表头的checkbox,全选或全不选
|
|
100
111
|
*/
|
|
101
112
|
|
|
102
113
|
|
|
103
|
-
_this.onSelectAll = function () {
|
|
114
|
+
_this.onSelectAll = function (checked) {
|
|
115
|
+
var getRowKey = _this.getRowKey;
|
|
104
116
|
var _a = _this.props,
|
|
105
117
|
dataSource = _a.dataSource,
|
|
106
|
-
|
|
107
|
-
onSelectedRowChange = _a.onSelectedRowChange;
|
|
108
|
-
var selectedRowKeys = _this.state.selectedRowKeys;
|
|
118
|
+
rowSelection = _a.rowSelection;
|
|
109
119
|
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
if (checked) {
|
|
121
|
+
var newSelectedRowKeys_1 = dataSource.map(getRowKey);
|
|
122
|
+
|
|
123
|
+
if (rowSelection.onSelectAll) {
|
|
124
|
+
rowSelection.onSelectAll(true);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_this.setState(function (prevState) {
|
|
128
|
+
return {
|
|
129
|
+
rowSelection: __assign(__assign({}, prevState.rowSelection), {
|
|
130
|
+
selectAllChecked: true
|
|
131
|
+
}),
|
|
132
|
+
selectedRowKeys: newSelectedRowKeys_1
|
|
133
|
+
};
|
|
114
134
|
});
|
|
115
135
|
|
|
116
|
-
onSelectedRowChange
|
|
136
|
+
if (rowSelection.onSelectedRowChange) {
|
|
137
|
+
rowSelection.onSelectedRowChange(newSelectedRowKeys_1, dataSource);
|
|
138
|
+
}
|
|
139
|
+
|
|
117
140
|
return;
|
|
118
141
|
}
|
|
119
142
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
143
|
+
if (rowSelection.onSelectAll) {
|
|
144
|
+
rowSelection.onSelectAll(false);
|
|
145
|
+
}
|
|
123
146
|
|
|
124
|
-
_this.setState({
|
|
125
|
-
|
|
126
|
-
|
|
147
|
+
_this.setState(function (prevState) {
|
|
148
|
+
return {
|
|
149
|
+
rowSelection: __assign(__assign({}, prevState.rowSelection), {
|
|
150
|
+
selectAllChecked: false
|
|
151
|
+
}),
|
|
152
|
+
selectedRowKeys: []
|
|
153
|
+
};
|
|
127
154
|
});
|
|
128
155
|
|
|
129
|
-
onSelectedRowChange
|
|
156
|
+
if (rowSelection.onSelectedRowChange) {
|
|
157
|
+
rowSelection.onSelectedRowChange([], []);
|
|
158
|
+
}
|
|
130
159
|
};
|
|
131
160
|
/**
|
|
132
161
|
* 点击某一行的checkbook
|
|
133
162
|
* @param visible
|
|
134
|
-
* @param
|
|
163
|
+
* @param rowData
|
|
135
164
|
*/
|
|
136
165
|
|
|
137
166
|
|
|
138
|
-
_this.
|
|
167
|
+
_this.onSelect = function (visible, rowData) {
|
|
168
|
+
var getRowKey = _this.getRowKey;
|
|
139
169
|
var _a = _this.props,
|
|
140
170
|
dataSource = _a.dataSource,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return j[primaryKey] === item;
|
|
147
|
-
});
|
|
148
|
-
});
|
|
171
|
+
rowSelection = _a.rowSelection;
|
|
172
|
+
var _b = _this.state,
|
|
173
|
+
selectedRowKeys = _b.selectedRowKeys,
|
|
174
|
+
selectedRows = _b.selectedRows;
|
|
175
|
+
var newRowKey = getRowKey(rowData);
|
|
149
176
|
var newSelectedRowKeys = [];
|
|
177
|
+
var newSelectedRows = [];
|
|
150
178
|
|
|
151
179
|
if (visible) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
_this.setState({
|
|
156
|
-
isSelectedAll: true
|
|
157
|
-
});
|
|
180
|
+
if (!selectedRowKeys.includes(newRowKey)) {
|
|
181
|
+
newSelectedRowKeys = selectedRowKeys.concat(newRowKey);
|
|
182
|
+
newSelectedRows = selectedRows.concat(rowData);
|
|
158
183
|
}
|
|
159
|
-
} else {
|
|
160
|
-
|
|
161
|
-
|
|
184
|
+
} else if (selectedRowKeys.includes(newRowKey)) {
|
|
185
|
+
var result = selectedRowKeys.reduce(function (previousValue, currentValue) {
|
|
186
|
+
if (currentValue === newRowKey) {
|
|
187
|
+
return previousValue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var data = dataSource.find(function (data) {
|
|
191
|
+
return getRowKey(data) === currentValue;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
if (data) {
|
|
195
|
+
previousValue.selectedRowKeys.push(currentValue);
|
|
196
|
+
previousValue.selectedRows.push(data);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return previousValue;
|
|
200
|
+
}, {
|
|
201
|
+
selectedRowKeys: [],
|
|
202
|
+
selectedRows: []
|
|
162
203
|
});
|
|
204
|
+
newSelectedRows = result.selectedRows;
|
|
205
|
+
newSelectedRowKeys = result.selectedRowKeys;
|
|
206
|
+
}
|
|
163
207
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
208
|
+
if (rowSelection.onSelect) {
|
|
209
|
+
rowSelection.onSelect(visible, rowData, selectedRows);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!visible && _this.state.rowSelection.selectAllChecked) {
|
|
213
|
+
_this.setState(function (prevState) {
|
|
214
|
+
return {
|
|
215
|
+
rowSelection: __assign(__assign({}, prevState.rowSelection), {
|
|
216
|
+
selectAllChecked: false
|
|
217
|
+
})
|
|
218
|
+
};
|
|
219
|
+
});
|
|
169
220
|
}
|
|
170
221
|
|
|
171
222
|
_this.setState({
|
|
172
|
-
selectedRowKeys: newSelectedRowKeys
|
|
223
|
+
selectedRowKeys: newSelectedRowKeys,
|
|
224
|
+
selectedRows: newSelectedRows
|
|
173
225
|
});
|
|
174
226
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
227
|
+
if (rowSelection.onSelectedRowChange) {
|
|
228
|
+
rowSelection.onSelectedRowChange(newSelectedRowKeys, newSelectedRows);
|
|
229
|
+
}
|
|
178
230
|
};
|
|
179
|
-
/**
|
|
180
|
-
* 点击某一列的表头,触发排序
|
|
181
|
-
* @param sortName
|
|
182
|
-
*/
|
|
183
231
|
|
|
232
|
+
_this.getDisabled = function (rowData) {
|
|
233
|
+
var rowSelection = _this.props.rowSelection;
|
|
184
234
|
|
|
185
|
-
|
|
186
|
-
|
|
235
|
+
if ('getDisabled' in rowSelection) {
|
|
236
|
+
var _a = _this.state,
|
|
237
|
+
selectedRowKeys = _a.selectedRowKeys,
|
|
238
|
+
selectedRows = _a.selectedRows;
|
|
239
|
+
return rowSelection.getDisabled(rowData, selectedRowKeys, selectedRows);
|
|
240
|
+
}
|
|
187
241
|
|
|
188
|
-
|
|
189
|
-
|
|
242
|
+
return false;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
_this.getRowSelection = function () {
|
|
246
|
+
if (!('rowSelection' in _this.props)) {
|
|
247
|
+
return null;
|
|
190
248
|
}
|
|
191
249
|
|
|
192
|
-
var
|
|
193
|
-
|
|
250
|
+
var propsRowSelection = _this.props.rowSelection;
|
|
251
|
+
return __assign(__assign(__assign({}, _this.defaultRowSelection), propsRowSelection), {
|
|
252
|
+
onSelect: _this.onSelect,
|
|
253
|
+
onSelectAll: _this.onSelectAll,
|
|
254
|
+
getDisabled: _this.getDisabled
|
|
255
|
+
});
|
|
194
256
|
};
|
|
195
257
|
/**
|
|
196
258
|
* 用colgroup设置每一列的宽度
|
|
@@ -200,15 +262,15 @@ function (_super) {
|
|
|
200
262
|
_this.renderColgroup = function () {
|
|
201
263
|
var _a = _this.props,
|
|
202
264
|
columns = _a.columns,
|
|
203
|
-
|
|
204
|
-
return React.createElement("colgroup", null,
|
|
265
|
+
rowSelection = _a.rowSelection;
|
|
266
|
+
return React.createElement("colgroup", null, rowSelection ? React.createElement("col", {
|
|
205
267
|
width: 32
|
|
206
268
|
}) : null, columns.map(function (item) {
|
|
207
269
|
var width = item.width;
|
|
208
270
|
|
|
209
271
|
if (width) {
|
|
210
272
|
return React.createElement("col", {
|
|
211
|
-
key: item.
|
|
273
|
+
key: item.key,
|
|
212
274
|
style: {
|
|
213
275
|
width: width,
|
|
214
276
|
minWidth: width
|
|
@@ -217,7 +279,7 @@ function (_super) {
|
|
|
217
279
|
}
|
|
218
280
|
|
|
219
281
|
return React.createElement("col", {
|
|
220
|
-
key: item.
|
|
282
|
+
key: item.key
|
|
221
283
|
});
|
|
222
284
|
}));
|
|
223
285
|
};
|
|
@@ -226,72 +288,53 @@ function (_super) {
|
|
|
226
288
|
var cls = _this.prefixCls;
|
|
227
289
|
var _a = _this.props,
|
|
228
290
|
columns = _a.columns,
|
|
229
|
-
onSelectedRowChange = _a.onSelectedRowChange,
|
|
230
291
|
sortName = _a.sortName,
|
|
231
|
-
isSortedDescending = _a.isSortedDescending
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
isSortedDescending: isSortedDescending,
|
|
245
|
-
onSort: _this.onSort
|
|
246
|
-
}));
|
|
247
|
-
})));
|
|
292
|
+
isSortedDescending = _a.isSortedDescending,
|
|
293
|
+
sortIcon = _a.sortIcon,
|
|
294
|
+
onSortChange = _a.onSortChange;
|
|
295
|
+
var rowSelection = _this.state.rowSelection;
|
|
296
|
+
return React.createElement("thead", null, React.createElement(HeaderRow, {
|
|
297
|
+
prefixCls: cls,
|
|
298
|
+
columns: columns,
|
|
299
|
+
sortName: sortName,
|
|
300
|
+
isSortedDescending: isSortedDescending,
|
|
301
|
+
sortIcon: sortIcon,
|
|
302
|
+
onSortChange: onSortChange,
|
|
303
|
+
rowSelection: rowSelection
|
|
304
|
+
}));
|
|
248
305
|
};
|
|
249
306
|
|
|
250
307
|
_this.renderBody = function () {
|
|
251
308
|
var cls = _this.prefixCls;
|
|
309
|
+
var getRowKey = _this.getRowKey;
|
|
252
310
|
var _a = _this.props,
|
|
253
311
|
columns = _a.columns,
|
|
254
312
|
dataSource = _a.dataSource,
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
onChange: _this.onChange,
|
|
268
|
-
name: rowKey
|
|
269
|
-
})) : null, columns.map(function (subItem, subIndex) {
|
|
270
|
-
return React.createElement(BodyCell, __assign({
|
|
271
|
-
key: subItem.fieldName,
|
|
272
|
-
index: subIndex,
|
|
273
|
-
rowData: item
|
|
274
|
-
}, subItem));
|
|
275
|
-
}));
|
|
313
|
+
expandable = _a.expandable;
|
|
314
|
+
var _b = _this.state,
|
|
315
|
+
rowSelection = _b.rowSelection,
|
|
316
|
+
selectedRowKeys = _b.selectedRowKeys;
|
|
317
|
+
return React.createElement("tbody", null, React.createElement(Body, {
|
|
318
|
+
prefixCls: cls,
|
|
319
|
+
getRowKey: getRowKey,
|
|
320
|
+
columns: columns,
|
|
321
|
+
dataSource: dataSource,
|
|
322
|
+
expandable: expandable,
|
|
323
|
+
rowSelection: rowSelection,
|
|
324
|
+
selectedRowKeys: selectedRowKeys
|
|
276
325
|
}));
|
|
277
326
|
};
|
|
278
327
|
|
|
279
|
-
var
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
selectedRowKeys = defaultSelectedRowKeys.filter(function (item) {
|
|
286
|
-
return !!dataSource.find(function (j) {
|
|
287
|
-
return j[primaryKey] === item;
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
|
|
328
|
+
var rowSelection = props.rowSelection,
|
|
329
|
+
rowKey = props.rowKey;
|
|
330
|
+
_this.getRowKey = typeof rowKey === 'string' ? function (data) {
|
|
331
|
+
return data[rowKey];
|
|
332
|
+
} : rowKey;
|
|
333
|
+
var defaultSelectedRowKeys = rowSelection && rowSelection.defaultSelectedRowKeys ? rowSelection.defaultSelectedRowKeys : [];
|
|
292
334
|
_this.state = {
|
|
293
|
-
|
|
294
|
-
|
|
335
|
+
selectedRowKeys: defaultSelectedRowKeys,
|
|
336
|
+
selectedRows: _this.getSelectedRows(defaultSelectedRowKeys),
|
|
337
|
+
rowSelection: _this.getRowSelection()
|
|
295
338
|
};
|
|
296
339
|
return _this;
|
|
297
340
|
}
|
|
@@ -300,27 +343,6 @@ function (_super) {
|
|
|
300
343
|
this.addScrollListener();
|
|
301
344
|
};
|
|
302
345
|
|
|
303
|
-
Table.prototype.componentDidUpdate = function () {
|
|
304
|
-
var _a = this.props,
|
|
305
|
-
dataSource = _a.dataSource,
|
|
306
|
-
onSelectedRowChange = _a.onSelectedRowChange;
|
|
307
|
-
var _b = this.state,
|
|
308
|
-
isSelectedAll = _b.isSelectedAll,
|
|
309
|
-
selectedRowKeys = _b.selectedRowKeys;
|
|
310
|
-
|
|
311
|
-
if (onSelectedRowChange && !isEmptyArray(dataSource)) {
|
|
312
|
-
if (isEmptyArray(selectedRowKeys) && isSelectedAll) {
|
|
313
|
-
this.setState({
|
|
314
|
-
isSelectedAll: false
|
|
315
|
-
});
|
|
316
|
-
} else if (selectedRowKeys.length === dataSource.length && !isSelectedAll) {
|
|
317
|
-
this.setState({
|
|
318
|
-
isSelectedAll: true
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
346
|
Table.prototype.componentWillUnmount = function () {
|
|
325
347
|
if (this.scrollHandler) {
|
|
326
348
|
this.scrollHandler.remove();
|
|
@@ -360,7 +382,8 @@ function (_super) {
|
|
|
360
382
|
|
|
361
383
|
Table.defaultProps = {
|
|
362
384
|
fixedHeader: false,
|
|
363
|
-
loading: false
|
|
385
|
+
loading: false,
|
|
386
|
+
rowKey: 'key'
|
|
364
387
|
};
|
|
365
388
|
return Table;
|
|
366
389
|
}(React.Component);
|
package/esm/table/interface.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export interface
|
|
2
|
+
export interface ColumnOnRenderReturnObjectInfo {
|
|
3
|
+
children: React.ReactNode | React.ReactNode[];
|
|
4
|
+
props: {
|
|
5
|
+
className?: string;
|
|
6
|
+
rowSpan?: number;
|
|
7
|
+
colSpan?: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface Column<T> {
|
|
3
11
|
title: React.ReactNode | React.ReactNode[];
|
|
4
|
-
|
|
12
|
+
key: string;
|
|
13
|
+
dataIndex?: string;
|
|
14
|
+
/**
|
|
15
|
+
* 当前触发排序的Column的sortName
|
|
16
|
+
*/
|
|
5
17
|
sortName?: string;
|
|
6
18
|
width?: string | number;
|
|
7
19
|
className?: string;
|
|
8
|
-
|
|
20
|
+
colSpan?: number;
|
|
21
|
+
onRender?: (rowData: T, rowIndex: number, colIndex: number) => React.ReactNode | React.ReactNode[] | ColumnOnRenderReturnObjectInfo;
|
|
9
22
|
}
|