Skip to content

Commit fae1a2c

Browse files
committed
chore: tmp of it
1 parent bb6e0ed commit fae1a2c

File tree

8 files changed

+144
-40
lines changed

8 files changed

+144
-40
lines changed

assets/index.less

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,21 @@
351351
}
352352
}
353353
}
354+
355+
// ============= Column Shadow ==============
356+
&-fixed-column-shadow {
357+
&-holder {
358+
pointer-events: none;
359+
position: absolute;
360+
inset: 0;
361+
}
362+
363+
position: absolute;
364+
top: 0;
365+
bottom: 0;
366+
left: 0;
367+
width: 10px;
368+
background: red;
369+
z-index: 10;
370+
}
354371
}

docs/examples/stack-columns.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,22 @@ interface RecordType {
1212
}
1313

1414
const columns: ColumnType<RecordType>[] = [
15-
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' },
15+
{
16+
title: 'title1',
17+
dataIndex: 'a',
18+
key: 'a',
19+
width: 100,
20+
// Fixed
21+
fixed: 'start',
22+
},
1623
{ title: 'title2', dataIndex: 'b', key: 'b', width: 50 },
17-
{ title: 'title3', dataIndex: 'c', key: 'c', fixed: 'left' },
24+
{
25+
title: 'title3',
26+
dataIndex: 'c',
27+
key: 'c',
28+
// Fixed
29+
fixed: 'start',
30+
},
1831
{ title: 'title4', dataIndex: 'b', key: 'd' },
1932
{ title: 'title5', dataIndex: 'b', key: 'e' },
2033
{ title: 'title6', dataIndex: 'b', key: 'f' },
@@ -25,9 +38,22 @@ const columns: ColumnType<RecordType>[] = [
2538
},
2639
{ title: 'title8', dataIndex: 'b', key: 'h' },
2740
{ title: 'title9', dataIndex: 'b', key: 'i' },
28-
{ title: 'title10', dataIndex: 'b', key: 'j', fixed: 'right' },
41+
{
42+
title: 'title10',
43+
dataIndex: 'b',
44+
key: 'j',
45+
// Fixed
46+
fixed: 'end',
47+
},
2948
{ title: 'title11', dataIndex: 'b', key: 'k', width: 50 },
30-
{ title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' },
49+
{
50+
title: 'title12',
51+
dataIndex: 'b',
52+
key: 'l',
53+
width: 100,
54+
// Fixed
55+
fixed: 'end',
56+
},
3157
];
3258

3359
const data: RecordType[] = [

src/Cell/index.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export interface CellProps<RecordType extends DefaultRecordType> {
3737
shouldCellUpdate?: (record: RecordType, prevRecord: RecordType) => boolean;
3838

3939
// Fixed
40-
fixLeft?: number | false;
41-
fixRight?: number | false;
40+
fixStart?: number | false;
41+
fixEnd?: number | false;
4242
firstFixLeft?: boolean;
4343
lastFixLeft?: boolean;
4444
firstFixRight?: boolean;
@@ -104,8 +104,8 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
104104
rowSpan,
105105

106106
// Fixed
107-
fixLeft,
108-
fixRight,
107+
fixStart,
108+
fixEnd,
109109
firstFixLeft,
110110
lastFixLeft,
111111
firstFixRight,
@@ -136,16 +136,16 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
136136

137137
// ====================== Fixed =======================
138138
const fixedStyle: React.CSSProperties = {};
139-
const isFixLeft = typeof fixLeft === 'number' && supportSticky;
140-
const isFixRight = typeof fixRight === 'number' && supportSticky;
139+
const isFixStart = typeof fixStart === 'number' && supportSticky;
140+
const isFixEnd = typeof fixEnd === 'number' && supportSticky;
141141

142-
if (isFixLeft) {
142+
if (isFixStart) {
143143
fixedStyle.position = 'sticky';
144-
fixedStyle.left = fixLeft as number;
144+
fixedStyle.insetInlineStart = fixStart as number;
145145
}
146-
if (isFixRight) {
146+
if (isFixEnd) {
147147
fixedStyle.position = 'sticky';
148-
fixedStyle.right = fixRight as number;
148+
fixedStyle.insetInlineEnd = fixEnd as number;
149149
}
150150

151151
// ================ RowSpan & ColSpan =================
@@ -190,16 +190,16 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
190190
cellPrefixCls,
191191
className,
192192
{
193-
[`${cellPrefixCls}-fix-left`]: isFixLeft && supportSticky,
193+
[`${cellPrefixCls}-fix-left`]: isFixStart && supportSticky,
194194
[`${cellPrefixCls}-fix-left-first`]: firstFixLeft && supportSticky,
195195
[`${cellPrefixCls}-fix-left-last`]: lastFixLeft && supportSticky,
196196
[`${cellPrefixCls}-fix-left-all`]: lastFixLeft && allColumnsFixedLeft && supportSticky,
197-
[`${cellPrefixCls}-fix-right`]: isFixRight && supportSticky,
197+
[`${cellPrefixCls}-fix-right`]: isFixEnd && supportSticky,
198198
[`${cellPrefixCls}-fix-right-first`]: firstFixRight && supportSticky,
199199
[`${cellPrefixCls}-fix-right-last`]: lastFixRight && supportSticky,
200200
[`${cellPrefixCls}-ellipsis`]: ellipsis,
201201
[`${cellPrefixCls}-with-append`]: appendNode,
202-
[`${cellPrefixCls}-fix-sticky`]: (isFixLeft || isFixRight) && isSticky && supportSticky,
202+
[`${cellPrefixCls}-fix-sticky`]: (isFixStart || isFixEnd) && isSticky && supportSticky,
203203
[`${cellPrefixCls}-row-hover`]: !legacyCellProps && hovering,
204204
},
205205
additionalProps.className,

src/FixedColumnShadows.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from 'react';
2+
import { getTargetScrollBarSize } from '@rc-component/util/lib/getScrollBarSize';
3+
4+
export interface FixedColumnShadowsProps {
5+
prefixCls: string;
6+
}
7+
8+
export default function FixedColumnShadows(props: FixedColumnShadowsProps) {
9+
const { prefixCls } = props;
10+
const holderRef = React.useRef<HTMLDivElement>(null);
11+
12+
const [scrollBarSize, setScrollBarSize] = React.useState<[height: number, width: number]>([0, 0]);
13+
14+
React.useEffect(() => {
15+
if (holderRef.current) {
16+
const { height, width } = getTargetScrollBarSize(holderRef.current);
17+
setScrollBarSize([height, width]);
18+
}
19+
}, []);
20+
21+
const fixedColumnShadowCls = `${prefixCls}-fixed-column-shadow`;
22+
23+
return (
24+
<div
25+
className={`${fixedColumnShadowCls}-holder`}
26+
ref={holderRef}
27+
style={{
28+
// TODO: update when parent scroll changed
29+
insetBlockEnd: scrollBarSize[0],
30+
insetInlineEnd: scrollBarSize[1],
31+
}}
32+
>
33+
<div className={fixedColumnShadowCls} />
34+
</div>
35+
);
36+
}

src/Table.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import Column from './sugar/Column';
7676
import ColumnGroup from './sugar/ColumnGroup';
7777
import { getColumnsKey, validateValue, validNumberValue } from './utils/valueUtil';
7878
import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode';
79+
import FixedColumnShadows from './FixedColumnShadows';
7980

8081
export const DEFAULT_PREFIX = 'rc-table';
8182

@@ -355,7 +356,7 @@ function Table<RecordType extends DefaultRecordType>(
355356
const colsKeys = getColumnsKey(flattenColumns);
356357
const pureColWidths = colsKeys.map(columnKey => colsWidths.get(columnKey));
357358
const colWidths = React.useMemo(() => pureColWidths, [pureColWidths.join('_')]);
358-
const stickyOffsets = useStickyOffsets(colWidths, flattenColumns, direction);
359+
const stickyOffsets = useStickyOffsets(colWidths, flattenColumns);
359360
const fixHeader = scroll && validateValue(scroll.y);
360361
const horizonScroll = (scroll && validateValue(mergedScrollX)) || Boolean(expandableConfig.fixed);
361362
const fixColumn = horizonScroll && flattenColumns.some(({ fixed }) => fixed);
@@ -765,6 +766,7 @@ function Table<RecordType extends DefaultRecordType>(
765766
<div
766767
className={classNames(prefixCls, className, {
767768
[`${prefixCls}-rtl`]: direction === 'rtl',
769+
// TODO: Remove these ping className
768770
[`${prefixCls}-ping-left`]: pingedLeft,
769771
[`${prefixCls}-ping-right`]: pingedRight,
770772
[`${prefixCls}-layout-fixed`]: tableLayout === 'fixed',
@@ -786,6 +788,7 @@ function Table<RecordType extends DefaultRecordType>(
786788
{title && <Panel className={`${prefixCls}-title`}>{title(mergedData)}</Panel>}
787789
<div ref={scrollBodyContainerRef} className={`${prefixCls}-container`}>
788790
{groupTableNode}
791+
<FixedColumnShadows prefixCls={prefixCls} />
789792
</div>
790793
{footer && <Panel className={`${prefixCls}-footer`}>{footer(mergedData)}</Panel>}
791794
</div>

src/hooks/useStickyOffsets.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { useMemo } from 'react';
2-
import type { ColumnType, Direction, StickyOffsets } from '../interface';
2+
import type {
3+
ColumnType,
4+
// Direction,
5+
StickyOffsets,
6+
} from '../interface';
37

48
/**
59
* Get sticky column offset width
610
*/
711
function useStickyOffsets<RecordType>(
812
colWidths: number[],
913
flattenColumns: readonly ColumnType<RecordType>[],
10-
direction: Direction,
14+
// direction: Direction,
1115
) {
1216
const stickyOffsets: StickyOffsets = useMemo(() => {
1317
const columnCount = flattenColumns.length;
@@ -30,16 +34,24 @@ function useStickyOffsets<RecordType>(
3034
const startOffsets = getOffsets(0, columnCount, 1);
3135
const endOffsets = getOffsets(columnCount - 1, -1, -1).reverse();
3236

33-
return direction === 'rtl'
34-
? {
35-
left: endOffsets,
36-
right: startOffsets,
37-
}
38-
: {
39-
left: startOffsets,
40-
right: endOffsets,
41-
};
42-
}, [colWidths, flattenColumns, direction]);
37+
// return direction === 'rtl'
38+
// ? {
39+
// left: endOffsets,
40+
// right: startOffsets,
41+
// }
42+
// : {
43+
// left: startOffsets,
44+
// right: endOffsets,
45+
// };
46+
return {
47+
start: startOffsets,
48+
end: endOffsets,
49+
};
50+
}, [
51+
colWidths,
52+
flattenColumns,
53+
// , direction
54+
]);
4355

4456
return stickyOffsets;
4557
}

src/interface.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ export type GetRowKey<RecordType> = (record: RecordType, index?: number) => Key;
131131

132132
// ================= Fix Column =================
133133
export interface StickyOffsets {
134-
left: readonly number[];
135-
right: readonly number[];
134+
// left: readonly number[];
135+
// right: readonly number[];
136+
start: readonly number[];
137+
end: readonly number[];
136138
isSticky?: boolean;
137139
}
138140

src/utils/fixUtil.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { Direction, FixedType, StickyOffsets } from '../interface';
33
export interface FixedInfo {
44
fixLeft: number | false;
55
fixRight: number | false;
6+
fixStart: number | false;
7+
fixEnd: number | false;
68
lastFixLeft: boolean;
79
firstFixRight: boolean;
810

@@ -23,13 +25,17 @@ export function getCellFixedInfo(
2325
const startColumn = columns[colStart] || {};
2426
const endColumn = columns[colEnd] || {};
2527

26-
let fixLeft: number;
27-
let fixRight: number;
28+
// let fixLeft: number;
29+
// let fixRight: number;
30+
let fixStart: number;
31+
let fixEnd: number;
2832

29-
if (startColumn.fixed === 'left') {
30-
fixLeft = stickyOffsets.left[direction === 'rtl' ? colEnd : colStart];
31-
} else if (endColumn.fixed === 'right') {
32-
fixRight = stickyOffsets.right[direction === 'rtl' ? colStart : colEnd];
33+
if (startColumn.fixed === 'left' || startColumn.fixed === 'start') {
34+
// fixLeft = stickyOffsets.left[direction === 'rtl' ? colEnd : colStart];
35+
fixStart = stickyOffsets.start[colStart];
36+
} else if (endColumn.fixed === 'right' || endColumn.fixed === 'end') {
37+
// fixRight = stickyOffsets.right[direction === 'rtl' ? colStart : colEnd];
38+
fixEnd = stickyOffsets.end[colEnd];
3339
}
3440

3541
let lastFixLeft: boolean = false;
@@ -64,8 +70,10 @@ export function getCellFixedInfo(
6470
// }
6571

6672
return {
67-
fixLeft,
68-
fixRight,
73+
fixLeft: fixStart,
74+
fixStart,
75+
fixRight: fixEnd,
76+
fixEnd,
6977
lastFixLeft,
7078
firstFixRight,
7179
lastFixRight,

0 commit comments

Comments
 (0)