@graphcommerce/next-ui 8.0.5 → 8.0.6-canary.1

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,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.0.6-canary.1
4
+
5
+ ## 8.0.6-canary.0
6
+
7
+ ### Patch Changes
8
+
9
+ - [#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.
10
+ ([@paales](https://github.com/paales))
11
+
3
12
  ## 8.0.5
4
13
 
5
14
  ### Patch Changes
@@ -1,17 +1,23 @@
1
+ import { useLocale } from '../hooks/useLocale'
2
+
1
3
  export type TimeAgoProps = {
2
4
  date: Date
5
+ /**
6
+ * @deprecated No longer used
7
+ */
3
8
  locale?: string
4
9
  }
5
10
 
6
11
  export function TimeAgo(props: TimeAgoProps) {
7
- const { date, locale = 'en' } = props
12
+ const { date } = props
8
13
  const msPerMinute = 60 * 1000
9
14
  const msPerHour = msPerMinute * 60
10
15
  const msPerDay = msPerHour * 24
11
16
 
12
17
  const timestamp = date.getTime()
13
18
  const elapsed = Date.now() - timestamp
14
- const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })
19
+
20
+ const rtf = new Intl.RelativeTimeFormat(useLocale(), { numeric: 'auto' })
15
21
 
16
22
  if (elapsed < msPerMinute) {
17
23
  return <span>{rtf.format(-Math.floor(elapsed / 1000), 'seconds')}</span>
package/hooks/index.ts CHANGED
@@ -5,3 +5,4 @@ export * from './useNumberFormat'
5
5
  export * from './useMemoObject'
6
6
  export * from './useStorefrontConfig'
7
7
  export * from './useUrlQuery'
8
+ export * from './useLocale'
@@ -1,15 +1,13 @@
1
1
  import { normalizeLocale } from '@graphcommerce/lingui-next'
2
- import { useRouter } from 'next/router'
3
2
  import { useMemo } from 'react'
3
+ import { useStorefrontConfig } from './useStorefrontConfig'
4
+ import { useLocale } from '@graphcommerce/next-ui'
4
5
 
5
6
  export type DateTimeFormatProps = Intl.DateTimeFormatOptions
6
7
 
7
8
  export function useDateTimeFormat(props?: DateTimeFormatProps) {
8
- const { locale } = useRouter()
9
+ const locale = useLocale()
9
10
 
10
- const formatter = useMemo(
11
- () => new Intl.DateTimeFormat(normalizeLocale(locale), props),
12
- [locale, props],
13
- )
11
+ const formatter = useMemo(() => new Intl.DateTimeFormat(locale, props), [locale, props])
14
12
  return formatter
15
13
  }
@@ -0,0 +1,7 @@
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
+ }
@@ -1,15 +1,10 @@
1
- import { normalizeLocale } from '@graphcommerce/lingui-next'
2
- import { useRouter } from 'next/router'
3
1
  import { useMemo } from 'react'
2
+ import { useLocale } from './useLocale'
4
3
 
5
4
  export type NumberFormatProps = Intl.NumberFormatOptions
6
5
 
7
6
  export function useNumberFormat(props?: NumberFormatProps) {
8
- const { locale } = useRouter()
9
-
10
- const formatter = useMemo(
11
- () => new Intl.NumberFormat(normalizeLocale(locale), props),
12
- [locale, props],
13
- )
7
+ const locale = useLocale()
8
+ const formatter = useMemo(() => new Intl.NumberFormat(locale, props), [locale, props])
14
9
  return formatter
15
10
  }
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.5",
5
+ "version": "8.0.6-canary.1",
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.5",
29
- "@graphcommerce/framer-next-pages": "^8.0.5",
30
- "@graphcommerce/framer-scroller": "^8.0.5",
31
- "@graphcommerce/framer-utils": "^8.0.5",
32
- "@graphcommerce/image": "^8.0.5",
33
- "@graphcommerce/lingui-next": "^8.0.5",
34
- "@graphcommerce/prettier-config-pwa": "^8.0.5",
35
- "@graphcommerce/typescript-config-pwa": "^8.0.5",
28
+ "@graphcommerce/eslint-config-pwa": "^8.0.6-canary.1",
29
+ "@graphcommerce/framer-next-pages": "^8.0.6-canary.1",
30
+ "@graphcommerce/framer-scroller": "^8.0.6-canary.1",
31
+ "@graphcommerce/framer-utils": "^8.0.6-canary.1",
32
+ "@graphcommerce/image": "^8.0.6-canary.1",
33
+ "@graphcommerce/lingui-next": "^8.0.6-canary.1",
34
+ "@graphcommerce/prettier-config-pwa": "^8.0.6-canary.1",
35
+ "@graphcommerce/typescript-config-pwa": "^8.0.6-canary.1",
36
36
  "@lingui/core": "^4.2.1",
37
37
  "@lingui/macro": "^4.2.1",
38
38
  "@lingui/react": "^4.2.1",