Skip to content

Commit 16ede58

Browse files
authored
Merge pull request #17 from easyops-cn/steve/table-style
fix(): sync table style with v2
2 parents 7cca433 + 27c1c3b commit 16ede58

File tree

11 files changed

+324
-206
lines changed

11 files changed

+324
-206
lines changed

bricks/advanced/docs/eo-next-table.md

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,15 @@
434434
- action: console.log
435435
properties:
436436
expandable:
437-
columnWidth: 100px
438437
rowExpandable: <% DATA.rowData.key % 2 === 0 %>
439-
expandIconBrick:
440-
useBrick:
441-
brick: eo-link
442-
properties:
443-
disabled: "<% !DATA.expandable %>"
444-
textContent: "<% DATA.expanded ? '点击收起' : '点击展开' %>"
445438
expandedRowBrick:
446439
useBrick:
447440
brick: eo-next-table
448441
properties:
442+
scrollConfig: false
449443
pagination: false
450444
bordered: true
445+
rowKey: title
451446
columns:
452447
- dataIndex: title
453448
key: title
@@ -459,21 +454,9 @@
459454
key: operator
460455
title: 操作
461456
useBrick:
462-
- brick: div
463-
properties:
464-
style:
465-
display: flex
466-
gap: 4px
467-
children:
468-
- brick: eo-button
469-
properties:
470-
type: link
471-
textContent: 操作
472-
events:
473-
click:
474-
- action: message.info
475-
args:
476-
- <% `id:${DATA.rowData.id}` %>
457+
brick: eo-link
458+
properties:
459+
textContent: 操作
477460
dataSource:
478461
list: <% DATA.rowData.info %>
479462
pagination:
@@ -524,7 +507,7 @@
524507
- key: 3
525508
name: Sam
526509
age: 28
527-
address: Guangzhou
510+
address: Shenzhen
528511
- key: 4
529512
name: Bob
530513
age: 35
@@ -536,7 +519,7 @@
536519
- key: 6
537520
name: Sophia
538521
age: 20
539-
address: Shanghai
522+
address: Nanjing
540523
- key: 7
541524
name: Charlotte
542525
age: 33
@@ -548,7 +531,7 @@
548531
- key: 9
549532
name: Noah
550533
age: 38
551-
address: Hainan
534+
address: Wuhan
552535
- key: 10
553536
name: William
554537
age: 16

bricks/advanced/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"postpublish": "mv package.json.bak package.json"
3636
},
3737
"dependencies": {
38-
"@ant-design/cssinjs": "^1.22.0",
39-
"@ant-design/icons": "^5.5.1",
38+
"@ant-design/cssinjs": "^1.22.1",
39+
"@ant-design/icons": "^5.5.2",
4040
"@dnd-kit/core": "^6.0.8",
4141
"@dnd-kit/modifiers": "^6.0.1",
4242
"@dnd-kit/sortable": "^7.0.2",
@@ -51,7 +51,7 @@
5151
"@react-pdf-viewer/core": "^3.12.0",
5252
"@react-pdf-viewer/default-layout": "^3.12.0",
5353
"@react-pdf-viewer/page-navigation": "^3.12.0",
54-
"antd": "^5.22.1",
54+
"antd": "^5.23.2",
5555
"classnames": "^2.3.2",
5656
"html2canvas": "^1.4.1",
5757
"immutability-helper": "^3.1.1",

bricks/advanced/src/next-table/Table.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ import { StyleProvider, createCache } from "@ant-design/cssinjs";
2222
import { useCurrentTheme } from "@next-core/react-runtime";
2323
import { RowSelectMethod, type SortOrder } from "antd/es/table/interface.js";
2424
import type { TableProps } from "antd/es/table";
25+
import { DownOutlined, RightOutlined } from "@ant-design/icons";
26+
import type { RenderExpandIconProps } from "rc-table/lib/interface.js";
2527
import { i18n } from "@next-core/i18n";
2628
import { useTranslation, initializeReactI18n } from "@next-core/i18n/react";
2729
import { Trans } from "react-i18next";
30+
import classNames from "classnames";
2831
import { K, NS, locales } from "./i18n.js";
2932
import {
3033
DEFAULT_PAGE,
@@ -297,7 +300,7 @@ export const NextTableComponent = forwardRef(function LegacyNextTableComponent(
297300
data={data}
298301
/>
299302
) : (
300-
<>{col.title}</>
303+
<>{col.title as string}</>
301304
);
302305
},
303306
onCell(record: RecordType) {
@@ -413,9 +416,22 @@ export const NextTableComponent = forwardRef(function LegacyNextTableComponent(
413416
: theme.defaultAlgorithm,
414417
components: {
415418
Table: {
416-
headerBorderRadius: 0,
419+
headerBorderRadius:
420+
"var(--eo-next-table-header-border-radius)" as unknown as number,
417421
headerSplitColor: "none",
418-
...(bordered ? { borderColor: "#f0f0f0" } : {}),
422+
headerBg: "var(--antd-table-header-bg)",
423+
headerSortActiveBg: "var(--antd-table-header-sort-active-bg)",
424+
headerSortHoverBg: "var(--antd-table-header-sort-active-bg)",
425+
bodySortBg: "var(--antd-table-header-overwrite-sort-td-active-bg)",
426+
// cellPaddingBlock: 11,
427+
// cellPaddingInline: 12,
428+
// cellPaddingBlockMD: 8,
429+
// cellPaddingInlineMD: 12,
430+
// cellPaddingBlockSM: 4,
431+
// cellPaddingInlineSM: 12,
432+
...(bordered
433+
? { borderColor: "var(--theme-gray-border-color)" }
434+
: {}),
419435
},
420436
},
421437
}}
@@ -462,6 +478,10 @@ export const NextTableComponent = forwardRef(function LegacyNextTableComponent(
462478
total: dataSource?.total,
463479
current: page,
464480
pageSize: pageSize,
481+
showSizeChanger: {
482+
showSearch: false,
483+
variant: "borderless",
484+
},
465485
showTotal: (total: number) => {
466486
return (
467487
<div className="pagination-wrapper">
@@ -558,12 +578,14 @@ export const NextTableComponent = forwardRef(function LegacyNextTableComponent(
558578
: true;
559579
},
560580
expandedRowRender: expandConfig.expandedRowBrick?.useBrick
561-
? (record, index, indent, expanded) => {
581+
? (record, index, indent /* , expanded */) => {
562582
const data = {
563583
rowData: record,
564584
index,
565585
indent,
566-
expanded,
586+
// Do not pass `expanded`, it changes every time the row is toggled,
587+
// thus the brick will be re-rendered every time as well.
588+
// expanded,
567589
};
568590
return (
569591
<CacheUseBrickItem
@@ -597,7 +619,7 @@ export const NextTableComponent = forwardRef(function LegacyNextTableComponent(
597619
</span>
598620
);
599621
}
600-
: undefined,
622+
: DefaultExpandIcon,
601623
onExpand: (expanded, record) => {
602624
onRowExpand?.({ expanded, record });
603625
},
@@ -662,3 +684,18 @@ export const NextTableComponent = forwardRef(function LegacyNextTableComponent(
662684
</ConfigProvider>
663685
);
664686
});
687+
688+
function DefaultExpandIcon({
689+
expanded,
690+
expandable,
691+
onExpand,
692+
record,
693+
}: RenderExpandIconProps<RecordType>) {
694+
const IconComponent = expanded ? DownOutlined : RightOutlined;
695+
return (
696+
<IconComponent
697+
className={classNames("expand-icon", { invisible: !expandable })}
698+
onClick={(e) => expandable && onExpand(record, e)}
699+
/>
700+
);
701+
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
:root {
22
--eo-table-head-cell-padding: 14px 12px;
3-
--eo-table-body-cell-padding: 12px 12px;
3+
--eo-table-body-cell-padding: 11px 12px;
44
}
55

66
html[data-ui="v8-2"] {
7-
--eo-table-head-cell-padding: 8px 12px;
7+
--eo-table-head-cell-padding: 9px 12px;
88

99
eo-next-table[size="large"] {
10-
--eo-table-body-cell-padding: 10px 12px;
10+
--eo-table-body-cell-padding: 11px 12px;
1111
}
1212

1313
eo-next-table[size="middle"] {
14+
--eo-table-head-cell-padding: 7px 12px;
1415
--eo-table-body-cell-padding: 8px 12px;
1516
}
1617

1718
eo-next-table[size="small"] {
19+
--eo-table-head-cell-padding: 3px 12px;
1820
--eo-table-body-cell-padding: 4px 12px;
1921
}
2022
}

bricks/advanced/src/next-table/index.spec.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,10 @@ describe("rowSelection", () => {
11881188
// Not including halfChecked
11891189
keys: [
11901190
...treeDataSource.list[0].student
1191-
.filter((v, i) => i !== 0)
1191+
.filter((_v, i) => i !== 0)
11921192
.map((v) => v.key),
11931193
],
1194-
rows: [...treeDataSource.list[0].student.filter((v, i) => i !== 0)],
1194+
rows: [...treeDataSource.list[0].student.filter((_v, i) => i !== 0)],
11951195
info: {
11961196
type: "single",
11971197
},
@@ -1286,15 +1286,19 @@ describe("expandable", () => {
12861286

12871287
await act(async () => {
12881288
fireEvent.click(
1289-
element.shadowRoot?.querySelectorAll(".expand-icon")[1] as Element
1289+
element.shadowRoot?.querySelectorAll(
1290+
".expand-icon:not(.invisible)"
1291+
)[1] as Element
12901292
);
12911293
});
12921294
expect(onRowExpand).not.toBeCalled();
12931295
expect(onExpandedRowsChange).not.toBeCalled();
12941296

12951297
await act(async () => {
12961298
fireEvent.click(
1297-
element.shadowRoot?.querySelectorAll(".expand-icon")[0] as Element
1299+
element.shadowRoot?.querySelectorAll(
1300+
".expand-icon:not(.invisible)"
1301+
)[0] as Element
12981302
);
12991303
});
13001304
expect(
@@ -1318,7 +1322,9 @@ describe("expandable", () => {
13181322

13191323
await act(async () => {
13201324
fireEvent.click(
1321-
element.shadowRoot?.querySelectorAll(".expand-icon")[0] as Element
1325+
element.shadowRoot?.querySelectorAll(
1326+
".expand-icon:not(.invisible)"
1327+
)[0] as Element
13221328
);
13231329
});
13241330
expect(onRowExpand).lastCalledWith(
@@ -1366,7 +1372,7 @@ describe("expandable", () => {
13661372
await act(async () => {
13671373
fireEvent.click(
13681374
element.shadowRoot?.querySelectorAll(
1369-
".ant-table-row-expand-icon:not(.ant-table-row-expand-icon-spaced)"
1375+
".expand-icon:not(.invisible)"
13701376
)[1] as Element
13711377
);
13721378
});
@@ -1390,7 +1396,7 @@ describe("expandable", () => {
13901396
await act(async () => {
13911397
fireEvent.click(
13921398
element.shadowRoot?.querySelectorAll(
1393-
".ant-table-row-expand-icon:not(.ant-table-row-expand-icon-spaced)"
1399+
".expand-icon:not(.invisible)"
13941400
)[2] as Element
13951401
);
13961402
});
@@ -1452,7 +1458,7 @@ describe("expandable", () => {
14521458
await act(async () => {
14531459
fireEvent.click(
14541460
element.shadowRoot?.querySelectorAll(
1455-
".ant-table-row-expand-icon:not(.ant-table-row-expand-icon-spaced)"
1461+
".expand-icon:not(.invisible)"
14561462
)[1] as Element
14571463
);
14581464
});
@@ -1545,7 +1551,7 @@ describe("draggable", () => {
15451551
});
15461552

15471553
describe("define cell brick", () => {
1548-
const columns = new Array(3).fill(null).map((d, key) => ({
1554+
const columns = new Array(3).fill(null).map((_d, key) => ({
15491555
dataIndex: key,
15501556
key,
15511557
title: key,

bricks/advanced/src/next-table/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class EoNextTable extends ReactNextElement {
182182
/**
183183
* 是否显示边框
184184
*/
185+
@property({ type: Boolean })
185186
accessor bordered: boolean | undefined;
186187

187188
/**

0 commit comments

Comments
 (0)