-
-
Notifications
You must be signed in to change notification settings - Fork 619
Expand file tree
/
Copy pathMeasureCell.tsx
More file actions
35 lines (28 loc) · 998 Bytes
/
MeasureCell.tsx
File metadata and controls
35 lines (28 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as React from 'react';
import ResizeObserver from '@rc-component/resize-observer';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
export interface MeasureCellProps {
columnKey: React.Key;
onColumnWidthChange: (key: React.Key, width: number) => void;
title?: React.ReactNode;
}
const MeasureCell: React.FC<MeasureCellProps> = (props) => {
const { columnKey, onColumnWidthChange, title } = props;
const cellRef = React.useRef<HTMLTableCellElement>(null);
useLayoutEffect(() => {
if (cellRef.current) {
onColumnWidthChange(columnKey, cellRef.current.offsetWidth);
}
}, []);
return (
<ResizeObserver data={columnKey}>
<td
ref={cellRef}
style={{ paddingTop: 0, paddingBottom: 0, borderTop: 0, borderBottom: 0, height: 0 }}
>
<div style={{ height: 0, overflow: 'hidden', fontWeight: 'bold' }}>{title || '\xa0'}</div>
</td>
</ResizeObserver>
);
};
export default MeasureCell;