@graphcommerce/framer-utils 3.0.5 → 3.1.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 +6 -0
- package/hooks/useClientSize.ts +30 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1360](https://github.com/graphcommerce-org/graphcommerce/pull/1360) [`829b8690b`](https://github.com/graphcommerce-org/graphcommerce/commit/829b8690bc5d0a46e596299e4120e9837a9f179c) Thanks [@paales](https://github.com/paales)! - Add a clientSizeCssVar that will change when the viewport changes size, as a better alternative for 100vh and in preparation for 100dvh
|
|
8
|
+
|
|
3
9
|
## 3.0.5
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/hooks/useClientSize.ts
CHANGED
|
@@ -2,10 +2,40 @@ import { motionValue, MotionValue } from 'framer-motion'
|
|
|
2
2
|
import { useEffect } from 'react'
|
|
3
3
|
import { clientSize } from '../utils/clientSize'
|
|
4
4
|
import { useConstant } from './useConstant'
|
|
5
|
+
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
5
6
|
|
|
6
7
|
export type UseClientSizeReturn = { x: MotionValue<string>; y: MotionValue<string> }
|
|
7
8
|
export type UseClientSizeOptions = { x?: string; y?: string }
|
|
8
9
|
|
|
10
|
+
export const clientSizeCssVar = {
|
|
11
|
+
y: `var(--client-size-y, 100vh)`,
|
|
12
|
+
x: `var(--client-size-x, 100vh)`,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let watching = false
|
|
16
|
+
|
|
17
|
+
export function useClientSizeCssVar() {
|
|
18
|
+
useIsomorphicLayoutEffect(() => {
|
|
19
|
+
if (watching === true) return () => {}
|
|
20
|
+
|
|
21
|
+
const recalc = () => {
|
|
22
|
+
if (typeof window !== 'undefined') {
|
|
23
|
+
const { x, y } = clientSize
|
|
24
|
+
document.body.style.setProperty('--client-size-x', `${x.get()}px`)
|
|
25
|
+
document.body.style.setProperty('--client-size-y', `${y.get()}px`)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
recalc()
|
|
29
|
+
watching = true
|
|
30
|
+
const reset = clientSize.y.onChange(recalc)
|
|
31
|
+
|
|
32
|
+
return () => {
|
|
33
|
+
watching = false
|
|
34
|
+
reset()
|
|
35
|
+
}
|
|
36
|
+
}, [])
|
|
37
|
+
}
|
|
38
|
+
|
|
9
39
|
/**
|
|
10
40
|
* Get the clientSize x|y as a motionValue
|
|
11
41
|
*
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/framer-utils",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "3.0
|
|
5
|
+
"version": "3.1.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "tsc -W"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@graphcommerce/eslint-config-pwa": "^4.
|
|
18
|
+
"@graphcommerce/eslint-config-pwa": "^4.1.2",
|
|
19
19
|
"@graphcommerce/prettier-config-pwa": "^4.0.3",
|
|
20
20
|
"@graphcommerce/typescript-config-pwa": "^4.0.2",
|
|
21
21
|
"@playwright/test": "^1.19.2"
|