Skip to content

Commit

Permalink
chore: add experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jan 21, 2021
1 parent 240c212 commit bf8c59d
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion pages/fixtures/experiments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Container from '../../docs/fixtures/Container'
import Expandable from '../../docs/fixtures/Expandable'
import Kbd from '../../docs/fixtures/Kbd'
import SheetContent from '../../docs/fixtures/SheetContent'
import { BottomSheet } from '../../src'
import { BottomSheet, BottomSheetRef } from '../../src'

// Just to test we can stop re-renders with this pattern when necessary
const MemoBottomSheet = memo(BottomSheet)
Expand Down Expand Up @@ -414,6 +414,51 @@ function Ten() {
)
}

function Eleven() {
const [open, setOpen] = useState(false)
const [height, setHeight] = useState(undefined)
const sheetRef = useRef<BottomSheetRef>()

return (
<>
<Button onClick={() => setOpen(true)}>11</Button>
<BottomSheet
ref={sheetRef}
open={open}
onDismiss={() => setOpen(false)}
snapPoints={({ minHeight, maxHeight }) => [
height ? minHeight : maxHeight,
200,
]}
onSpringStart={(event) => {
if (event.type === 'SNAP' && event.source === 'custom') {
setTimeout(() => setHeight('80vh'), 100)
}
}}
onSpringEnd={(event) => {
if (event.type === 'SNAP' && event.source === 'custom') {
setHeight(undefined)
}
}}
>
<SheetContent style={{ height }}>
<Button
onClick={() =>
sheetRef.current.snapTo(({ height, snapPoints }) => {
const minSnap = Math.min(...snapPoints)
return height > minSnap ? minSnap : Math.max(...snapPoints)
})
}
>
snapTo
</Button>
<div className="bg-gray-200 block rounded-md h-screen w-full my-10" />
</SheetContent>
</BottomSheet>
</>
)
}

export default function ExperimentsFixturePage() {
return (
<Container
Expand All @@ -432,6 +477,7 @@ export default function ExperimentsFixturePage() {
<Eight />
<Nine />
<Ten />
<Eleven />
</Container>
)
}

0 comments on commit bf8c59d

Please sign in to comment.