forked from stipsan/react-spring-bottom-sheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sticky.tsx
104 lines (98 loc) · 3.44 KB
/
sticky.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type { NextPage } from 'next'
import { useEffect, useState } from 'react'
import Button from '../../docs/fixtures/Button'
import Container from '../../docs/fixtures/Container'
import Expandable from '../../docs/fixtures/Expandable'
import SheetContent from '../../docs/fixtures/SheetContent'
import { sticky } from '../../docs/headings'
import MetaTags from '../../docs/MetaTags'
import { BottomSheet } from '../../src'
import type { GetStaticProps } from '../_app'
export { getStaticProps } from '../_app'
const StickyFixturePage: NextPage<GetStaticProps> = ({
description,
homepage,
meta,
name,
}) => {
const [open, setOpen] = useState(false)
useEffect(() => {
setOpen(true)
}, [])
function onDismiss() {
setOpen(false)
}
return (
<>
<MetaTags
{...meta}
name={name}
description={description}
homepage={homepage}
title={sticky}
/>
<Container>
<Button onClick={() => setOpen(true)}>Open</Button>
<BottomSheet
open={open}
onDismiss={onDismiss}
defaultSnap={({ snapPoints, lastSnap }) =>
lastSnap ?? Math.min(...snapPoints)
}
snapPoints={({ maxHeight }) => [
maxHeight - maxHeight / 5,
maxHeight * 0.6,
]}
header={
<h1 className="flex items-center text-xl justify-center font-bold text-gray-800">
Sticky!
</h1>
}
footer={
<Button onClick={onDismiss} className="w-full">
Done
</Button>
}
>
<SheetContent>
<p>
Just as with content, if the header or footer changes their height
the sheet will readjust accordingly.
</p>
<Expandable>
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
<p>
Putting the "Done" button in a sticky footer is a nice touch on
long bottom sheets with a lot of content. And on resize events
the sticky elements are always visible, unlike the "Dismiss"
button in the first example that needs to be animated first.
</p>
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
</Expandable>
<p>
When you provide a header the draggable area increases, making it
easier for users to adjust the height of the bottom sheet.
</p>
<p>
The same is true for a sticky footer, as it supports drag gestures
as well to optimize for large phones where the header might be
difficult to reach with one hand.
</p>
<Expandable>
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
<p>
Additionally this bottom sheet uses stable viewpoints that are
equivalent to vh CSS units. Predictable heights like this is
also handy if there's content loaded async, or you're
implementing a virtual list so the sheet can't rely on measuring
the height of its content.
</p>
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
</Expandable>
</SheetContent>
</BottomSheet>
</Container>
</>
)
}
export default StickyFixturePage