@graphcommerce/next-ui 8.0.6-canary.3 → 8.0.6

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.
@@ -1,10 +1,5 @@
1
1
  /* eslint-disable import/no-extraneous-dependencies */
2
- import {
3
- Controller,
4
- ControllerProps,
5
- FieldValues,
6
- useController,
7
- } from '@graphcommerce/react-hook-form'
2
+ import { Controller, ControllerProps, FieldValues } from '@graphcommerce/react-hook-form'
8
3
  import React, { MouseEventHandler } from 'react'
9
4
  import { ActionCardProps } from './ActionCard'
10
5
  import { ActionCardList, ActionCardListProps } from './ActionCardList'
@@ -48,41 +43,38 @@ export function ActionCardListForm<
48
43
  : selectValues === itemValue
49
44
  }
50
45
 
51
- const {
52
- field: { onChange, value, ref },
53
- fieldState,
54
- formState,
55
- } = useController({
56
- ...props,
57
- control,
58
- name,
59
- defaultValue,
60
- rules: { required: errorMessage || required, ...rules },
61
- })
62
-
63
46
  return (
64
- <ActionCardList
65
- {...other}
66
- multiple={multiple}
67
- required={required}
68
- value={value}
69
- ref={ref}
70
- onChange={(_, incomming) => onChange(incomming)}
71
- error={formState.isSubmitted && !!fieldState.error}
72
- errorMessage={fieldState.error?.message}
73
- >
74
- {items.map((item) => (
75
- <RenderItem
76
- {...item}
77
- key={item.value ?? ''}
78
- value={item.value}
79
- selected={onSelect(item.value, value)}
80
- onReset={(e) => {
81
- e.preventDefault()
82
- onChange(null)
83
- }}
84
- />
85
- ))}
86
- </ActionCardList>
47
+ <Controller
48
+ {...props}
49
+ control={control}
50
+ name={name}
51
+ defaultValue={defaultValue}
52
+ rules={{ required: errorMessage || required, ...rules }}
53
+ render={({ field: { onChange, value, ref }, fieldState, formState }) => (
54
+ <ActionCardList
55
+ {...other}
56
+ multiple={multiple}
57
+ required={required}
58
+ value={value}
59
+ ref={ref}
60
+ onChange={(_, incomming) => onChange(incomming)}
61
+ error={formState.isSubmitted && !!fieldState.error}
62
+ errorMessage={fieldState.error?.message}
63
+ >
64
+ {items.map((item) => (
65
+ <RenderItem
66
+ {...item}
67
+ key={item.value ?? ''}
68
+ value={item.value}
69
+ selected={onSelect(item.value, value)}
70
+ onReset={(e) => {
71
+ e.preventDefault()
72
+ onChange(null)
73
+ }}
74
+ />
75
+ ))}
76
+ </ActionCardList>
77
+ )}
78
+ />
87
79
  )
88
80
  }
package/CHANGELOG.md CHANGED
@@ -1,25 +1,6 @@
1
1
  # Change Log
2
2
 
3
- ## 8.0.6-canary.3
4
-
5
- ## 8.0.6-canary.2
6
-
7
- ### Patch Changes
8
-
9
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Added useIsSSR hook that will properly resolve when the page is rendered on the server and on first render, but will return false when a component is rendered on the client directly.
10
- ([@FrankHarland](https://github.com/FrankHarland))
11
-
12
- - [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`0767bc4`](https://github.com/graphcommerce-org/graphcommerce/commit/0767bc40f7b596209f24ca4e745ff0441f3275c9) - Upgrade input components to no longer use muiRegister, which improves INP scores
13
- ([@FrankHarland](https://github.com/FrankHarland))
14
-
15
- ## 8.0.6-canary.1
16
-
17
- ## 8.0.6-canary.0
18
-
19
- ### Patch Changes
20
-
21
- - [#2196](https://github.com/graphcommerce-org/graphcommerce/pull/2196) [`84c50e4`](https://github.com/graphcommerce-org/graphcommerce/commit/84c50e49a1a7f154d4a8f4045c37e773e20283ad) - Allow Lingui to use linguiLocale with country identifiers like `en-us`, it would always load `en` in this case. Introced a new `useLocale` hook to use the correct locale string to use in Intl methods.
22
- ([@paales](https://github.com/paales))
3
+ ## 8.0.6
23
4
 
24
5
  ## 8.0.5
25
6
 
@@ -1,23 +1,17 @@
1
- import { useLocale } from '../hooks/useLocale'
2
-
3
1
  export type TimeAgoProps = {
4
2
  date: Date
5
- /**
6
- * @deprecated No longer used
7
- */
8
3
  locale?: string
9
4
  }
10
5
 
11
6
  export function TimeAgo(props: TimeAgoProps) {
12
- const { date } = props
7
+ const { date, locale = 'en' } = props
13
8
  const msPerMinute = 60 * 1000
14
9
  const msPerHour = msPerMinute * 60
15
10
  const msPerDay = msPerHour * 24
16
11
 
17
12
  const timestamp = date.getTime()
18
13
  const elapsed = Date.now() - timestamp
19
-
20
- const rtf = new Intl.RelativeTimeFormat(useLocale(), { numeric: 'auto' })
14
+ const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })
21
15
 
22
16
  if (elapsed < msPerMinute) {
23
17
  return <span>{rtf.format(-Math.floor(elapsed / 1000), 'seconds')}</span>
package/hooks/index.ts CHANGED
@@ -5,5 +5,3 @@ export * from './useNumberFormat'
5
5
  export * from './useMemoObject'
6
6
  export * from './useStorefrontConfig'
7
7
  export * from './useUrlQuery'
8
- export * from './useSsr'
9
- export * from './useLocale'
@@ -1,13 +1,15 @@
1
1
  import { normalizeLocale } from '@graphcommerce/lingui-next'
2
+ import { useRouter } from 'next/router'
2
3
  import { useMemo } from 'react'
3
- import { useStorefrontConfig } from './useStorefrontConfig'
4
- import { useLocale } from '@graphcommerce/next-ui'
5
4
 
6
5
  export type DateTimeFormatProps = Intl.DateTimeFormatOptions
7
6
 
8
7
  export function useDateTimeFormat(props?: DateTimeFormatProps) {
9
- const locale = useLocale()
8
+ const { locale } = useRouter()
10
9
 
11
- const formatter = useMemo(() => new Intl.DateTimeFormat(locale, props), [locale, props])
10
+ const formatter = useMemo(
11
+ () => new Intl.DateTimeFormat(normalizeLocale(locale), props),
12
+ [locale, props],
13
+ )
12
14
  return formatter
13
15
  }
@@ -1,10 +1,15 @@
1
+ import { normalizeLocale } from '@graphcommerce/lingui-next'
2
+ import { useRouter } from 'next/router'
1
3
  import { useMemo } from 'react'
2
- import { useLocale } from './useLocale'
3
4
 
4
5
  export type NumberFormatProps = Intl.NumberFormatOptions
5
6
 
6
7
  export function useNumberFormat(props?: NumberFormatProps) {
7
- const locale = useLocale()
8
- const formatter = useMemo(() => new Intl.NumberFormat(locale, props), [locale, props])
8
+ const { locale } = useRouter()
9
+
10
+ const formatter = useMemo(
11
+ () => new Intl.NumberFormat(normalizeLocale(locale), props),
12
+ [locale, props],
13
+ )
9
14
  return formatter
10
15
  }
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": "8.0.6-canary.3",
5
+ "version": "8.0.6",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -25,14 +25,14 @@
25
25
  "typescript": "5.3.3"
26
26
  },
27
27
  "peerDependencies": {
28
- "@graphcommerce/eslint-config-pwa": "^8.0.6-canary.3",
29
- "@graphcommerce/framer-next-pages": "^8.0.6-canary.3",
30
- "@graphcommerce/framer-scroller": "^8.0.6-canary.3",
31
- "@graphcommerce/framer-utils": "^8.0.6-canary.3",
32
- "@graphcommerce/image": "^8.0.6-canary.3",
33
- "@graphcommerce/lingui-next": "^8.0.6-canary.3",
34
- "@graphcommerce/prettier-config-pwa": "^8.0.6-canary.3",
35
- "@graphcommerce/typescript-config-pwa": "^8.0.6-canary.3",
28
+ "@graphcommerce/eslint-config-pwa": "^8.0.6",
29
+ "@graphcommerce/framer-next-pages": "^8.0.6",
30
+ "@graphcommerce/framer-scroller": "^8.0.6",
31
+ "@graphcommerce/framer-utils": "^8.0.6",
32
+ "@graphcommerce/image": "^8.0.6",
33
+ "@graphcommerce/lingui-next": "^8.0.6",
34
+ "@graphcommerce/prettier-config-pwa": "^8.0.6",
35
+ "@graphcommerce/typescript-config-pwa": "^8.0.6",
36
36
  "@lingui/core": "^4.2.1",
37
37
  "@lingui/macro": "^4.2.1",
38
38
  "@lingui/react": "^4.2.1",
@@ -1,7 +0,0 @@
1
- import { normalizeLocale } from '@graphcommerce/lingui-next'
2
- import { useStorefrontConfig } from './useStorefrontConfig'
3
-
4
- export function useLocale() {
5
- const { locale } = useStorefrontConfig()
6
- return normalizeLocale(locale)
7
- }
package/hooks/useSsr.ts DELETED
@@ -1,11 +0,0 @@
1
- import { useSyncExternalStore } from 'react'
2
-
3
- const emptySubscribe = () => () => {}
4
-
5
- export function useIsSSR() {
6
- return useSyncExternalStore(
7
- emptySubscribe,
8
- () => false,
9
- () => true,
10
- )
11
- }