-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathFiller.tsx
More file actions
90 lines (74 loc) 路 2.01 KB
/
Copy pathFiller.tsx
File metadata and controls
90 lines (74 loc) 路 2.01 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as React from 'react';
import ResizeObserver from '@rc-component/resize-observer';
import classNames from 'classnames';
export type InnerProps = Pick<React.HTMLAttributes<HTMLDivElement>, 'role' | 'id'>;
interface FillerProps {
prefixCls?: string;
/** Virtual filler height. Should be `count * itemMinHeight` */
height: number;
/** Set offset of visible items. Should be the top of start item position */
offsetY?: number;
offsetX?: number;
scrollWidth?: number;
children: React.ReactNode;
onInnerResize?: () => void;
innerProps?: InnerProps;
rtl: boolean;
extra?: React.ReactNode;
}
/**
* Fill component to provided the scroll content real height.
*/
const Filler = React.forwardRef<HTMLDivElement, FillerProps>((props, ref) => {
const { height, offsetY, offsetX, children, prefixCls, onInnerResize, innerProps, rtl, extra } =
props;
let outerStyle: React.CSSProperties = {};
let innerStyle: React.CSSProperties = {
display: 'flex',
flexDirection: 'column',
};
if (offsetY !== undefined) {
// Not set `width` since this will break `sticky: right`
outerStyle = {
height,
position: 'relative',
overflow: 'hidden',
};
innerStyle = {
...innerStyle,
transform: `translateY(${offsetY}px)`,
[rtl ? 'marginRight' : 'marginLeft']: -offsetX,
position: 'absolute',
left: 0,
right: 0,
top: 0,
};
}
return (
<div style={outerStyle}>
<ResizeObserver
onResize={({ offsetHeight }) => {
if (offsetHeight && onInnerResize) {
onInnerResize();
}
}}
>
<div
style={innerStyle}
className={classNames({
[`${prefixCls}-holder-inner`]: prefixCls,
})}
ref={ref}
{...innerProps}
>
{children}
{extra}
</div>
</ResizeObserver>
</div>
);
});
if (process.env.NODE_ENV !== 'production') {
Filler.displayName = 'Filler';
}
export default Filler;