@graphcommerce/next-ui 9.1.0-canary.34 → 9.1.0-canary.36

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
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.1.0-canary.36
4
+
5
+ ### Patch Changes
6
+
7
+ - [`90f8dd8`](https://github.com/graphcommerce-org/graphcommerce/commit/90f8dd89efd62e2b5a13e9c2bf265840d99e2473) - Create useCookies hook and simplify the useCookie query ([@paales](https://github.com/paales))
8
+
9
+ ## 9.1.0-canary.35
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2528](https://github.com/graphcommerce-org/graphcommerce/pull/2528) [`6a3e7f9`](https://github.com/graphcommerce-org/graphcommerce/commit/6a3e7f9bec6d03c146718ad594b064a75b536e99) - cssFlag and cssNotFlag css selector can now select values ([@paales](https://github.com/paales))
14
+
15
+ - [#2528](https://github.com/graphcommerce-org/graphcommerce/pull/2528) [`a4344ed`](https://github.com/graphcommerce-org/graphcommerce/commit/a4344ed7ff7b3b5f88185c1f6a5fc4b6306fc472) - Created a useCookie hook that is synced between usages ([@paales](https://github.com/paales))
16
+
17
+ - [#2528](https://github.com/graphcommerce-org/graphcommerce/pull/2528) [`f89210b`](https://github.com/graphcommerce-org/graphcommerce/commit/f89210b09e64f520d308cb1bac693c027be1ac46) - Solve issue where the MenuFabSecondaryItem coudn't handle text overflow. ([@paales](https://github.com/paales))
18
+
3
19
  ## 9.1.0-canary.34
4
20
 
5
21
  ## 9.1.0-canary.33
@@ -43,7 +43,14 @@ export function MenuFabSecondaryItem(props: FabMenuSecondaryItemProps) {
43
43
  {icon}
44
44
  </ListItemIcon>
45
45
  )}
46
- <ListItemText className={classes.icon}>{children}</ListItemText>
46
+ <ListItemText
47
+ className={classes.icon}
48
+ primaryTypographyProps={{
49
+ sx: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' },
50
+ }}
51
+ >
52
+ {children}
53
+ </ListItemText>
47
54
  </ListItemButton>
48
55
  )
49
56
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/next-ui",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.1.0-canary.34",
5
+ "version": "9.1.0-canary.36",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -24,13 +24,13 @@
24
24
  "@emotion/react": "^11",
25
25
  "@emotion/server": "^11",
26
26
  "@emotion/styled": "^11",
27
- "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.34",
28
- "@graphcommerce/framer-next-pages": "^9.1.0-canary.34",
29
- "@graphcommerce/framer-scroller": "^9.1.0-canary.34",
30
- "@graphcommerce/framer-utils": "^9.1.0-canary.34",
31
- "@graphcommerce/image": "^9.1.0-canary.34",
32
- "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.34",
33
- "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.34",
27
+ "@graphcommerce/eslint-config-pwa": "^9.1.0-canary.36",
28
+ "@graphcommerce/framer-next-pages": "^9.1.0-canary.36",
29
+ "@graphcommerce/framer-scroller": "^9.1.0-canary.36",
30
+ "@graphcommerce/framer-utils": "^9.1.0-canary.36",
31
+ "@graphcommerce/image": "^9.1.0-canary.36",
32
+ "@graphcommerce/prettier-config-pwa": "^9.1.0-canary.36",
33
+ "@graphcommerce/typescript-config-pwa": "^9.1.0-canary.36",
34
34
  "@lingui/core": "^4.2.1",
35
35
  "@lingui/macro": "^4.2.1",
36
36
  "@lingui/react": "^4.2.1",
package/utils/cookie.ts CHANGED
@@ -1,17 +1,25 @@
1
+ import { useMotionValueValue } from '@graphcommerce/framer-utils'
1
2
  import type { SerializeOptions } from 'cookie'
2
3
  import { parse, serialize } from 'cookie'
4
+ import { motionValue } from 'framer-motion'
5
+ import { useIsSSR } from '../hooks'
3
6
 
7
+ // We need this motionValue to be synced with the actual cookie store.
8
+ const cookieNotify = motionValue<number>(0)
9
+
10
+ export function cookie(): Record<string, string | undefined>
4
11
  /** Read a cookie */
5
- export function cookie(name: string): string | undefined
12
+ export function cookie<T extends string>(name: string): T | undefined
6
13
  /** Set a cookie */
7
14
  export function cookie(name: string, value: string, options?: SerializeOptions): void
8
15
  /** Delete a cookie */
9
16
  export function cookie(name: string, value: null): void
10
17
  /** Function to handle the three different cases */
11
- export function cookie(name: string, value?: string | null, options?: SerializeOptions) {
12
- if (typeof window === 'undefined') {
13
- return undefined
14
- }
18
+ export function cookie(name?: string, value?: string | null, options?: SerializeOptions) {
19
+ if (typeof window === 'undefined') return undefined
20
+
21
+ // Read all cookies
22
+ if (typeof name === 'undefined') return parse(document.cookie)
15
23
 
16
24
  // Read a cookie
17
25
  if (typeof value === 'undefined') return parse(document.cookie)[name]
@@ -20,6 +28,7 @@ export function cookie(name: string, value?: string | null, options?: SerializeO
20
28
  if (typeof value === 'string') {
21
29
  const serialized = serialize(name, value, { path: '/', maxAge: 31536000, ...options })
22
30
  document.cookie = serialized
31
+ cookieNotify.set(cookieNotify.get() + 1)
23
32
  return undefined
24
33
  }
25
34
 
@@ -27,8 +36,38 @@ export function cookie(name: string, value?: string | null, options?: SerializeO
27
36
  if (value === null) {
28
37
  const serialized = serialize(name, '', { path: '/', maxAge: 0 })
29
38
  document.cookie = serialized
39
+ cookieNotify.set(cookieNotify.get() + 1)
30
40
  return undefined
31
41
  }
32
42
 
33
43
  return undefined
34
44
  }
45
+
46
+ /**
47
+ * This makes sure this hook is rerendered when the cookie changes, we do not actually use the
48
+ * value.
49
+ */
50
+ export function useCookies(): Record<string, string | undefined> {
51
+ // Initial render it should always be empty since the server renders cookie-less.
52
+ // Whenever the server can handle cookies, we can remove this and directly return the cookie value.
53
+ const isSsr = useIsSSR()
54
+
55
+ useMotionValueValue(cookieNotify, (v) => v)
56
+
57
+ return isSsr ? {} : cookie()
58
+ }
59
+
60
+ export function useCookie<T extends string>(
61
+ name: string,
62
+ options: SerializeOptions = { sameSite: true },
63
+ defaultValue?: T | null,
64
+ ): [T | undefined | null, (value: T | null) => void] {
65
+ const update = (val: T | null) => {
66
+ if (val) cookie(name, val, options)
67
+ else cookie(name, null)
68
+ }
69
+
70
+ const cookies = useCookies()
71
+ const value = (cookies[name] as T | undefined | null) ?? defaultValue
72
+ return [value, update] as const
73
+ }
@@ -35,10 +35,11 @@ export function getCssFlag(flagName: string) {
35
35
  * Example:
36
36
  *
37
37
  * ```tsx
38
- * ;<Box sx={{ [cssFlagSelector('dark')]: { color: 'white' } }} />
38
+ * ;<Box sx={{ [cssFlag('mode', 'dark')]: { color: 'white' } }} />
39
39
  * ```
40
40
  */
41
- export const cssFlag = <T extends string>(flagName: T) => `html[data-${flagName}] &` as const
41
+ export const cssFlag = <T extends string>(flagName: T, val?: string) =>
42
+ `html[data-${flagName}${val ? `=${val}` : ''}] &` as const
42
43
 
43
44
  /**
44
45
  * Easily create a CSS selector that only applies when a flag is not set.
@@ -46,8 +47,8 @@ export const cssFlag = <T extends string>(flagName: T) => `html[data-${flagName}
46
47
  * Example:
47
48
  *
48
49
  * ```tsx
49
- * ;<Box sx={{ [cssNotFlagSelector('dark')]: { color: 'black' } }} />
50
+ * ;<Box sx={{ [cssNotFlag('mode', 'dark')]: { color: 'black' } }} />
50
51
  * ```
51
52
  */
52
- export const cssNotFlag = <T extends string>(flagName: T) =>
53
- `html:not([data-${flagName}]) &` as const
53
+ export const cssNotFlag = <T extends string>(flagName: T, val?: string) =>
54
+ `html:not([data-${flagName}${val ? `=${val}` : ''}]) &` as const