Skip to content

Commit d06f8a0

Browse files
authored
Merge branch 'master' into antd-5.x
2 parents 6fff957 + 2cbe690 commit d06f8a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+6603
-19032
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ es/
3333
.storybook
3434
.doc
3535
!__mocks__/rc-util/lib
36+
!__mocks__/@rc-component/util/lib
3637
examples/debug.tsx
3738
.history
3839
~*

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shamefully-hoist=true

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# rc-table
1+
# @rc-component/table
22

33
React table component with useful functions.
44

55
[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
66

7-
[npm-image]: http://img.shields.io/npm/v/rc-table.svg?style=flat-square
8-
[npm-url]: http://npmjs.org/package/rc-table
7+
[npm-image]: http://img.shields.io/npm/v/@rc-component/table.svg?style=flat-square
8+
[npm-url]: http://npmjs.org/package/@rc-component/table
99
[github-actions-image]: https://github.com/react-component/table/workflows/CI/badge.svg
1010
[github-actions-url]: https://github.com/react-component/table/actions
1111
[coveralls-image]: https://img.shields.io/coveralls/react-component/table.svg?style=flat-square
@@ -16,14 +16,14 @@ React table component with useful functions.
1616
[david-image]: https://david-dm.org/react-component/table/status.svg?style=flat-square
1717
[david-dev-url]: https://david-dm.org/react-component/table?type=dev
1818
[david-dev-image]: https://david-dm.org/react-component/table/dev-status.svg?style=flat-square
19-
[download-image]: https://img.shields.io/npm/dm/rc-table.svg?style=flat-square
20-
[download-url]: https://npmjs.org/package/rc-table
21-
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-table
22-
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-table
19+
[download-image]: https://img.shields.io/npm/dm/@rc-component/table.svg?style=flat-square
20+
[download-url]: https://npmjs.org/package/@rc-component/table
21+
[bundlephobia-url]: https://bundlephobia.com/result?p=@rc-component/table
22+
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/table
2323

2424
## install
2525

26-
[![rc-table](https://nodei.co/npm/rc-table.png)](https://npmjs.org/package/rc-table)
26+
[![@rc-component/table](https://nodei.co/npm/@rc-component/table.png)](https://npmjs.org/package/@rc-component/table)
2727

2828
## Development
2929

@@ -39,7 +39,7 @@ https://table-react-component.vercel.app/
3939
## Usage
4040

4141
```js
42-
import Table from 'rc-table';
42+
import Table from '@rc-component/table';
4343

4444
const columns = [
4545
{
@@ -83,7 +83,7 @@ React.render(<Table columns={columns} data={data} />, mountNode);
8383
| Name | Type | Default | Description |
8484
| --- | --- | --- | --- |
8585
| tableLayout | `auto` \| `fixed` | `auto` \| `fixed` for any columns is fixed or ellipsis or header is fixed | https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout |
86-
| prefixCls | String | rc-table | |
86+
| prefixCls | String | `rc-table` | |
8787
| className | String | | additional className |
8888
| id | String | | identifier of the container div |
8989
| useFixedHeader | Boolean | false | whether use separator table for header. better set width for columns |
@@ -158,4 +158,4 @@ React.render(<Table columns={columns} data={data} />, mountNode);
158158

159159
## License
160160

161-
rc-table is released under the MIT license.
161+
@rc-component/table is released under the MIT license.

assets/index.less

Lines changed: 38 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -55,76 +55,37 @@
5555
}
5656

5757
// ================== Cell ==================
58-
&-fixed-column-gapped {
59-
.@{tablePrefixCls}-cell-fix-left-last::after,
60-
.@{tablePrefixCls}-cell-fix-right-first::after {
61-
display: none !important;
62-
}
63-
}
64-
6558
&-cell {
6659
background: #f4f4f4;
6760

68-
&-fix-left,
69-
&-fix-right {
70-
z-index: 2;
61+
&-fix {
62+
position: sticky !important;
63+
z-index: calc(2 + var(--z-offset));
7164
}
7265

73-
&-fix-right:last-child:not(&-fix-sticky) {
74-
border-right-color: transparent;
75-
}
76-
77-
.@{tablePrefixCls}-rtl & {
78-
&-fix-right:last-child {
79-
border-right-color: @border-color;
80-
}
81-
&-fix-left:last-child {
82-
border-left-color: transparent;
66+
&-fix-start-shadow,
67+
&-fix-end-shadow {
68+
&::after {
69+
position: absolute;
70+
top: 0;
71+
bottom: 0;
72+
width: 5px;
73+
background: rgba(0, 0, 0, 0.5);
74+
opacity: 0;
75+
content: '';
76+
transition: opacity 0.3s;
8377
}
84-
}
8578

86-
&-fix-left-first {
87-
.@{tablePrefixCls}-rtl & {
88-
box-shadow: 1px 0 0 @border-color;
79+
&-show::after {
80+
opacity: 1;
8981
}
9082
}
9183

92-
&-fix-left-first::after,
93-
&-fix-left-last::after {
94-
position: absolute;
95-
top: 0;
96-
right: -1px;
97-
bottom: -1px;
98-
width: 20px;
99-
transform: translateX(100%);
100-
transition: box-shadow 0.3s;
101-
content: '';
102-
pointer-events: none;
103-
}
104-
105-
&-fix-left-all::after {
106-
display: none;
84+
&-fix-start-shadow::after {
85+
inset-inline-start: 100%;
10786
}
108-
109-
&-fix-right-first,
110-
&-fix-right-last {
111-
box-shadow: -1px 0 0 @border-color;
112-
113-
.@{tablePrefixCls}-rtl & {
114-
box-shadow: none;
115-
}
116-
117-
&::after {
118-
position: absolute;
119-
top: 0;
120-
bottom: -1px;
121-
left: -1px;
122-
width: 20px;
123-
transform: translateX(-100%);
124-
transition: box-shadow 0.3s;
125-
content: '';
126-
pointer-events: none;
127-
}
87+
&-fix-end-shadow::after {
88+
inset-inline-end: 100%;
12889
}
12990

13091
&&-ellipsis {
@@ -133,9 +94,8 @@
13394
text-overflow: ellipsis;
13495

13596
// Fixed first or last should special process
136-
&.@{tablePrefixCls}-cell-fix-left-first,
137-
&.@{tablePrefixCls}-cell-fix-left-last,
138-
&.@{tablePrefixCls}-cell-fix-right-first &.@{tablePrefixCls}-cell-fix-right-last {
97+
&.@{tablePrefixCls}-cell-fix-start-shadow,
98+
&.@{tablePrefixCls}-cell-fix-end-shadow {
13999
overflow: visible;
140100

141101
.@{tablePrefixCls}-cell-content {
@@ -151,18 +111,24 @@
151111
}
152112
}
153113

154-
&-ping-left {
155-
.@{tablePrefixCls}-cell-fix-left-first::after,
156-
.@{tablePrefixCls}-cell-fix-left-last::after {
157-
box-shadow: inset 10px 0 8px -8px green;
158-
}
114+
&-fix-start-shadow::before,
115+
&-fix-end-shadow::after {
116+
content: '';
117+
position: absolute;
118+
z-index: 1;
119+
top: 0;
120+
bottom: 0;
121+
width: 5px;
159122
}
160123

161-
&-ping-right {
162-
.@{tablePrefixCls}-cell-fix-right-first::after,
163-
.@{tablePrefixCls}-cell-fix-right-last::after {
164-
box-shadow: inset -10px 0 8px -8px green;
165-
}
124+
&-fix-start-shadow-show::before {
125+
inset-inline-start: 0;
126+
background: rgba(0, 0, 0, 0.5);
127+
}
128+
129+
&-fix-end-shadow-show::after {
130+
inset-inline-end: 0;
131+
background: rgba(0, 0, 0, 0.5);
166132
}
167133

168134
// ================= Expand =================

docs/examples/animation.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import CSSMotionList from 'rc-animate/lib/CSSMotionList';
33
import classNames from 'classnames';
4-
import toArray from 'rc-util/lib/Children/toArray';
4+
import toArray from '@rc-component/util/lib/Children/toArray';
55
import type { TableProps } from 'rc-table';
66
import Table from 'rc-table';
77
import '../../assets/index.less';
@@ -11,7 +11,7 @@ type MotionBodyProps = React.HTMLAttributes<HTMLTableSectionElement>;
1111

1212
const MotionBody: React.FC<MotionBodyProps> = ({ children, ...props }) => {
1313
const nodeList = toArray(children);
14-
const nodesRef = React.useRef<Record<string, React.ReactElement>>({});
14+
const nodesRef = React.useRef<Record<string, React.ReactElement<any>>>({});
1515

1616
// Better apply clean up logic to avoid OOM
1717
const keys: React.Key[] = [];
@@ -26,7 +26,7 @@ const MotionBody: React.FC<MotionBodyProps> = ({ children, ...props }) => {
2626
<CSSMotionList keys={keys} component={false} motionName="move">
2727
{({ key, className }) => {
2828
const node = nodesRef.current[key];
29-
return React.cloneElement(node, {
29+
return React.cloneElement<any>(node, {
3030
className: classNames(node.props.className, className),
3131
});
3232
}}

docs/examples/className.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ const Demo = () => (
5252
expandedRowClassName={(record, i) => `ex-row-${i}`}
5353
data={data}
5454
className="table"
55+
title={() => <span>title</span>}
56+
footer={() => <span>footer</span>}
57+
/>
58+
<h2>scroll</h2>
59+
<Table
60+
columns={columns}
61+
rowClassName={(record, i) => `row-${i}`}
62+
expandedRowRender={record => <p>extra: {record.a}</p>}
63+
expandedRowClassName={(record, i) => `ex-row-${i}`}
64+
data={Array(5).fill(data)}
65+
className="table"
66+
scroll={{ x: 'calc(700px + 50%)', y: 47 * 5 }}
67+
title={() => <span>title</span>}
68+
footer={() => <span>footer</span>}
5569
/>
5670
</div>
5771
);

docs/examples/components.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ const Demo = () => {
2424
return (
2525
<div>
2626
<Table
27+
classNames={{
28+
body: {
29+
wrapper: 'test-body-wrapper',
30+
cell: 'test-body-cell',
31+
row: 'test-body-row',
32+
},
33+
header: {
34+
wrapper: 'test-header-wrapper',
35+
cell: 'test-header-cell',
36+
row: 'test-header-row',
37+
},
38+
}}
2739
components={{ header: { table } }}
2840
sticky
2941
columns={[

docs/examples/expandedSticky.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ import type { ColumnType } from 'rc-table';
33
import Table from 'rc-table';
44
import '../../assets/index.less';
55

6+
// 合并单元格
7+
export const getRowSpan = (source: (string | number | undefined)[] = []) => {
8+
const list: { rowSpan?: number }[] = [];
9+
let span = 0;
10+
source.reverse().forEach((key, index) => {
11+
span = span + 1;
12+
if (key !== source[index + 1]) {
13+
list.push({ rowSpan: span });
14+
span = 0;
15+
} else {
16+
list.push({ rowSpan: 0 });
17+
}
18+
});
19+
return list.reverse();
20+
};
21+
622
const Demo = () => {
723
const [expandedRowKeys, setExpandedRowKeys] = useState<readonly React.Key[]>([]);
824

@@ -11,13 +27,33 @@ const Demo = () => {
1127
{ key: 'b', a: '张三', d: '文一西路' },
1228
{ key: 'c', a: '张三', d: '文二西路' },
1329
];
30+
// const rowKeys = data.map(item => item.key);
31+
32+
// const rowSpanList = getRowSpan(data.map(item => item.a));
1433

1534
const columns: ColumnType<Record<string, any>>[] = [
1635
{
1736
title: '手机号',
1837
dataIndex: 'a',
1938
width: 100,
39+
colSpan: 2,
40+
// fixed: 'left',
2041
onCell: (_, index) => {
42+
// const { rowSpan = 1 } = rowSpanList[index];
43+
// const props: React.TdHTMLAttributes<HTMLTableCellElement> = {};
44+
// props.rowSpan = rowSpan;
45+
// if (rowSpan >= 1) {
46+
// let currentRowSpan = rowSpan;
47+
// for (let i = index; i < index + rowSpan; i += 1) {
48+
// const rowKey = rowKeys[i];
49+
// if (expandedRowKeys.includes(rowKey)) {
50+
// currentRowSpan += 1;
51+
// }
52+
// }
53+
// props.rowSpan = currentRowSpan;
54+
// }
55+
// return props;
56+
2157
if (index === 1) {
2258
return {
2359
rowSpan: 2,
@@ -29,7 +65,7 @@ const Demo = () => {
2965
}
3066
},
3167
},
32-
{ title: 'key', dataIndex: 'key2', width: 100 },
68+
{ title: 'key', dataIndex: 'key2', colSpan: 0, width: 100 },
3369
Table.EXPAND_COLUMN,
3470
{ title: 'key', dataIndex: 'key' },
3571
{ title: 'Address', fixed: 'right', dataIndex: 'd', width: 200 },
@@ -41,7 +77,7 @@ const Demo = () => {
4177
<Table<Record<string, any>>
4278
rowKey="key"
4379
sticky
44-
scroll={{ x: 2000 }}
80+
scroll={{ x: 1000 }}
4581
columns={columns}
4682
data={data}
4783
expandable={{

docs/examples/fixedColumns.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const columns: ColumnType<RecordType>[] = [
3434
{ title: 'title8', dataIndex: 'b', key: 'h' },
3535
{ title: 'title9', dataIndex: 'b', key: 'i' },
3636
{ title: 'title10', dataIndex: 'b', key: 'j' },
37-
{ title: 'title11', dataIndex: 'b', key: 'k', width: 50 },
37+
{ title: 'title11', dataIndex: 'b', key: 'k', width: 50, fixed: 'right' },
3838
{ title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' },
3939
];
4040

0 commit comments

Comments
 (0)