@42-central/ui-react 0.28.0 → 0.29.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/dist/{chunk-I53TMAV2.js → chunk-2RQLPN4U.js} +3 -3
- package/dist/{chunk-I53TMAV2.js.map → chunk-2RQLPN4U.js.map} +1 -1
- package/dist/{chunk-SOUDKESO.js → chunk-37HYN7PC.js} +3 -3
- package/dist/{chunk-SOUDKESO.js.map → chunk-37HYN7PC.js.map} +1 -1
- package/dist/{chunk-TGGNSSOJ.js → chunk-5EOMSWNO.js} +4 -4
- package/dist/{chunk-TGGNSSOJ.js.map → chunk-5EOMSWNO.js.map} +1 -1
- package/dist/{chunk-K3FZHYJL.js → chunk-7FPSQBWB.js} +3 -3
- package/dist/{chunk-K3FZHYJL.js.map → chunk-7FPSQBWB.js.map} +1 -1
- package/dist/{chunk-WERJ44ZN.js → chunk-DTFSCR3U.js} +3 -3
- package/dist/{chunk-WERJ44ZN.js.map → chunk-DTFSCR3U.js.map} +1 -1
- package/dist/{chunk-PFZMB3US.js → chunk-FQJNQW3G.js} +3 -3
- package/dist/{chunk-PFZMB3US.js.map → chunk-FQJNQW3G.js.map} +1 -1
- package/dist/{chunk-ASKQ6N5V.js → chunk-FSPS7TVD.js} +4 -4
- package/dist/{chunk-ASKQ6N5V.js.map → chunk-FSPS7TVD.js.map} +1 -1
- package/dist/{chunk-GJFCIG34.js → chunk-GEZYGBXY.js} +5 -5
- package/dist/{chunk-GJFCIG34.js.map → chunk-GEZYGBXY.js.map} +1 -1
- package/dist/{chunk-ULF5LOBS.js → chunk-HMNXNKDA.js} +3 -3
- package/dist/{chunk-ULF5LOBS.js.map → chunk-HMNXNKDA.js.map} +1 -1
- package/dist/{chunk-NF2PBGD3.js → chunk-IANYMDKH.js} +3 -3
- package/dist/{chunk-NF2PBGD3.js.map → chunk-IANYMDKH.js.map} +1 -1
- package/dist/{chunk-QEMXXQQO.js → chunk-JKFPRQB2.js} +3 -3
- package/dist/{chunk-QEMXXQQO.js.map → chunk-JKFPRQB2.js.map} +1 -1
- package/dist/{chunk-P7SH3XWY.js → chunk-MQHD3EJE.js} +3 -3
- package/dist/{chunk-P7SH3XWY.js.map → chunk-MQHD3EJE.js.map} +1 -1
- package/dist/{chunk-IUK7OJXZ.js → chunk-OBSZ4NE2.js} +5 -4
- package/dist/chunk-OBSZ4NE2.js.map +1 -0
- package/dist/{chunk-DJ72KP32.js → chunk-OXR7BXZA.js} +3 -3
- package/dist/{chunk-DJ72KP32.js.map → chunk-OXR7BXZA.js.map} +1 -1
- package/dist/{chunk-LIZWCWED.js → chunk-PQZSTI3R.js} +3 -3
- package/dist/{chunk-LIZWCWED.js.map → chunk-PQZSTI3R.js.map} +1 -1
- package/dist/{chunk-7BY5I2RB.js → chunk-S5CQRCTF.js} +4 -4
- package/dist/{chunk-7BY5I2RB.js.map → chunk-S5CQRCTF.js.map} +1 -1
- package/dist/{chunk-BGDVUC3B.js → chunk-TUP7WXQE.js} +3 -3
- package/dist/{chunk-BGDVUC3B.js.map → chunk-TUP7WXQE.js.map} +1 -1
- package/dist/{chunk-KYVXPSNW.js → chunk-V2QZG4IT.js} +3 -3
- package/dist/{chunk-KYVXPSNW.js.map → chunk-V2QZG4IT.js.map} +1 -1
- package/dist/components/alert/index.js +1 -1
- package/dist/components/ambient-background/index.js +1 -1
- package/dist/components/app-shell/index.js +3 -3
- package/dist/components/avatar/index.js +2 -2
- package/dist/components/calendar/index.js +3 -3
- package/dist/components/calendar-heatmap/index.js +2 -2
- package/dist/components/camera/index.js +3 -3
- package/dist/components/carousel/index.js +2 -2
- package/dist/components/code-block/index.js +1 -1
- package/dist/components/code-block/static.js.map +1 -1
- package/dist/components/compare/index.js +2 -2
- package/dist/components/data-table/index.js +10 -10
- package/dist/components/date-picker/index.js +7 -7
- package/dist/components/drawer/index.js +3 -3
- package/dist/components/file-item/index.js +4 -4
- package/dist/components/file-preview/index.js +3 -3
- package/dist/components/file-upload/index.js +4 -4
- package/dist/components/gallery/index.js +2 -2
- package/dist/components/image-cropper/index.js +4 -4
- package/dist/components/indicator/index.js +1 -1
- package/dist/components/kbd/index.js +3 -3
- package/dist/components/lightbox/index.js +4 -4
- package/dist/components/menu/index.js +2 -2
- package/dist/components/modal/index.js +3 -3
- package/dist/components/multi-select/index.js +3 -3
- package/dist/components/overlays/index.js +4 -4
- package/dist/components/password-input/index.js +1 -1
- package/dist/components/phone-input/flag.d.ts +9 -0
- package/dist/components/phone-input/flag.d.ts.map +1 -0
- package/dist/components/phone-input/index.d.ts +4 -0
- package/dist/components/phone-input/index.d.ts.map +1 -0
- package/dist/components/phone-input/index.js +503 -0
- package/dist/components/phone-input/index.js.map +1 -0
- package/dist/components/phone-input/phone-input.d.ts +125 -0
- package/dist/components/phone-input/phone-input.d.ts.map +1 -0
- package/dist/components/phone-input/phone.d.ts +117 -0
- package/dist/components/phone-input/phone.d.ts.map +1 -0
- package/dist/components/photo-capture/index.js +5 -5
- package/dist/components/pills-input/index.js +3 -3
- package/dist/components/schedule/index.js +3 -3
- package/dist/components/segment-group/index.js +3 -3
- package/dist/components/spotlight/index.js +5 -5
- package/dist/components/tabs/index.js +3 -3
- package/dist/components/tags-input/index.js +3 -3
- package/dist/components/time-input/index.js +4 -4
- package/dist/components/timeline/index.d.ts +1 -1
- package/dist/components/timeline/index.d.ts.map +1 -1
- package/dist/components/timeline/index.js +40 -11
- package/dist/components/timeline/index.js.map +1 -1
- package/dist/components/timeline/timeline.d.ts +8 -3
- package/dist/components/timeline/timeline.d.ts.map +1 -1
- package/dist/components/tree-multi-select/index.js +3 -3
- package/dist/index.js +4 -4
- package/dist/lib/dev-warn.d.ts +1 -0
- package/dist/lib/dev-warn.d.ts.map +1 -1
- package/dist/lib/intl.d.ts +5 -0
- package/dist/lib/intl.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/as-child.contract.test.tsx +2 -0
- package/src/components/phone-input/flag.tsx +86 -0
- package/src/components/phone-input/index.ts +14 -0
- package/src/components/phone-input/phone-input.test.tsx +285 -0
- package/src/components/phone-input/phone-input.tsx +527 -0
- package/src/components/phone-input/phone.test.ts +187 -0
- package/src/components/phone-input/phone.ts +298 -0
- package/src/components/timeline/index.ts +1 -0
- package/src/components/timeline/timeline.test.tsx +105 -4
- package/src/components/timeline/timeline.tsx +46 -11
- package/src/lib/dev-warn.ts +1 -1
- package/src/lib/intl-direction.test.tsx +23 -0
- package/src/lib/intl.tsx +8 -2
- package/dist/chunk-IUK7OJXZ.js.map +0 -1
|
@@ -174,14 +174,25 @@ const timelineVariants = cva(
|
|
|
174
174
|
const RING_CUTOUT =
|
|
175
175
|
"ring-2 ring-offset-2 ring-offset-brand-50 dark:ring-offset-brand-950 ring-transparent ring-inset"
|
|
176
176
|
|
|
177
|
-
const timelineBulletVariants = cva(["
|
|
177
|
+
const timelineBulletVariants = cva(["shrink-0"], {
|
|
178
178
|
variants: {
|
|
179
179
|
variant: {
|
|
180
|
-
// `
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
|
|
180
|
+
// `filled` paints the palette's solid, so its icon takes the palette's
|
|
181
|
+
// own on-solid colour, like any text in it (navy on the bright dark-mode
|
|
182
|
+
// solids: white there fell under 3:1 on yellow, green, pink).
|
|
183
|
+
// `outline`/`dashed` have no fill: their icon sits on the page, so
|
|
184
|
+
// `dark:[&_svg]:text-white` keeps it readable on the dark ground.
|
|
185
|
+
// `default`/`gradient` invert to a *light* dark-mode surface and keep
|
|
186
|
+
// their own text colour.
|
|
187
|
+
filled: "bg-(--c-solid) text-(--c-on-solid)",
|
|
188
|
+
// A tile, as Badge's `light`: the palette's soft surface (opaque, so the
|
|
189
|
+
// line stops under it), a soft ring of its solid, the icon in its text
|
|
190
|
+
// colour. Quieter than `filled` for a feed of many events.
|
|
191
|
+
light: "bg-(--c-soft) border border-(--c-solid)/40 text-(--c-text)",
|
|
192
|
+
// No surface and no ring: the custom `bullet` is drawn as it is (a
|
|
193
|
+
// geodesic badge, an avatar). `color` still tints the line and the
|
|
194
|
+
// icon, so the item keeps its place in the line's colours.
|
|
195
|
+
subtle: "text-(--c-text)",
|
|
185
196
|
outline: "border-(--c-solid) border dark:[&_svg]:text-white",
|
|
186
197
|
dashed: "border-dashed border-(--c-solid) border dark:[&_svg]:text-white",
|
|
187
198
|
default: "bg-brand-950 text-white dark:bg-white dark:text-brand-950 border",
|
|
@@ -206,7 +217,21 @@ const timelineBulletVariants = cva(["rounded-full shrink-0"], {
|
|
|
206
217
|
none: "",
|
|
207
218
|
complete: "",
|
|
208
219
|
active: "",
|
|
209
|
-
pending:
|
|
220
|
+
pending: [
|
|
221
|
+
"[--c-solid:var(--c-solid-disabled)] [--c-on-solid:var(--c-on-solid-disabled)]",
|
|
222
|
+
// `light` and `subtle` read the soft surface and the text colour too.
|
|
223
|
+
"[--c-soft:var(--c-soft-disabled)] [--c-text:var(--c-text-disabled)]",
|
|
224
|
+
],
|
|
225
|
+
},
|
|
226
|
+
/** The bullet's corners, the scale ActionIcon uses: `full` is the dot, a
|
|
227
|
+
* smaller radius a rounded tile. */
|
|
228
|
+
radius: {
|
|
229
|
+
xs: "rounded-xs",
|
|
230
|
+
sm: "rounded-sm",
|
|
231
|
+
md: "rounded-md",
|
|
232
|
+
lg: "rounded-lg",
|
|
233
|
+
xl: "rounded-xl",
|
|
234
|
+
full: "rounded-full",
|
|
210
235
|
},
|
|
211
236
|
},
|
|
212
237
|
compoundVariants: [
|
|
@@ -240,7 +265,7 @@ const timelineBulletVariants = cva(["rounded-full shrink-0"], {
|
|
|
240
265
|
class: "bg-none bg-(--c-solid-disabled) text-(--c-on-solid-disabled)",
|
|
241
266
|
},
|
|
242
267
|
],
|
|
243
|
-
defaultVariants: { variant: "default", ringed: true, state: "none" },
|
|
268
|
+
defaultVariants: { variant: "default", ringed: true, state: "none", radius: "full" },
|
|
244
269
|
})
|
|
245
270
|
|
|
246
271
|
/** Inline override values for `--tl-line-mask` — see `timelineVariants`' `lineVariant`. */
|
|
@@ -332,6 +357,9 @@ function stateAt(items: ReactNode[], active: number | undefined): TimelineItemSt
|
|
|
332
357
|
/** `Timeline`'s density scale — the kit's canonical `Size` (xs–xl). */
|
|
333
358
|
export type TimelineSize = Size
|
|
334
359
|
export type TimelineLineVariant = NonNullable<VariantProps<typeof timelineVariants>["lineVariant"]>
|
|
360
|
+
export type TimelineBulletRadius = NonNullable<
|
|
361
|
+
VariantProps<typeof timelineBulletVariants>["radius"]
|
|
362
|
+
>
|
|
335
363
|
export type TimelineBulletVariant = NonNullable<
|
|
336
364
|
VariantProps<typeof timelineBulletVariants>["variant"]
|
|
337
365
|
>
|
|
@@ -469,8 +497,11 @@ const TimelineRoot = ({
|
|
|
469
497
|
}
|
|
470
498
|
|
|
471
499
|
export type TimelineItemProps = Omit<HTMLArkProps<"li">, "color"> &
|
|
472
|
-
Omit<VariantProps<typeof timelineBulletVariants>, "ringed" | "state"> &
|
|
500
|
+
Omit<VariantProps<typeof timelineBulletVariants>, "ringed" | "state" | "radius"> &
|
|
473
501
|
WithTestId & {
|
|
502
|
+
/** The bullet's corners: `full` (the default) is a dot, a smaller radius a
|
|
503
|
+
* rounded tile — `light` with `md` reads as an icon tile. */
|
|
504
|
+
radius?: TimelineBulletRadius
|
|
474
505
|
/** Accent palette for the bullet. Re-exported as `Color` from `@42/ui-react`. */
|
|
475
506
|
color?: Color
|
|
476
507
|
/** Overrides the default dot with any node — an icon, `<Avatar>`, or a
|
|
@@ -538,6 +569,7 @@ const TimelineItem = ({
|
|
|
538
569
|
className,
|
|
539
570
|
color,
|
|
540
571
|
variant,
|
|
572
|
+
radius,
|
|
541
573
|
bullet,
|
|
542
574
|
size,
|
|
543
575
|
lineVariant,
|
|
@@ -691,9 +723,12 @@ const TimelineItem = ({
|
|
|
691
723
|
// and center to draw.
|
|
692
724
|
ringed: !bullet && !(pending && (variant ?? "default") === "default"),
|
|
693
725
|
state,
|
|
726
|
+
radius,
|
|
694
727
|
}),
|
|
695
728
|
"size-(--tl-bullet-size) grid place-items-center overflow-hidden",
|
|
696
|
-
|
|
729
|
+
// Zero specificity (`:where`), as in ActionIcon: a size class on
|
|
730
|
+
// the icon itself wins over the bullet's default fill.
|
|
731
|
+
"[:where(&)_svg]:size-full [:where(&)_svg]:p-0.5",
|
|
697
732
|
isGradient && !pending && gradient?.dir && GRADIENT_DIR_CLASS[gradient.dir],
|
|
698
733
|
)}
|
|
699
734
|
>
|
|
@@ -727,7 +762,7 @@ const TimelineLabel = ({ className, color, testId, ...rest }: TimelineLabelProps
|
|
|
727
762
|
data-part="label"
|
|
728
763
|
data-color={color}
|
|
729
764
|
className={cn(
|
|
730
|
-
"col-start-1 inline-flex items-center gap-1.5 self-start pt-px [&_svg]:size-3.5 [&_svg]:shrink-0",
|
|
765
|
+
"col-start-1 inline-flex items-center gap-1.5 self-start pt-px [:where(&)_svg]:size-3.5 [:where(&)_svg]:shrink-0",
|
|
731
766
|
color ? "text-(--c-text)" : TEXT_COLOR_CLASSES.muted,
|
|
732
767
|
className,
|
|
733
768
|
)}
|
package/src/lib/dev-warn.ts
CHANGED
|
@@ -26,6 +26,8 @@ beforeEach(async () => {
|
|
|
26
26
|
afterEach(() => {
|
|
27
27
|
cleanup()
|
|
28
28
|
warn.mockRestore()
|
|
29
|
+
vi.unstubAllEnvs()
|
|
30
|
+
vi.restoreAllMocks()
|
|
29
31
|
})
|
|
30
32
|
|
|
31
33
|
const Strip = () => (
|
|
@@ -94,3 +96,24 @@ it("warns the other way round: an rtl locale inside an explicitly ltr page", ()
|
|
|
94
96
|
|
|
95
97
|
expect(directionWarnings()).toHaveLength(1)
|
|
96
98
|
})
|
|
99
|
+
|
|
100
|
+
it("skips the check entirely in production: no warning, and no computed-style read on the roots' parents", () => {
|
|
101
|
+
vi.stubEnv("NODE_ENV", "production")
|
|
102
|
+
const read = vi.spyOn(window, "getComputedStyle")
|
|
103
|
+
|
|
104
|
+
const { container } = render(
|
|
105
|
+
<div dir="rtl">
|
|
106
|
+
<Strip />
|
|
107
|
+
<kit.SegmentGroup data={["day", "week"]} />
|
|
108
|
+
</div>,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
expect(directionWarnings()).toHaveLength(0)
|
|
112
|
+
const parents = [...container.querySelectorAll('[data-part="root"]')].map(
|
|
113
|
+
(root) => root.parentElement,
|
|
114
|
+
)
|
|
115
|
+
expect(parents.length).toBeGreaterThan(0)
|
|
116
|
+
expect(read.mock.calls.filter(([element]) => parents.includes(element as HTMLElement))).toEqual(
|
|
117
|
+
[],
|
|
118
|
+
)
|
|
119
|
+
})
|
package/src/lib/intl.tsx
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { LocaleProvider, useLocaleContext } from "@ark-ui/react/locale"
|
|
4
4
|
import { getLocalTimeZone } from "@internationalized/date"
|
|
5
5
|
import { createContext, type ReactNode, useCallback, useContext, useSyncExternalStore } from "react"
|
|
6
|
-
import { devWarn } from "./dev-warn"
|
|
6
|
+
import { devWarn, isProduction } from "./dev-warn"
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The one seam where "which locale" and "which time zone" are decided.
|
|
@@ -150,13 +150,19 @@ let warnedDirection = false
|
|
|
150
150
|
*
|
|
151
151
|
* Returns a callback ref for an Ark root. It reads the **parent**'s direction, since the root
|
|
152
152
|
* itself carries Ark's stamped `dir`. Runs on attach, so SSR and hydration never see it.
|
|
153
|
+
*
|
|
154
|
+
* The whole check is dev-only, not just the warning: `getComputedStyle` forces a style recalc
|
|
155
|
+
* while React is committing, and in a correctly set-up app the directions match, so nothing would
|
|
156
|
+
* ever stop it repeating on every Ark root mounted (#462). In a production build the gate reduces
|
|
157
|
+
* to `if (true) return` and the minifier drops the read.
|
|
153
158
|
*/
|
|
154
159
|
export const useDirectionCheck = () => {
|
|
155
160
|
const { dir } = useLocaleContext()
|
|
156
161
|
return useCallback(
|
|
157
162
|
(node: HTMLElement | null) => {
|
|
163
|
+
if (isProduction() || warnedDirection) return
|
|
158
164
|
const parent = node?.parentElement
|
|
159
|
-
if (
|
|
165
|
+
if (!parent) return
|
|
160
166
|
// Computed rather than `closest("[dir]")`, so a CSS-only `direction: rtl` counts too.
|
|
161
167
|
const inherited = getComputedStyle(parent).direction
|
|
162
168
|
if (inherited === dir) return
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/intl.tsx"],"names":[],"mappings":";;;;;;AAiCA,IAAM,IAAA,GAAO,MAAA;AAQN,IAAM,cAAA,GAAiB;AAQvB,IAAM,iBAAA,GAAoB;AAcjC,SAAS,oBAAoB,aAAA,EAA2B;AACtD,EAAA,MAAA,CAAO,gBAAA,CAAiB,kBAAkB,aAAa,CAAA;AACvD,EAAA,OAAO,MAAM,MAAA,CAAO,mBAAA,CAAoB,gBAAA,EAAkB,aAAa,CAAA;AACzE;AAEA,SAAS,mBAAA,GAAsB;AAC7B,EAAA,OAAO,UAAU,QAAA,IAAY,cAAA;AAC/B;AAEA,SAAS,yBAAA,GAA4B;AACnC,EAAA,OAAO,cAAA;AACT;AAKA,IAAM,0BAA0B,MAAM;AAAC,CAAA;AAEvC,SAAS,mBAAA,GAAsB;AAC7B,EAAA,OAAO,uBAAA;AACT;AAEA,SAAS,mBAAA,GAAsB;AAI7B,EAAA,OAAO,kBAAiB,IAAK,iBAAA;AAC/B;AAEA,SAAS,yBAAA,GAA4B;AACnC,EAAA,OAAO,iBAAA;AACT;AAEA,IAAM,eAAA,GAAkB,cAAkC,MAAS,CAAA;AAU5D,IAAM,SAAA,GAAY,CAAC,QAAA,KAA8C;AACtE,EAAA,MAAM,EAAE,MAAA,EAAQ,QAAA,EAAS,GAAI,gBAAA,EAAiB;AAC9C,EAAA,MAAM,YAAY,QAAA,IAAY,QAAA;AAC9B,EAAA,MAAM,UAAA,GAAa,oBAAA;AAAA,IACjB,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,SAAA,KAAc,OAAO,UAAA,GAAa,SAAA;AAC3C;AAaO,IAAM,WAAA,GAAc,CAAC,QAAA,KAA8C;AACxE,EAAA,MAAM,QAAA,GAAW,WAAW,eAAe,CAAA;AAC3C,EAAA,MAAM,SAAA,GAAY,YAAY,QAAA,IAAY,IAAA;AAC1C,EAAA,MAAM,YAAA,GAAe,oBAAA;AAAA,IACnB,mBAAA;AAAA,IACA,mBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,SAAA,KAAc,OAAO,YAAA,GAAe,SAAA;AAC7C;AAIA,IAAI,eAAA,GAAkB,KAAA;AAYf,IAAM,oBAAoB,MAAM;AACrC,EAAA,MAAM,EAAE,GAAA,EAAI,GAAI,gBAAA,EAAiB;AACjC,EAAA,OAAO,WAAA;AAAA,IACL,CAAC,IAAA,KAA6B;AAC5B,MAAA,MAAM,SAAS,IAAA,EAAM,aAAA;AACrB,MAAA,IAAI,eAAA,IAAmB,CAAC,MAAA,EAAQ;AAEhC,MAAA,MAAM,SAAA,GAAY,gBAAA,CAAiB,MAAM,CAAA,CAAE,SAAA;AAC3C,MAAA,IAAI,cAAc,GAAA,EAAK;AACvB,MAAA,eAAA,GAAkB,IAAA;AAClB,MAAA,OAAA;AAAA,QACE,CAAA,iCAAA,EAAoC,SAAS,CAAA,mCAAA,EAAsC,GAAG,+EAA0E,GAAG,CAAA,gKAAA;AAAA,OACrK;AAAA,IACF,CAAA;AAAA,IACA,CAAC,GAAG;AAAA,GACN;AACF;AA+BO,IAAM,eAAe,CAAC,EAAE,MAAA,EAAQ,QAAA,EAAU,UAAS,KAAyB;AACjF,EAAA,MAAM,cAAA,GAAiB,UAAU,MAAM,CAAA;AACvC,EAAA,MAAM,gBAAA,GAAmB,YAAY,QAAQ,CAAA;AAE7C,EAAA,uBACE,GAAA,CAAC,cAAA,EAAA,EAAe,MAAA,EAAQ,cAAA,EACtB,QAAA,kBAAA,GAAA,CAAC,eAAA,CAAgB,QAAA,EAAhB,EAAyB,KAAA,EAAO,gBAAA,EAAmB,QAAA,EAAS,CAAA,EAC/D,CAAA;AAEJ","file":"chunk-IUK7OJXZ.js","sourcesContent":["\"use client\"\n\nimport { LocaleProvider, useLocaleContext } from \"@ark-ui/react/locale\"\nimport { getLocalTimeZone } from \"@internationalized/date\"\nimport { createContext, type ReactNode, useCallback, useContext, useSyncExternalStore } from \"react\"\nimport { devWarn } from \"./dev-warn\"\n\n/**\n * The one seam where \"which locale\" and \"which time zone\" are decided.\n *\n * Every `Intl` constructor takes a locale as its first argument and a `timeZone` as an option,\n * and both have a runtime default — `Intl.DateTimeFormat()` resolves to Node's `en-US` on a\n * server and to the visitor's locale in a browser; `getLocalTimeZone()` resolves to the server's\n * zone (UTC on most hosts) and to the visitor's. Reading either implicitly therefore makes the\n * rendered output a property of *where the code ran*, which is a hydration mismatch waiting for\n * the first visitor configured differently from the build server. So nothing in this kit reads\n * them implicitly: components resolve both through the hooks below, and the value they get is\n * either something the app stated or a documented constant.\n *\n * Locale and time zone stay **fully independent** — separate prop, separate hook, separate\n * per-instance override, no coupling. They share only this module and `IntlProvider`'s single\n * mount point, because the resolution mechanism is the whole of the fix and writing it twice is\n * how the two would drift apart.\n *\n * Locale deliberately needs no context of its own: `IntlProvider` renders Ark's own\n * `LocaleProvider`, so Ark's state machines (`Calendar`, `DatePicker`, `NumberInput`,\n * `FileUpload`) and this kit's own formatting can only ever read one value — and `dir`/RTL comes\n * along for free for the components already reading `useLocaleContext().dir` (`menu.tsx`,\n * `tooltip.tsx`, `hover-card.tsx`). An app that mounts Ark's `LocaleProvider` directly still\n * works. Only the time zone needs a new context, since Ark has no equivalent.\n */\n\n/** Follow the host runtime. Accepted anywhere a locale or zone is: provider, or a single prop. */\nconst AUTO = \"auto\"\n\n/**\n * The locale used when nothing configures one, and what `\"auto\"` reports during SSR and the\n * hydration render. Pinned to the same tag as Ark's own `useLocaleContext()` default so the two\n * halves of a `Calendar` — Ark's machine and this kit's formatting around it — cannot disagree,\n * the same \"one constant, two readers\" reasoning `lib/theme.ts` uses for the theme storage key.\n */\nexport const DEFAULT_LOCALE = \"en-US\"\n\n/**\n * What `timeZone=\"auto\"` reports during SSR and the hydration render, before the host zone is\n * readable. Note this is *not* the default for the `timeZone` prop itself — that is `\"auto\"`\n * (see `useTimeZone`), because a wrong zone is wrong data rather than merely an unfamiliar\n * format. UTC is the one zone every runtime agrees on.\n */\nexport const DEFAULT_TIME_ZONE = \"UTC\"\n\n// `\"auto\"` is resolved through `useSyncExternalStore` with a fixed `getServerSnapshot`, the same\n// shape (and for the same reason) as `use-media-query.ts`, `use-local-storage.ts` and\n// `use-now.ts`: the server and the first client render are handed a value that cannot differ, so\n// hydration always matches, and React swaps in the real one immediately afterwards. A plain\n// `useEffect` would work too, but this way the fallback is declared once next to the real read\n// instead of living in a `useState` initializer somewhere else.\n//\n// Caveat worth knowing before reaching for `\"auto\"` under SSR, carried over from `use-theme.ts`:\n// React does not specify that the post-hydration correction lands before the browser paints, and\n// empirically it does not reliably, so the default value can be visible for a frame. That is the\n// accepted cost of opting in, and precisely why `locale` does not default to `\"auto\"`.\n\nfunction subscribeToLanguage(onStoreChange: () => void) {\n window.addEventListener(\"languagechange\", onStoreChange)\n return () => window.removeEventListener(\"languagechange\", onStoreChange)\n}\n\nfunction getLanguageSnapshot() {\n return navigator.language || DEFAULT_LOCALE\n}\n\nfunction getLanguageServerSnapshot() {\n return DEFAULT_LOCALE\n}\n\n// The host zone has no change event to listen for — a machine moving zone mid-session re-resolves\n// on the next render at worst. `subscribe` still has to return an unsubscribe function, and it\n// has to be a stable reference or `useSyncExternalStore` resubscribes on every render.\nconst unsubscribeFromTimeZone = () => {}\n\nfunction subscribeToTimeZone() {\n return unsubscribeFromTimeZone\n}\n\nfunction getTimeZoneSnapshot() {\n // `getLocalTimeZone()` is `Intl.DateTimeFormat().resolvedOptions().timeZone` behind a cache.\n // This is the only call to it left in the kit, which is the point: one reader of the ambient\n // zone, wrapped in the hydration-safe store, instead of ~13 scattered prop defaults.\n return getLocalTimeZone() || DEFAULT_TIME_ZONE\n}\n\nfunction getTimeZoneServerSnapshot() {\n return DEFAULT_TIME_ZONE\n}\n\nconst TimeZoneContext = createContext<string | undefined>(undefined)\n\n/**\n * The active locale as a concrete BCP-47 tag, never `\"auto\"` and never `undefined`.\n *\n * `override` is the component's own `locale` prop, so precedence reads\n * **prop → provider → `DEFAULT_LOCALE`** — the same shape as `useLinkComponent`.\n *\n * const locale = useLocale(props.locale)\n */\nexport const useLocale = (override?: \"auto\" | (string & {})): string => {\n const { locale: provided } = useLocaleContext()\n const requested = override ?? provided\n const hostLocale = useSyncExternalStore(\n subscribeToLanguage,\n getLanguageSnapshot,\n getLanguageServerSnapshot,\n )\n return requested === AUTO ? hostLocale : requested\n}\n\n/**\n * The active time zone as a concrete IANA name, never `\"auto\"` and never `undefined`.\n *\n * `override` is the component's own `timeZone` prop, so precedence reads\n * **prop → provider → `\"auto\"`**. The default is `\"auto\"` rather than a fixed zone because a\n * wrong zone shows wrong times, not merely an unfamiliar format — and `\"auto\"` costs a\n * client-only app nothing, since `getServerSnapshot` never runs there and the first render is\n * already the true zone.\n *\n * const timeZone = useTimeZone(props.timeZone)\n */\nexport const useTimeZone = (override?: \"auto\" | (string & {})): string => {\n const provided = useContext(TimeZoneContext)\n const requested = override ?? provided ?? AUTO\n const hostTimeZone = useSyncExternalStore(\n subscribeToTimeZone,\n getTimeZoneSnapshot,\n getTimeZoneServerSnapshot,\n )\n return requested === AUTO ? hostTimeZone : requested\n}\n\n// One warning per page, however many components run the check: the fix is a single provider at\n// the app root, so repeating the message per Tabs would only bury it.\nlet warnedDirection = false\n\n/**\n * Dev-only guard for the one RTL setup that silently breaks: direction stated on the DOM\n * (`<html dir=\"rtl\">`, or an ancestor) while no locale says so. Ark derives `dir` from the\n * locale alone and stamps it on every part, so its parts render `ltr` inside an `rtl` page —\n * and its arrow-key handling runs `ltr` too, which is why the kit can't simply let the parts\n * inherit from the DOM: the direction has to be known in JS, i.e. come from `IntlProvider`.\n *\n * Returns a callback ref for an Ark root. It reads the **parent**'s direction, since the root\n * itself carries Ark's stamped `dir`. Runs on attach, so SSR and hydration never see it.\n */\nexport const useDirectionCheck = () => {\n const { dir } = useLocaleContext()\n return useCallback(\n (node: HTMLElement | null) => {\n const parent = node?.parentElement\n if (warnedDirection || !parent) return\n // Computed rather than `closest(\"[dir]\")`, so a CSS-only `direction: rtl` counts too.\n const inherited = getComputedStyle(parent).direction\n if (inherited === dir) return\n warnedDirection = true\n devWarn(\n `[@42/ui-react] This page is dir=\"${inherited}\", but the locale resolves to dir=\"${dir}\", so Ark-backed parts (Tabs, SegmentGroup, Menu…) render and navigate ${dir}. Direction comes from the locale: wrap the app in <IntlProvider locale=\"…\"> with a matching locale. See \"Text direction\" in the Internationalization docs.`,\n )\n },\n [dir],\n )\n}\n\nexport type IntlProviderProps = {\n /** A BCP-47 tag (`\"fr-FR\"`), or `\"auto\"` to follow the browser. Inherited from an outer\n * `IntlProvider` when omitted, and `\"en-US\"` when there is none. */\n locale?: \"auto\" | (string & {})\n /** An IANA zone (`\"Europe/Paris\"`), or `\"auto\"` to follow the host. Inherited from an outer\n * `IntlProvider` when omitted, and `\"auto\"` when there is none. @default \"auto\" */\n timeZone?: \"auto\" | (string & {})\n children?: ReactNode\n}\n\n/**\n * Wrap the app once to state how it formats dates, times and numbers:\n * `<IntlProvider locale=\"fr-FR\" timeZone=\"Europe/Paris\"><App /></IntlProvider>`.\n *\n * Both props are optional and independent — setting only `timeZone` leaves the locale alone, and\n * a nested provider inherits whichever value it doesn't set, so a section can override one\n * without restating the other.\n *\n * It resolves both values and publishes the results, so `\"auto\"` is subscribed to once here\n * rather than once per component, and everything downstream — Ark's machines included — reads a\n * concrete tag and zone.\n *\n * Text direction follows the locale: `locale=\"ar\"` makes every Ark part `rtl`. `<html dir=\"rtl\">`\n * alone never reaches Ark, which is what `useDirectionCheck` warns about in development.\n *\n * This provider carries the inputs to `Intl`, and nothing else. Translated microcopy stays on\n * each component's own `translations` prop by design (`code-style.md`); there is deliberately no\n * message context here.\n */\nexport const IntlProvider = ({ locale, timeZone, children }: IntlProviderProps) => {\n const resolvedLocale = useLocale(locale)\n const resolvedTimeZone = useTimeZone(timeZone)\n\n return (\n <LocaleProvider locale={resolvedLocale}>\n <TimeZoneContext.Provider value={resolvedTimeZone}>{children}</TimeZoneContext.Provider>\n </LocaleProvider>\n )\n}\n"]}
|