@graphcommerce/framer-scroller 1.1.4 → 1.1.8

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,28 @@
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
+ ## [1.1.8](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/framer-scroller@1.1.7...@graphcommerce/framer-scroller@1.1.8) (2021-12-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * scroller should not snap to off-axis while dragging and direction isn't set to both ([9118bfc](https://github.com/ho-nl/m2-pwa/commit/9118bfcb1eb9ade5f144167e47e0c26724ce832f))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.1.5](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/framer-scroller@1.1.4...@graphcommerce/framer-scroller@1.1.5) (2021-12-06)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * Accessibility, SEO ([a258837](https://github.com/ho-nl/m2-pwa/commit/a258837476d94d20d33e13a4c4f950fff57f7dca))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [1.1.2](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/framer-scroller@1.1.1...@graphcommerce/framer-scroller@1.1.2) (2021-12-03)
7
29
 
8
30
 
@@ -13,16 +13,15 @@ const useStyles = makeStyles(
13
13
  width: 'fit-content',
14
14
  display: 'grid',
15
15
  gridAutoFlow: 'column',
16
- padding: `0 7px`,
17
- borderRadius: '20px',
16
+ padding: `0 6px`,
17
+ borderRadius: '99em',
18
18
  },
19
19
  dot: {
20
20
  boxShadow: 'none',
21
- margin: `0 -7px`,
22
21
  background: 'transparent',
23
22
  },
24
23
  circle: {
25
- borderRadius: '50%',
24
+ borderRadius: '99em',
26
25
  width: 10,
27
26
  height: 10,
28
27
  background: theme.palette.text.primary,
@@ -1,4 +1,4 @@
1
- import { MotionValue, motionValue, Point2D, useMotionValue } from 'framer-motion'
1
+ import { MotionValue, motionValue, Point, useMotionValue } from 'framer-motion'
2
2
  import { PlaybackControls } from 'popmotion'
3
3
  import React, { useEffect, useRef, useMemo, useCallback } from 'react'
4
4
  import { scrollerContext } from '../context/scrollerContext'
@@ -279,7 +279,7 @@ export default function ScrollerProvider(props: ScrollerProviderProps) {
279
279
  }
280
280
  }
281
281
 
282
- function getSnapPosition(direction: 'left' | 'right' | 'up' | 'down'): Point2D {
282
+ function getSnapPosition(direction: 'left' | 'right' | 'up' | 'down'): Point {
283
283
  if (!scrollerRef.current) return { x: 0, y: 0 }
284
284
 
285
285
  const axis: Axis = direction === 'up' || direction === 'down' ? 'y' : 'x'
@@ -1,5 +1,5 @@
1
1
  import { useElementScroll } from '@graphcommerce/framer-utils'
2
- import { Point2D } from 'framer-motion'
2
+ import { Point } from 'framer-motion'
3
3
  import { animate } from 'popmotion'
4
4
  import { useScrollerContext } from './useScrollerContext'
5
5
 
@@ -7,7 +7,7 @@ export function useScrollTo() {
7
7
  const { scrollerRef, register, disableSnap, enableSnap } = useScrollerContext()
8
8
  const scroll = useElementScroll(scrollerRef)
9
9
 
10
- return async (to: Point2D) => {
10
+ return async (to: Point) => {
11
11
  const ref = scrollerRef.current
12
12
  if (!ref) return
13
13
 
@@ -13,6 +13,7 @@ import {
13
13
  import React, { ReactHTML, useState } from 'react'
14
14
  import { ScrollSnapProps, ScrollSnapType } from '../types'
15
15
  import { isHTMLMousePointerEvent } from '../utils/isHTMLMousePointerEvent'
16
+ import { scrollSnapTypeDirection } from '../utils/scrollSnapTypeDirection'
16
17
  import { useScrollerContext } from './useScrollerContext'
17
18
  import { useVelocitySnapTo } from './useVelocitySnapTo'
18
19
 
@@ -123,13 +124,6 @@ const useStyles = makeStyles(
123
124
  export type ScrollableProps<TagName extends keyof ReactHTML = 'div'> = UseStyles<typeof useStyles> &
124
125
  HTMLMotionProps<TagName> & { hideScrollbar?: boolean; grid?: boolean }
125
126
 
126
- export function scrollSnapTypeDirection(scrollSnapType: ScrollSnapType) {
127
- let smSnapDir = scrollSnapType.split(' ')[0]
128
- smSnapDir = smSnapDir.replace('y', 'block')
129
- smSnapDir = smSnapDir.replace('x', 'inline') as 'block' | 'inline' | 'both' | 'inline'
130
- return smSnapDir
131
- }
132
-
133
127
  /** Make any HTML */
134
128
  export function useScroller<TagName extends keyof ReactHTML = 'div'>(
135
129
  props: ScrollableProps<TagName>,
@@ -1,5 +1,7 @@
1
+ import { Theme, useMediaQuery } from '@material-ui/core'
1
2
  import { PanInfo } from 'framer-motion'
2
3
  import { inertia, InertiaOptions } from 'popmotion'
4
+ import { scrollSnapTypeDirection } from '../utils/scrollSnapTypeDirection'
3
5
  import { useScrollerContext } from './useScrollerContext'
4
6
 
5
7
  const clamp = ({ velocity, offset }: PanInfo, axis: 'x' | 'y') =>
@@ -17,7 +19,11 @@ const closest = (counts: number[], target: number) =>
17
19
  export const useVelocitySnapTo = (
18
20
  ref: React.RefObject<HTMLElement> | React.MutableRefObject<HTMLElement | undefined>,
19
21
  ) => {
20
- const { disableSnap, enableSnap, register, getScrollSnapPositions } = useScrollerContext()
22
+ const { disableSnap, enableSnap, register, getScrollSnapPositions, scrollSnap } =
23
+ useScrollerContext()
24
+ const direction = useMediaQuery<Theme>((theme) => theme.breakpoints.down('sm'))
25
+ ? scrollSnapTypeDirection(scrollSnap.scrollSnapTypeSm)
26
+ : scrollSnapTypeDirection(scrollSnap.scrollSnapTypeMd)
21
27
 
22
28
  const inertiaOptions: InertiaOptions = {
23
29
  power: 1,
@@ -36,7 +42,8 @@ export const useVelocitySnapTo = (
36
42
 
37
43
  const xDone = new Promise<void>((onComplete) => {
38
44
  const targetX = clamp(info, 'x') * -1 + scrollLeft
39
- const closestX = closest(getScrollSnapPositions().x, targetX)
45
+ const closestX =
46
+ direction !== 'block' ? closest(getScrollSnapPositions().x, targetX) : undefined
40
47
 
41
48
  if (closestX !== scrollLeft) {
42
49
  disableSnap()
@@ -46,7 +53,9 @@ export const useVelocitySnapTo = (
46
53
  max: typeof closestX !== 'undefined' ? closestX - scrollLeft : undefined,
47
54
  min: typeof closestX !== 'undefined' ? closestX - scrollLeft : undefined,
48
55
  ...inertiaOptions,
49
- onUpdate: (v: number) => (el.scrollLeft = Math.round(v + scrollLeft)),
56
+ onUpdate: (v: number) => {
57
+ el.scrollLeft = Math.round(v + scrollLeft)
58
+ },
50
59
  onComplete,
51
60
  }),
52
61
  )
@@ -57,7 +66,8 @@ export const useVelocitySnapTo = (
57
66
 
58
67
  const yDone = new Promise<void>((onComplete) => {
59
68
  const targetY = clamp(info, 'y') * -1 + scrollTop
60
- const closestY = closest(getScrollSnapPositions().y, targetY)
69
+ const closestY =
70
+ direction !== 'inline' ? closest(getScrollSnapPositions().y, targetY) : undefined
61
71
 
62
72
  if (closestY !== scrollTop) {
63
73
  disableSnap()
@@ -67,7 +77,9 @@ export const useVelocitySnapTo = (
67
77
  max: typeof closestY !== 'undefined' ? closestY - scrollTop : undefined,
68
78
  min: typeof closestY !== 'undefined' ? closestY - scrollTop : undefined,
69
79
  ...inertiaOptions,
70
- onUpdate: (v: number) => (el.scrollTop = Math.round(v + scrollTop)),
80
+ onUpdate: (v: number) => {
81
+ el.scrollTop = Math.round(v + scrollTop)
82
+ },
71
83
  onComplete,
72
84
  }),
73
85
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/framer-scroller",
3
- "version": "1.1.4",
3
+ "version": "1.1.8",
4
4
  "sideEffects": false,
5
5
  "scripts": {
6
6
  "dev": "tsc -W"
@@ -16,25 +16,25 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@graphcommerce/framer-utils": "^2.103.16",
20
- "@graphcommerce/image": "^2.105.5",
21
- "@graphcommerce/next-ui": "^3.20.4",
19
+ "@graphcommerce/framer-utils": "^2.103.19",
20
+ "@graphcommerce/image": "^2.105.8",
21
+ "@graphcommerce/next-ui": "^3.20.8",
22
22
  "@material-ui/core": "^4.12.3",
23
- "popmotion": "9.3.6"
23
+ "popmotion": "11.0.3"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@graphcommerce/browserslist-config-pwa": "^3.0.2",
27
- "@graphcommerce/eslint-config-pwa": "^3.1.6",
27
+ "@graphcommerce/eslint-config-pwa": "^3.1.8",
28
28
  "@graphcommerce/prettier-config-pwa": "^3.0.4",
29
29
  "@graphcommerce/typescript-config-pwa": "^3.1.1",
30
- "@playwright/test": "^1.16.2"
30
+ "@playwright/test": "^1.17.1"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "clsx": "^1.1.1",
34
- "framer-motion": "^4.1.3",
34
+ "framer-motion": "^5.4.5",
35
35
  "react": "^17.0.2",
36
36
  "react-dom": "^17.0.2",
37
- "type-fest": "^2.5.1"
37
+ "type-fest": "^2.8.0"
38
38
  },
39
- "gitHead": "b992ac3fbe719310988edb8ad811366431509bc2"
39
+ "gitHead": "a69bd94ffdcca6ca9487eec1cafe9ade3fcdffa3"
40
40
  }
package/types.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { MotionValue } from 'framer-motion'
1
+ import { MotionValue, Point } from 'framer-motion'
2
2
  import { PlaybackControls } from 'popmotion'
3
- import { Point2D } from 'popmotion/lib/types'
4
3
  import React from 'react'
5
4
 
6
5
  export type ItemState = {
@@ -37,7 +36,7 @@ export type ScrollerContext = {
37
36
  /** @private */
38
37
  stop(): void
39
38
  /** @private */
40
- getSnapPosition(direction: SnapPositionDirection): Point2D
39
+ getSnapPosition(direction: SnapPositionDirection): Point
41
40
  /** @private */
42
41
  getScrollSnapPositions(): Record<Axis, number[]>
43
42
  /** @private */
@@ -0,0 +1,9 @@
1
+ import { ScrollSnapType } from '../types'
2
+
3
+ type SnapTypeDirection = 'block' | 'inline' | 'both' | 'inline'
4
+ export function scrollSnapTypeDirection(scrollSnapType: ScrollSnapType): SnapTypeDirection {
5
+ let snapDir = scrollSnapType.split(' ')[0]
6
+ snapDir = snapDir.replace('y', 'block')
7
+ snapDir = snapDir.replace('x', 'inline')
8
+ return snapDir as SnapTypeDirection
9
+ }