Skip to content

Commit 4a866bc

Browse files
committed
add more demo
1 parent 5407ff8 commit 4a866bc

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

examples/height.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as React from 'react';
2+
import List from '../src/List';
3+
4+
interface Item {
5+
id: number;
6+
height: number;
7+
}
8+
9+
const MyItem: React.FC<Item> = ({ id, height }, ref) => {
10+
return (
11+
<span
12+
ref={ref}
13+
style={{
14+
border: '1px solid gray',
15+
padding: '0 16px',
16+
height,
17+
lineHeight: '30px',
18+
boxSizing: 'border-box',
19+
display: 'inline-block',
20+
}}
21+
>
22+
{id}
23+
</span>
24+
);
25+
};
26+
27+
const ForwardMyItem = React.forwardRef(MyItem);
28+
29+
const dataSource: Item[] = [];
30+
for (let i = 0; i < 100; i += 1) {
31+
dataSource.push({
32+
id: i,
33+
height: 30 + (i % 2 ? 70 : 0),
34+
});
35+
}
36+
37+
const Demo = () => {
38+
return (
39+
<React.StrictMode>
40+
<div>
41+
<h2>Dynamic Height</h2>
42+
43+
<List
44+
dataSource={dataSource}
45+
height={500}
46+
itemHeight={30}
47+
itemKey="id"
48+
style={{
49+
border: '1px solid red',
50+
boxSizing: 'border-box',
51+
}}
52+
>
53+
{item => <ForwardMyItem {...item} />}
54+
</List>
55+
</div>
56+
</React.StrictMode>
57+
);
58+
};
59+
60+
export default Demo;

0 commit comments

Comments
 (0)