@xsolla/xui-b2c-top-navigation 0.0.0-stage → 0.224.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.
@@ -0,0 +1,940 @@
1
+ // src/TopNavigation.tsx
2
+ import React3, {
3
+ useCallback,
4
+ useEffect,
5
+ useLayoutEffect,
6
+ useRef,
7
+ useState
8
+ } from "react";
9
+
10
+ // ../../foundation/primitives-native/src/Box.tsx
11
+ import React from "react";
12
+ import {
13
+ View,
14
+ Pressable,
15
+ Image
16
+ } from "react-native";
17
+ var roleToAccessibilityRole = {
18
+ button: "button",
19
+ link: "link",
20
+ img: "image",
21
+ image: "image",
22
+ summary: "summary",
23
+ switch: "switch",
24
+ checkbox: "checkbox",
25
+ radio: "radio",
26
+ heading: "header",
27
+ text: "text",
28
+ search: "search",
29
+ alert: "alert",
30
+ none: "none",
31
+ presentation: "none",
32
+ progressbar: "progressbar",
33
+ scrollbar: "scrollbar",
34
+ adjustable: "adjustable",
35
+ tab: "tab",
36
+ menu: "menu",
37
+ menuitem: "menuitem",
38
+ list: "list",
39
+ timer: "timer"
40
+ };
41
+ var toGapValue = (gap) => {
42
+ if (gap === void 0) return void 0;
43
+ if (typeof gap === "number") return gap;
44
+ const pxMatch = /^(\d+(?:\.\d+)?)px$/.exec(gap);
45
+ if (pxMatch) return Number(pxMatch[1]);
46
+ const asNumber = Number(gap);
47
+ return Number.isFinite(asNumber) ? asNumber : void 0;
48
+ };
49
+ var toNativeDisplay = (display) => display === "none" ? "none" : void 0;
50
+ var Box = ({
51
+ children,
52
+ onPress,
53
+ onLayout,
54
+ onMoveShouldSetResponder,
55
+ onResponderGrant,
56
+ onResponderMove,
57
+ onResponderRelease,
58
+ onResponderTerminate,
59
+ backgroundColor,
60
+ borderColor,
61
+ borderWidth,
62
+ borderBottomWidth,
63
+ borderBottomColor,
64
+ borderTopWidth,
65
+ borderTopColor,
66
+ borderLeftWidth,
67
+ borderLeftColor,
68
+ borderRightWidth,
69
+ borderRightColor,
70
+ borderRadius,
71
+ borderStyle,
72
+ height,
73
+ padding,
74
+ paddingHorizontal,
75
+ paddingVertical,
76
+ margin,
77
+ marginTop,
78
+ marginBottom,
79
+ marginLeft,
80
+ marginRight,
81
+ display,
82
+ flexDirection,
83
+ flexWrap,
84
+ alignItems,
85
+ justifyContent,
86
+ alignSelf,
87
+ position,
88
+ top,
89
+ bottom,
90
+ left,
91
+ right,
92
+ width,
93
+ minWidth,
94
+ minHeight,
95
+ maxWidth,
96
+ maxHeight,
97
+ flex,
98
+ flexShrink,
99
+ gap,
100
+ overflow,
101
+ opacity,
102
+ zIndex,
103
+ hoverStyle,
104
+ pressStyle,
105
+ style,
106
+ disabled,
107
+ "data-testid": dataTestId,
108
+ testID,
109
+ as,
110
+ src,
111
+ alt,
112
+ ...rest
113
+ }) => {
114
+ const getContainerStyle = (pressed) => ({
115
+ backgroundColor: pressed && pressStyle?.backgroundColor ? pressStyle.backgroundColor : backgroundColor,
116
+ borderColor,
117
+ borderWidth,
118
+ borderBottomWidth,
119
+ borderBottomColor,
120
+ borderTopWidth,
121
+ borderTopColor,
122
+ borderLeftWidth,
123
+ borderLeftColor,
124
+ borderRightWidth,
125
+ borderRightColor,
126
+ borderRadius,
127
+ borderStyle,
128
+ overflow,
129
+ opacity: opacity ?? (disabled ? 0.5 : void 0),
130
+ zIndex,
131
+ height,
132
+ width,
133
+ minWidth,
134
+ minHeight,
135
+ maxWidth,
136
+ maxHeight,
137
+ padding,
138
+ paddingHorizontal,
139
+ paddingVertical,
140
+ margin,
141
+ marginTop,
142
+ marginBottom,
143
+ marginLeft,
144
+ marginRight,
145
+ display: toNativeDisplay(display),
146
+ flexDirection,
147
+ flexWrap,
148
+ alignItems,
149
+ justifyContent,
150
+ alignSelf,
151
+ position,
152
+ top,
153
+ bottom,
154
+ left,
155
+ right,
156
+ flex,
157
+ flexShrink,
158
+ gap: toGapValue(gap),
159
+ ...style
160
+ });
161
+ const finalTestID = dataTestId || testID;
162
+ const {
163
+ role,
164
+ tabIndex,
165
+ onKeyDown,
166
+ onKeyUp,
167
+ "aria-label": ariaLabel,
168
+ "aria-labelledby": _ariaLabelledBy,
169
+ "aria-current": _ariaCurrent,
170
+ "aria-disabled": ariaDisabled,
171
+ "aria-live": ariaLive,
172
+ "aria-busy": ariaBusy,
173
+ className,
174
+ "data-testid": _dataTestId,
175
+ cursor: _cursor,
176
+ type: _type,
177
+ ...nativeRest
178
+ } = rest;
179
+ const accessibilityRole = typeof role === "string" && roleToAccessibilityRole[role] || (as === "button" ? "button" : void 0);
180
+ const isDisabled = Boolean(disabled || ariaDisabled);
181
+ const accessibilityState = {
182
+ disabled: isDisabled || void 0,
183
+ busy: Boolean(ariaBusy) || void 0
184
+ };
185
+ const accessibilityLiveRegion = ariaLive === "polite" || ariaLive === "assertive" ? ariaLive : void 0;
186
+ if (as === "img" && src) {
187
+ const imageStyle = {
188
+ width,
189
+ height,
190
+ borderRadius,
191
+ position,
192
+ top,
193
+ bottom,
194
+ left,
195
+ right,
196
+ ...style
197
+ };
198
+ return /* @__PURE__ */ React.createElement(
199
+ Image,
200
+ {
201
+ source: { uri: src },
202
+ style: imageStyle,
203
+ testID: finalTestID,
204
+ accessibilityLabel: typeof ariaLabel === "string" ? ariaLabel : alt,
205
+ resizeMode: "cover",
206
+ ...nativeRest
207
+ }
208
+ );
209
+ }
210
+ if (onPress || as === "button") {
211
+ return /* @__PURE__ */ React.createElement(
212
+ Pressable,
213
+ {
214
+ onPress: !isDisabled && onPress ? onPress : void 0,
215
+ disabled: isDisabled,
216
+ onLayout,
217
+ onMoveShouldSetResponder,
218
+ onResponderGrant,
219
+ onResponderMove,
220
+ onResponderRelease,
221
+ onResponderTerminate,
222
+ style: ({ pressed }) => getContainerStyle(pressed),
223
+ testID: finalTestID,
224
+ accessibilityRole,
225
+ accessibilityLabel: typeof ariaLabel === "string" ? ariaLabel : void 0,
226
+ accessibilityState,
227
+ accessibilityLiveRegion,
228
+ ...nativeRest
229
+ },
230
+ children
231
+ );
232
+ }
233
+ return /* @__PURE__ */ React.createElement(
234
+ View,
235
+ {
236
+ style: getContainerStyle(),
237
+ testID: finalTestID,
238
+ onLayout,
239
+ onMoveShouldSetResponder,
240
+ onResponderGrant,
241
+ onResponderMove,
242
+ onResponderRelease,
243
+ onResponderTerminate,
244
+ accessibilityRole,
245
+ accessibilityLabel: typeof ariaLabel === "string" ? ariaLabel : void 0,
246
+ accessibilityState,
247
+ accessibilityLiveRegion,
248
+ ...nativeRest
249
+ },
250
+ children
251
+ );
252
+ };
253
+
254
+ // ../../foundation/primitives-native/src/Text.tsx
255
+ import React2 from "react";
256
+ import {
257
+ Text as RNText,
258
+ StyleSheet
259
+ } from "react-native";
260
+ var roleMap = {
261
+ alert: "alert",
262
+ heading: "header",
263
+ button: "button",
264
+ link: "link",
265
+ text: "text"
266
+ };
267
+ var parseNumericValue = (value) => {
268
+ if (value === void 0) return void 0;
269
+ if (typeof value === "number") return value;
270
+ const parsed = parseFloat(value);
271
+ return isNaN(parsed) ? void 0 : parsed;
272
+ };
273
+ var Text = ({
274
+ children,
275
+ color,
276
+ fontSize,
277
+ fontWeight,
278
+ fontFamily,
279
+ textAlign,
280
+ lineHeight,
281
+ numberOfLines,
282
+ id,
283
+ role,
284
+ testID,
285
+ "data-testid": dataTestId,
286
+ style: styleProp,
287
+ ...props
288
+ }) => {
289
+ let resolvedFontFamily = fontFamily ? fontFamily.split(",")[0].replace(/['"]/g, "").trim() : void 0;
290
+ if (resolvedFontFamily === "Pilat Wide" || resolvedFontFamily === "Pilat Wide Bold" || resolvedFontFamily === "Aktiv Grotesk") {
291
+ resolvedFontFamily = void 0;
292
+ }
293
+ const incomingStyle = StyleSheet.flatten(styleProp);
294
+ const baseStyle = {
295
+ color: color ?? incomingStyle?.color,
296
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
297
+ fontWeight,
298
+ fontFamily: resolvedFontFamily,
299
+ textDecorationLine: props.textDecoration,
300
+ textAlign: textAlign ?? incomingStyle?.textAlign,
301
+ lineHeight: parseNumericValue(lineHeight ?? incomingStyle?.lineHeight),
302
+ marginTop: parseNumericValue(
303
+ incomingStyle?.marginTop
304
+ ),
305
+ marginBottom: parseNumericValue(
306
+ incomingStyle?.marginBottom
307
+ )
308
+ };
309
+ const accessibilityRole = role ? roleMap[role] : void 0;
310
+ return /* @__PURE__ */ React2.createElement(
311
+ RNText,
312
+ {
313
+ style: baseStyle,
314
+ numberOfLines,
315
+ testID: dataTestId || testID || id,
316
+ accessibilityRole
317
+ },
318
+ children
319
+ );
320
+ };
321
+
322
+ // src/TopNavigation.tsx
323
+ import { useResolvedTheme } from "@xsolla/xui-core";
324
+ import { Avatar } from "@xsolla/xui-avatar";
325
+ import { Breadcrumbs } from "@xsolla/xui-breadcrumbs";
326
+ import { IconButton } from "@xsolla/xui-button";
327
+ import { ContextMenu } from "@xsolla/xui-context-menu";
328
+ import {
329
+ ArrowLeft,
330
+ ChevronDown,
331
+ ChevronUp,
332
+ Minus,
333
+ Remove,
334
+ User
335
+ } from "@xsolla/xui-icons-base";
336
+ var BAR_HEIGHT = 88;
337
+ var BAR_PADDING_VERTICAL = 24;
338
+ var CLUSTER_GAP = 40;
339
+ var MENU_GAP = 24;
340
+ var ACCOUNT_GAP = 8;
341
+ var WINDOWS_LOGO_GAP = 88;
342
+ var LOGO_HEIGHT = 40;
343
+ var NAV_ICON_SIZE = 20;
344
+ var BACK_ICON_SIZE = 18;
345
+ var CURRENCY_ICON_SIZE = 18;
346
+ var MENU_DIVIDER_HEIGHT = 16;
347
+ var ICON_SLIDE_MS = 360;
348
+ var ICON_SLIDE_EASE = "cubic-bezier(0.22, 1, 0.36, 1)";
349
+ var prefersReducedMotion = () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
350
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
351
+ var isDarkMode = (mode) => !(mode ?? "dark").includes("light");
352
+ var tintIcon = (icon, color, size) => {
353
+ if (!React3.isValidElement(icon)) return icon;
354
+ const existing = icon.props;
355
+ return React3.cloneElement(
356
+ icon,
357
+ {
358
+ size: existing.size ?? size,
359
+ color,
360
+ "aria-hidden": true
361
+ }
362
+ );
363
+ };
364
+ var MaximizeGlyph = ({
365
+ size = NAV_ICON_SIZE,
366
+ color
367
+ }) => /* @__PURE__ */ React3.createElement(
368
+ Box,
369
+ {
370
+ width: Math.round(size * 0.7),
371
+ height: Math.round(size * 0.7),
372
+ borderWidth: 1.5,
373
+ borderColor: color,
374
+ borderRadius: 2
375
+ }
376
+ );
377
+ var ActiveIcon = ({ icon, color, phase, play, travel }) => {
378
+ const moving = phase === "in" || phase === "out";
379
+ const collapsed = phase === "out" && play || phase === "in" && !play;
380
+ const offset = phase === "out" && play ? travel : phase === "in" && !play ? -travel : 0;
381
+ return /* @__PURE__ */ React3.createElement(
382
+ Box,
383
+ {
384
+ height: NAV_ICON_SIZE,
385
+ flexShrink: 0,
386
+ alignItems: "center",
387
+ justifyContent: "center",
388
+ overflow: "visible",
389
+ "aria-hidden": true,
390
+ style: {
391
+ width: collapsed ? 0 : NAV_ICON_SIZE,
392
+ marginRight: collapsed ? 0 : 4,
393
+ transform: `translateX(${offset}px)`,
394
+ opacity: collapsed ? 0 : 1,
395
+ pointerEvents: "none",
396
+ transition: moving ? `transform ${ICON_SLIDE_MS}ms ${ICON_SLIDE_EASE}, opacity ${ICON_SLIDE_MS}ms ${ICON_SLIDE_EASE}, width ${ICON_SLIDE_MS}ms ${ICON_SLIDE_EASE}, margin-right ${ICON_SLIDE_MS}ms ${ICON_SLIDE_EASE}` : void 0
397
+ }
398
+ },
399
+ tintIcon(icon, color, NAV_ICON_SIZE)
400
+ );
401
+ };
402
+ var NavPoint = ({
403
+ item,
404
+ isActive,
405
+ isOpen,
406
+ iconSlide,
407
+ iconPlaying,
408
+ registerAnchor,
409
+ theme,
410
+ themeMode,
411
+ themeProductContext,
412
+ onOpenChange,
413
+ onPress,
414
+ onSelect,
415
+ linkComponent: LinkComponent
416
+ }) => {
417
+ const [hovered, setHovered] = useState(false);
418
+ const hasMenu = Boolean(item.children?.length);
419
+ const isDisabled = Boolean(item.disabled);
420
+ const emphasized = isActive || hovered || isOpen;
421
+ const color = emphasized ? theme.colors.content.brand.secondary : theme.colors.content.secondary;
422
+ const body = theme.typographyTokens.basic["body-sm"];
423
+ const iconPhase = item.icon === void 0 || item.icon === null ? "off" : iconSlide?.to === item.key ? "in" : iconSlide?.from === item.key ? "out" : isActive ? "rest" : "off";
424
+ const showIcon = iconPhase !== "off";
425
+ const anchorRef = useCallback(
426
+ (node) => {
427
+ registerAnchor(item.key, node);
428
+ },
429
+ [item.key, registerAnchor]
430
+ );
431
+ const trigger = /* @__PURE__ */ React3.createElement(
432
+ Box,
433
+ {
434
+ as: !LinkComponent || hasMenu ? "button" : void 0,
435
+ type: !LinkComponent || hasMenu ? "button" : void 0,
436
+ position: "relative",
437
+ zIndex: iconPhase === "out" ? 2 : iconPhase === "in" ? 1 : void 0,
438
+ flexDirection: "row",
439
+ alignItems: "center",
440
+ paddingVertical: !hasMenu && !showIcon ? 2 : 0,
441
+ cursor: isDisabled ? "not-allowed" : "pointer",
442
+ "aria-label": item.accessibilityLabel || item.label,
443
+ "aria-current": isActive && !hasMenu ? "page" : void 0,
444
+ "aria-disabled": isDisabled || void 0,
445
+ disabled: isDisabled,
446
+ onMouseEnter: () => setHovered(true),
447
+ onMouseLeave: () => setHovered(false),
448
+ onPress: !isDisabled && !hasMenu && !LinkComponent ? onPress : void 0,
449
+ testID: item.testID || `top-navigation-item-${item.key}`
450
+ },
451
+ item.icon !== void 0 && item.icon !== null && /* @__PURE__ */ React3.createElement(
452
+ Box,
453
+ {
454
+ ref: anchorRef,
455
+ position: "absolute",
456
+ top: 0,
457
+ left: 0,
458
+ width: 0,
459
+ height: 0,
460
+ "aria-hidden": true
461
+ }
462
+ ),
463
+ showIcon && /* @__PURE__ */ React3.createElement(
464
+ ActiveIcon,
465
+ {
466
+ icon: item.icon,
467
+ color: theme.colors.content.brand.secondary,
468
+ phase: iconPhase,
469
+ play: iconPlaying,
470
+ travel: iconSlide?.travel ?? 0
471
+ }
472
+ ),
473
+ /* @__PURE__ */ React3.createElement(
474
+ Text,
475
+ {
476
+ color,
477
+ fontFamily: theme.fonts.body,
478
+ fontSize: body.fontSize,
479
+ lineHeight: body.lineHeight,
480
+ fontWeight: String(body.accent?.fontWeight ?? 500),
481
+ numberOfLines: 1
482
+ },
483
+ item.label
484
+ ),
485
+ hasMenu && /* @__PURE__ */ React3.createElement(Box, { marginLeft: 4, alignItems: "center" }, isOpen ? /* @__PURE__ */ React3.createElement(ChevronUp, { size: NAV_ICON_SIZE, color, "aria-hidden": true }) : /* @__PURE__ */ React3.createElement(ChevronDown, { size: NAV_ICON_SIZE, color, "aria-hidden": true }))
486
+ );
487
+ const content = LinkComponent && !hasMenu ? /* @__PURE__ */ React3.createElement(
488
+ LinkComponent,
489
+ {
490
+ item,
491
+ href: item.href,
492
+ isActive,
493
+ disabled: isDisabled,
494
+ onPress,
495
+ testID: item.testID || `top-navigation-link-${item.key}`
496
+ },
497
+ trigger
498
+ ) : trigger;
499
+ if (!hasMenu) return content;
500
+ return /* @__PURE__ */ React3.createElement(
501
+ ContextMenu,
502
+ {
503
+ isOpen,
504
+ onOpenChange,
505
+ placement: "bottom-start",
506
+ offset: 0,
507
+ trigger: content,
508
+ "aria-label": item.label,
509
+ themeMode,
510
+ themeProductContext,
511
+ items: item.children.map((child) => ({
512
+ type: "option",
513
+ label: child.label,
514
+ disabled: child.disabled,
515
+ onSelect: () => onSelect(child)
516
+ })),
517
+ testID: `top-navigation-menu-${item.key}`
518
+ }
519
+ );
520
+ };
521
+ var Currencies = ({ currencies, theme }) => {
522
+ const body = theme.typographyTokens.basic["body-sm"];
523
+ const radius = theme.shape.button.sm.borderRadius;
524
+ return /* @__PURE__ */ React3.createElement(
525
+ Box,
526
+ {
527
+ role: "group",
528
+ "aria-label": "Currencies",
529
+ flexDirection: "row",
530
+ alignItems: "center",
531
+ gap: 8,
532
+ paddingHorizontal: 8,
533
+ paddingVertical: 11,
534
+ borderRadius: radius,
535
+ position: "relative",
536
+ style: { backdropFilter: "blur(6px)" },
537
+ testID: "top-navigation-currencies"
538
+ },
539
+ /* @__PURE__ */ React3.createElement(
540
+ Box,
541
+ {
542
+ position: "absolute",
543
+ top: 0,
544
+ right: 0,
545
+ bottom: 0,
546
+ left: 0,
547
+ backgroundColor: theme.colors.background.neutral.secondary,
548
+ opacity: 0.5,
549
+ borderRadius: radius
550
+ }
551
+ ),
552
+ currencies.map((currency, index) => /* @__PURE__ */ React3.createElement(
553
+ Box,
554
+ {
555
+ key: `${currency.amount}-${index}`,
556
+ as: currency.onPress ? "button" : void 0,
557
+ type: currency.onPress ? "button" : void 0,
558
+ flexDirection: "row",
559
+ alignItems: "center",
560
+ gap: 4,
561
+ zIndex: 1,
562
+ cursor: currency.onPress ? "pointer" : void 0,
563
+ "aria-label": currency.accessibilityLabel,
564
+ onPress: currency.onPress,
565
+ testID: `top-navigation-currency-${index}`
566
+ },
567
+ currency.icon && /* @__PURE__ */ React3.createElement(
568
+ Box,
569
+ {
570
+ width: CURRENCY_ICON_SIZE,
571
+ height: CURRENCY_ICON_SIZE,
572
+ alignItems: "center",
573
+ justifyContent: "center"
574
+ },
575
+ currency.icon
576
+ ),
577
+ /* @__PURE__ */ React3.createElement(
578
+ Text,
579
+ {
580
+ color: theme.colors.content.primary,
581
+ fontFamily: theme.fonts.body,
582
+ fontSize: body.fontSize,
583
+ lineHeight: body.lineHeight,
584
+ fontWeight: String(body.fontWeight),
585
+ numberOfLines: 1
586
+ },
587
+ currency.amount
588
+ )
589
+ ))
590
+ );
591
+ };
592
+ var AccountAvatar = ({ user, themeMode, themeProductContext }) => {
593
+ const showInitials = !user.src && Boolean(user.text);
594
+ const icon = showInitials ? void 0 : user.icon ?? /* @__PURE__ */ React3.createElement(User, { variant: "solid", "aria-hidden": true });
595
+ return /* @__PURE__ */ React3.createElement(
596
+ Avatar,
597
+ {
598
+ size: "sm",
599
+ square: true,
600
+ tone: "brand",
601
+ badge: false,
602
+ src: user.src,
603
+ text: showInitials ? user.text : void 0,
604
+ icon: user.src ? void 0 : icon,
605
+ disableHover: !user.onPress,
606
+ "aria-label": user.onPress ? `Account: ${user.name}` : user.name,
607
+ onClick: user.onPress,
608
+ testID: "top-navigation-avatar",
609
+ themeMode,
610
+ themeProductContext
611
+ }
612
+ );
613
+ };
614
+ var WindowControls = ({ controls, themeMode, themeProductContext }) => /* @__PURE__ */ React3.createElement(
615
+ Box,
616
+ {
617
+ role: "group",
618
+ "aria-label": "Window controls",
619
+ flexDirection: "row",
620
+ alignItems: "center",
621
+ flexShrink: 0,
622
+ testID: "top-navigation-window-controls"
623
+ },
624
+ /* @__PURE__ */ React3.createElement(
625
+ IconButton,
626
+ {
627
+ size: "sm",
628
+ variant: "tertiary",
629
+ tone: "mono",
630
+ icon: /* @__PURE__ */ React3.createElement(Minus, null),
631
+ "aria-label": "Minimize window",
632
+ disabled: !controls.onMinimize,
633
+ onPress: controls.onMinimize,
634
+ testID: "top-navigation-window-minimize",
635
+ themeMode,
636
+ themeProductContext
637
+ }
638
+ ),
639
+ /* @__PURE__ */ React3.createElement(
640
+ IconButton,
641
+ {
642
+ size: "sm",
643
+ variant: "tertiary",
644
+ tone: "mono",
645
+ icon: /* @__PURE__ */ React3.createElement(MaximizeGlyph, null),
646
+ "aria-label": "Maximize window",
647
+ disabled: !controls.onMaximize,
648
+ onPress: controls.onMaximize,
649
+ testID: "top-navigation-window-maximize",
650
+ themeMode,
651
+ themeProductContext
652
+ }
653
+ ),
654
+ /* @__PURE__ */ React3.createElement(
655
+ IconButton,
656
+ {
657
+ size: "sm",
658
+ variant: "tertiary",
659
+ tone: "mono",
660
+ icon: /* @__PURE__ */ React3.createElement(Remove, null),
661
+ "aria-label": "Close window",
662
+ disabled: !controls.onClose,
663
+ onPress: controls.onClose,
664
+ testID: "top-navigation-window-close",
665
+ themeMode,
666
+ themeProductContext
667
+ }
668
+ )
669
+ );
670
+ var TopNavigation = ({
671
+ platform = "web",
672
+ logo,
673
+ items = [],
674
+ extraItems = [],
675
+ activeKey,
676
+ onItemClick,
677
+ linkComponent,
678
+ showMenu = true,
679
+ currencies,
680
+ user,
681
+ showAccount = true,
682
+ breadcrumbs = [],
683
+ onBack,
684
+ windowControls,
685
+ "aria-label": ariaLabel = "Main navigation",
686
+ testID,
687
+ themeMode,
688
+ themeProductContext = "b2c"
689
+ }) => {
690
+ const { theme, mode } = useResolvedTheme({ themeMode, themeProductContext });
691
+ const [openKey, setOpenKey] = useState(null);
692
+ const [iconMotion, setIconMotion] = useState({ slide: null, playing: false });
693
+ const iconSlide = iconMotion.slide;
694
+ const iconPlaying = iconMotion.playing;
695
+ const previousKey = useRef(activeKey);
696
+ const iconPositions = useRef(/* @__PURE__ */ new Map());
697
+ const iconAnchors = useRef(/* @__PURE__ */ new Map());
698
+ const itemsRef = useRef(items);
699
+ const extraItemsRef = useRef(extraItems);
700
+ itemsRef.current = items;
701
+ extraItemsRef.current = extraItems;
702
+ const isWindows = platform === "windows";
703
+ const isDark = isDarkMode(mode);
704
+ const registerAnchor = useCallback(
705
+ (key, node) => {
706
+ if (node) iconAnchors.current.set(key, node);
707
+ else iconAnchors.current.delete(key);
708
+ },
709
+ []
710
+ );
711
+ const recordIconPositions = () => {
712
+ const next = /* @__PURE__ */ new Map();
713
+ iconAnchors.current.forEach((node, key) => {
714
+ if (typeof node.getBoundingClientRect !== "function") return;
715
+ next.set(key, node.getBoundingClientRect().left);
716
+ });
717
+ iconPositions.current = next;
718
+ };
719
+ useIsomorphicLayoutEffect(() => {
720
+ const from = previousKey.current;
721
+ if (from !== activeKey) {
722
+ const fromX = from ? iconPositions.current.get(from) : void 0;
723
+ const toX = activeKey ? iconPositions.current.get(activeKey) : void 0;
724
+ previousKey.current = activeKey;
725
+ if (from && activeKey && fromX !== void 0 && !prefersReducedMotion() && (toX === void 0 || Math.abs(toX - fromX) >= 1)) {
726
+ const keys = [...itemsRef.current, ...extraItemsRef.current].map(
727
+ (item) => item.key
728
+ );
729
+ const fallback = (keys.indexOf(activeKey) >= keys.indexOf(from) ? 1 : -1) * 28;
730
+ setIconMotion({
731
+ playing: false,
732
+ slide: {
733
+ from,
734
+ to: activeKey,
735
+ travel: toX === void 0 ? fallback : toX - fromX
736
+ }
737
+ });
738
+ return;
739
+ }
740
+ setIconMotion(
741
+ (current) => current.slide === null && !current.playing ? current : { slide: null, playing: false }
742
+ );
743
+ }
744
+ if (!iconSlide) recordIconPositions();
745
+ }, [activeKey, iconSlide]);
746
+ useEffect(() => {
747
+ if (!iconSlide) return;
748
+ const frame = requestAnimationFrame(() => {
749
+ setIconMotion(
750
+ (current) => current.slide ? { slide: current.slide, playing: true } : current
751
+ );
752
+ });
753
+ const timeout = setTimeout(() => {
754
+ setIconMotion({ slide: null, playing: false });
755
+ }, ICON_SLIDE_MS + 40);
756
+ return () => {
757
+ cancelAnimationFrame(frame);
758
+ clearTimeout(timeout);
759
+ };
760
+ }, [iconSlide]);
761
+ const resolvedLogo = typeof logo === "function" ? logo({ isDark }) : logo ?? null;
762
+ const handlePress = (item) => {
763
+ setOpenKey(null);
764
+ item.onPress?.();
765
+ onItemClick?.(item);
766
+ };
767
+ const renderPoint = (item) => /* @__PURE__ */ React3.createElement(
768
+ NavPoint,
769
+ {
770
+ key: item.key,
771
+ item,
772
+ isActive: item.key === activeKey,
773
+ isOpen: openKey === item.key,
774
+ iconSlide,
775
+ iconPlaying,
776
+ registerAnchor,
777
+ theme,
778
+ themeMode,
779
+ themeProductContext,
780
+ onOpenChange: (open) => setOpenKey(open ? item.key : null),
781
+ onPress: () => handlePress(item),
782
+ onSelect: handlePress,
783
+ linkComponent
784
+ }
785
+ );
786
+ const menu = showMenu && (items.length > 0 || extraItems.length > 0) ? /* @__PURE__ */ React3.createElement(
787
+ Box,
788
+ {
789
+ as: "nav",
790
+ "aria-label": ariaLabel,
791
+ flexDirection: "row",
792
+ alignItems: "center",
793
+ flexShrink: 1,
794
+ minWidth: 0,
795
+ gap: MENU_GAP,
796
+ testID: "top-navigation-menu"
797
+ },
798
+ items.map(renderPoint),
799
+ items.length > 0 && extraItems.length > 0 && /* @__PURE__ */ React3.createElement(
800
+ Box,
801
+ {
802
+ role: "separator",
803
+ "aria-orientation": "vertical",
804
+ width: 1,
805
+ height: MENU_DIVIDER_HEIGHT,
806
+ backgroundColor: theme.colors.border.secondary,
807
+ testID: "top-navigation-menu-divider"
808
+ }
809
+ ),
810
+ extraItems.map(renderPoint)
811
+ ) : null;
812
+ const account = showAccount && (currencies && currencies.length > 0 || user) ? /* @__PURE__ */ React3.createElement(
813
+ Box,
814
+ {
815
+ flexDirection: "row",
816
+ alignItems: "center",
817
+ flexShrink: 0,
818
+ gap: ACCOUNT_GAP,
819
+ testID: "top-navigation-account"
820
+ },
821
+ currencies && currencies.length > 0 && /* @__PURE__ */ React3.createElement(Currencies, { currencies, theme }),
822
+ user && /* @__PURE__ */ React3.createElement(
823
+ AccountAvatar,
824
+ {
825
+ user,
826
+ themeMode,
827
+ themeProductContext
828
+ }
829
+ )
830
+ ) : null;
831
+ const windowsTrail = isWindows && (onBack || breadcrumbs.length > 0) ? /* @__PURE__ */ React3.createElement(
832
+ Box,
833
+ {
834
+ flexDirection: "row",
835
+ alignItems: "center",
836
+ gap: 4,
837
+ paddingVertical: 2,
838
+ testID: "top-navigation-windows-trail"
839
+ },
840
+ onBack && /* @__PURE__ */ React3.createElement(
841
+ Box,
842
+ {
843
+ as: "button",
844
+ type: "button",
845
+ "aria-label": "Go back",
846
+ cursor: "pointer",
847
+ onPress: onBack,
848
+ testID: "top-navigation-back"
849
+ },
850
+ /* @__PURE__ */ React3.createElement(
851
+ ArrowLeft,
852
+ {
853
+ size: BACK_ICON_SIZE,
854
+ color: theme.colors.content.primary,
855
+ "aria-hidden": true
856
+ }
857
+ )
858
+ ),
859
+ breadcrumbs.length > 0 && /* @__PURE__ */ React3.createElement(
860
+ Breadcrumbs,
861
+ {
862
+ size: "md",
863
+ items: breadcrumbs.map((crumb) => ({
864
+ label: crumb.label,
865
+ href: crumb.href,
866
+ onClick: crumb.onPress
867
+ })),
868
+ testID: "top-navigation-breadcrumbs",
869
+ themeMode,
870
+ themeProductContext
871
+ }
872
+ )
873
+ ) : null;
874
+ return /* @__PURE__ */ React3.createElement(
875
+ Box,
876
+ {
877
+ as: "header",
878
+ width: "100%",
879
+ minWidth: 0,
880
+ maxWidth: 2560,
881
+ flex: 1,
882
+ height: BAR_HEIGHT,
883
+ flexDirection: "row",
884
+ alignItems: "center",
885
+ paddingVertical: BAR_PADDING_VERTICAL,
886
+ backgroundColor: theme.colors.background.secondary,
887
+ "data-platform": platform,
888
+ testID: testID || "top-navigation"
889
+ },
890
+ (resolvedLogo || windowsTrail) && /* @__PURE__ */ React3.createElement(
891
+ Box,
892
+ {
893
+ flexShrink: windowsTrail ? 1 : 0,
894
+ minWidth: windowsTrail ? 0 : void 0,
895
+ flexDirection: "row",
896
+ alignItems: "center",
897
+ gap: windowsTrail ? WINDOWS_LOGO_GAP : 0
898
+ },
899
+ resolvedLogo && /* @__PURE__ */ React3.createElement(
900
+ Box,
901
+ {
902
+ height: LOGO_HEIGHT,
903
+ justifyContent: "center",
904
+ flexShrink: 0,
905
+ testID: "top-navigation-logo"
906
+ },
907
+ resolvedLogo
908
+ ),
909
+ windowsTrail && /* @__PURE__ */ React3.createElement(Box, { flexShrink: 1, minWidth: 0, overflow: "hidden" }, windowsTrail)
910
+ ),
911
+ /* @__PURE__ */ React3.createElement(
912
+ Box,
913
+ {
914
+ flexDirection: "row",
915
+ alignItems: "center",
916
+ justifyContent: "flex-end",
917
+ gap: CLUSTER_GAP,
918
+ flexShrink: 1,
919
+ minWidth: 0,
920
+ overflow: "hidden",
921
+ marginLeft: "auto"
922
+ },
923
+ menu,
924
+ account,
925
+ isWindows && windowControls && /* @__PURE__ */ React3.createElement(
926
+ WindowControls,
927
+ {
928
+ controls: windowControls,
929
+ themeMode,
930
+ themeProductContext
931
+ }
932
+ )
933
+ )
934
+ );
935
+ };
936
+ TopNavigation.displayName = "TopNavigation";
937
+ export {
938
+ TopNavigation
939
+ };
940
+ //# sourceMappingURL=index.mjs.map