forked from petyosi/react-virtuoso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.tsx
83 lines (75 loc) · 2.12 KB
/
grid.tsx
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
import * as React from 'react'
import { VirtuosoGrid, VirtuosoGridHandle, GridComponents } from '../src'
import styled from '@emotion/styled'
const ItemContainer = styled.div`
box-sizing: border-box;
padding: 5px;
width: 25%;
background: #f5f5f5;
display: flex;
flex: none;
align-content: stretch;
/*
@media (max-width: 1024px) {
width: 33%;
}
@media (max-width: 768px) {
width: 50%;
}
@media (max-width: 480px) {
width: 100%;
}
*/
`
const ItemWrapper = styled.div`
flex: 1;
text-align: center;
font-size: 80%;
padding: 20px;
box-shadow: 0 5px 6px -6px #777;
background: white;
}
`
const ListContainer = styled.div`
display: flex;
flex-wrap: wrap;
` as GridComponents['List']
export default function App() {
const ref = React.createRef<VirtuosoGridHandle>()
return (
<>
<VirtuosoGrid
ref={ref}
components={{
Item: ItemContainer,
List: ListContainer,
ScrollSeekPlaceholder: () => (
<ItemContainer>
<ItemWrapper>Placeholder</ItemWrapper>
</ItemContainer>
),
}}
totalCount={100}
startReached={() => console.log('start reached')}
endReached={() => console.log('end reached')}
// rangeChanged={({ startIndex, endIndex }) => console.log({ startIndex, endIndex })}
scrollSeekConfiguration={{
enter: (velocity) => Math.abs(velocity) > 200,
exit: (velocity) => Math.abs(velocity) < 30,
change: (_, range) => console.log({ range }),
}}
itemContent={(index) => <ItemWrapper>Item {index}</ItemWrapper>}
style={{ height: 300, width: 1200 }}
/>
<button id="start-30" onClick={() => ref.current!.scrollToIndex({ index: 30, align: 'start' })}>
Start 30
</button>
<button id="center-50" onClick={() => ref.current!.scrollToIndex({ index: 50, align: 'center', behavior: 'smooth' })}>
Center 50
</button>
<button id="end-99" onClick={() => ref.current!.scrollToIndex({ index: 99, align: 'end' })}>
End 99
</button>
</>
)
}