@graphcommerce/next-ui 3.19.0 → 3.20.2
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/AppShell/AppShellSticky/index.tsx +3 -19
- package/AppShell/DesktopNavActions.tsx +3 -4
- package/AppShell/DesktopNavBar.tsx +2 -3
- package/AppShell/FixedFab.tsx +1 -6
- package/AppShell/GlobalHead.tsx +36 -0
- package/AppShell/Logo.tsx +11 -20
- package/AppShell/MenuFab.tsx +5 -3
- package/AppShell/MenuFabSecondaryItem.tsx +3 -3
- package/AppShell/PlaceholderFab/index.tsx +8 -27
- package/AppShell/index.tsx +19 -0
- package/AppShell/useFabAnimation.tsx +3 -2
- package/AppShell/useFixedFabAnimation.tsx +3 -2
- package/Blog/BlogAuthor/index.tsx +1 -1
- package/Blog/BlogHeader/index.tsx +2 -3
- package/Blog/BlogList/index.tsx +1 -1
- package/Blog/BlogListItem/index.tsx +1 -1
- package/Blog/BlogTitle/index.tsx +5 -5
- package/Button/index.tsx +26 -21
- package/ButtonLink/index.tsx +1 -1
- package/CHANGELOG.md +56 -0
- package/ChipMenu/index.tsx +2 -2
- package/FlagAvatar/index.tsx +3 -3
- package/{AppShell/Footer/index.tsx → Footer/Footer.tsx} +3 -3
- package/{AppShell/Footer → Footer}/SocialIcon.tsx +3 -3
- package/Footer/index.ts +2 -0
- package/Form/InputCheckmark.tsx +3 -3
- package/Form/index.tsx +1 -1
- package/FramerScroller/components/SidebarGallery.tsx +24 -20
- package/FramerScroller/components/SidebarSlider.tsx +1 -3
- package/FullPageMessage/index.tsx +1 -1
- package/IconHeader/index.tsx +2 -15
- package/Layout/components/LayoutHeader.tsx +151 -0
- package/Layout/components/LayoutHeaderBack.tsx +58 -0
- package/Layout/components/LayoutHeaderClose.tsx +27 -0
- package/Layout/components/LayoutHeaderContent.tsx +182 -0
- package/Layout/components/LayoutHeadertypes.ts +10 -0
- package/Layout/components/LayoutProvider.tsx +17 -0
- package/{Title/index.tsx → Layout/components/LayoutTitle.tsx} +24 -15
- package/Layout/context/layoutContext.tsx +7 -0
- package/Layout/hooks/useScrollY.tsx +6 -0
- package/Layout/index.ts +5 -0
- package/Layout/types.ts +5 -0
- package/LayoutDefault/components/LayoutDefault.tsx +90 -0
- package/LayoutDefault/index.ts +1 -0
- package/LayoutOverlay/components/LayoutOverlay.tsx +25 -0
- package/LayoutOverlay/components/LayoutOverlayBase.tsx +354 -0
- package/LayoutOverlay/components/LayoutOverlayHeader.tsx +5 -0
- package/LayoutOverlay/hooks/useOverlayPosition.ts +70 -0
- package/LayoutOverlay/index.ts +2 -0
- package/Page/App.tsx +2 -0
- package/PageMeta/index.tsx +3 -0
- package/Pagination/index.tsx +0 -1
- package/Row/ButtonLinkList/index.tsx +1 -1
- package/Row/ColumnOneBoxed/index.tsx +1 -1
- package/Row/ColumnTwoWithTop/index.tsx +3 -3
- package/Row/ContentLinks/index.tsx +3 -3
- package/Row/HeroBanner/index.tsx +7 -11
- package/Row/IconBlocks/index.tsx +1 -1
- package/Row/ImageText/index.tsx +1 -1
- package/Row/ImageTextBoxed/index.tsx +1 -1
- package/Row/ParagraphWithSidebarSlide/index.tsx +1 -1
- package/Row/SpecialBanner/index.tsx +4 -3
- package/Row/index.tsx +1 -1
- package/Snackbar/MessageSnackbarImpl.tsx +1 -1
- package/StarRatingField/index.tsx +3 -4
- package/Stepper/Stepper.tsx +1 -1
- package/Styles/breakpointVal.tsx +2 -2
- package/Styles/classesPicker.ts +41 -0
- package/Styles/responsiveVal.tsx +1 -1
- package/SvgImage/SvgImageSimple.tsx +9 -8
- package/SvgImage/index.tsx +9 -11
- package/TextInputNumber/index.tsx +3 -4
- package/Theme/types.ts +14 -12
- package/ToggleButton/index.tsx +2 -4
- package/UspList/UspListItem.tsx +1 -1
- package/index.ts +9 -43
- package/package.json +8 -9
- package/AppShell/AppShellHeader/appShellHeaderContext.tsx +0 -11
- package/AppShell/AppShellHeader/index.tsx +0 -439
- package/AppShell/AppShellHeader/useAppShellHeaderContext.tsx +0 -6
- package/AppShell/AppShellProvider/index.tsx +0 -18
- package/AppShell/AppShellTitle/index.tsx +0 -45
- package/AppShell/ForwardButton.tsx +0 -53
- package/AppShell/FullPageShellBase.tsx +0 -82
- package/AppShell/MinimalPageShellBase.tsx +0 -22
- package/AppShell/PageShellHeader/index.tsx +0 -14
- package/AppShell/SheetShellBase/index.tsx +0 -114
- package/AppShell/SheetShellBase/useSheetStyles.ts +0 -18
- package/AppShell/SheetShellDragIndicator/index.tsx +0 -55
- package/AppShell/SheetShellHeader/index.tsx +0 -28
- package/AppShell/ShellBase.tsx +0 -45
- package/Debug/DebugSpacer.tsx +0 -51
- package/FramerNextPagesSlider/Slide.tsx +0 -71
- package/FramerNextPagesSlider/Slider.tsx +0 -39
- package/FramerNextPagesSlider/index.ts +0 -1
- package/FramerNextPagesSlider/types.ts +0 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { makeStyles, Theme, Typography, TypographyProps } from '@material-ui/core'
|
|
2
|
-
import clsx from 'clsx'
|
|
3
2
|
import React from 'react'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
3
|
+
import { UseStyles } from '../../Styles'
|
|
4
|
+
import { classesPicker } from '../../Styles/classesPicker'
|
|
5
|
+
import { responsiveVal } from '../../Styles/responsiveVal'
|
|
6
|
+
import { SvgImageProps } from '../../SvgImage'
|
|
7
|
+
import SvgImageSimple from '../../SvgImage/SvgImageSimple'
|
|
8
8
|
|
|
9
9
|
const useStyles = makeStyles(
|
|
10
10
|
(theme: Theme) => ({
|
|
@@ -18,8 +18,7 @@ const useStyles = makeStyles(
|
|
|
18
18
|
flexFlow: 'column',
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
-
|
|
22
|
-
small: {
|
|
21
|
+
containerSizeSmall: {
|
|
23
22
|
flexFlow: 'unset',
|
|
24
23
|
'& svg': {
|
|
25
24
|
width: responsiveVal(24, 28),
|
|
@@ -27,10 +26,15 @@ const useStyles = makeStyles(
|
|
|
27
26
|
strokeWidth: 1.4,
|
|
28
27
|
},
|
|
29
28
|
},
|
|
29
|
+
containerGutterTop: {
|
|
30
|
+
marginTop: theme.spacings.xl,
|
|
31
|
+
},
|
|
32
|
+
containerGutterBottom: {
|
|
33
|
+
marginBottom: theme.spacings.lg,
|
|
34
|
+
},
|
|
35
|
+
typography: {},
|
|
30
36
|
}),
|
|
31
|
-
{
|
|
32
|
-
name: 'Title',
|
|
33
|
-
},
|
|
37
|
+
{ name: 'Title' },
|
|
34
38
|
)
|
|
35
39
|
|
|
36
40
|
export type TitleProps = {
|
|
@@ -38,17 +42,24 @@ export type TitleProps = {
|
|
|
38
42
|
icon?: SvgImageProps['src']
|
|
39
43
|
size?: 'small' | 'medium'
|
|
40
44
|
variant?: TypographyProps['variant']
|
|
45
|
+
gutterTop?: boolean
|
|
46
|
+
gutterBottom?: boolean
|
|
41
47
|
component?: React.ElementType
|
|
42
48
|
} & UseStyles<typeof useStyles>
|
|
43
49
|
|
|
44
|
-
const
|
|
50
|
+
export const LayoutTitle = React.forwardRef<HTMLDivElement, TitleProps>((props, ref) => {
|
|
45
51
|
const { children, icon, size = 'medium', component, variant } = props
|
|
46
52
|
const classes = useStyles(props)
|
|
47
53
|
const small = size === 'small'
|
|
48
54
|
|
|
55
|
+
const gutterTop = !!(props.gutterTop ?? size !== 'small')
|
|
56
|
+
const gutterBottom = !!(props.gutterBottom ?? size !== 'small')
|
|
57
|
+
|
|
58
|
+
const className = classesPicker(classes, { size, gutterBottom, gutterTop })
|
|
59
|
+
|
|
49
60
|
return (
|
|
50
|
-
<div className
|
|
51
|
-
{icon && <SvgImageSimple src={icon} size='xl' />}
|
|
61
|
+
<div {...className('container')}>
|
|
62
|
+
{icon && <SvgImageSimple src={icon} size={small ? 'large' : 'xl'} />}
|
|
52
63
|
<Typography
|
|
53
64
|
ref={ref}
|
|
54
65
|
variant={variant || (small ? 'h6' : 'h3')}
|
|
@@ -60,5 +71,3 @@ const Title = React.forwardRef<HTMLDivElement, TitleProps>((props, ref) => {
|
|
|
60
71
|
</div>
|
|
61
72
|
)
|
|
62
73
|
})
|
|
63
|
-
|
|
64
|
-
export default Title
|
package/Layout/index.ts
ADDED
package/Layout/types.ts
ADDED
|
@@ -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, ClickAwayListener } 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
|
+
},
|
|
157
|
+
},
|
|
158
|
+
overlayPaneVariantMdBottom: {
|
|
159
|
+
[theme.breakpoints.up('md')]: {
|
|
160
|
+
width: '100vw',
|
|
161
|
+
borderRadius: 10,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
overlayPaneVariantSmLeft: {
|
|
165
|
+
[theme.breakpoints.down('sm')]: {
|
|
166
|
+
paddingBottom: 1,
|
|
167
|
+
minHeight: '100vh',
|
|
168
|
+
'@supports (-webkit-touch-callout: none)': {
|
|
169
|
+
minHeight: '-webkit-fill-available',
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
overlayPaneVariantMdLeft: {
|
|
174
|
+
[theme.breakpoints.up('md')]: {
|
|
175
|
+
paddingBottom: 1,
|
|
176
|
+
minHeight: '100vh',
|
|
177
|
+
'@supports (-webkit-touch-callout: none)': {
|
|
178
|
+
minHeight: '-webkit-fill-available',
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
overlayPaneVariantSmRight: {
|
|
183
|
+
[theme.breakpoints.down('sm')]: {
|
|
184
|
+
paddingBottom: 1,
|
|
185
|
+
minHeight: '100vh',
|
|
186
|
+
'@supports (-webkit-touch-callout: none)': {
|
|
187
|
+
minHeight: '-webkit-fill-available',
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
overlayPaneVariantMdRight: {
|
|
192
|
+
[theme.breakpoints.up('md')]: {
|
|
193
|
+
paddingBottom: 1,
|
|
194
|
+
minHeight: '100vh',
|
|
195
|
+
'@supports (-webkit-touch-callout: none)': {
|
|
196
|
+
minHeight: '-webkit-fill-available',
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
afterOverlay: {
|
|
201
|
+
gridArea: 'afterOverlay',
|
|
202
|
+
scrollSnapAlign: 'start',
|
|
203
|
+
},
|
|
204
|
+
backdrop: {
|
|
205
|
+
zIndex: -1,
|
|
206
|
+
position: 'fixed',
|
|
207
|
+
display: 'flex',
|
|
208
|
+
alignItems: 'center',
|
|
209
|
+
justifyContent: 'center',
|
|
210
|
+
right: 0,
|
|
211
|
+
bottom: 0,
|
|
212
|
+
top: 0,
|
|
213
|
+
left: 0,
|
|
214
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
215
|
+
WebkitTapHighlightColor: 'transparent',
|
|
216
|
+
},
|
|
217
|
+
}),
|
|
218
|
+
{ name: 'Overlay' },
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
export type LayoutOverlayVariant = 'left' | 'bottom' | 'right'
|
|
222
|
+
|
|
223
|
+
export type LayoutOverlayBaseProps = {
|
|
224
|
+
children?: React.ReactNode
|
|
225
|
+
variantSm: LayoutOverlayVariant
|
|
226
|
+
variantMd: LayoutOverlayVariant
|
|
227
|
+
} & UseStyles<typeof useStyles>
|
|
228
|
+
|
|
229
|
+
export enum OverlayPosition {
|
|
230
|
+
UNOPENED = -1,
|
|
231
|
+
OPENED = 1,
|
|
232
|
+
CLOSED = 0,
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function LayoutOverlayBase(props: LayoutOverlayBaseProps) {
|
|
236
|
+
const { children, variantSm, variantMd } = props
|
|
237
|
+
const { scrollerRef } = useScrollerContext()
|
|
238
|
+
const positions = useOverlayPosition()
|
|
239
|
+
const scrollTo = useScrollTo()
|
|
240
|
+
const [isPresent, safeToRemove] = usePresence()
|
|
241
|
+
|
|
242
|
+
const { closeSteps, active, direction } = usePageContext()
|
|
243
|
+
const pageRouter = usePageRouter()
|
|
244
|
+
|
|
245
|
+
const position = useMotionValue<OverlayPosition>(OverlayPosition.UNOPENED)
|
|
246
|
+
|
|
247
|
+
const classes = useStyles(props)
|
|
248
|
+
const className = classesPicker(classes, { variantSm, variantMd })
|
|
249
|
+
|
|
250
|
+
const overlayRef = useRef<HTMLDivElement>(null)
|
|
251
|
+
|
|
252
|
+
const scroll = useElementScroll(scrollerRef)
|
|
253
|
+
|
|
254
|
+
useIsomorphicLayoutEffect(() => {
|
|
255
|
+
const scroller = scrollerRef.current
|
|
256
|
+
if (!scroller || !isPresent) return
|
|
257
|
+
|
|
258
|
+
const open = { x: positions.open.x.get(), y: positions.open.y.get() }
|
|
259
|
+
|
|
260
|
+
if (direction === 1 && position.get() !== OverlayPosition.OPENED) {
|
|
261
|
+
scroller.scrollLeft = positions.closed.x.get()
|
|
262
|
+
scroller.scrollTop = positions.closed.y.get()
|
|
263
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
264
|
+
scrollTo(open).then(() => {
|
|
265
|
+
scroller.scrollLeft = positions.open.x.get()
|
|
266
|
+
scroller.scrollTop = positions.open.y.get()
|
|
267
|
+
position.set(OverlayPosition.OPENED)
|
|
268
|
+
})
|
|
269
|
+
} else {
|
|
270
|
+
scroller.scrollLeft = open.x
|
|
271
|
+
scroller.scrollTop = open.y
|
|
272
|
+
}
|
|
273
|
+
}, [direction, isPresent, position, positions, scrollTo, scrollerRef])
|
|
274
|
+
|
|
275
|
+
// Make sure the overlay stays open when resizing the window.
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
const scroller = scrollerRef.current
|
|
278
|
+
if (!scroller) return () => {}
|
|
279
|
+
|
|
280
|
+
const resize = () => {
|
|
281
|
+
if (positions.open.visible.get() !== 1) return
|
|
282
|
+
scroller.scrollLeft = positions.open.x.get()
|
|
283
|
+
scroller.scrollTop = positions.open.y.get()
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
window.addEventListener('resize', resize)
|
|
287
|
+
return () => window.removeEventListener('resize', resize)
|
|
288
|
+
// We're not checking for all deps, because that will cause rerenders.
|
|
289
|
+
// The scroller context shouldn't be changing, but at the moment it is.
|
|
290
|
+
}, [positions, scrollerRef])
|
|
291
|
+
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
if (isPresent) return
|
|
294
|
+
|
|
295
|
+
position.set(OverlayPosition.CLOSED)
|
|
296
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
297
|
+
scrollTo({
|
|
298
|
+
x: positions.closed.x.get(),
|
|
299
|
+
y: positions.closed.y.get(),
|
|
300
|
+
}).then(() => safeToRemove?.())
|
|
301
|
+
}, [isPresent, position, positions, safeToRemove, scrollTo])
|
|
302
|
+
|
|
303
|
+
// Only go back to a previous page if the overlay isn't closed.
|
|
304
|
+
const closeOverlay = useCallback(() => {
|
|
305
|
+
if (position.get() !== OverlayPosition.OPENED) return
|
|
306
|
+
position.set(OverlayPosition.CLOSED)
|
|
307
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
308
|
+
pageRouter.go(closeSteps * -1)
|
|
309
|
+
}, [closeSteps, pageRouter, position])
|
|
310
|
+
|
|
311
|
+
// Handle escape key
|
|
312
|
+
const windowRef = useRef(typeof window !== 'undefined' ? window : null)
|
|
313
|
+
const handleEscape = (e: KeyboardEvent | Event) => {
|
|
314
|
+
if (active && (e as KeyboardEvent)?.key === 'Escape') closeOverlay()
|
|
315
|
+
}
|
|
316
|
+
useDomEvent(windowRef, 'keyup', handleEscape, { passive: true })
|
|
317
|
+
|
|
318
|
+
// When the overlay isn't visible anymore, we navigate back.
|
|
319
|
+
useEffect(() => positions.open.visible.onChange((o) => o === 0 && closeOverlay()))
|
|
320
|
+
|
|
321
|
+
// Measure the offset of the overlay in the scroller.
|
|
322
|
+
|
|
323
|
+
const offsetY = useMotionValue(0)
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
if (!overlayRef.current) return () => {}
|
|
326
|
+
const ro = new ResizeObserver(([entry]) => offsetY.set(entry.contentRect.top))
|
|
327
|
+
ro.observe(overlayRef.current)
|
|
328
|
+
return () => ro.disconnect()
|
|
329
|
+
}, [offsetY])
|
|
330
|
+
|
|
331
|
+
// Create the exact position for the LayoutProvider which offsets the top of the overlay
|
|
332
|
+
const offsetPageY = useScrollOffset().y
|
|
333
|
+
const scrollWithoffset = useTransform(
|
|
334
|
+
[scroll.y, positions.open.y, offsetY] as MotionValue<number | string>[],
|
|
335
|
+
([y, openY, offsetYv]: number[]) => Math.max(0, y - openY - offsetYv + offsetPageY),
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
return (
|
|
339
|
+
<>
|
|
340
|
+
<m.div {...className('backdrop')} style={{ opacity: positions.open.visible }} />
|
|
341
|
+
<Scroller {...className('root')} grid={false} hideScrollbar>
|
|
342
|
+
<div {...className('beforeOverlay')} />
|
|
343
|
+
<div {...className('overlay')} ref={overlayRef}>
|
|
344
|
+
<ClickAwayListener onClickAway={closeOverlay}>
|
|
345
|
+
<div {...className('overlayPane')}>
|
|
346
|
+
<LayoutProvider scroll={scrollWithoffset}>{children}</LayoutProvider>
|
|
347
|
+
</div>
|
|
348
|
+
</ClickAwayListener>
|
|
349
|
+
</div>
|
|
350
|
+
<div {...className('afterOverlay')} />
|
|
351
|
+
</Scroller>
|
|
352
|
+
</>
|
|
353
|
+
)
|
|
354
|
+
}
|
|
@@ -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] ?? 0)
|
|
30
|
+
state.closed.x.set(positions.x[0])
|
|
31
|
+
state.open.y.set(positions.y[1] ?? 0)
|
|
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
|
+
}
|
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
|
)
|