@graphcommerce/next-ui 3.1.7 → 3.2.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 CHANGED
@@ -3,6 +3,30 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.2.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/next-ui@3.1.7...@graphcommerce/next-ui@3.2.0) (2021-10-09)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **framer-scroller:** pan snap does not work on mobile ([660f242](https://github.com/ho-nl/m2-pwa/commit/660f242a38558669fa896a74e14cafdd85069d57))
12
+ * **framer-slider:** route changes ([4cadbea](https://github.com/ho-nl/m2-pwa/commit/4cadbea3e494326377e74e2fa9370ab80f8d8c35))
13
+ * make sure the gallery never gets higher than 100% ([1eae8c7](https://github.com/ho-nl/m2-pwa/commit/1eae8c7cfb2a9e67f03f1e4e4db5c95213d2dbe0))
14
+ * poistioning on mobile ([bec497f](https://github.com/ho-nl/m2-pwa/commit/bec497fca426346b80b453a3871b9c66521a2161))
15
+ * **sidebar-gallery:** differentiate drag from click ([acd408e](https://github.com/ho-nl/m2-pwa/commit/acd408e400f8285e2b3a9105b4694d5fd839dd99))
16
+ * **sidebar-gallery:** push gallery to history one time ([2c45b64](https://github.com/ho-nl/m2-pwa/commit/2c45b64e171577f7b584662d56416eeae4a22554))
17
+ * **sidebar-gallery:** route handling ([1c3b8b1](https://github.com/ho-nl/m2-pwa/commit/1c3b8b1687b0bf637da6c88d2d9b30a734b98d11))
18
+ * **sidebar-gallery:** use fullscreen and fullscreen exit icons ([1328d22](https://github.com/ho-nl/m2-pwa/commit/1328d220030f766be2d4046abd87d45175e4fe38))
19
+ * use better URL handling and remove drag temporarily ([0b99387](https://github.com/ho-nl/m2-pwa/commit/0b993876280270320eef5301130c5cc3eb339ea9))
20
+
21
+
22
+ ### Features
23
+
24
+ * **sidebar-gallery:** toggle with browser back buttons ([a2f804b](https://github.com/ho-nl/m2-pwa/commit/a2f804b0cedb98df8f6a7b197aeeeeda43c6b1ba))
25
+
26
+
27
+
28
+
29
+
6
30
  ## [3.1.7](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/next-ui@3.1.6...@graphcommerce/next-ui@3.1.7) (2021-10-08)
7
31
 
8
32
 
@@ -1,3 +1,4 @@
1
+ import { usePrevPageRouter } from '@graphcommerce/framer-next-pages/hooks/usePrevPageRouter'
1
2
  import {
2
3
  CenterSlide,
3
4
  MotionImageAspect,
@@ -10,18 +11,14 @@ import {
10
11
  import { clientSize, useMotionValueValue } from '@graphcommerce/framer-utils'
11
12
  import { Fab, makeStyles, Theme, useTheme } from '@material-ui/core'
12
13
  import clsx from 'clsx'
13
- import { m, useDomEvent } from 'framer-motion'
14
- import React, { useRef, useState } from 'react'
14
+ import { m, useDomEvent, useMotionValue } from 'framer-motion'
15
+ import { useRouter } from 'next/router'
16
+ import React, { useEffect, useRef } from 'react'
15
17
  import { UseStyles } from '../../Styles'
16
18
  import responsiveVal from '../../Styles/responsiveVal'
17
19
  import SvgImage from '../../SvgImage'
18
20
  import SvgImageSimple from '../../SvgImage/SvgImageSimple'
19
- import {
20
- iconChevronLeft,
21
- iconChevronRight,
22
- iconCollapseVertical,
23
- iconExpandVertical,
24
- } from '../../icons'
21
+ import { iconChevronLeft, iconChevronRight, iconFullscreen, iconFullscreenExit } from '../../icons'
25
22
 
26
23
  type StyleProps = {
27
24
  aspectRatio: [number, number]
@@ -42,7 +39,7 @@ const useStyles = makeStyles(
42
39
  rootZoomed: {
43
40
  position: 'relative',
44
41
  zIndex: theme.zIndex.modal,
45
- marginTop: 0,
42
+ marginTop: `calc(${theme.page.headerInnerHeight.sm} * -1)`,
46
43
  [theme.breakpoints.up('md')]: {
47
44
  marginTop: `calc(${theme.page.headerInnerHeight.md} * -1 - ${theme.spacings.sm})`,
48
45
  },
@@ -79,8 +76,12 @@ const useStyles = makeStyles(
79
76
  gridAutoFlow: `column`,
80
77
  gridTemplateColumns: `repeat(100, 100%)`,
81
78
  gridTemplateRows: `100%`,
79
+ cursor: 'zoom-in',
82
80
  },
83
-
81
+ scrollerZoomed: ({ clientHeight }: StyleProps) => ({
82
+ height: clientHeight,
83
+ cursor: 'inherit',
84
+ }),
84
85
  sidebarWrapper: {
85
86
  boxSizing: 'content-box',
86
87
  display: 'grid',
@@ -163,27 +164,41 @@ export type SidebarGalleryProps = {
163
164
  sidebar: React.ReactNode
164
165
  images: MotionImageAspectProps[]
165
166
  aspectRatio?: [number, number]
167
+ routeHash?: string
166
168
  } & UseStyles<typeof useStyles>
167
169
 
168
170
  export default function SidebarGallery(props: SidebarGalleryProps) {
169
- const { sidebar, images, aspectRatio = [1, 1] } = props
170
- const [zoomed, setZoomed] = useState(false)
171
-
171
+ const { sidebar, images, aspectRatio = [1, 1], routeHash = 'gallery' } = props
172
+ const router = useRouter()
173
+ const prevRoute = usePrevPageRouter()
172
174
  const clientHeight = useMotionValueValue(clientSize.y, (y) => y)
173
175
  const classes = useStyles({ clientHeight, aspectRatio })
174
176
 
177
+ const route = `#${routeHash}`
178
+ // We're using the URL to manage the state of the gallery.
179
+ const zoomed = router.asPath.endsWith(route)
180
+
181
+ // cleanup if someone enters the page with #gallery
182
+ useEffect(() => {
183
+ if (!prevRoute?.pathname && zoomed) {
184
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
185
+ router.replace(router.asPath.replace(route, ''))
186
+ }
187
+ }, [prevRoute?.pathname, route, router, zoomed])
188
+
175
189
  const toggle = () => {
176
- setZoomed(!zoomed)
177
190
  if (!zoomed) {
191
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
192
+ router.push(route, undefined, { shallow: true })
178
193
  document.body.style.overflow = 'hidden'
179
194
  window.scrollTo({ top: 0, behavior: 'smooth' })
195
+ } else {
196
+ router.back()
180
197
  }
181
198
  }
182
199
 
183
200
  const clsxZoom = (key: string) => clsx(classes?.[key], zoomed && classes?.[`${key}Zoomed`])
184
-
185
201
  const theme = useTheme()
186
-
187
202
  const windowRef = useRef(typeof window !== 'undefined' ? window : null)
188
203
 
189
204
  const handleEscapeKey = (e: KeyboardEvent | Event) => {
@@ -194,6 +209,16 @@ export default function SidebarGallery(props: SidebarGalleryProps) {
194
209
  }
195
210
  }
196
211
 
212
+ const dragStart = useMotionValue<number>(0)
213
+ const onMouseDownScroller: React.MouseEventHandler<HTMLDivElement> = (e) => {
214
+ if (dragStart.get() === e.clientX) return
215
+ dragStart.set(e.clientX)
216
+ }
217
+ const onMouseUpScroller: React.MouseEventHandler<HTMLDivElement> = (e) => {
218
+ const currentDragLoc = e.clientX
219
+ if (Math.abs(currentDragLoc - dragStart.get()) < 8) toggle()
220
+ }
221
+
197
222
  useDomEvent(windowRef, 'keyup', handleEscapeKey, { passive: true })
198
223
 
199
224
  return (
@@ -206,7 +231,12 @@ export default function SidebarGallery(props: SidebarGalleryProps) {
206
231
  if (!zoomed) document.body.style.overflow = ''
207
232
  }}
208
233
  >
209
- <Scroller className={clsxZoom('scroller')} hideScrollbar>
234
+ <Scroller
235
+ className={clsxZoom('scroller')}
236
+ hideScrollbar
237
+ onMouseDown={onMouseDownScroller}
238
+ onMouseUp={onMouseUpScroller}
239
+ >
210
240
  {images.map((image, idx) => (
211
241
  <CenterSlide key={typeof image.src === 'string' ? image.src : idx}>
212
242
  <MotionImageAspect
@@ -225,11 +255,11 @@ export default function SidebarGallery(props: SidebarGalleryProps) {
225
255
  ))}
226
256
  </Scroller>
227
257
  <m.div layout className={classes.topRight}>
228
- <Fab color='inherit' size='small' className={classes.toggleIcon} onClick={toggle}>
258
+ <Fab color='inherit' size='small' className={classes.toggleIcon} onMouseUp={toggle}>
229
259
  {!zoomed ? (
230
- <SvgImage src={iconExpandVertical} alt='Zoom in' loading='eager' />
260
+ <SvgImage src={iconFullscreen} alt='Zoom in' loading='eager' size='small' />
231
261
  ) : (
232
- <SvgImage src={iconCollapseVertical} alt='Zoom out' loading='eager' />
262
+ <SvgImage src={iconFullscreenExit} alt='Zoom out' loading='eager' size='small' />
233
263
  )}
234
264
  </Fab>
235
265
  </m.div>
@@ -248,6 +278,7 @@ export default function SidebarGallery(props: SidebarGalleryProps) {
248
278
  <ScrollerDots layout />
249
279
  </div>
250
280
  </m.div>
281
+
251
282
  <div className={clsxZoom('sidebarWrapper')}>
252
283
  <m.div layout className={clsxZoom('sidebar')}>
253
284
  {sidebar}
@@ -1,4 +1,3 @@
1
- import { relative } from 'path/posix'
2
1
  import {
3
2
  Scroller,
4
3
  ScrollerButton,
@@ -8,9 +7,10 @@ import {
8
7
  import { Theme } from '@material-ui/core'
9
8
  import { makeStyles } from '@material-ui/styles'
10
9
  import React, { ReactNode } from 'react'
11
- import { SvgImageSimple, iconChevronLeft, iconChevronRight } from '../..'
12
10
  import { UseStyles } from '../../Styles'
13
11
  import responsiveVal from '../../Styles/responsiveVal'
12
+ import SvgImageSimple from '../../SvgImage/SvgImageSimple'
13
+ import { iconChevronLeft, iconChevronRight } from '../../icons'
14
14
 
15
15
  const useStyles = makeStyles(
16
16
  (theme: Theme) => ({
@@ -37,7 +37,6 @@ const useStyles = makeStyles(
37
37
  gridRowGap: theme.spacings.lg,
38
38
  alignContent: 'space-around',
39
39
  paddingRight: theme.page.horizontal,
40
-
41
40
  '& > *': {
42
41
  minWidth: responsiveVal(200, 400),
43
42
  },
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"/></svg>
package/icons/index.tsx CHANGED
@@ -12,11 +12,9 @@ export { default as iconChevronRight } from './icon_chevron_right.svg'
12
12
  export { default as iconChevronUp } from './icon_chevron_up.svg'
13
13
  export { default as iconClose } from './icon_close.svg'
14
14
  export { default as iconCloseCircle } from './icon_close_circle.svg'
15
- export { default as iconCollapseVertical } from './icon_collapse_vertical.svg'
16
15
  export { default as iconCustomerService } from './icon_customer_service.svg'
17
16
  export { default as iconEmail } from './icon_email.svg'
18
17
  export { default as iconEmailOutline } from './icon_email_outline.svg'
19
- export { default as iconExpandVertical } from './icon_expand_vertical.svg'
20
18
  export { default as iconHeart } from './icon_heart.svg'
21
19
  export { default as iconHome } from './icon_home.svg'
22
20
  export { default as iconId } from './icon_id.svg'
@@ -40,3 +38,5 @@ export { default as iconStar } from './icon_star.svg'
40
38
  export { default as iconStarFilledMuted } from './icon_star_filled_muted.svg'
41
39
  export { default as iconStarYellow } from './icon_star_yellow.svg'
42
40
  export { default as iconParty } from './icon_party.svg'
41
+ export { default as iconFullscreenExit } from './icon_fullscreen_exit.svg'
42
+ export { default as iconFullscreen } from './icon_fullscreen.svg'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/next-ui",
3
- "version": "3.1.7",
3
+ "version": "3.2.0",
4
4
  "author": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -10,12 +10,12 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@apollo/client": "^3.4.16",
13
- "@graphcommerce/framer-next-pages": "^2.106.6",
14
- "@graphcommerce/framer-scroller": "^0.2.7",
15
- "@graphcommerce/framer-sheet": "^2.105.5",
16
- "@graphcommerce/framer-utils": "^2.103.5",
13
+ "@graphcommerce/framer-next-pages": "^2.106.7",
14
+ "@graphcommerce/framer-scroller": "^0.2.8",
15
+ "@graphcommerce/framer-sheet": "^2.105.6",
16
+ "@graphcommerce/framer-utils": "^2.103.6",
17
17
  "@graphcommerce/graphql": "^2.103.5",
18
- "@graphcommerce/image": "^2.104.6",
18
+ "@graphcommerce/image": "^2.104.7",
19
19
  "@graphql-typed-document-node/core": "^3.1.0",
20
20
  "@material-ui/core": "^4.12.3",
21
21
  "@material-ui/lab": "^4.0.0-alpha.60",
@@ -55,5 +55,5 @@
55
55
  "project": "./tsconfig.json"
56
56
  }
57
57
  },
58
- "gitHead": "7c6ad9b6fdf91e48b33013218d962ad15f931db8"
58
+ "gitHead": "b3dd4c996ac571874bb03d0a5c16b2c37f41abcb"
59
59
  }
@@ -1,11 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
- <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
4
- <g id="arrow-bar-right" transform="translate(16.000000, 16.000000) scale(-1, 1) translate(-16.000000, -16.000000) translate(8.000000, 8.000000)" stroke="#000000" stroke-width="1.5">
5
- <line x1="16" y1="8" x2="6" y2="8" id="Path"></line>
6
- <line x1="16" y1="8" x2="12" y2="12" id="Path"></line>
7
- <line x1="16" y1="8" x2="12" y2="4" id="Path"></line>
8
- <line x1="1" y1="0" x2="1" y2="16" id="Path"></line>
9
- </g>
10
- </g>
11
- </svg>
@@ -1,11 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
- <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
4
- <g id="arrow-bar-right" transform="translate(8.000000, 8.000000)" stroke="#000000" stroke-width="1.5">
5
- <line x1="16" y1="8" x2="6" y2="8" id="Path"></line>
6
- <line x1="16" y1="8" x2="12" y2="12" id="Path"></line>
7
- <line x1="16" y1="8" x2="12" y2="4" id="Path"></line>
8
- <line x1="1" y1="0" x2="1" y2="16" id="Path"></line>
9
- </g>
10
- </g>
11
- </svg>