Skip to content

Commit 4f2fe09

Browse files
authored
fix: improve rubber band effect when out of bounds (#29)
1 parent ec01a01 commit 4f2fe09

File tree

9 files changed

+196
-156
lines changed

9 files changed

+196
-156
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ npm i react-spring-bottom-sheet
1818

1919
## [Basic](https://react-spring-bottom-sheet.cocody.dev/fixtures/simple)
2020

21-
> [View demo code](/pages/fixtures/simple.tsx#L43-L47)
21+
> [View demo code](/pages/fixtures/simple.tsx#L44-L48)
2222
2323
MVP example, showing what you get by implementing `open`, `onDismiss` and a single **snap point** always set to `minHeight`.
2424

@@ -30,13 +30,13 @@ A more elaborate example that showcases how snap points work. It also shows how
3030

3131
## [Sticky header & footer](https://react-spring-bottom-sheet.cocody.dev/fixtures/sticky)
3232

33-
> [View demo code](/pages/fixtures/sticky.tsx#L40-L60)
33+
> [View demo code](/pages/fixtures/sticky.tsx#L41-L61)
3434
3535
If you provide either a `header` or `footer` prop you'll enable the special behavior seen in this example. And they're not just sticky positioned, both areas support touch gestures.
3636

3737
## [Non-blocking overlay mode](https://react-spring-bottom-sheet.cocody.dev/fixtures/aside)
3838

39-
> [View demo code](/pages/fixtures/aside.tsx#L41-L46)
39+
> [View demo code](/pages/fixtures/aside.tsx#L41-L53)
4040
4141
In most cases you use a bottom sheet the same way you do with a dialog: you want it to overlay the page and block out distractions. But there are times when you want a bottom sheet but without it taking all the attention and overlaying the entire page. Providing `blocking={false}` helps this use case. By doing so you disable a couple of behaviors that are there for accessibility (focus-locking and more) that prevents a screen reader or a keyboard user from accidentally leaving the bottom sheet.
4242

@@ -226,9 +226,9 @@ ef.current.snapTo(({ // Showing all the available props
226226
227227
# Credits
228228
229-
- Play icon used on frame overlays: https://fontawesome.com/icons/play-circle?style=regular
230-
- Phone frame used in logo: https://www.figma.com/community/file/896042888090872154/Mono-Devices-1.0
231-
- iPhone frame used to wrap examples: https://www.figma.com/community/file/858143367356468985/(Variants)-iOS-%26-iPadOS-14-UI-Kit-for-Figma
229+
- Play icon used on frame overlays: [font-awesome](https://fontawesome.com/icons/play-circle?style=regular)
230+
- Phone frame used in logo: [Mono Devices 1.0](https://www.figma.com/community/file/896042888090872154/Mono-Devices-1.0)
231+
- iPhone frame used to wrap examples: [iOS 14 UI Kit for Figma](<https://www.figma.com/community/file/858143367356468985/(Variants)-iOS-%26-iPadOS-14-UI-Kit-for-Figma>)
232232
233233
[gzip-badge]: http://img.badgesize.io/https://unpkg.com/react-spring-bottom-sheet/dist/index.es.js?compression=gzip&label=gzip%20size&style=flat-square
234234
[size-badge]: http://img.badgesize.io/https://unpkg.com/react-spring-bottom-sheet/dist/index.es.js?label=size&style=flat-square

package-lock.json

Lines changed: 44 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"devDependencies": {
4646
"@semantic-release/changelog": "^5.0.1",
4747
"@semantic-release/git": "^9.0.0",
48+
"@tailwindcss/forms": "^0.2.1",
4849
"@types/classnames": "^2.2.11",
4950
"@types/node": "^14.14.10",
5051
"@types/react": "^17.0.0",

pages/fixtures/aside.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ const AsideFixturePage: NextPage<GetStaticProps> = ({
4242
open={open}
4343
onDismiss={() => setOpen(false)}
4444
blocking={false}
45+
header={
46+
<input
47+
className="mt-1 block w-full rounded-md bg-gray-100 border-transparent focus:border-gray-300 focus:bg-white focus:ring-0"
48+
type="text"
49+
placeholder="Text input field in a sticky header"
50+
/>
51+
}
4552
snapPoints={({ maxHeight }) => [maxHeight / 4, maxHeight * 0.6]}
4653
>
4754
<SheetContent>

pages/fixtures/experiments.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
33
import Button from '../../docs/fixtures/Button'
44
import Code from '../../docs/fixtures/Code'
55
import Container from '../../docs/fixtures/Container'
6+
import Expandable from '../../docs/fixtures/Expandable'
67
import Kbd from '../../docs/fixtures/Kbd'
78
import SheetContent from '../../docs/fixtures/SheetContent'
89
import { BottomSheet } from '../../src'
@@ -155,17 +156,39 @@ function Four() {
155156
<>
156157
<Button onClick={() => setOpen(true)}>4</Button>
157158
<BottomSheet
158-
style={{ ['--rsbs-bg' as any]: '#EFF6FF' }}
159159
open={open}
160160
onDismiss={onDismiss}
161-
snapPoints={({ minHeight }) => [0, minHeight]}
161+
header={
162+
<input
163+
className="mt-1 block w-full rounded-md bg-gray-100 border-transparent focus:border-gray-300 focus:bg-white focus:ring-0"
164+
type="text"
165+
placeholder="Text input field in a sticky header"
166+
/>
167+
}
168+
footer={
169+
<input
170+
className="mt-1 block w-full rounded-md bg-gray-100 border-transparent focus:border-gray-300 focus:bg-white focus:ring-0"
171+
type="text"
172+
placeholder="Text input field in a sticky header"
173+
/>
174+
}
162175
>
163176
<SheetContent>
164-
<p>
165-
Using <Code>onDismiss</Code> lets users close the sheet by swiping
166-
it down, tapping on the backdrop or by hitting <Kbd>esc</Kbd> on
167-
their keyboard.
168-
</p>
177+
<input
178+
className="mt-1 block w-full rounded-md bg-gray-100 border-transparent focus:border-gray-300 focus:bg-white focus:ring-0"
179+
type="text"
180+
placeholder="Text input field in a sticky header"
181+
/>
182+
<Expandable>
183+
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
184+
<p>Testing focus management and keyboard behavior on open.</p>
185+
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
186+
</Expandable>
187+
<input
188+
className="mt-1 block w-full rounded-md bg-gray-100 border-transparent focus:border-gray-300 focus:bg-white focus:ring-0"
189+
type="text"
190+
placeholder="Text input field in a sticky header"
191+
/>
169192
</SheetContent>
170193
</BottomSheet>
171194
</>

pages/fixtures/sticky.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const StickyFixturePage: NextPage<GetStaticProps> = ({
4242
open={open}
4343
onDismiss={onDismiss}
4444
defaultSnap={({ snapPoints, lastSnap }) =>
45-
lastSnap ?? Math.max(...snapPoints)
45+
lastSnap ?? Math.min(...snapPoints)
4646
}
4747
snapPoints={({ maxHeight }) => [
4848
maxHeight - maxHeight / 5,
@@ -67,8 +67,10 @@ const StickyFixturePage: NextPage<GetStaticProps> = ({
6767
<Expandable>
6868
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
6969
<p>
70-
Notice how much better the UX is on resize events when the
71-
"Dismiss" button is sticky.
70+
Putting the "Done" button in a sticky footer is a nice touch on
71+
long bottom sheets with a lot of content. And on resize events
72+
the sticky elements are always visible, unlike the "Dismiss"
73+
button in the first example that needs to be animated first.
7274
</p>
7375
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
7476
</Expandable>
@@ -81,6 +83,17 @@ const StickyFixturePage: NextPage<GetStaticProps> = ({
8183
as well to optimize for large phones where the header might be
8284
difficult to reach with one hand.
8385
</p>
86+
<Expandable>
87+
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
88+
<p>
89+
Additionally this bottom sheet uses stable viewpoints that are
90+
equivalent to vh CSS units. Predictable heights like this is
91+
also handy if there's content loaded async, or you're
92+
implementing a virtual list so the sheet can't rely on measuring
93+
the height of its content.
94+
</p>
95+
<div className="bg-gray-200 block rounded-md h-10 w-full my-10" />
96+
</Expandable>
8497
</SheetContent>
8598
</BottomSheet>
8699
</Container>

0 commit comments

Comments
 (0)