@graphcommerce/next-ui 6.0.0 → 6.0.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/Overlay/components/OverlayBase.tsx +58 -51
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 6.0.1-canary.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1854](https://github.com/graphcommerce-org/graphcommerce/pull/1854) [`f4df162c5`](https://github.com/graphcommerce-org/graphcommerce/commit/f4df162c59d90298f305f51d409974592ab8e680) - Overlay desktop bottom didn't have a box-shadow ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
- [#1854](https://github.com/graphcommerce-org/graphcommerce/pull/1854) [`ba92b3ebe`](https://github.com/graphcommerce-org/graphcommerce/commit/ba92b3ebe9dae16f156f6c0d62bdf25a7df1a2a7) - Allow bottom overlays to resize and animate in position ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
3
11
|
## 6.0.0
|
|
4
12
|
|
|
5
13
|
### Major Changes
|
|
@@ -119,8 +119,9 @@ export function OverlayBase(incomingProps: LayoutOverlayBaseProps) {
|
|
|
119
119
|
props.smSpacingTop ?? ((theme) => `calc(${theme.appShell.headerHeightSm} * 0.5)`)
|
|
120
120
|
)(th)
|
|
121
121
|
|
|
122
|
-
const { scrollerRef, snap, scroll, getScrollSnapPositions } = useScrollerContext()
|
|
122
|
+
const { scrollerRef, snap, scroll, getScrollSnapPositions, disableSnap } = useScrollerContext()
|
|
123
123
|
const scrollTo = useScrollTo()
|
|
124
|
+
|
|
124
125
|
const beforeRef = useRef<HTMLDivElement>(null)
|
|
125
126
|
const overlayRef = useRef<HTMLDivElement>(null)
|
|
126
127
|
const overlayPaneRef = useRef<HTMLDivElement>(null)
|
|
@@ -142,6 +143,21 @@ export function OverlayBase(incomingProps: LayoutOverlayBaseProps) {
|
|
|
142
143
|
)
|
|
143
144
|
const prevVariant = useRef<LayoutOverlayVariant>()
|
|
144
145
|
|
|
146
|
+
const openClosePositions = useCallback((): {
|
|
147
|
+
open: [number, number]
|
|
148
|
+
closed: [number, number]
|
|
149
|
+
} => {
|
|
150
|
+
const { x, y } = getScrollSnapPositions()
|
|
151
|
+
|
|
152
|
+
if (variant() === 'left') {
|
|
153
|
+
return { open: [x.length - 2, 0], closed: [x.length - 1, 0] }
|
|
154
|
+
}
|
|
155
|
+
if (variant() === 'right') {
|
|
156
|
+
return { open: [x.length - 1, 0], closed: [0, 0] }
|
|
157
|
+
}
|
|
158
|
+
return { open: [0, y.length - 1], closed: [0, 0] }
|
|
159
|
+
}, [getScrollSnapPositions, variant])
|
|
160
|
+
|
|
145
161
|
useIsomorphicLayoutEffect(() => {
|
|
146
162
|
const scroller = scrollerRef.current
|
|
147
163
|
if (!scroller || !beforeRef.current || !overlayRef.current || !overlayPaneRef.current)
|
|
@@ -165,35 +181,44 @@ export function OverlayBase(incomingProps: LayoutOverlayBaseProps) {
|
|
|
165
181
|
}
|
|
166
182
|
|
|
167
183
|
const forceScrollPosition = () => {
|
|
184
|
+
if (scroll.animating.get()) return
|
|
168
185
|
// Set the initial position of the overlay.
|
|
169
186
|
// Make sure the overlay stays open when the variant changes.
|
|
170
187
|
if (position.get() !== OverlayPosition.OPENED) {
|
|
171
188
|
scroller.scrollLeft = positions.closed.x.get()
|
|
172
189
|
scroller.scrollTop = positions.closed.y.get()
|
|
190
|
+
scroll.x.set(positions.closed.x.get())
|
|
191
|
+
scroll.y.set(positions.closed.y.get())
|
|
173
192
|
} else {
|
|
174
|
-
|
|
175
|
-
scroller.
|
|
193
|
+
disableSnap()
|
|
194
|
+
scroller.scrollLeft = scroll.x.getPrevious()
|
|
195
|
+
scroller.scrollTop = scroll.y.getPrevious()
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
197
|
+
scrollTo(openClosePositions().open)
|
|
176
198
|
}
|
|
177
199
|
}
|
|
178
200
|
|
|
179
201
|
const calcVisible = () => {
|
|
180
202
|
const clampRound = (value: number) => Math.round(Math.max(0, Math.min(1, value)) * 100) / 100
|
|
181
203
|
|
|
182
|
-
|
|
183
|
-
const scrollY = scroll.y.get()
|
|
184
|
-
|
|
204
|
+
let vis = 0
|
|
185
205
|
if (variant() === 'left') {
|
|
186
206
|
const closedX = positions.closed.x.get()
|
|
187
|
-
|
|
207
|
+
vis = closedX === 0 ? 0 : clampRound((scroll.x.get() - closedX) / -closedX)
|
|
188
208
|
}
|
|
189
209
|
if (variant() === 'right') {
|
|
190
210
|
const openedX = positions.open.x.get()
|
|
191
|
-
|
|
211
|
+
vis = openedX === 0 ? 0 : clampRound(scroll.x.get() / openedX)
|
|
192
212
|
}
|
|
193
213
|
if (variant() === 'bottom') {
|
|
194
214
|
const openedY = positions.open.y.get()
|
|
195
|
-
|
|
215
|
+
vis = openedY === 0 ? 0 : clampRound(scroll.y.get() / openedY)
|
|
196
216
|
}
|
|
217
|
+
|
|
218
|
+
// If we're opening, make sure the visbility doesn't got below the current visibility
|
|
219
|
+
if (position.get() === OverlayPosition.UNOPENED && positions.open.visible.get() >= vis) return
|
|
220
|
+
|
|
221
|
+
positions.open.visible.set(vis)
|
|
197
222
|
}
|
|
198
223
|
|
|
199
224
|
const handleScroll = () => {
|
|
@@ -214,27 +239,35 @@ export function OverlayBase(incomingProps: LayoutOverlayBaseProps) {
|
|
|
214
239
|
forceScrollPosition()
|
|
215
240
|
}
|
|
216
241
|
|
|
217
|
-
const measureScroll = () => framesync.read(handleScroll)
|
|
218
|
-
const measureResize = () => framesync.read(handleResize)
|
|
219
242
|
handleScroll()
|
|
220
243
|
|
|
221
|
-
const cancelX = scroll.x.on('change',
|
|
222
|
-
const cancelY = scroll.y.on('change',
|
|
244
|
+
const cancelX = scroll.x.on('change', handleScroll)
|
|
245
|
+
const cancelY = scroll.y.on('change', handleScroll)
|
|
223
246
|
|
|
224
|
-
const ro = new ResizeObserver(
|
|
247
|
+
const ro = new ResizeObserver(handleResize)
|
|
225
248
|
ro.observe(scrollerRef.current)
|
|
226
249
|
ro.observe(beforeRef.current)
|
|
227
250
|
ro.observe(overlayPaneRef.current)
|
|
228
251
|
ro.observe(overlayRef.current)
|
|
229
252
|
|
|
230
|
-
window.addEventListener('resize',
|
|
253
|
+
window.addEventListener('resize', handleResize)
|
|
231
254
|
return () => {
|
|
232
|
-
window.removeEventListener('resize',
|
|
255
|
+
window.removeEventListener('resize', handleResize)
|
|
233
256
|
ro.disconnect()
|
|
234
257
|
cancelX()
|
|
235
258
|
cancelY()
|
|
236
259
|
}
|
|
237
|
-
}, [
|
|
260
|
+
}, [
|
|
261
|
+
disableSnap,
|
|
262
|
+
getScrollSnapPositions,
|
|
263
|
+
openClosePositions,
|
|
264
|
+
position,
|
|
265
|
+
positions,
|
|
266
|
+
scroll,
|
|
267
|
+
scrollTo,
|
|
268
|
+
scrollerRef,
|
|
269
|
+
variant,
|
|
270
|
+
])
|
|
238
271
|
|
|
239
272
|
// When the component is mounted, we need to set the initial position of the overlay.
|
|
240
273
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -242,57 +275,30 @@ export function OverlayBase(incomingProps: LayoutOverlayBaseProps) {
|
|
|
242
275
|
|
|
243
276
|
if (!scroller || !isPresent) return
|
|
244
277
|
|
|
245
|
-
const open = { x: positions.open.x.get(), y: positions.open.y.get() }
|
|
246
|
-
|
|
247
278
|
if (variant() === 'right') document.body.style.overflow = 'hidden'
|
|
248
279
|
|
|
249
280
|
if (position.get() !== OverlayPosition.OPENED) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
scroller.scrollTop = positions.closed.y.get()
|
|
253
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
254
|
-
scrollTo(open).then(() => {
|
|
255
|
-
scroller.scrollLeft = positions.open.x.get()
|
|
256
|
-
scroller.scrollTop = positions.open.y.get()
|
|
257
|
-
position.set(OverlayPosition.OPENED)
|
|
258
|
-
})
|
|
259
|
-
} else {
|
|
260
|
-
scroller.scrollLeft = open.x
|
|
261
|
-
scroller.scrollTop = open.y
|
|
262
|
-
position.set(OverlayPosition.OPENED)
|
|
263
|
-
snap.set(true)
|
|
264
|
-
}
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
282
|
+
scrollTo(openClosePositions().open).then(() => position.set(OverlayPosition.OPENED))
|
|
265
283
|
}
|
|
266
|
-
}, [
|
|
284
|
+
}, [isPresent, openClosePositions, position, scrollTo, scrollerRef, variant])
|
|
267
285
|
|
|
268
286
|
// When the overlay is closed by navigating away, we're closing the overlay.
|
|
269
287
|
useEffect(() => {
|
|
270
288
|
const scroller = scrollerRef.current
|
|
271
289
|
if (isPresent || !scroller) return
|
|
272
290
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
scroller.scrollLeft = positions.closed.x.get()
|
|
276
|
-
scroller.scrollTop = positions.closed.y.get()
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
292
|
+
scrollTo(openClosePositions().closed).then(() => {
|
|
277
293
|
safeToRemove?.()
|
|
278
294
|
document.body.style.overflow = ''
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
scrollTo({
|
|
282
|
-
x: positions.closed.x.get(),
|
|
283
|
-
y: positions.closed.y.get(),
|
|
284
|
-
}).then(() => {
|
|
285
|
-
safeToRemove?.()
|
|
286
|
-
document.body.style.overflow = ''
|
|
287
|
-
})
|
|
288
|
-
}
|
|
289
|
-
}, [isPresent, position, positions, safeToRemove, scrollTo, scrollerRef])
|
|
295
|
+
})
|
|
296
|
+
}, [isPresent, openClosePositions, position, positions, safeToRemove, scrollTo, scrollerRef])
|
|
290
297
|
|
|
291
298
|
// Only go back to a previous page if the overlay isn't closed.
|
|
292
299
|
const closeOverlay = useCallback(() => {
|
|
293
300
|
if (position.get() !== OverlayPosition.OPENED) return
|
|
294
301
|
position.set(OverlayPosition.CLOSED)
|
|
295
|
-
// document.body.style.overflow = ''
|
|
296
302
|
onClosed()
|
|
297
303
|
}, [onClosed, position])
|
|
298
304
|
|
|
@@ -547,6 +553,7 @@ export function OverlayBase(incomingProps: LayoutOverlayBaseProps) {
|
|
|
547
553
|
maxHeight: `calc(${dvh(100)} - ${mdSpacingTop})`,
|
|
548
554
|
paddingTop: mdSpacingTop,
|
|
549
555
|
boxSizing: 'border-box',
|
|
556
|
+
boxShadow: theme.shadows[24],
|
|
550
557
|
|
|
551
558
|
scrollbarWidth: 'none',
|
|
552
559
|
'&::-webkit-scrollbar': {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/next-ui",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "6.0.0",
|
|
5
|
+
"version": "6.0.1-canary.0",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
"@emotion/react": "^11.10.6",
|
|
19
19
|
"@emotion/server": "^11.4.0",
|
|
20
20
|
"@emotion/styled": "^11.10.6",
|
|
21
|
-
"@graphcommerce/framer-next-pages": "6.0.0",
|
|
22
|
-
"@graphcommerce/framer-scroller": "6.0.0",
|
|
23
|
-
"@graphcommerce/framer-utils": "6.0.0",
|
|
24
|
-
"@graphcommerce/image": "6.0.0",
|
|
21
|
+
"@graphcommerce/framer-next-pages": "6.0.1-canary.0",
|
|
22
|
+
"@graphcommerce/framer-scroller": "6.0.1-canary.0",
|
|
23
|
+
"@graphcommerce/framer-utils": "6.0.1-canary.0",
|
|
24
|
+
"@graphcommerce/image": "6.0.1-canary.0",
|
|
25
25
|
"cookie": "^0.5.0",
|
|
26
26
|
"react-is": "^18.2.0",
|
|
27
27
|
"schema-dts": "^1.1.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@graphcommerce/eslint-config-pwa": "6.0.0",
|
|
31
|
-
"@graphcommerce/prettier-config-pwa": "6.0.0",
|
|
32
|
-
"@graphcommerce/typescript-config-pwa": "6.0.0",
|
|
30
|
+
"@graphcommerce/eslint-config-pwa": "6.0.1-canary.0",
|
|
31
|
+
"@graphcommerce/prettier-config-pwa": "6.0.1-canary.0",
|
|
32
|
+
"@graphcommerce/typescript-config-pwa": "6.0.1-canary.0",
|
|
33
33
|
"@types/cookie": "^0.5.1",
|
|
34
34
|
"@types/react-is": "^17.0.3",
|
|
35
35
|
"typescript": "4.9.5"
|