@autobest-ui/components 1.1.1 → 1.1.8
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/style/index.scss +37 -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/index.d.ts +1 -0
- package/esm/date-picker/index.js +17 -7
- package/esm/date-picker/style/index.css +1 -1
- package/esm/date-picker/style/index.scss +23 -19
- 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 +2 -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 +14 -14
- package/esm/table/__stories__/style.css +1 -1
- package/esm/table/__stories__/style.scss +33 -2
- package/esm/table/body/BodyRow.d.ts +19 -0
- package/esm/table/body/BodyRow.js +98 -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 +62 -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/style/index.scss +37 -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/index.d.ts +1 -0
- package/lib/date-picker/index.js +17 -7
- package/lib/date-picker/style/index.css +1 -1
- package/lib/date-picker/style/index.scss +23 -19
- 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 +2 -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 +14 -14
- package/lib/table/__stories__/style.css +1 -1
- package/lib/table/__stories__/style.scss +33 -2
- package/lib/table/body/BodyRow.d.ts +19 -0
- package/lib/table/body/BodyRow.js +112 -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 +74 -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,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Column } from '../interface';
|
|
3
|
+
export interface BodyRowProps<T> {
|
|
4
|
+
className?: string;
|
|
5
|
+
prefixCls: string;
|
|
6
|
+
rowData: T;
|
|
7
|
+
index: number;
|
|
8
|
+
columns: Column<T>[];
|
|
9
|
+
indent: number;
|
|
10
|
+
CheckCell: React.ReactElement;
|
|
11
|
+
isExpand?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare function BodyRow<RowDataType>({ className, prefixCls: cls, rowData, index, columns, indent, CheckCell, isExpand }: BodyRowProps<RowDataType>): JSX.Element;
|
|
14
|
+
declare namespace BodyRow {
|
|
15
|
+
var defaultProps: {
|
|
16
|
+
isExpand: boolean;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export default BodyRow;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
|
|
3
|
+
var __assign = this && this.__assign || function () {
|
|
4
|
+
__assign = Object.assign || function (t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
|
|
8
|
+
for (var p in s) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return t;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return __assign.apply(this, arguments);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
import React from 'react';
|
|
20
|
+
import classNames from 'classnames';
|
|
21
|
+
import { isEmptyArray } from '@autobest-ui/utils';
|
|
22
|
+
|
|
23
|
+
var getIndentCol = function getIndentCol(prefixCls, number) {
|
|
24
|
+
if (number === 0) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new Array(number).fill(false).map(function (_item, index) {
|
|
29
|
+
return React.createElement("td", {
|
|
30
|
+
key: index,
|
|
31
|
+
className: prefixCls + "-indent"
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function BodyRow(_a) {
|
|
37
|
+
var className = _a.className,
|
|
38
|
+
cls = _a.prefixCls,
|
|
39
|
+
rowData = _a.rowData,
|
|
40
|
+
index = _a.index,
|
|
41
|
+
columns = _a.columns,
|
|
42
|
+
indent = _a.indent,
|
|
43
|
+
CheckCell = _a.CheckCell,
|
|
44
|
+
isExpand = _a.isExpand;
|
|
45
|
+
var indentCell = React.useMemo(function () {
|
|
46
|
+
return getIndentCol(cls, indent);
|
|
47
|
+
}, [cls, indent]);
|
|
48
|
+
var contentCells = [];
|
|
49
|
+
columns.forEach(function (col, colIndex) {
|
|
50
|
+
var renderer = (columns[colIndex] || {}).onRender;
|
|
51
|
+
var renderInfo = renderer ? renderer(rowData, index, colIndex) : rowData[col.dataIndex];
|
|
52
|
+
var cellProps = {};
|
|
53
|
+
var content;
|
|
54
|
+
|
|
55
|
+
if (renderInfo && _typeof(renderInfo) === 'object' && !Array.isArray(renderInfo) && !React.isValidElement(renderInfo)) {
|
|
56
|
+
var children = renderInfo.children,
|
|
57
|
+
props = renderInfo.props;
|
|
58
|
+
content = children;
|
|
59
|
+
cellProps = props;
|
|
60
|
+
} else {
|
|
61
|
+
content = renderInfo;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var colSpan = cellProps.colSpan,
|
|
65
|
+
rowSpan = cellProps.rowSpan,
|
|
66
|
+
className = cellProps.className;
|
|
67
|
+
|
|
68
|
+
var cellInfo = __assign(__assign({}, col), {
|
|
69
|
+
content: content,
|
|
70
|
+
colSpan: colSpan === undefined ? 1 : colSpan,
|
|
71
|
+
rowSpan: rowSpan === undefined ? 1 : rowSpan
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (cellInfo.colSpan === 0 || cellInfo.rowSpan === 0 || isExpand && !cellInfo.content) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
contentCells.push(React.createElement("td", {
|
|
79
|
+
className: className,
|
|
80
|
+
key: cellInfo.key,
|
|
81
|
+
colSpan: cellInfo.colSpan,
|
|
82
|
+
rowSpan: cellInfo.rowSpan
|
|
83
|
+
}, cellInfo.content));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (!isEmptyArray(contentCells)) {
|
|
87
|
+
return React.createElement("tr", {
|
|
88
|
+
className: classNames(cls + "-row", className)
|
|
89
|
+
}, indentCell, CheckCell, contentCells);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
BodyRow.defaultProps = {
|
|
96
|
+
isExpand: false
|
|
97
|
+
};
|
|
98
|
+
export default BodyRow;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { ReactText } from 'react';
|
|
2
|
+
export interface BodyRowSelectionInfo<T> {
|
|
3
|
+
checkIcon?: (checked: boolean, rowData: T, index: number) => React.ReactElement;
|
|
4
|
+
getDisabled?: (rowData: T) => boolean;
|
|
5
|
+
onSelect?: (checked: boolean, rowData: T) => void;
|
|
6
|
+
}
|
|
7
|
+
export interface BodyCheckIconProps<T> {
|
|
8
|
+
prefixCls: string;
|
|
9
|
+
rowData: T;
|
|
10
|
+
rowKey: ReactText;
|
|
11
|
+
rowIndex: number;
|
|
12
|
+
rowSelection: BodyRowSelectionInfo<T>;
|
|
13
|
+
selectedRowKeys: ReactText[];
|
|
14
|
+
}
|
|
15
|
+
declare const _default: React.NamedExoticComponent<BodyCheckIconProps<any>>;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Checkbox from '../../checkbox';
|
|
3
|
+
|
|
4
|
+
function BodyCheckIcon(_a) {
|
|
5
|
+
var cls = _a.prefixCls,
|
|
6
|
+
rowData = _a.rowData,
|
|
7
|
+
rowKey = _a.rowKey,
|
|
8
|
+
rowIndex = _a.rowIndex,
|
|
9
|
+
selectedRowKeys = _a.selectedRowKeys,
|
|
10
|
+
_b = _a.rowSelection,
|
|
11
|
+
checkIcon = _b.checkIcon,
|
|
12
|
+
getDisabled = _b.getDisabled,
|
|
13
|
+
onSelect = _b.onSelect;
|
|
14
|
+
var checked = selectedRowKeys.includes(rowKey);
|
|
15
|
+
|
|
16
|
+
if (checkIcon) {
|
|
17
|
+
return React.createElement("td", null, checkIcon(checked, rowData, rowIndex));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var disabled = getDisabled(rowData);
|
|
21
|
+
|
|
22
|
+
var onCheckBoxChange = function onCheckBoxChange(checked) {
|
|
23
|
+
onSelect(checked, rowData);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return React.createElement("td", {
|
|
27
|
+
className: cls + "-checkbox"
|
|
28
|
+
}, React.createElement(Checkbox, {
|
|
29
|
+
checked: checked,
|
|
30
|
+
disabled: disabled,
|
|
31
|
+
onChange: onCheckBoxChange
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default React.memo(BodyCheckIcon);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React, { ReactText } from 'react';
|
|
2
|
+
import { BodyRowProps } from './BodyRow';
|
|
3
|
+
import { BodyCheckIconProps, BodyRowSelectionInfo } from './CheckIcon';
|
|
4
|
+
import { ColumnOnRenderReturnObjectInfo } from '../interface';
|
|
5
|
+
/**
|
|
6
|
+
* 可展开子列表
|
|
7
|
+
*/
|
|
8
|
+
export interface TableExpandableInfo<T> {
|
|
9
|
+
expandedRowRender: (rowData: T, index: number) => React.ReactNode | React.ReactNode[] | ColumnOnRenderReturnObjectInfo;
|
|
10
|
+
}
|
|
11
|
+
export interface BodyProps<T> extends Pick<BodyRowProps<T>, 'prefixCls' | 'columns'>, Pick<BodyCheckIconProps<T>, 'selectedRowKeys'> {
|
|
12
|
+
/**
|
|
13
|
+
* 表格数据
|
|
14
|
+
*/
|
|
15
|
+
dataSource: T[];
|
|
16
|
+
/**
|
|
17
|
+
* 子列表渲染(不赋值则没有子列表),详见Expandable
|
|
18
|
+
*/
|
|
19
|
+
expandable?: TableExpandableInfo<T>;
|
|
20
|
+
getRowKey: (rowData: T) => ReactText;
|
|
21
|
+
rowSelection: BodyRowSelectionInfo<T>;
|
|
22
|
+
}
|
|
23
|
+
declare function Body<RowDataType>({ prefixCls, columns, dataSource, getRowKey, rowSelection, selectedRowKeys, expandable }: BodyProps<RowDataType>): JSX.Element;
|
|
24
|
+
export default Body;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import BodyRow from './BodyRow';
|
|
3
|
+
import CheckIcon from './CheckIcon';
|
|
4
|
+
|
|
5
|
+
var noop = function noop() {
|
|
6
|
+
return null;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function Body(_a) {
|
|
10
|
+
var prefixCls = _a.prefixCls,
|
|
11
|
+
columns = _a.columns,
|
|
12
|
+
dataSource = _a.dataSource,
|
|
13
|
+
getRowKey = _a.getRowKey,
|
|
14
|
+
rowSelection = _a.rowSelection,
|
|
15
|
+
selectedRowKeys = _a.selectedRowKeys,
|
|
16
|
+
expandable = _a.expandable;
|
|
17
|
+
var rows = [];
|
|
18
|
+
var expandedRowRenderer = expandable ? expandable.expandedRowRender : noop;
|
|
19
|
+
dataSource.forEach(function (row, rowIndex) {
|
|
20
|
+
var rowKey = getRowKey(row);
|
|
21
|
+
var CheckCell = rowSelection ? React.createElement(CheckIcon, {
|
|
22
|
+
prefixCls: prefixCls,
|
|
23
|
+
rowSelection: rowSelection,
|
|
24
|
+
rowKey: rowKey,
|
|
25
|
+
rowData: row,
|
|
26
|
+
rowIndex: rowIndex,
|
|
27
|
+
selectedRowKeys: selectedRowKeys
|
|
28
|
+
}) : null;
|
|
29
|
+
rows.push(React.createElement(BodyRow, {
|
|
30
|
+
key: rowKey,
|
|
31
|
+
prefixCls: prefixCls,
|
|
32
|
+
rowData: row,
|
|
33
|
+
index: rowIndex,
|
|
34
|
+
columns: columns,
|
|
35
|
+
CheckCell: CheckCell,
|
|
36
|
+
indent: 0
|
|
37
|
+
}));
|
|
38
|
+
var expandedRowKey = rowKey + " expanded";
|
|
39
|
+
var expandedColumns = [{
|
|
40
|
+
title: null,
|
|
41
|
+
key: expandedRowKey,
|
|
42
|
+
onRender: expandedRowRenderer
|
|
43
|
+
}];
|
|
44
|
+
|
|
45
|
+
if (expandable) {
|
|
46
|
+
rows.push(React.createElement(BodyRow, {
|
|
47
|
+
key: expandedRowKey,
|
|
48
|
+
className: prefixCls + "-expand-row",
|
|
49
|
+
prefixCls: prefixCls,
|
|
50
|
+
rowData: row,
|
|
51
|
+
index: rowIndex,
|
|
52
|
+
columns: expandedColumns,
|
|
53
|
+
CheckCell: null,
|
|
54
|
+
indent: CheckCell ? 1 : 0,
|
|
55
|
+
isExpand: true
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return React.createElement(React.Fragment, null, rows);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default Body;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface HeaderRowSelectionInfo {
|
|
3
|
+
checkIcon?: (checked: boolean, rowData: null, index: number) => React.ReactElement;
|
|
4
|
+
selectAllVisible?: boolean;
|
|
5
|
+
selectAllChecked: boolean;
|
|
6
|
+
onSelectAll?: (checked: boolean) => void;
|
|
7
|
+
}
|
|
8
|
+
interface HeaderCheckIconProps {
|
|
9
|
+
prefixCls: string;
|
|
10
|
+
rowSelection: HeaderRowSelectionInfo;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: React.NamedExoticComponent<HeaderCheckIconProps>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Checkbox from '../../checkbox';
|
|
3
|
+
|
|
4
|
+
function HeaderCheckIcon(_a) {
|
|
5
|
+
var cls = _a.prefixCls,
|
|
6
|
+
rowSelection = _a.rowSelection;
|
|
7
|
+
|
|
8
|
+
if (!rowSelection) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!rowSelection.selectAllVisible) {
|
|
13
|
+
// 有勾选功能,但是没有全选功能,需有占位元素
|
|
14
|
+
return React.createElement("th", null, " ");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var checkIcon = rowSelection.checkIcon,
|
|
18
|
+
selectAllChecked = rowSelection.selectAllChecked,
|
|
19
|
+
onSelectAll = rowSelection.onSelectAll;
|
|
20
|
+
|
|
21
|
+
if (checkIcon) {
|
|
22
|
+
return React.createElement("th", null, checkIcon(selectAllChecked, null, -1));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var onCheckBoxChange = function onCheckBoxChange() {
|
|
26
|
+
onSelectAll(!selectAllChecked);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return React.createElement("th", {
|
|
30
|
+
className: cls + "-checkbox"
|
|
31
|
+
}, React.createElement(Checkbox, {
|
|
32
|
+
checked: selectAllChecked,
|
|
33
|
+
onChange: onCheckBoxChange
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default React.memo(HeaderCheckIcon);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Column } from '../interface';
|
|
3
|
+
export interface HeaderCellProps<T> extends Column<T> {
|
|
4
|
+
prefixCls: string;
|
|
5
|
+
isSort: boolean;
|
|
6
|
+
isSortedDescending?: boolean;
|
|
7
|
+
onSort: (sortColumn: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 自定义排序图标,若不传,则采用默认的排序图标
|
|
10
|
+
* @param isSortDesc
|
|
11
|
+
*/
|
|
12
|
+
sortIcon?: (isSortDesc: boolean) => React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export default class HeaderCell<RowDataType> extends React.PureComponent<HeaderCellProps<RowDataType>> {
|
|
15
|
+
onClick: () => void;
|
|
16
|
+
renderArrow: () => {};
|
|
17
|
+
render(): JSX.Element;
|
|
18
|
+
}
|
|
@@ -26,7 +26,7 @@ var __extends = this && this.__extends || function () {
|
|
|
26
26
|
|
|
27
27
|
import React from 'react';
|
|
28
28
|
import classNames from 'classnames';
|
|
29
|
-
import Icon from '
|
|
29
|
+
import Icon from '../../icon';
|
|
30
30
|
|
|
31
31
|
var HeaderCell =
|
|
32
32
|
/** @class */
|
|
@@ -50,12 +50,17 @@ function (_super) {
|
|
|
50
50
|
var _a = _this.props,
|
|
51
51
|
prefixCls = _a.prefixCls,
|
|
52
52
|
isSort = _a.isSort,
|
|
53
|
-
isSortedDescending = _a.isSortedDescending
|
|
53
|
+
isSortedDescending = _a.isSortedDescending,
|
|
54
|
+
sortIcon = _a.sortIcon;
|
|
54
55
|
|
|
55
56
|
if (!isSort) {
|
|
56
57
|
return null;
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
if (sortIcon) {
|
|
61
|
+
return sortIcon(isSortedDescending);
|
|
62
|
+
}
|
|
63
|
+
|
|
59
64
|
return React.createElement(Icon, {
|
|
60
65
|
className: prefixCls + "-arrow",
|
|
61
66
|
name: "arrow",
|
|
@@ -72,11 +77,13 @@ function (_super) {
|
|
|
72
77
|
|
|
73
78
|
var _b = this.props,
|
|
74
79
|
prefixCls = _b.prefixCls,
|
|
80
|
+
className = _b.className,
|
|
75
81
|
title = _b.title,
|
|
76
82
|
sortName = _b.sortName,
|
|
77
|
-
|
|
83
|
+
colSpan = _b.colSpan;
|
|
78
84
|
return React.createElement("th", {
|
|
79
|
-
|
|
85
|
+
className: className,
|
|
86
|
+
colSpan: colSpan
|
|
80
87
|
}, React.createElement("div", {
|
|
81
88
|
className: classNames(prefixCls + "-title", (_a = {}, _a[prefixCls + "-point"] = sortName, _a)),
|
|
82
89
|
onClick: this.onClick
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Column } from '../interface';
|
|
2
|
+
import { HeaderCellProps } from './HeaderCell';
|
|
3
|
+
import { HeaderRowSelectionInfo } from './CheckIcon';
|
|
4
|
+
export interface HeaderRowProps<T> extends Pick<HeaderCellProps<T>, 'sortName' | 'isSortedDescending' | 'sortIcon'> {
|
|
5
|
+
prefixCls: string;
|
|
6
|
+
columns: Column<T>[];
|
|
7
|
+
/**
|
|
8
|
+
* 点击表头触发的排序函数
|
|
9
|
+
* @param isSortedDescending
|
|
10
|
+
* @param sortName
|
|
11
|
+
*/
|
|
12
|
+
onSortChange?: (isSortedDescending: boolean, sortName: string) => void;
|
|
13
|
+
rowSelection: HeaderRowSelectionInfo;
|
|
14
|
+
}
|
|
15
|
+
declare function HeaderRow<RowDataType>({ prefixCls: cls, columns, rowSelection, sortName, isSortedDescending, onSortChange, sortIcon }: HeaderRowProps<RowDataType>): JSX.Element;
|
|
16
|
+
export default HeaderRow;
|
|
@@ -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
|
*/
|