-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathsticky.tsx
More file actions
69 lines (62 loc) · 1.33 KB
/
sticky.tsx
File metadata and controls
69 lines (62 loc) · 1.33 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
import * as React from 'react';
import List from '../src/List';
interface Item {
id: number;
height: number;
style?: React.CSSProperties;
}
const MyItem: React.ForwardRefRenderFunction<HTMLElement, Item> = ({ id, height, style }, ref) => {
return (
<span
ref={ref}
style={{
border: '1px solid gray',
padding: '0 16px',
height,
lineHeight: '30px',
boxSizing: 'border-box',
display: 'inline-block',
width: '100%',
...style,
...(style.position
? {
background: 'white',
}
: {}),
}}
>
{id}
</span>
);
};
const ForwardMyItem = React.forwardRef(MyItem);
const data: Item[] = [];
for (let i = 0; i < 100; i += 1) {
data.push({
id: i,
height: 30 + (i % 2 ? 70 : 0),
});
}
const Demo = () => {
return (
<React.StrictMode>
<div>
<h2>Sticky</h2>
<List
data={data}
height={500}
itemHeight={30}
itemKey="id"
stickyIndexes={[2, 4, 6]}
style={{
border: '1px solid red',
boxSizing: 'border-box',
}}
>
{(item, _, { style }) => <ForwardMyItem {...item} style={style} />}
</List>
</div>
</React.StrictMode>
);
};
export default Demo;