@graphcommerce/next-ui 3.19.1 → 3.20.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.
Files changed (95) hide show
  1. package/AppShell/AppShellSticky/index.tsx +3 -19
  2. package/AppShell/DesktopNavActions.tsx +3 -4
  3. package/AppShell/DesktopNavBar.tsx +2 -3
  4. package/AppShell/FixedFab.tsx +1 -6
  5. package/AppShell/GlobalHead.tsx +36 -0
  6. package/AppShell/Logo.tsx +11 -20
  7. package/AppShell/MenuFab.tsx +5 -3
  8. package/AppShell/MenuFabSecondaryItem.tsx +3 -3
  9. package/AppShell/PlaceholderFab/index.tsx +8 -27
  10. package/AppShell/index.tsx +19 -0
  11. package/AppShell/useFabAnimation.tsx +3 -2
  12. package/AppShell/useFixedFabAnimation.tsx +3 -2
  13. package/Blog/BlogAuthor/index.tsx +1 -1
  14. package/Blog/BlogHeader/index.tsx +2 -3
  15. package/Blog/BlogList/index.tsx +1 -1
  16. package/Blog/BlogListItem/index.tsx +1 -1
  17. package/Blog/BlogTitle/index.tsx +5 -5
  18. package/Button/index.tsx +26 -21
  19. package/CHANGELOG.md +30 -0
  20. package/ChipMenu/index.tsx +2 -2
  21. package/FlagAvatar/index.tsx +3 -3
  22. package/{AppShell/Footer/index.tsx → Footer/Footer.tsx} +3 -3
  23. package/{AppShell/Footer → Footer}/SocialIcon.tsx +3 -3
  24. package/Footer/index.ts +2 -0
  25. package/Form/InputCheckmark.tsx +3 -3
  26. package/Form/index.tsx +1 -1
  27. package/FramerScroller/components/SidebarGallery.tsx +24 -20
  28. package/FramerScroller/components/SidebarSlider.tsx +2 -6
  29. package/FullPageMessage/index.tsx +1 -1
  30. package/IconHeader/index.tsx +2 -15
  31. package/Layout/components/LayoutHeader.tsx +151 -0
  32. package/Layout/components/LayoutHeaderBack.tsx +50 -0
  33. package/Layout/components/LayoutHeaderClose.tsx +27 -0
  34. package/Layout/components/LayoutHeaderContent.tsx +173 -0
  35. package/Layout/components/LayoutHeadertypes.ts +10 -0
  36. package/Layout/components/LayoutProvider.tsx +17 -0
  37. package/{Title/index.tsx → Layout/components/LayoutTitle.tsx} +24 -15
  38. package/Layout/context/layoutContext.tsx +7 -0
  39. package/Layout/hooks/useScrollY.tsx +6 -0
  40. package/Layout/index.ts +5 -0
  41. package/Layout/types.ts +5 -0
  42. package/LayoutDefault/components/LayoutDefault.tsx +90 -0
  43. package/LayoutDefault/index.ts +1 -0
  44. package/LayoutOverlay/components/LayoutOverlay.tsx +25 -0
  45. package/LayoutOverlay/components/LayoutOverlayBase.tsx +354 -0
  46. package/LayoutOverlay/components/LayoutOverlayHeader.tsx +5 -0
  47. package/LayoutOverlay/hooks/useOverlayPosition.ts +70 -0
  48. package/LayoutOverlay/index.ts +2 -0
  49. package/Page/App.tsx +2 -0
  50. package/PageMeta/index.tsx +3 -0
  51. package/Pagination/index.tsx +0 -1
  52. package/Row/ButtonLinkList/index.tsx +1 -1
  53. package/Row/ColumnOneBoxed/index.tsx +1 -1
  54. package/Row/ColumnTwoWithTop/index.tsx +3 -3
  55. package/Row/ContentLinks/index.tsx +3 -3
  56. package/Row/HeroBanner/index.tsx +7 -11
  57. package/Row/IconBlocks/index.tsx +1 -1
  58. package/Row/ImageText/index.tsx +1 -1
  59. package/Row/ImageTextBoxed/index.tsx +1 -1
  60. package/Row/ParagraphWithSidebarSlide/index.tsx +1 -1
  61. package/Row/SpecialBanner/index.tsx +4 -3
  62. package/Row/index.tsx +1 -1
  63. package/Snackbar/MessageSnackbarImpl.tsx +1 -1
  64. package/StarRatingField/index.tsx +3 -4
  65. package/Stepper/Stepper.tsx +1 -1
  66. package/Styles/breakpointVal.tsx +2 -2
  67. package/Styles/classesPicker.ts +41 -0
  68. package/Styles/responsiveVal.tsx +1 -1
  69. package/SvgImage/SvgImageSimple.tsx +9 -8
  70. package/SvgImage/index.tsx +9 -11
  71. package/TextInputNumber/index.tsx +3 -4
  72. package/Theme/types.ts +14 -12
  73. package/ToggleButton/index.tsx +2 -4
  74. package/UspList/UspListItem.tsx +1 -1
  75. package/index.ts +9 -43
  76. package/package.json +8 -9
  77. package/AppShell/AppShellHeader/appShellHeaderContext.tsx +0 -11
  78. package/AppShell/AppShellHeader/index.tsx +0 -439
  79. package/AppShell/AppShellHeader/useAppShellHeaderContext.tsx +0 -6
  80. package/AppShell/AppShellProvider/index.tsx +0 -18
  81. package/AppShell/AppShellTitle/index.tsx +0 -45
  82. package/AppShell/ForwardButton.tsx +0 -53
  83. package/AppShell/FullPageShellBase.tsx +0 -82
  84. package/AppShell/MinimalPageShellBase.tsx +0 -22
  85. package/AppShell/PageShellHeader/index.tsx +0 -14
  86. package/AppShell/SheetShellBase/index.tsx +0 -114
  87. package/AppShell/SheetShellBase/useSheetStyles.ts +0 -18
  88. package/AppShell/SheetShellDragIndicator/index.tsx +0 -55
  89. package/AppShell/SheetShellHeader/index.tsx +0 -28
  90. package/AppShell/ShellBase.tsx +0 -45
  91. package/Debug/DebugSpacer.tsx +0 -51
  92. package/FramerNextPagesSlider/Slide.tsx +0 -71
  93. package/FramerNextPagesSlider/Slider.tsx +0 -39
  94. package/FramerNextPagesSlider/index.ts +0 -1
  95. package/FramerNextPagesSlider/types.ts +0 -3
@@ -0,0 +1,7 @@
1
+ import React from 'react'
2
+ import { LayoutContext } from '../types'
3
+
4
+ const layoutContext = React.createContext(undefined as unknown as LayoutContext)
5
+ layoutContext.displayName = 'layoutContext'
6
+
7
+ export default layoutContext
@@ -0,0 +1,6 @@
1
+ import { useContext } from 'react'
2
+ import layoutContext from '../context/layoutContext'
3
+
4
+ export function useScrollY() {
5
+ return useContext(layoutContext).scroll
6
+ }
@@ -0,0 +1,5 @@
1
+ export * from './types'
2
+ export * from './components/LayoutHeader'
3
+ export * from './components/LayoutProvider'
4
+ export * from './components/LayoutTitle'
5
+ export * from './hooks/useScrollY'
@@ -0,0 +1,5 @@
1
+ import { MotionValue } from 'framer-motion'
2
+
3
+ export type LayoutContext = {
4
+ scroll: MotionValue<number>
5
+ }
@@ -0,0 +1,90 @@
1
+ import { usePageRouter, useScrollOffset } from '@graphcommerce/framer-next-pages'
2
+ import { makeStyles, Theme } from '@material-ui/core'
3
+ import clsx from 'clsx'
4
+ import { useTransform, useViewportScroll } from 'framer-motion'
5
+ import React from 'react'
6
+ import LayoutProvider from '../../Layout/components/LayoutProvider'
7
+ import { UseStyles } from '../../Styles'
8
+
9
+ const useStyles = makeStyles(
10
+ (theme: Theme) => ({
11
+ root: {
12
+ minHeight: '100vh',
13
+ '@supports (-webkit-touch-callout: none)': {
14
+ minHeight: '-webkit-fill-available',
15
+ },
16
+ display: 'grid',
17
+ gridTemplateRows: `auto 1fr auto`,
18
+ gridTemplateColumns: '100%',
19
+ background: theme.palette.background.default,
20
+ },
21
+ hideFabsOnVirtualKeyboardOpen: {
22
+ [theme.breakpoints.down('sm')]: {
23
+ '@media (max-height: 530px)': {
24
+ display: 'none',
25
+ },
26
+ },
27
+ },
28
+ header: {
29
+ zIndex: theme.zIndex.appBar - 1,
30
+ display: 'flex',
31
+ alignItems: 'center',
32
+ justifyContent: 'center',
33
+ height: theme.appShell.headerHeightSm,
34
+ pointerEvents: 'none',
35
+ '& > *': {
36
+ pointerEvents: 'all',
37
+ },
38
+ [theme.breakpoints.up('md')]: {
39
+ height: theme.appShell.headerHeightMd,
40
+ padding: `0 ${theme.page.horizontal} 0`,
41
+ top: 0,
42
+ display: 'flex',
43
+ justifyContent: 'left',
44
+ width: '100%',
45
+ },
46
+ },
47
+ headerSticky: {
48
+ [theme.breakpoints.down('sm')]: {
49
+ position: 'sticky',
50
+ top: 0,
51
+ },
52
+ },
53
+ }),
54
+ { name: 'LayoutDefault' },
55
+ )
56
+
57
+ export type LayoutDefaultProps = {
58
+ header: React.ReactNode
59
+ footer: React.ReactNode
60
+ menuFab?: React.ReactNode
61
+ cartFab?: React.ReactNode
62
+ children?: React.ReactNode
63
+ noSticky?: boolean
64
+ } & UseStyles<typeof useStyles>
65
+
66
+ export function LayoutDefault(props: LayoutDefaultProps) {
67
+ const { children, header, footer, menuFab, cartFab, noSticky } = props
68
+ const classes = useStyles(props)
69
+
70
+ const offset = useScrollOffset().y
71
+ const scrollWithOffset = useTransform(useViewportScroll().scrollY, (y) => y + offset)
72
+
73
+ return (
74
+ <div className={classes.root}>
75
+ <LayoutProvider scroll={scrollWithOffset}>
76
+ <header className={clsx(classes.header, !noSticky && classes.headerSticky)}>
77
+ {header}
78
+ </header>
79
+ <div>
80
+ <div className={classes.hideFabsOnVirtualKeyboardOpen}>
81
+ {menuFab}
82
+ {cartFab}
83
+ </div>
84
+ {children}
85
+ </div>
86
+ <div>{footer}</div>
87
+ </LayoutProvider>
88
+ </div>
89
+ )
90
+ }
@@ -0,0 +1 @@
1
+ export * from './components/LayoutDefault'
@@ -0,0 +1,25 @@
1
+ import { ScrollerProvider, ScrollSnapType } from '@graphcommerce/framer-scroller'
2
+ import React from 'react'
3
+ import { SetOptional } from 'type-fest'
4
+ import { LayoutOverlayBase, LayoutOverlayBaseProps } from './LayoutOverlayBase'
5
+
6
+ export type { LayoutOverlayVariant } from './LayoutOverlayBase'
7
+
8
+ export type LayoutOverlayProps = SetOptional<LayoutOverlayBaseProps, 'variantSm' | 'variantMd'>
9
+
10
+ export function LayoutOverlay(props: LayoutOverlayProps) {
11
+ const { children, variantSm = 'bottom', variantMd = 'right', classes } = props
12
+
13
+ const scrollSnapTypeSm: ScrollSnapType =
14
+ variantSm === 'left' || variantSm === 'right' ? 'both mandatory' : 'block proximity'
15
+ const scrollSnapTypeMd: ScrollSnapType =
16
+ variantMd === 'left' || variantMd === 'right' ? 'both mandatory' : 'block proximity'
17
+
18
+ return (
19
+ <ScrollerProvider scrollSnapTypeSm={scrollSnapTypeSm} scrollSnapTypeMd={scrollSnapTypeMd}>
20
+ <LayoutOverlayBase variantMd={variantMd} variantSm={variantSm} classes={classes}>
21
+ {children}
22
+ </LayoutOverlayBase>
23
+ </ScrollerProvider>
24
+ )
25
+ }
@@ -0,0 +1,354 @@
1
+ import { usePageContext, usePageRouter, useScrollOffset } from '@graphcommerce/framer-next-pages'
2
+ import { Scroller, useScrollerContext, useScrollTo } from '@graphcommerce/framer-scroller'
3
+ import { useElementScroll, useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
4
+ import { makeStyles, Theme } from '@material-ui/core'
5
+ import {
6
+ m,
7
+ MotionValue,
8
+ useDomEvent,
9
+ useMotionValue,
10
+ usePresence,
11
+ useTransform,
12
+ } from 'framer-motion'
13
+ import React, { useCallback, useEffect, useRef } from 'react'
14
+ import LayoutProvider from '../../Layout/components/LayoutProvider'
15
+ import { UseStyles } from '../../Styles'
16
+ import { classesPicker } from '../../Styles/classesPicker'
17
+ import { useOverlayPosition } from '../hooks/useOverlayPosition'
18
+
19
+ const useStyles = makeStyles(
20
+ (theme: Theme) => ({
21
+ root: {
22
+ display: 'grid',
23
+ cursor: 'default',
24
+ overflow: 'auto',
25
+ height: '100vh',
26
+ '@supports (-webkit-touch-callout: none)': {
27
+ height: '-webkit-fill-available',
28
+ },
29
+ },
30
+ rootVariantSmLeft: {
31
+ [theme.breakpoints.down('sm')]: {
32
+ gridTemplate: `
33
+ "overlay beforeOverlay"
34
+ "afterOverlay afterOverlay"
35
+ `,
36
+ },
37
+ },
38
+ rootVariantMdLeft: {
39
+ [theme.breakpoints.up('md')]: {
40
+ gridTemplate: `
41
+ "overlay beforeOverlay"
42
+ "afterOverlay afterOverlay"
43
+ `,
44
+ },
45
+ },
46
+ rootVariantSmRight: {
47
+ [theme.breakpoints.down('sm')]: {
48
+ gridTemplate: `
49
+ "beforeOverlay overlay"
50
+ "afterOverlay afterOverlay"
51
+ `,
52
+ },
53
+ },
54
+ rootVariantMdRight: {
55
+ [theme.breakpoints.up('md')]: {
56
+ gridTemplate: `
57
+ "beforeOverlay overlay"
58
+ "afterOverlay afterOverlay"
59
+ `,
60
+ },
61
+ },
62
+ rootVariantSmBottom: {
63
+ [theme.breakpoints.down('sm')]: {
64
+ gridTemplate: `"beforeOverlay" "overlay" "afterOverlay"`,
65
+ height: '100vh',
66
+ '@supports (-webkit-touch-callout: none)': {
67
+ height: '-webkit-fill-available',
68
+ },
69
+ },
70
+ },
71
+ rootVariantMdBottom: {
72
+ [theme.breakpoints.up('md')]: {
73
+ gridTemplate: `"beforeOverlay" "overlay" "afterOverlay"`,
74
+ height: '100vh',
75
+ },
76
+ },
77
+ beforeOverlay: {
78
+ gridArea: 'beforeOverlay',
79
+ scrollSnapAlign: 'start',
80
+ scrollSnapStop: 'always',
81
+ display: 'grid',
82
+ alignContent: 'end',
83
+ },
84
+ beforeOverlayVariantSmRight: {
85
+ [theme.breakpoints.down('sm')]: {
86
+ width: '100vw',
87
+ },
88
+ },
89
+ beforeOverlayVariantMdRight: {
90
+ [theme.breakpoints.up('md')]: {
91
+ width: '100vw',
92
+ },
93
+ },
94
+
95
+ beforeOverlayVariantSmLeft: {
96
+ [theme.breakpoints.down('sm')]: {
97
+ width: '100vw',
98
+ },
99
+ },
100
+ beforeOverlayVariantMdLeft: {
101
+ [theme.breakpoints.up('md')]: {
102
+ width: '100vw',
103
+ },
104
+ },
105
+
106
+ beforeOverlayVariantMdBottom: {
107
+ [theme.breakpoints.up('md')]: {
108
+ height: '100vh',
109
+ },
110
+ },
111
+ beforeOverlayVariantSmBottom: {
112
+ [theme.breakpoints.down('sm')]: {
113
+ height: '100vh',
114
+ '@supports (-webkit-touch-callout: none)': {
115
+ height: '-webkit-fill-available',
116
+ },
117
+ },
118
+ },
119
+ overlay: {
120
+ pointerEvents: 'none',
121
+ gridArea: 'overlay',
122
+ scrollSnapAlign: 'start',
123
+ width: 'min-content',
124
+ minHeight: '100vh',
125
+ '@supports (-webkit-touch-callout: none)': {
126
+ minHeight: '-webkit-fill-available',
127
+ },
128
+ },
129
+ overlayVariantSmBottom: {
130
+ [theme.breakpoints.down('sm')]: {
131
+ marginTop: `calc(${theme.appShell.headerHeightSm} * 0.5 * -1)`,
132
+ paddingTop: `calc(${theme.appShell.headerHeightSm} * 0.5)`,
133
+ scrollSnapStop: 'always',
134
+ display: 'grid',
135
+ },
136
+ },
137
+ overlayVariantMdBottom: {
138
+ [theme.breakpoints.up('md')]: {
139
+ marginTop: `calc(${theme.appShell.headerHeightMd} + (${theme.appShell.appBarHeightMd} - ${theme.appShell.appBarInnerHeightMd}) * 0.5)`,
140
+ paddingTop: `calc(${theme.appShell.headerHeightMd} + (${theme.appShell.appBarHeightMd} - ${theme.appShell.appBarInnerHeightMd}) * -0.5)`,
141
+ scrollSnapAlign: 'start',
142
+ scrollSnapStop: 'always',
143
+ display: 'grid',
144
+ },
145
+ },
146
+ overlayPane: {
147
+ pointerEvents: 'all',
148
+ backgroundColor: theme.palette.background.paper,
149
+ boxShadow: theme.shadows[24],
150
+ minWidth: 'min(800px, 90vw)',
151
+ },
152
+ overlayPaneVariantSmBottom: {
153
+ [theme.breakpoints.down('sm')]: {
154
+ width: '100vw',
155
+ borderRadius: 10,
156
+ boxShadow: '0px 0px 20px rgba(0, 0, 0, 0.1)',
157
+ },
158
+ },
159
+ overlayPaneVariantMdBottom: {
160
+ [theme.breakpoints.up('md')]: {
161
+ width: '100vw',
162
+ borderRadius: 10,
163
+ boxShadow: '0px 0px 20px rgba(0, 0, 0, 0.1)',
164
+ },
165
+ },
166
+ overlayPaneVariantSmLeft: {
167
+ [theme.breakpoints.down('sm')]: {
168
+ paddingBottom: 1,
169
+ minHeight: '100vh',
170
+ '@supports (-webkit-touch-callout: none)': {
171
+ minHeight: '-webkit-fill-available',
172
+ },
173
+ },
174
+ },
175
+ overlayPaneVariantMdLeft: {
176
+ [theme.breakpoints.up('md')]: {
177
+ paddingBottom: 1,
178
+ minHeight: '100vh',
179
+ '@supports (-webkit-touch-callout: none)': {
180
+ minHeight: '-webkit-fill-available',
181
+ },
182
+ },
183
+ },
184
+ overlayPaneVariantSmRight: {
185
+ [theme.breakpoints.down('sm')]: {
186
+ paddingBottom: 1,
187
+ minHeight: '100vh',
188
+ '@supports (-webkit-touch-callout: none)': {
189
+ minHeight: '-webkit-fill-available',
190
+ },
191
+ },
192
+ },
193
+ overlayPaneVariantMdRight: {
194
+ [theme.breakpoints.up('md')]: {
195
+ paddingBottom: 1,
196
+ minHeight: '100vh',
197
+ '@supports (-webkit-touch-callout: none)': {
198
+ minHeight: '-webkit-fill-available',
199
+ },
200
+ },
201
+ },
202
+ afterOverlay: {
203
+ gridArea: 'afterOverlay',
204
+ scrollSnapAlign: 'start',
205
+ },
206
+ backdrop: {
207
+ zIndex: -1,
208
+ position: 'fixed',
209
+ display: 'flex',
210
+ alignItems: 'center',
211
+ justifyContent: 'center',
212
+ right: 0,
213
+ bottom: 0,
214
+ top: 0,
215
+ left: 0,
216
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
217
+ WebkitTapHighlightColor: 'transparent',
218
+ },
219
+ }),
220
+ { name: 'Overlay' },
221
+ )
222
+
223
+ export type LayoutOverlayVariant = 'left' | 'bottom' | 'right'
224
+
225
+ export type LayoutOverlayBaseProps = {
226
+ children?: React.ReactNode
227
+ variantSm: LayoutOverlayVariant
228
+ variantMd: LayoutOverlayVariant
229
+ } & UseStyles<typeof useStyles>
230
+
231
+ export enum OverlayPosition {
232
+ UNOPENED = -1,
233
+ OPENED = 1,
234
+ CLOSED = 0,
235
+ }
236
+
237
+ export function LayoutOverlayBase(props: LayoutOverlayBaseProps) {
238
+ const { children, variantSm, variantMd } = props
239
+ const { scrollerRef } = useScrollerContext()
240
+ const positions = useOverlayPosition()
241
+ const scrollTo = useScrollTo()
242
+ const [isPresent, safeToRemove] = usePresence()
243
+
244
+ const { closeSteps, active, direction } = usePageContext()
245
+ const pageRouter = usePageRouter()
246
+
247
+ const position = useMotionValue<OverlayPosition>(OverlayPosition.UNOPENED)
248
+
249
+ const classes = useStyles(props)
250
+ const className = classesPicker(classes, { variantSm, variantMd })
251
+
252
+ const overlayRef = useRef<HTMLDivElement>(null)
253
+
254
+ const scroll = useElementScroll(scrollerRef)
255
+
256
+ useIsomorphicLayoutEffect(() => {
257
+ const scroller = scrollerRef.current
258
+ if (!scroller || !isPresent) return
259
+
260
+ const open = { x: positions.open.x.get(), y: positions.open.y.get() }
261
+
262
+ if (direction === 1 && position.get() !== OverlayPosition.OPENED) {
263
+ scroller.scrollLeft = positions.closed.x.get()
264
+ scroller.scrollTop = positions.closed.y.get()
265
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
266
+ scrollTo(open).then(() => {
267
+ scroller.scrollLeft = positions.open.x.get()
268
+ scroller.scrollTop = positions.open.y.get()
269
+ position.set(OverlayPosition.OPENED)
270
+ })
271
+ } else {
272
+ scroller.scrollLeft = open.x
273
+ scroller.scrollTop = open.y
274
+ }
275
+ }, [direction, isPresent, position, positions, scrollTo, scrollerRef])
276
+
277
+ // Make sure the overlay stays open when resizing the window.
278
+ useEffect(() => {
279
+ const scroller = scrollerRef.current
280
+ if (!scroller) return () => {}
281
+
282
+ const resize = () => {
283
+ if (positions.open.visible.get() !== 1) return
284
+ scroller.scrollLeft = positions.open.x.get()
285
+ scroller.scrollTop = positions.open.y.get()
286
+ }
287
+
288
+ window.addEventListener('resize', resize)
289
+ return () => window.removeEventListener('resize', resize)
290
+ // We're not checking for all deps, because that will cause rerenders.
291
+ // The scroller context shouldn't be changing, but at the moment it is.
292
+ }, [positions, scrollerRef])
293
+
294
+ useEffect(() => {
295
+ if (isPresent) return
296
+
297
+ position.set(OverlayPosition.CLOSED)
298
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
299
+ scrollTo({
300
+ x: positions.closed.x.get(),
301
+ y: positions.closed.y.get(),
302
+ }).then(() => safeToRemove?.())
303
+ }, [isPresent, position, positions, safeToRemove, scrollTo])
304
+
305
+ // Only go back to a previous page if the overlay isn't closed.
306
+ const closeOverlay = useCallback(() => {
307
+ if (position.get() !== OverlayPosition.OPENED) return
308
+ position.set(OverlayPosition.CLOSED)
309
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
310
+ pageRouter.go(closeSteps * -1)
311
+ }, [closeSteps, pageRouter, position])
312
+
313
+ // Handle escape key
314
+ const windowRef = useRef(typeof window !== 'undefined' ? window : null)
315
+ const handleEscape = (e: KeyboardEvent | Event) => {
316
+ if (active && (e as KeyboardEvent)?.key === 'Escape') closeOverlay()
317
+ }
318
+ useDomEvent(windowRef, 'keyup', handleEscape, { passive: true })
319
+
320
+ // When the overlay isn't visible anymore, we navigate back.
321
+ useEffect(() => positions.open.visible.onChange((o) => o === 0 && closeOverlay()))
322
+
323
+ // Measure the offset of the overlay in the scroller.
324
+
325
+ const offsetY = useMotionValue(0)
326
+ useEffect(() => {
327
+ if (!overlayRef.current) return () => {}
328
+ const ro = new ResizeObserver(([entry]) => offsetY.set(entry.contentRect.top))
329
+ ro.observe(overlayRef.current)
330
+ return () => ro.disconnect()
331
+ }, [offsetY])
332
+
333
+ // Create the exact position for the LayoutProvider which offsets the top of the overlay
334
+ const offsetPageY = useScrollOffset().y
335
+ const scrollWithoffset = useTransform(
336
+ [scroll.y, positions.open.y, offsetY] as MotionValue<number | string>[],
337
+ ([y, openY, offsetYv]: number[]) => Math.max(0, y - openY - offsetYv + offsetPageY),
338
+ )
339
+
340
+ return (
341
+ <>
342
+ <m.div {...className('backdrop')} style={{ opacity: positions.open.visible }} />
343
+ <Scroller {...className('root')} grid={false} hideScrollbar>
344
+ <div {...className('beforeOverlay')} onClick={closeOverlay} />
345
+ <div {...className('overlay')} ref={overlayRef}>
346
+ <div {...className('overlayPane')}>
347
+ <LayoutProvider scroll={scrollWithoffset}>{children}</LayoutProvider>
348
+ </div>
349
+ </div>
350
+ <div {...className('afterOverlay')} />
351
+ </Scroller>
352
+ </>
353
+ )
354
+ }
@@ -0,0 +1,5 @@
1
+ import { LayoutHeaderProps, LayoutHeader } from '../../Layout'
2
+
3
+ export function LayoutOverlayHeader(props: LayoutHeaderProps) {
4
+ return <LayoutHeader {...props} noAlign />
5
+ }
@@ -0,0 +1,70 @@
1
+ import { useScrollerContext } from '@graphcommerce/framer-scroller'
2
+ import {
3
+ useConstant,
4
+ useElementScroll,
5
+ useIsomorphicLayoutEffect,
6
+ } from '@graphcommerce/framer-utils'
7
+ import { motionValue } from 'framer-motion'
8
+ import { useEffect } from 'react'
9
+
10
+ export function useOverlayPosition() {
11
+ const { getScrollSnapPositions, scrollerRef } = useScrollerContext()
12
+
13
+ const state = useConstant(() => ({
14
+ open: {
15
+ x: motionValue(0),
16
+ y: motionValue(0),
17
+ visible: motionValue(0),
18
+ },
19
+ closed: { x: motionValue(0), y: motionValue(0) },
20
+ }))
21
+
22
+ const scroll = useElementScroll(scrollerRef)
23
+
24
+ useIsomorphicLayoutEffect(() => {
25
+ if (!scrollerRef.current) return () => {}
26
+
27
+ const measure = () => {
28
+ const positions = getScrollSnapPositions()
29
+ state.open.x.set(positions.x[1])
30
+ state.closed.x.set(positions.x[0])
31
+ state.open.y.set(positions.y[1])
32
+ state.closed.y.set(positions.y[0])
33
+ }
34
+ const ro = new ResizeObserver(measure)
35
+ measure()
36
+
37
+ ro.observe(scrollerRef.current)
38
+ return () => ro.disconnect()
39
+ })
40
+
41
+ // sets a float between 0 and 1 for the visibility of the overlay
42
+ useEffect(() => {
43
+ const calc = () => {
44
+ const x = scroll.x.get()
45
+ const y = scroll.y.get()
46
+
47
+ const yC = state.closed.y.get()
48
+ const yO = state.open.y.get()
49
+ const visY = yC === yO ? 1 : Math.max(0, Math.min(1, (y - yC) / (yO - yC)))
50
+
51
+ const xC = state.closed.x.get()
52
+ const xO = state.open.x.get()
53
+ const visX = xO === xC ? 1 : Math.max(0, Math.min(1, (x - xC) / (xO - xC)))
54
+
55
+ // todo: visibility sometimes flickers
56
+ state.open.visible.set(visY * visX)
57
+ }
58
+
59
+ const cancelY = scroll.y.onChange(calc)
60
+ const cancelX = scroll.x.onChange(calc)
61
+ calc()
62
+
63
+ return () => {
64
+ cancelY()
65
+ cancelX()
66
+ }
67
+ }, [state, scroll])
68
+
69
+ return state
70
+ }
@@ -0,0 +1,2 @@
1
+ export * from './components/LayoutOverlay'
2
+ export * from './components/LayoutOverlayHeader'
package/Page/App.tsx CHANGED
@@ -2,6 +2,7 @@ import { FramerNextPages } from '@graphcommerce/framer-next-pages'
2
2
  import { LazyMotion } from 'framer-motion'
3
3
  import { AppPropsType } from 'next/dist/shared/lib/utils'
4
4
  import React, { useEffect } from 'react'
5
+ import PageLoadIndicator from '../PageLoadIndicator'
5
6
  import { AppProps } from './types'
6
7
 
7
8
  export default function App(props: AppProps & AppPropsType) {
@@ -9,6 +10,7 @@ export default function App(props: AppProps & AppPropsType) {
9
10
 
10
11
  return (
11
12
  <LazyMotion features={async () => (await import('./framerFeatures')).default} strict>
13
+ <PageLoadIndicator />
12
14
  <FramerNextPages {...props} />
13
15
  </LazyMotion>
14
16
  )
@@ -1,3 +1,4 @@
1
+ import { usePageContext } from '@graphcommerce/framer-next-pages'
1
2
  import Head from 'next/head'
2
3
 
3
4
  // https://developers.google.com/search/docs/advanced/robots/robots_meta_tag#directives
@@ -22,11 +23,13 @@ export type PageMetaProps = {
22
23
  }
23
24
 
24
25
  export default function PageMeta(props: PageMetaProps) {
26
+ const { active } = usePageContext()
25
27
  const { title, canonical, metaDescription, metaRobots = ['all'] } = props
26
28
 
27
29
  if (!(canonical ?? 'http').startsWith('http'))
28
30
  throw new Error(`canonical must start with http:// or https://, '${canonical}' given`)
29
31
 
32
+ if (!active) return null
30
33
  return (
31
34
  <Head>
32
35
  <title>{title.trim()}</title>
@@ -1,6 +1,5 @@
1
1
  import { Fab, makeStyles, Theme, Typography } from '@material-ui/core'
2
2
  import { PaginationProps, usePagination } from '@material-ui/lab'
3
- import clsx from 'clsx'
4
3
  import React from 'react'
5
4
  import { UseStyles } from '../Styles'
6
5
  import SvgImageSimple from '../SvgImage/SvgImageSimple'
@@ -3,7 +3,7 @@ import React from 'react'
3
3
  import Row from '..'
4
4
  import SectionContainer from '../../SectionContainer'
5
5
  import { UseStyles } from '../../Styles'
6
- import responsiveVal from '../../Styles/responsiveVal'
6
+ import { responsiveVal } from '../../Styles/responsiveVal'
7
7
 
8
8
  const useStyles = makeStyles(
9
9
  (theme: Theme) => ({
@@ -1,4 +1,4 @@
1
- import { Container, ContainerProps, makeStyles, Theme } from '@material-ui/core'
1
+ import { ContainerProps, makeStyles, Theme } from '@material-ui/core'
2
2
  import React from 'react'
3
3
  import Row from '..'
4
4
 
@@ -1,5 +1,5 @@
1
- import { Container, makeStyles, Theme } from '@material-ui/core'
2
- import React, { PropsWithChildren } from 'react'
1
+ import { makeStyles, Theme } from '@material-ui/core'
2
+ import React from 'react'
3
3
  import Row from '..'
4
4
  import { UseStyles } from '../../Styles'
5
5
 
@@ -19,7 +19,7 @@ const useStyles = makeStyles(
19
19
  "left right"
20
20
  `,
21
21
  gridTemplateColumns: '1fr auto',
22
- gap: `${theme.spacings.sm} ${theme.spacings.xl}`,
22
+ gap: `${theme.spacings.sm} ${theme.spacings.xxl}`,
23
23
  },
24
24
  },
25
25
  top: {
@@ -5,12 +5,12 @@ import { UseStyles } from '../../Styles'
5
5
 
6
6
  const useStyles = makeStyles(
7
7
  (theme: Theme) => ({
8
- root: {},
9
- scroller: {
8
+ root: {
10
9
  marginBottom: `${theme.spacings.lg}`,
10
+ },
11
+ scroller: {
11
12
  justifyContent: 'start',
12
13
  gap: `${theme.spacings.md}`,
13
- alignContent: 'center',
14
14
  gridAutoColumns: `max-content`,
15
15
  },
16
16
  title: {