-
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: recalc grid state when viewport dimensions change
- Loading branch information
1 parent
561fb7f
commit e02669f
Showing
3 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as React from 'react' | ||
import { GridComponents, VirtuosoGrid } from '../src' | ||
import styled from '@emotion/styled' | ||
|
||
const ItemContainer = styled.div` | ||
width: 100px; | ||
height: 100px; | ||
display: flex; | ||
` | ||
|
||
const ItemWrapper = styled.div` | ||
flex: 1; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 80%; | ||
border: 1px solid #000; | ||
white-space: nowrap; | ||
` | ||
|
||
const ListContainer = styled.div` | ||
display: grid; | ||
grid-gap: 10px; | ||
grid-template-columns: repeat(auto-fill, 100px); | ||
grid-template-rows: repeat(auto-fill, 100px); | ||
justify-content: space-evenly; | ||
margin: 10px; | ||
` as GridComponents['List'] | ||
|
||
export function Example() { | ||
return ( | ||
<VirtuosoGrid | ||
style={{ height: 340 }} | ||
totalCount={10000} | ||
overscan={200} | ||
components={{ | ||
Item: ItemContainer, | ||
List: ListContainer, | ||
ScrollSeekPlaceholder: () => ( | ||
<ItemContainer> | ||
<ItemWrapper>{'--'}</ItemWrapper> | ||
</ItemContainer> | ||
), | ||
}} | ||
itemContent={(index) => <ItemWrapper>Item {index}</ItemWrapper>} | ||
scrollSeekConfiguration={{ | ||
enter: (velocity) => Math.abs(velocity) > 200, | ||
exit: (velocity) => Math.abs(velocity) < 30, | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters