@rainbow-oh/yee-c 0.5.1 → 0.6.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/dist/cjs/Table/demo/components-override.d.ts +3 -0
- package/dist/cjs/Table/demo/components-override.js +54 -0
- package/dist/cjs/Table/demo/grouping.d.ts +3 -0
- package/dist/cjs/Table/demo/grouping.js +129 -0
- package/dist/cjs/Table/hooks/useColumns.d.ts +2 -2
- package/dist/cjs/Table/hooks/useColumns.js +15 -37
- package/dist/cjs/Table/index.d.ts +1 -1
- package/dist/cjs/Table/interface.d.ts +59 -8
- package/dist/cjs/Table/style/index.less +19 -1
- package/dist/cjs/Table/table.js +5 -7
- package/dist/cjs/Table/tbody/cell.d.ts +0 -1
- package/dist/cjs/Table/tbody/cell.js +0 -4
- package/dist/cjs/Table/tbody/index.js +19 -2
- package/dist/cjs/Table/tbody/row.js +15 -11
- package/dist/cjs/Table/theader/cell.js +7 -1
- package/dist/cjs/Table/theader/index.d.ts +5 -5
- package/dist/cjs/Table/theader/index.js +41 -27
- package/dist/cjs/Table/util/header.d.ts +23 -0
- package/dist/cjs/Table/util/header.js +109 -0
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Table/demo/components-override.d.ts +3 -0
- package/dist/esm/Table/demo/components-override.js +86 -0
- package/dist/esm/Table/demo/grouping.d.ts +3 -0
- package/dist/esm/Table/demo/grouping.js +102 -0
- package/dist/esm/Table/hooks/useColumns.d.ts +2 -2
- package/dist/esm/Table/hooks/useColumns.js +24 -50
- package/dist/esm/Table/index.d.ts +1 -1
- package/dist/esm/Table/interface.d.ts +59 -8
- package/dist/esm/Table/style/index.less +19 -1
- package/dist/esm/Table/table.js +5 -7
- package/dist/esm/Table/tbody/cell.d.ts +0 -1
- package/dist/esm/Table/tbody/cell.js +0 -5
- package/dist/esm/Table/tbody/index.js +21 -2
- package/dist/esm/Table/tbody/row.js +19 -15
- package/dist/esm/Table/theader/cell.js +6 -2
- package/dist/esm/Table/theader/index.d.ts +5 -5
- package/dist/esm/Table/theader/index.js +48 -35
- package/dist/esm/Table/util/header.d.ts +23 -0
- package/dist/esm/Table/util/header.js +107 -0
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +1 -1
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Table/demo/components-override.tsx +49 -0
- package/src/Table/demo/grouping.tsx +104 -0
- package/src/Table/hooks/useColumns.ts +29 -46
- package/src/Table/index.en-US.md +31 -3
- package/src/Table/index.ts +4 -0
- package/src/Table/index.zh-CN.md +30 -2
- package/src/Table/interface.ts +66 -8
- package/src/Table/style/index.less +19 -1
- package/src/Table/table.tsx +5 -7
- package/src/Table/tbody/cell.tsx +0 -6
- package/src/Table/tbody/index.tsx +21 -2
- package/src/Table/tbody/row.tsx +25 -14
- package/src/Table/theader/cell.tsx +4 -0
- package/src/Table/theader/index.tsx +61 -42
- package/src/Table/util/header.ts +111 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Table/demo/components-override.tsx
|
|
30
|
+
var components_override_exports = {};
|
|
31
|
+
__export(components_override_exports, {
|
|
32
|
+
default: () => components_override_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(components_override_exports);
|
|
35
|
+
var import_yee_c = require("../..");
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var CustomTbody = (props) => /* @__PURE__ */ import_react.default.createElement("tbody", { className: props.className, "data-custom-tbody": true }, props.children);
|
|
38
|
+
var CustomRow = ({ record, index, columns, rowKey }) => /* @__PURE__ */ import_react.default.createElement("tr", { "data-row-key": rowKey, style: { background: index % 2 === 0 ? "#f8fafc" : void 0 } }, /* @__PURE__ */ import_react.default.createElement("td", { style: { width: 40, textAlign: "center", color: "#2563eb", fontWeight: 700 } }, index + 1), columns.map((col) => /* @__PURE__ */ import_react.default.createElement("td", { key: String(col.key) }, record[col.dataIndex || ""])));
|
|
39
|
+
var components_override_default = () => {
|
|
40
|
+
const columns = [
|
|
41
|
+
{ title: "Name", dataIndex: "name", key: "name" },
|
|
42
|
+
{ title: "Age", dataIndex: "age", key: "age" },
|
|
43
|
+
{ title: "Address", dataIndex: "address", key: "address" }
|
|
44
|
+
];
|
|
45
|
+
const dataSource = [
|
|
46
|
+
{ key: "1", name: "John Brown", age: 32, address: "New York No. 1 Lake Park" },
|
|
47
|
+
{ key: "2", name: "Jim Green", age: 42, address: "London No. 1 Lake Park" },
|
|
48
|
+
{ key: "3", name: "Joe Black", age: 32, address: "Sidney No. 1 Lake Park" }
|
|
49
|
+
];
|
|
50
|
+
const components = {
|
|
51
|
+
body: { tbody: CustomTbody, row: CustomRow }
|
|
52
|
+
};
|
|
53
|
+
return /* @__PURE__ */ import_react.default.createElement(import_yee_c.Table, { columns, dataSource, components });
|
|
54
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Table/demo/grouping.tsx
|
|
30
|
+
var grouping_exports = {};
|
|
31
|
+
__export(grouping_exports, {
|
|
32
|
+
default: () => grouping_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(grouping_exports);
|
|
35
|
+
var import_yee_c = require("../..");
|
|
36
|
+
var import_react = __toESM(require("react"));
|
|
37
|
+
var grouping_default = () => {
|
|
38
|
+
const [selectedRowKeys, setSelectedRowKeys] = (0, import_react.useState)([]);
|
|
39
|
+
const columns = [
|
|
40
|
+
{
|
|
41
|
+
title: "Name",
|
|
42
|
+
dataIndex: "name",
|
|
43
|
+
key: "name",
|
|
44
|
+
fixed: "left",
|
|
45
|
+
width: 120,
|
|
46
|
+
sorter: true
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
title: "Info",
|
|
50
|
+
key: "info",
|
|
51
|
+
children: [
|
|
52
|
+
{ title: "Age", dataIndex: "age", key: "age", width: 100, sorter: true },
|
|
53
|
+
{
|
|
54
|
+
title: "Address",
|
|
55
|
+
dataIndex: "address",
|
|
56
|
+
key: "address",
|
|
57
|
+
width: 200
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
title: "Company",
|
|
63
|
+
key: "company",
|
|
64
|
+
children: [
|
|
65
|
+
{
|
|
66
|
+
title: "Name",
|
|
67
|
+
dataIndex: "companyName",
|
|
68
|
+
key: "companyName",
|
|
69
|
+
width: 180
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: "Address",
|
|
73
|
+
dataIndex: "companyAddress",
|
|
74
|
+
key: "companyAddress",
|
|
75
|
+
width: 220
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
title: "Action",
|
|
81
|
+
key: "action",
|
|
82
|
+
fixed: "right",
|
|
83
|
+
width: 100,
|
|
84
|
+
render: (record) => /* @__PURE__ */ import_react.default.createElement("a", { onClick: () => console.log(record) }, "Edit")
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
const dataSource = [
|
|
88
|
+
{
|
|
89
|
+
key: "1",
|
|
90
|
+
name: "John Brown",
|
|
91
|
+
age: 32,
|
|
92
|
+
address: "New York No. 1 Lake Park",
|
|
93
|
+
companyName: "Acme Inc.",
|
|
94
|
+
companyAddress: "NY Office"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: "2",
|
|
98
|
+
name: "Jim Green",
|
|
99
|
+
age: 42,
|
|
100
|
+
address: "London No. 1 Lake Park",
|
|
101
|
+
companyName: "Globex",
|
|
102
|
+
companyAddress: "London Office"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
key: "3",
|
|
106
|
+
name: "Joe Black",
|
|
107
|
+
age: 28,
|
|
108
|
+
address: "Sidney No. 1 Lake Park",
|
|
109
|
+
companyName: "Initech",
|
|
110
|
+
companyAddress: "Sidney Office"
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
const rowSelection = {
|
|
114
|
+
type: "checkbox",
|
|
115
|
+
selectedRowKeys,
|
|
116
|
+
onChange: (keys) => setSelectedRowKeys(keys)
|
|
117
|
+
};
|
|
118
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
119
|
+
import_yee_c.Table,
|
|
120
|
+
{
|
|
121
|
+
columns,
|
|
122
|
+
dataSource,
|
|
123
|
+
rowKey: "key",
|
|
124
|
+
rowSelection,
|
|
125
|
+
bordered: true,
|
|
126
|
+
scroll: { x: 1200 }
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ColumnProps, ExpandableType, RowSelectionType } from '../interface';
|
|
2
|
+
import type { ColumnProps, ExpandableType, RowSelectionType } from '../interface';
|
|
3
3
|
export default function useColumns({ children, columns, rowSelection, expandable, }: {
|
|
4
4
|
children?: React.ReactElement<ColumnProps> | React.ReactElement<ColumnProps>[];
|
|
5
5
|
columns: ColumnProps[];
|
|
@@ -7,5 +7,5 @@ export default function useColumns({ children, columns, rowSelection, expandable
|
|
|
7
7
|
expandable?: ExpandableType;
|
|
8
8
|
}): {
|
|
9
9
|
wrapedColumns: any;
|
|
10
|
-
|
|
10
|
+
headerRows: any;
|
|
11
11
|
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
@@ -20,7 +18,6 @@ var __spreadValues = (a, b) => {
|
|
|
20
18
|
}
|
|
21
19
|
return a;
|
|
22
20
|
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
21
|
var __export = (target, all) => {
|
|
25
22
|
for (var name in all)
|
|
26
23
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -53,6 +50,7 @@ var import_react = __toESM(require("react"));
|
|
|
53
50
|
var import_useDeepCompareMemo = __toESM(require("../../hooks/useDeepCompareMemo"));
|
|
54
51
|
var import_deepClone = __toESM(require("../../utils/deepClone"));
|
|
55
52
|
var import_util = require("../util");
|
|
53
|
+
var import_header = require("../util/header");
|
|
56
54
|
function useColumns({
|
|
57
55
|
children,
|
|
58
56
|
columns,
|
|
@@ -61,48 +59,28 @@ function useColumns({
|
|
|
61
59
|
}) {
|
|
62
60
|
const shouldRenderSelection = !!rowSelection;
|
|
63
61
|
const shouldRenderExpand = !!expandable;
|
|
64
|
-
const getColumnsFromChild = (
|
|
65
|
-
const
|
|
66
|
-
import_react.default.Children.forEach(
|
|
62
|
+
const getColumnsFromChild = (childs) => {
|
|
63
|
+
const cols = [];
|
|
64
|
+
import_react.default.Children.forEach(childs, (child) => {
|
|
67
65
|
if (child) {
|
|
68
|
-
|
|
66
|
+
cols.push(__spreadValues({}, child.props));
|
|
69
67
|
}
|
|
70
68
|
});
|
|
71
|
-
return
|
|
69
|
+
return cols.length ? cols : null;
|
|
72
70
|
};
|
|
73
71
|
const childColumns = (0, import_react.useMemo)(() => {
|
|
74
72
|
return children ? getColumnsFromChild(children) : null;
|
|
75
73
|
}, [children]);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}, rowSelection), {
|
|
84
|
-
key: "YEE_SELECTION_COL"
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
if (expandable) {
|
|
88
|
-
const { index = 1, visible = true } = expandable;
|
|
89
|
-
const loc = index ? index - 1 : rowSelection ? 1 : 0;
|
|
90
|
-
if (visible !== false) {
|
|
91
|
-
result.splice(loc, 0, __spreadProps(__spreadValues({
|
|
92
|
-
width: 50
|
|
93
|
-
}, expandable), {
|
|
94
|
-
key: "YEE_EXPAND_COL"
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
result = (0, import_util.handleColumns)(result);
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
const mergedColumns = (0, import_useDeepCompareMemo.default)(() => {
|
|
102
|
-
return wrapColumns(childColumns || columns || []);
|
|
74
|
+
const { wrapedColumns, headerRows } = (0, import_useDeepCompareMemo.default)(() => {
|
|
75
|
+
const base = (0, import_deepClone.default)(childColumns || columns || []) || [];
|
|
76
|
+
const tree = (0, import_header.injectSelectionExpand)(base, rowSelection, expandable);
|
|
77
|
+
const leaves = (0, import_header.flattenLeafColumns)(tree);
|
|
78
|
+
const wraped = (0, import_util.handleColumns)(leaves);
|
|
79
|
+
const rows = (0, import_header.parseHeaderRows)(tree);
|
|
80
|
+
return { wrapedColumns: wraped, headerRows: rows };
|
|
103
81
|
}, [childColumns, columns, shouldRenderSelection, shouldRenderExpand]);
|
|
104
82
|
return {
|
|
105
|
-
wrapedColumns
|
|
106
|
-
|
|
83
|
+
wrapedColumns,
|
|
84
|
+
headerRows
|
|
107
85
|
};
|
|
108
86
|
}
|
|
@@ -2,7 +2,7 @@ import Column from './column';
|
|
|
2
2
|
import Summary from './summary';
|
|
3
3
|
import InternalTable from './table';
|
|
4
4
|
import Head from './theader';
|
|
5
|
-
export type { ColumnProps, PaginationType, RowSelectionType, TableProps, onChangeParams, } from './interface';
|
|
5
|
+
export type { ColumnProps, PaginationType, RowSelectionType, TableProps, TableComponents, TableBodyComponents, TableRowRendererProps, HeaderCell, onChangeParams, } from './interface';
|
|
6
6
|
type TableType = typeof InternalTable & {
|
|
7
7
|
Column: typeof Column;
|
|
8
8
|
Summary: typeof Summary;
|
|
@@ -66,6 +66,14 @@ export interface HeadCellProps extends Omit<WrapedColumnProps, 'title'> {
|
|
|
66
66
|
};
|
|
67
67
|
onSort?: (dataIndex: string, sorter: any) => void;
|
|
68
68
|
onInternalFilter?: (dataIndex: string, value: string) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Horizontal span, used for grouped header cells
|
|
71
|
+
*/
|
|
72
|
+
colSpan?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Vertical span, used for grouped header cells
|
|
75
|
+
*/
|
|
76
|
+
rowSpan?: number;
|
|
69
77
|
}
|
|
70
78
|
export interface RowSelectionType {
|
|
71
79
|
/**
|
|
@@ -226,9 +234,9 @@ export interface ColumnProps {
|
|
|
226
234
|
*/
|
|
227
235
|
helper?: string | React.ReactNode;
|
|
228
236
|
/**
|
|
229
|
-
*
|
|
237
|
+
* Sub-columns for header grouping (multi-level header). Use cell `render` for custom cell content.
|
|
230
238
|
*/
|
|
231
|
-
children?:
|
|
239
|
+
children?: ColumnProps[];
|
|
232
240
|
/**
|
|
233
241
|
* Set cell properties
|
|
234
242
|
*/
|
|
@@ -252,7 +260,50 @@ export interface WrapedColumnProps extends ColumnProps, ExpandableType, Omit<Row
|
|
|
252
260
|
*/
|
|
253
261
|
isFixedRightFirst?: boolean;
|
|
254
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* A header cell resolved from the column tree, with computed span info for multi-level headers.
|
|
265
|
+
*/
|
|
266
|
+
export interface HeaderCell {
|
|
267
|
+
/**
|
|
268
|
+
* The source wrapped column (leaf or group)
|
|
269
|
+
*/
|
|
270
|
+
column: WrapedColumnProps;
|
|
271
|
+
/**
|
|
272
|
+
* Horizontal span (number of leaf columns covered)
|
|
273
|
+
*/
|
|
274
|
+
colSpan: number;
|
|
275
|
+
/**
|
|
276
|
+
* Vertical span (number of header rows covered)
|
|
277
|
+
*/
|
|
278
|
+
rowSpan: number;
|
|
279
|
+
/**
|
|
280
|
+
* Whether this cell has sub-columns (group header)
|
|
281
|
+
*/
|
|
282
|
+
hasSubColumns?: boolean;
|
|
283
|
+
}
|
|
255
284
|
type DownloadType = ButtonProps;
|
|
285
|
+
/**
|
|
286
|
+
* 行接管渲染器收到的 props(components.body.row)
|
|
287
|
+
*/
|
|
288
|
+
export interface TableRowRendererProps {
|
|
289
|
+
record: Record<string, any>;
|
|
290
|
+
index: number;
|
|
291
|
+
columns: WrapedColumnProps[];
|
|
292
|
+
/** 当前行 key 值(= record[rowKey]),可作 sortable id */
|
|
293
|
+
rowKey: string | number;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 可被外部接管的 <tbody> / 行渲染
|
|
297
|
+
*/
|
|
298
|
+
export interface TableBodyComponents {
|
|
299
|
+
/** 替换 <tbody>;常用于在外部包 SortableContext 等 Provider */
|
|
300
|
+
tbody?: React.ElementType;
|
|
301
|
+
/** 整行接管:消费方自行渲染 <tr> + 单元格(含拖拽手柄等) */
|
|
302
|
+
row?: React.ComponentType<TableRowRendererProps>;
|
|
303
|
+
}
|
|
304
|
+
export interface TableComponents {
|
|
305
|
+
body?: TableBodyComponents;
|
|
306
|
+
}
|
|
256
307
|
export type SemanticProps = {
|
|
257
308
|
/**
|
|
258
309
|
* Semantic class names
|
|
@@ -265,7 +316,7 @@ export type SemanticProps = {
|
|
|
265
316
|
/**
|
|
266
317
|
* Custom table elements
|
|
267
318
|
*/
|
|
268
|
-
components?:
|
|
319
|
+
components?: TableComponents;
|
|
269
320
|
};
|
|
270
321
|
export interface HeaderProps extends SemanticProps {
|
|
271
322
|
/**
|
|
@@ -316,8 +367,8 @@ export interface TableRowProps {
|
|
|
316
367
|
stripe?: boolean;
|
|
317
368
|
expandedKeyType?: string;
|
|
318
369
|
onRow?: (record: Record<string, any>, index: number) => Record<string, any>;
|
|
319
|
-
rowClassName?: (record: Record<string, any>, index: number) => string;
|
|
320
|
-
rowStyle?: (record: Record<string, any>, index: number) => React.CSSProperties;
|
|
370
|
+
rowClassName?: (record: Record<string, any>, index: number) => string | undefined;
|
|
371
|
+
rowStyle?: (record: Record<string, any>, index: number) => React.CSSProperties | undefined;
|
|
321
372
|
onDoubleClick?: (record: Record<string, any>, event: React.MouseEvent<HTMLTableRowElement>) => void;
|
|
322
373
|
onExpand: ({ expanded, record, index, }: {
|
|
323
374
|
expanded: boolean;
|
|
@@ -403,7 +454,7 @@ export interface TableProps extends FooterProps, Omit<HeaderProps, 'pageData'>,
|
|
|
403
454
|
/**
|
|
404
455
|
* Custom table elements
|
|
405
456
|
*/
|
|
406
|
-
components?:
|
|
457
|
+
components?: TableComponents;
|
|
407
458
|
/**
|
|
408
459
|
* Whether to show outer and column borders
|
|
409
460
|
*/
|
|
@@ -447,11 +498,11 @@ export interface TableProps extends FooterProps, Omit<HeaderProps, 'pageData'>,
|
|
|
447
498
|
/**
|
|
448
499
|
* Row class name, unlike classNames, this prop can be set dynamically via a function
|
|
449
500
|
*/
|
|
450
|
-
rowClassName?: (record: object) => string;
|
|
501
|
+
rowClassName?: (record: object) => string | undefined;
|
|
451
502
|
/**
|
|
452
503
|
* Row style, unlike styles, this prop can be set dynamically via a function
|
|
453
504
|
*/
|
|
454
|
-
rowStyle?: (record: object) => React.CSSProperties;
|
|
505
|
+
rowStyle?: (record: object) => React.CSSProperties | undefined;
|
|
455
506
|
/**
|
|
456
507
|
* Pagination config
|
|
457
508
|
*/
|
|
@@ -153,7 +153,25 @@
|
|
|
153
153
|
|
|
154
154
|
&-tbody {
|
|
155
155
|
@{pls}-cell {
|
|
156
|
-
background-color: var(--yee-table-cell-bg-color,
|
|
156
|
+
background-color: var(--yee-table-cell-bg-color, inherit);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@{pls}-row {
|
|
160
|
+
&:hover {
|
|
161
|
+
background-color: var(--yee-table-tbody-tr-hover-bg-color);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
&-odd-row {
|
|
167
|
+
> @{pls}-cell {
|
|
168
|
+
background-color: var(--yee-table-odd-row-bg-color);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
&-even-row {
|
|
173
|
+
> @{pls}-cell {
|
|
174
|
+
background-color: var(--yee-table-even-row-bg-color);
|
|
157
175
|
}
|
|
158
176
|
}
|
|
159
177
|
|
package/dist/cjs/Table/table.js
CHANGED
|
@@ -149,7 +149,7 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
149
149
|
const allKeys = (0, import_react.useMemo)(() => {
|
|
150
150
|
return Array.isArray(dataSource) ? dataSource.map((item) => getRowKey(item)) : [];
|
|
151
151
|
}, [dataSource, rowKey, getRowKey]);
|
|
152
|
-
const { wrapedColumns,
|
|
152
|
+
const { wrapedColumns, headerRows } = (0, import_useColumns.default)({
|
|
153
153
|
children,
|
|
154
154
|
columns: propColumns,
|
|
155
155
|
expandable,
|
|
@@ -162,7 +162,7 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
162
162
|
data: sortedData,
|
|
163
163
|
sorters,
|
|
164
164
|
onSort
|
|
165
|
-
} = (0, import_useSorter.default)({ data: filteredData, columns });
|
|
165
|
+
} = (0, import_useSorter.default)({ data: filteredData, columns: wrapedColumns });
|
|
166
166
|
const { pageData, current, pageSize, pagination } = (0, import_usePagination.default)({
|
|
167
167
|
data: sortedData,
|
|
168
168
|
pagination: propPagination,
|
|
@@ -185,7 +185,6 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
185
185
|
const {
|
|
186
186
|
selectedRowKeys,
|
|
187
187
|
checkedAll,
|
|
188
|
-
pageDataRowKeys,
|
|
189
188
|
onCheckAll,
|
|
190
189
|
onChange: onSelectionChange
|
|
191
190
|
} = (0, import_useSelection.default)({ pageData, dataSource, getRowKey, rowSelection, allKeys });
|
|
@@ -237,7 +236,7 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
237
236
|
prefixCls,
|
|
238
237
|
header,
|
|
239
238
|
download,
|
|
240
|
-
columns,
|
|
239
|
+
columns: wrapedColumns,
|
|
241
240
|
pageData,
|
|
242
241
|
dataSource
|
|
243
242
|
}
|
|
@@ -251,8 +250,7 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
251
250
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
252
251
|
import_theader.default,
|
|
253
252
|
__spreadProps(__spreadValues({}, ths), {
|
|
254
|
-
|
|
255
|
-
pageDataRowKeys,
|
|
253
|
+
headerRows,
|
|
256
254
|
checkedAll,
|
|
257
255
|
sorters,
|
|
258
256
|
onSort,
|
|
@@ -297,7 +295,7 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
297
295
|
{
|
|
298
296
|
value: {
|
|
299
297
|
prefixCls,
|
|
300
|
-
columns,
|
|
298
|
+
columns: wrapedColumns,
|
|
301
299
|
classNames,
|
|
302
300
|
styles,
|
|
303
301
|
components,
|
|
@@ -66,7 +66,6 @@ var TableCell = (props) => {
|
|
|
66
66
|
className,
|
|
67
67
|
styles,
|
|
68
68
|
classNames,
|
|
69
|
-
children,
|
|
70
69
|
onCell,
|
|
71
70
|
render
|
|
72
71
|
} = column;
|
|
@@ -75,9 +74,6 @@ var TableCell = (props) => {
|
|
|
75
74
|
if (render) {
|
|
76
75
|
return typeof render === "function" ? render(record, rowIndex) : render;
|
|
77
76
|
}
|
|
78
|
-
if (typeof children === "function") {
|
|
79
|
-
return children(record, rowIndex);
|
|
80
|
-
}
|
|
81
77
|
return /* @__PURE__ */ React.createElement(
|
|
82
78
|
"div",
|
|
83
79
|
{
|
|
@@ -67,19 +67,36 @@ var import_table = require("../table");
|
|
|
67
67
|
var import_lazy_row = __toESM(require("./lazy-row"));
|
|
68
68
|
var import_row = __toESM(require("./row"));
|
|
69
69
|
var TableBody = (props) => {
|
|
70
|
+
var _b, _c, _d;
|
|
70
71
|
const _a = props, { columns, pageData, lazyLoad } = _a, rest = __objRest(_a, ["columns", "pageData", "lazyLoad"]);
|
|
71
|
-
const { prefixCls } = import_react.default.useContext(import_table.TableCtx);
|
|
72
|
+
const { prefixCls, components, rowKey } = import_react.default.useContext(import_table.TableCtx);
|
|
72
73
|
const { locale } = (0, import_locale.useLocale)();
|
|
73
74
|
const { table: tableLocale } = locale;
|
|
74
75
|
const empty = /* @__PURE__ */ import_react.default.createElement("tbody", { className: `${prefixCls}-tbody` }, /* @__PURE__ */ import_react.default.createElement("tr", { className: `${prefixCls}-no-record` }, /* @__PURE__ */ import_react.default.createElement("td", { colSpan: 999 }, tableLocale.emptyText)));
|
|
75
76
|
const dataLength = pageData.length;
|
|
76
77
|
if (dataLength === 0)
|
|
77
78
|
return empty;
|
|
79
|
+
const BodyWrapper = (_c = (_b = components == null ? void 0 : components.body) == null ? void 0 : _b.tbody) != null ? _c : "tbody";
|
|
80
|
+
const RowRenderer = (_d = components == null ? void 0 : components.body) == null ? void 0 : _d.row;
|
|
81
|
+
const resolveRowKey = (record) => typeof rowKey === "function" ? rowKey(record) : record[rowKey];
|
|
78
82
|
const getRenderRows = () => {
|
|
79
83
|
if (lazyLoad) {
|
|
80
84
|
return /* @__PURE__ */ import_react.default.createElement(import_lazy_row.default, __spreadProps(__spreadValues({}, rest), { pageData, columns }));
|
|
81
85
|
}
|
|
82
86
|
return pageData.map((record, index) => {
|
|
87
|
+
if (RowRenderer) {
|
|
88
|
+
const rk = resolveRowKey(record);
|
|
89
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
90
|
+
RowRenderer,
|
|
91
|
+
{
|
|
92
|
+
key: rk != null ? rk : index,
|
|
93
|
+
record,
|
|
94
|
+
index,
|
|
95
|
+
columns,
|
|
96
|
+
rowKey: rk
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}
|
|
83
100
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
84
101
|
import_row.default,
|
|
85
102
|
__spreadProps(__spreadValues({}, rest), {
|
|
@@ -91,7 +108,7 @@ var TableBody = (props) => {
|
|
|
91
108
|
);
|
|
92
109
|
});
|
|
93
110
|
};
|
|
94
|
-
const tbody = /* @__PURE__ */ import_react.default.createElement(
|
|
111
|
+
const tbody = /* @__PURE__ */ import_react.default.createElement(BodyWrapper, { className: `${prefixCls}-tbody` }, getRenderRows());
|
|
95
112
|
return tbody;
|
|
96
113
|
};
|
|
97
114
|
var tbody_default = TableBody;
|
|
@@ -127,20 +127,24 @@ var TableRow = (props) => {
|
|
|
127
127
|
});
|
|
128
128
|
};
|
|
129
129
|
const getSelection = (column) => {
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const props2 = onCell ? onCell(record, index)
|
|
133
|
-
const checked = selectedRowKeys == null ? void 0 : selectedRowKeys.includes(
|
|
134
|
-
const
|
|
130
|
+
const { type, disabled: colDisabled, onCell } = column;
|
|
131
|
+
const rowKeyValue = record[rowKey];
|
|
132
|
+
const props2 = (onCell == null ? void 0 : onCell(record, index)) || {};
|
|
133
|
+
const checked = selectedRowKeys == null ? void 0 : selectedRowKeys.includes(rowKeyValue);
|
|
134
|
+
const disabled = typeof colDisabled === "function" ? colDisabled(record, index) : Array.isArray(colDisabled) ? colDisabled[index] : !!colDisabled;
|
|
135
|
+
const commonProps = __spreadValues({
|
|
135
136
|
checked,
|
|
136
|
-
value:
|
|
137
|
-
onChange: onSelectionChange
|
|
138
|
-
|
|
137
|
+
value: rowKeyValue,
|
|
138
|
+
onChange: onSelectionChange,
|
|
139
|
+
disabled
|
|
140
|
+
}, props2);
|
|
139
141
|
if (type === "checkbox") {
|
|
140
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
141
|
-
|
|
142
|
-
|
|
142
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
143
|
+
import_Checkbox.default,
|
|
144
|
+
__spreadValues({}, commonProps)
|
|
145
|
+
);
|
|
143
146
|
}
|
|
147
|
+
return /* @__PURE__ */ import_react.default.createElement(import_Radio.default, __spreadValues({}, commonProps));
|
|
144
148
|
};
|
|
145
149
|
let colSpanStart = Infinity;
|
|
146
150
|
let colSpanEnd = -1;
|
|
@@ -86,6 +86,8 @@ var HeadCell = (props) => {
|
|
|
86
86
|
internalFilters,
|
|
87
87
|
style,
|
|
88
88
|
width,
|
|
89
|
+
colSpan,
|
|
90
|
+
rowSpan,
|
|
89
91
|
onHeaderCell,
|
|
90
92
|
onSort,
|
|
91
93
|
onInternalFilter
|
|
@@ -107,6 +109,8 @@ var HeadCell = (props) => {
|
|
|
107
109
|
"internalFilters",
|
|
108
110
|
"style",
|
|
109
111
|
"width",
|
|
112
|
+
"colSpan",
|
|
113
|
+
"rowSpan",
|
|
110
114
|
"onHeaderCell",
|
|
111
115
|
"onSort",
|
|
112
116
|
"onInternalFilter"
|
|
@@ -203,7 +207,9 @@ var HeadCell = (props) => {
|
|
|
203
207
|
return __spreadProps(__spreadValues({}, cellProps), {
|
|
204
208
|
className: cls,
|
|
205
209
|
scope: "col",
|
|
206
|
-
style: styles2
|
|
210
|
+
style: styles2,
|
|
211
|
+
colSpan,
|
|
212
|
+
rowSpan
|
|
207
213
|
});
|
|
208
214
|
};
|
|
209
215
|
const thProps = getThProps();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { HeaderCell } from '../interface';
|
|
3
3
|
export interface TableHeadProps {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Resolved 2D header rows (one array per header row), produced by parseHeaderRows
|
|
6
|
+
*/
|
|
7
|
+
headerRows?: HeaderCell[][];
|
|
8
8
|
}
|
|
9
9
|
declare const _default: React.NamedExoticComponent<any>;
|
|
10
10
|
export default _default;
|