Skip to content

Commit 60657fb

Browse files
authored
fix: remove padding wrappers (stipsan#57)
BREAKING CHANGE: The resize observer logic is rewritten to no longer require wrapper elements like `[data-rsbs-footer-padding]`. If you're not using custom CSS and are simply importing `react-spring-bottom-sheet/dist/style.css` in your app then this isn't a breaking change for you. If you're using custom CSS, here's the breaking changes: - `[data-rsbs-header-padding]` removed, update selectors to `[data-rsbs-header]` - `[data-rsbs-content-padding]` removed, update selectors to `[data-rsbs-scroll]` - `[data-rsbs-footer-padding]` removed, update selectors to `[data-rsbs-footer]` - `[data-rsbs-antigap]` removed, update selectors to `[data-rsbs-root]:after` and make sure to add `content: '';`. - `[data-rsbs-content]` is changed, update selectors to `[data-rsbs-scroll]`. - The `<div style="overflow:hidden;">` wrapper that used to be between `[data-rsbs-content]` and `[data-rsbs-content-padding]` is now within `[data-rsbs-scroll]`, and no longer hardcode `overflow: hidden`, add `[data-rsbs-content] { overflow: hidden; }` to your CSS.
1 parent 1cfacbe commit 60657fb

File tree

11 files changed

+133
-96
lines changed

11 files changed

+133
-96
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
![Logo with the text Accessible, Delightful and Performant](https://react-spring-bottom-sheet.cocody.dev/readme.svg)
88

9-
**react-spring-bottom-sheet** is built on top of **react-spring** and **react-use-gesture**. It busts the myth that accessibility and supporting keyboard navigation and screen readers are allegedly at odds with delightful, beautiful and highly animated UIs. Every animation and transition is implemented using CSS custom properties instead of manipulating them directly, allowing complete control over the experience from CSS alone.
9+
**react-spring-bottom-sheet** is built on top of **[react-spring]** and **[react-use-gesture]**. It busts the myth that accessibility and supporting keyboard navigation and screen readers are allegedly at odds with delightful, beautiful, and highly animated UIs. Every animation and transition use CSS custom properties instead of manipulating them directly, allowing complete control over the experience from CSS alone.
1010

1111
# Install
1212

@@ -241,3 +241,5 @@ ref.current.snapTo(({ // Showing all the available props
241241
[size-badge]: http://img.badgesize.io/https://unpkg.com/react-spring-bottom-sheet/dist/index.es.js?label=size&style=flat-square
242242
[unpkg-dist]: https://unpkg.com/react-spring-bottom-sheet/dist/
243243
[module-formats-badge]: https://img.shields.io/badge/module%20formats-cjs%2C%20es%2C%20modern-green.svg?style=flat-square
244+
[react-spring]: https://github.com/pmndrs/react-spring
245+
[react-use-gesture]: https://github.com/pmndrs/react-use-gesture

defaults.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"--rsbs-max-w": "auto",
1010
"--rsbs-ml": "env(safe-area-inset-left)",
1111
"--rsbs-mr": "env(safe-area-inset-right)",
12+
"--rsbs-overlay-h": "0px",
1213
"--rsbs-overlay-rounded": "16px",
13-
"--rsbs-overlay-translate-y": "0px",
14-
"--rsbs-overlay-h": "0px"
14+
"--rsbs-overlay-translate-y": "0px"
1515
}
1616
}

docs/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
--rsbs-mr: 0px;
3232

3333
/* the bottom sheet doesn't need display cutout paddings when in the iframe */
34-
& [data-rsbs-has-footer='false'] [data-rsbs-content-padding] {
34+
& [data-rsbs-has-footer='false'] [data-rsbs-scroll] {
3535
padding-bottom: 0px !important;
3636
}
37-
& [data-rsbs-footer-padding] {
37+
& [data-rsbs-footer] {
3838
padding-bottom: 16px !important;
3939
}
4040
}

next.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 58 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,20 @@
3333
],
3434
"types": "dist/index.d.ts",
3535
"dependencies": {
36+
"@juggle/resize-observer": "^3.2.0",
3637
"@reach/portal": "^0.12.1",
3738
"@xstate/react": "^1.2.0",
3839
"body-scroll-lock": "^3.1.5",
3940
"focus-trap": "^6.2.2",
4041
"react-spring": "^8.0.27",
4142
"react-use-gesture": "^8.0.1",
42-
"resize-observer-polyfill": "^1.5.1",
4343
"xstate": "^4.15.1"
4444
},
4545
"peerDependencies": {
4646
"react": "^16.14.0 || 17"
4747
},
4848
"devDependencies": {
49+
"@rooks/use-raf": "^4.5.0",
4950
"@semantic-release/changelog": "^5.0.1",
5051
"@semantic-release/git": "^9.0.0",
5152
"@tailwindcss/forms": "^0.2.1",

pages/fixtures/experiments.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import useRaf from '@rooks/use-raf'
12
import useInterval from '@use-it/interval'
23
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
34
import Button from '../../docs/fixtures/Button'
@@ -14,7 +15,7 @@ const MemoBottomSheet = memo(BottomSheet)
1415
function One() {
1516
const [open, setOpen] = useState(false)
1617

17-
const [seconds, setSeconds] = useState(1)
18+
const [renders, setRenders] = useState(1)
1819

1920
const style = useMemo(() => ({ ['--rsbs-bg' as any]: '#EFF6FF' }), [])
2021
const onDismiss = useCallback(() => setOpen(false), [])
@@ -37,23 +38,21 @@ function One() {
3738
[onDismiss]
3839
)
3940

40-
useInterval(() => {
41-
if (open) {
42-
setSeconds(seconds + 1)
43-
}
44-
}, 100)
41+
useRaf(() => {
42+
setRenders(renders + 1)
43+
}, open)
4544

4645
useEffect(() => {
4746
if (open) {
4847
return () => {
49-
setSeconds(1)
48+
setRenders(1)
5049
}
5150
}
5251
}, [open])
5352

5453
return (
5554
<>
56-
<Button onClick={() => setOpen(true)}>{seconds}</Button>
55+
<Button onClick={() => setOpen(true)}>{renders}</Button>
5756
<MemoBottomSheet
5857
style={style}
5958
open={open}
@@ -380,7 +379,6 @@ function Nine() {
380379
>
381380
<SheetContent>
382381
<Button onClick={() => setExpandContent(true)}>Expand</Button>
383-
<br />
384382
{expandContent && (
385383
<Button onClick={() => setExpandContent(false)}>No!</Button>
386384
)}

src/BottomSheet.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export const BottomSheet = React.forwardRef<
8989
const [spring, set] = useSpring()
9090

9191
const containerRef = useRef<HTMLDivElement>(null)
92+
const scrollRef = useRef<HTMLDivElement>(null)
9293
const contentRef = useRef<HTMLDivElement>(null)
93-
const contentContainerRef = useRef<HTMLDivElement>(null)
9494
const headerRef = useRef<HTMLDivElement>(null)
9595
const footerRef = useRef<HTMLDivElement>(null)
9696
const overlayRef = useRef<HTMLDivElement | null>(null)
@@ -102,7 +102,7 @@ export const BottomSheet = React.forwardRef<
102102

103103
// "Plugins" huhuhu
104104
const scrollLockRef = useScrollLock({
105-
targetRef: contentRef,
105+
targetRef: scrollRef,
106106
enabled: ready && scrollLocking,
107107
reserveScrollBarGap,
108108
})
@@ -118,7 +118,7 @@ export const BottomSheet = React.forwardRef<
118118
})
119119

120120
const { minSnap, maxSnap, maxHeight, findSnap } = useSnapPoints({
121-
contentContainerRef,
121+
contentRef,
122122
controlledMaxHeight,
123123
footerEnabled: !!footer,
124124
footerRef,
@@ -542,25 +542,20 @@ export const BottomSheet = React.forwardRef<
542542
>
543543
{header !== false && (
544544
<div key="header" data-rsbs-header ref={headerRef} {...bind()}>
545-
<div data-rsbs-header-padding>{header}</div>
545+
{header}
546546
</div>
547547
)}
548-
<div key="content" data-rsbs-content ref={contentRef}>
549-
<div
550-
ref={contentContainerRef}
551-
// The overflow hidden is for the resize observer to get dimensions including margins and paddings
552-
style={{ overflow: 'hidden' }}
553-
>
554-
<div data-rsbs-content-padding>{children}</div>
548+
<div key="scroll" data-rsbs-scroll ref={scrollRef}>
549+
<div data-rsbs-content ref={contentRef}>
550+
{children}
555551
</div>
556552
</div>
557553
{footer && (
558554
<div key="footer" ref={footerRef} data-rsbs-footer {...bind()}>
559-
<div data-rsbs-footer-padding>{footer}</div>
555+
{footer}
560556
</div>
561557
)}
562558
</div>
563-
<div key="antigap" data-rsbs-antigap />
564559
</animated.div>
565560
)
566561
})

0 commit comments

Comments
 (0)