@flamingo-stack/openframe-frontend-core 0.0.705 → 0.0.706-snapshot.20261006190707
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-4KX6OED2.cjs → chunk-2G7UYK35.cjs} +46 -46
- package/dist/{chunk-KOWVJD4V.cjs → chunk-2KXTOP6G.cjs} +70 -57
- package/dist/{chunk-A75QY6CD.cjs → chunk-2RNB5DTN.cjs} +21 -21
- package/dist/{chunk-PN2RKPDF.js → chunk-36BCTE7D.js} +10 -10
- package/dist/{chunk-ZSAGLQOD.cjs → chunk-3AHTOSXJ.cjs} +17 -17
- package/dist/{chunk-VR2ZLFCP.js → chunk-4IBPRIQH.js} +1 -1
- package/dist/{chunk-FCGC42TS.js → chunk-4L6XCMOU.js} +66 -62
- package/dist/{chunk-X5MQ7JRP.js → chunk-4UM2ETLM.js} +9 -9
- package/dist/{chunk-6NJKKO73.cjs → chunk-6I4ZAFO2.cjs} +15 -15
- package/dist/{chunk-RBDP4WDE.js → chunk-6IW7TWPV.js} +6 -6
- package/dist/{chunk-MMOODW57.cjs → chunk-6NTPY5QA.cjs} +1887 -94
- package/dist/{chunk-QFXRPRFT.js → chunk-6YKAT7NV.js} +3 -3
- package/dist/{chunk-HPWWNJE7.cjs → chunk-AOWDNSTM.cjs} +89 -89
- package/dist/{chunk-IHERL5V4.cjs → chunk-B73373AG.cjs} +34 -34
- package/dist/{chunk-DENB2XJC.js → chunk-CNWOMQQJ.js} +2 -2
- package/dist/{chunk-MP2C3LJ4.js → chunk-CUME3VTQ.js} +1 -1
- package/dist/{chunk-PDWVPI3S.js → chunk-CZ7Y7UG4.js} +4 -72
- package/dist/{chunk-YHM5AWTT.js → chunk-CZSZSDD4.js} +6 -6
- package/dist/{chunk-F6I6XZMN.js → chunk-DA5UDTLG.js} +5 -5
- package/dist/{chunk-MFFCUVWG.js → chunk-F57ECE2I.js} +1 -1
- package/dist/{chunk-CH5232HV.js → chunk-FI6GMDO7.js} +2455 -662
- package/dist/{chunk-NDESEPW5.js → chunk-FXJ3WWUB.js} +68 -0
- package/dist/{chunk-G5A3PSPV.js → chunk-HDOYSEOJ.js} +1080 -691
- package/dist/{chunk-VA5T32XA.js → chunk-I3ST4PLM.js} +2 -2
- package/dist/{chunk-5HBHO5TB.js → chunk-JPG7OHEG.js} +1 -1
- package/dist/{chunk-YFBM2K6X.cjs → chunk-JRU2CXLB.cjs} +4 -4
- package/dist/{chunk-MKXO4Q5P.js → chunk-KUC673HM.js} +383 -142
- package/dist/{chunk-JEZKGCZI.cjs → chunk-L6Y6OOKG.cjs} +26 -26
- package/dist/{chunk-F6AFPNDF.js → chunk-LFFB6EMB.js} +29 -16
- package/dist/{chunk-X72J4ACL.cjs → chunk-LLSUVPQC.cjs} +252 -8
- package/dist/{chunk-RKV5B7EU.cjs → chunk-LM7TXMLU.cjs} +72 -4
- package/dist/{chunk-6SEANMOU.js → chunk-LNW45N2C.js} +11 -11
- package/dist/{chunk-OUY3HHW6.cjs → chunk-LRQTJOF2.cjs} +928 -539
- package/dist/{chunk-DW7G4KG3.js → chunk-MR3A4MZV.js} +3 -3
- package/dist/{chunk-2YXVWZVF.js → chunk-N45D4ZXQ.js} +959 -715
- package/dist/{chunk-Z2VNQQ74.js → chunk-NCPTID44.js} +978 -942
- package/dist/{chunk-WA6GUYQ4.cjs → chunk-NSGXARGJ.cjs} +104 -104
- package/dist/{chunk-ABU3TGXA.cjs → chunk-OF6GEI5A.cjs} +3 -3
- package/dist/{chunk-IKTQ3ZAG.cjs → chunk-OJLR5MEO.cjs} +6 -6
- package/dist/{chunk-VESKITRQ.cjs → chunk-P42V6N34.cjs} +736 -732
- package/dist/{chunk-OHFS7VOU.cjs → chunk-PLYEKV3N.cjs} +2 -2
- package/dist/{chunk-7VVFKJY5.js → chunk-PO33GZVY.js} +1799 -3449
- package/dist/{chunk-7LS22BZU.cjs → chunk-QAOFMK2A.cjs} +14 -14
- package/dist/{chunk-VHCACDKP.cjs → chunk-RQRX4YC3.cjs} +39 -39
- package/dist/{chunk-3MX5S4CF.cjs → chunk-SEXWHIMS.cjs} +899 -2549
- package/dist/{chunk-AQWZNP6A.js → chunk-SS5MBHDP.js} +4 -4
- package/dist/{chunk-ZSAO2HBW.js → chunk-TDYIREDJ.js} +15 -15
- package/dist/{chunk-XOYH2YQE.cjs → chunk-UDFRUKLC.cjs} +2 -2
- package/dist/{chunk-TYWLNCNH.cjs → chunk-UVTD52MD.cjs} +14 -82
- package/dist/{chunk-N3COXDBH.cjs → chunk-VX4E6YSB.cjs} +41 -5
- package/dist/{chunk-2QEUFXNS.cjs → chunk-WCVZCGK5.cjs} +312 -71
- package/dist/{chunk-6XIF2Z7I.js → chunk-WMX26HB5.js} +3 -3
- package/dist/{chunk-D7BTSVMS.cjs → chunk-Y2GSOUCS.cjs} +2 -2
- package/dist/{chunk-4I45Y3DN.cjs → chunk-YBUT4AMG.cjs} +6 -6
- package/dist/components/case-studies/index.cjs +30 -32
- package/dist/components/case-studies/index.js +14 -16
- package/dist/components/chat/entity-cards/case-study-card.d.ts +11 -4
- package/dist/components/chat/entity-cards/case-study-card.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +11 -11
- package/dist/components/chat/index.d.ts +1 -1
- package/dist/components/chat/index.d.ts.map +1 -1
- package/dist/components/chat/index.js +16 -16
- package/dist/components/chat/nav-link-anchor-via-runtime.d.ts +34 -5
- package/dist/components/chat/nav-link-anchor-via-runtime.d.ts.map +1 -1
- package/dist/components/chat/utils/icon-library.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +12 -14
- package/dist/components/contact/index.js +11 -13
- package/dist/components/docs/index.cjs +15 -17
- package/dist/components/docs/index.js +14 -16
- package/dist/components/embeds/index.cjs +12 -14
- package/dist/components/embeds/index.js +11 -13
- package/dist/components/faq/index.cjs +13 -15
- package/dist/components/faq/index.js +12 -14
- package/dist/components/features/index.cjs +12 -14
- package/dist/components/features/index.js +21 -23
- package/dist/components/help-center-pages/index.cjs +118 -120
- package/dist/components/help-center-pages/index.js +33 -35
- package/dist/components/icons/index.cjs +3 -5
- package/dist/components/icons/index.js +9 -11
- package/dist/components/icons-v2-generated/index.cjs +3 -5
- package/dist/components/icons-v2-generated/index.js +2 -4
- package/dist/components/index.cjs +87 -158
- package/dist/components/index.d.ts +0 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +331 -402
- package/dist/components/loading/page-layout-skeleton.d.ts +1 -1
- package/dist/components/meeting-scheduler/index.cjs +62 -64
- package/dist/components/meeting-scheduler/index.js +12 -14
- package/dist/components/navigation/index.cjs +28 -16
- package/dist/components/navigation/index.d.ts +14 -10
- package/dist/components/navigation/index.d.ts.map +1 -1
- package/dist/components/navigation/index.js +38 -26
- package/dist/components/navigation/mingo-ai-button.d.ts +38 -3
- package/dist/components/navigation/mingo-ai-button.d.ts.map +1 -1
- package/dist/components/navigation/mobile-nav-sheet-id.d.ts +3 -0
- package/dist/components/navigation/mobile-nav-sheet-id.d.ts.map +1 -0
- package/dist/components/navigation/mobile-nav-sheet.d.ts +48 -0
- package/dist/components/navigation/mobile-nav-sheet.d.ts.map +1 -0
- package/dist/components/navigation/nav-item-row.d.ts +27 -0
- package/dist/components/navigation/nav-item-row.d.ts.map +1 -0
- package/dist/components/navigation/nav-panel.d.ts +43 -0
- package/dist/components/navigation/nav-panel.d.ts.map +1 -0
- package/dist/components/navigation/navigation-sidebar-item.d.ts +1 -2
- package/dist/components/navigation/navigation-sidebar-item.d.ts.map +1 -1
- package/dist/components/navigation/site-footer.d.ts +28 -0
- package/dist/components/navigation/site-footer.d.ts.map +1 -0
- package/dist/components/navigation/site-header.d.ts +61 -0
- package/dist/components/navigation/site-header.d.ts.map +1 -0
- package/dist/components/navigation/site-nav-link.d.ts +26 -0
- package/dist/components/navigation/site-nav-link.d.ts.map +1 -0
- package/dist/components/navigation/top-navigation.d.ts +2 -2
- package/dist/components/navigation/top-navigation.d.ts.map +1 -1
- package/dist/components/onboarding-guides/index.cjs +15 -17
- package/dist/components/onboarding-guides/index.js +14 -16
- package/dist/components/platform/ToolBadge.d.ts +6 -0
- package/dist/components/platform/ToolBadge.d.ts.map +1 -1
- package/dist/components/related-content/index.cjs +10 -8
- package/dist/components/related-content/index.js +9 -7
- package/dist/components/tickets/index.cjs +16 -18
- package/dist/components/tickets/index.js +15 -17
- package/dist/components/ui/brand-association-card.d.ts +7 -0
- package/dist/components/ui/brand-association-card.d.ts.map +1 -1
- package/dist/components/ui/index.cjs +14 -14
- package/dist/components/ui/index.js +19 -19
- package/dist/hooks/index.cjs +19 -11
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +19 -11
- package/dist/hooks/ui/index.d.ts +3 -0
- package/dist/hooks/ui/index.d.ts.map +1 -1
- package/dist/hooks/ui/use-active-section.d.ts +10 -0
- package/dist/hooks/ui/use-active-section.d.ts.map +1 -0
- package/dist/hooks/ui/use-nav-menus.d.ts +48 -0
- package/dist/hooks/ui/use-nav-menus.d.ts.map +1 -0
- package/dist/hooks/ui/use-visitor-os.d.ts +15 -0
- package/dist/hooks/ui/use-visitor-os.d.ts.map +1 -0
- package/dist/hooks/use-location-hash.d.ts +9 -0
- package/dist/hooks/use-location-hash.d.ts.map +1 -0
- package/dist/index.cjs +56 -21
- package/dist/index.js +231 -196
- package/dist/types/case-study.d.ts +9 -0
- package/dist/types/case-study.d.ts.map +1 -1
- package/dist/types/navigation.d.ts +95 -65
- package/dist/types/navigation.d.ts.map +1 -1
- package/dist/utils/index.cjs +55 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +50 -1
- package/dist/utils/source-icons.d.ts.map +1 -1
- package/dist/utils/visitor-os.d.ts +45 -0
- package/dist/utils/visitor-os.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/chat/entity-cards/case-study-card.tsx +115 -5
- package/src/components/chat/index.ts +7 -1
- package/src/components/chat/nav-link-anchor-via-runtime.tsx +62 -9
- package/src/components/chat/utils/icon-library.tsx +35 -1
- package/src/components/index.ts +0 -2
- package/src/components/loading/page-layout-skeleton.tsx +1 -1
- package/src/components/navigation/index.ts +21 -14
- package/src/components/navigation/mingo-ai-button.tsx +139 -63
- package/src/components/navigation/mobile-nav-sheet-id.ts +2 -0
- package/src/components/navigation/mobile-nav-sheet.tsx +241 -0
- package/src/components/navigation/nav-item-row.tsx +129 -0
- package/src/components/navigation/nav-panel.tsx +196 -0
- package/src/components/navigation/navigation-sidebar-item.tsx +1 -2
- package/src/components/navigation/site-footer.tsx +256 -0
- package/src/components/navigation/site-header.tsx +339 -0
- package/src/components/navigation/site-nav-link.tsx +41 -0
- package/src/components/navigation/ticket-alerts-button.tsx +2 -2
- package/src/components/navigation/top-navigation.tsx +2 -2
- package/src/components/platform/ToolBadge.tsx +18 -1
- package/src/components/ui/brand-association-card.tsx +25 -3
- package/src/hooks/index.ts +1 -0
- package/src/hooks/ui/index.ts +3 -0
- package/src/hooks/ui/use-active-section.ts +44 -0
- package/src/hooks/ui/use-nav-menus.ts +200 -0
- package/src/hooks/ui/use-visitor-os.ts +33 -0
- package/src/hooks/use-location-hash.ts +34 -0
- package/src/styles/chat-animations.css +57 -2
- package/src/types/case-study.ts +16 -0
- package/src/types/navigation.ts +80 -66
- package/src/utils/index.ts +1 -0
- package/src/utils/source-icons.ts +13 -0
- package/src/utils/visitor-os.ts +84 -0
- package/dist/chunk-LMBC5FFP.js +0 -43
- package/dist/chunk-O43V3EOS.js +0 -252
- package/dist/chunk-QZVSJF2K.cjs +0 -252
- package/dist/chunk-RALRPFDW.cjs +0 -43
- package/dist/components/footer-waitlist-button.d.ts +0 -29
- package/dist/components/footer-waitlist-button.d.ts.map +0 -1
- package/dist/components/footer.d.ts +0 -47
- package/dist/components/footer.d.ts.map +0 -1
- package/dist/components/navigation/client-only-header.d.ts +0 -8
- package/dist/components/navigation/client-only-header.d.ts.map +0 -1
- package/dist/components/navigation/header-skeleton.d.ts +0 -12
- package/dist/components/navigation/header-skeleton.d.ts.map +0 -1
- package/dist/components/navigation/header.d.ts +0 -9
- package/dist/components/navigation/header.d.ts.map +0 -1
- package/dist/components/navigation/mobile-nav-panel.d.ts +0 -10
- package/dist/components/navigation/mobile-nav-panel.d.ts.map +0 -1
- package/src/components/footer-waitlist-button.tsx +0 -53
- package/src/components/footer.tsx +0 -195
- package/src/components/navigation/client-only-header.tsx +0 -22
- package/src/components/navigation/header-skeleton.tsx +0 -74
- package/src/components/navigation/header.tsx +0 -429
- package/src/components/navigation/mobile-nav-panel.tsx +0 -155
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import type React from 'react';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import Link from '../../embed-shims/next-link';
|
|
6
|
+
import { useActiveSection } from '../../hooks/ui/use-active-section';
|
|
7
|
+
import { useNavMenus } from '../../hooks/ui/use-nav-menus';
|
|
8
|
+
import type { NavMenu, SiteNav } from '../../types/navigation';
|
|
9
|
+
import { cn } from '../../utils/cn';
|
|
10
|
+
import { EntityIcon } from '../icon-display';
|
|
11
|
+
import { Chevron02DownIcon } from '../icons-v2-generated/arrows/chevron-02-down-icon';
|
|
12
|
+
import { Menu01Icon } from '../icons-v2-generated/interface/menu-01-icon';
|
|
13
|
+
import { XmarkIcon } from '../icons-v2-generated/signs-and-symbols/xmark-icon';
|
|
14
|
+
import { Button } from '../ui/button';
|
|
15
|
+
import { HeaderButton } from './header-button';
|
|
16
|
+
import { MingoAiButton } from './mingo-ai-button';
|
|
17
|
+
import { MOBILE_NAV_SHEET_ID } from './mobile-nav-sheet-id';
|
|
18
|
+
import { isMegaMenu, NavPanel, type NavPanelMotion } from './nav-panel';
|
|
19
|
+
import { defaultRenderSiteNavLink, NAV_FOCUS_CLASS, type SiteNavLinkRenderer } from './site-nav-link';
|
|
20
|
+
import { TopNavigation } from './top-navigation';
|
|
21
|
+
|
|
22
|
+
export interface SiteHeaderProps {
|
|
23
|
+
nav: SiteNav;
|
|
24
|
+
/** The host router's pathname: marks the active section and closes menus on navigation. */
|
|
25
|
+
pathname: string;
|
|
26
|
+
logo: React.ReactNode;
|
|
27
|
+
/** Omitted: the logo is not a link. */
|
|
28
|
+
logoHref?: string;
|
|
29
|
+
/** The host's link (Next `Link`, unified navigation). Default: `<a>`. */
|
|
30
|
+
renderLink?: SiteNavLinkRenderer;
|
|
31
|
+
/** Leading cells (admin sidebar toggle). Each cell owns its divider. */
|
|
32
|
+
leading?: React.ReactNode;
|
|
33
|
+
/** Host actions at the right (profile button, custom buttons). Shown at every width. */
|
|
34
|
+
actions?: React.ReactNode;
|
|
35
|
+
/** The primary CTA node when `nav.primaryCta` is `'trial'` or `'waitlist'`. */
|
|
36
|
+
cta?: React.ReactNode;
|
|
37
|
+
/** Trailing cells (ticket alerts). Each cell owns its divider. */
|
|
38
|
+
sideActions?: React.ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* The Mingo AI launcher, first in the right cluster (before Sign in).
|
|
41
|
+
* Omitted: no launcher. `icon` and `label` are the server-configured
|
|
42
|
+
* assistant identity (the same ones the chat panel shows); `source` scopes
|
|
43
|
+
* the `ask-ai:open` event the launcher dispatches.
|
|
44
|
+
*/
|
|
45
|
+
mingo?: { source?: string; icon?: React.ReactNode; label?: string; shortcutHint?: boolean };
|
|
46
|
+
/** Omitted: no burger. */
|
|
47
|
+
mobile?: { isOpen: boolean; onToggle: () => void; controlsId?: string };
|
|
48
|
+
/** Values for `NavLink.badgeKey`. */
|
|
49
|
+
badges?: Record<string, number>;
|
|
50
|
+
/** Rendered under a menu with `showSocial`. */
|
|
51
|
+
social?: React.ReactNode;
|
|
52
|
+
autoHide?: boolean;
|
|
53
|
+
/** Opaque ODS background class. */
|
|
54
|
+
backgroundClassName?: string;
|
|
55
|
+
className?: string;
|
|
56
|
+
style?: React.CSSProperties;
|
|
57
|
+
/** The id the "Skip to content" link targets. Default `main-content`. */
|
|
58
|
+
skipToContentId?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// A top-level item (prototype `.nv-l`): 40px tall, quiet until hovered, open
|
|
62
|
+
// or current.
|
|
63
|
+
const TOP_ITEM_CLASS =
|
|
64
|
+
'relative inline-flex h-10 items-center gap-1.5 whitespace-nowrap rounded-md px-3.5 text-ods-text-secondary transition-colors text-h6 hover:bg-ods-bg-hover hover:text-ods-text-primary';
|
|
65
|
+
// The current section: a 2px accent underline and an accent wash.
|
|
66
|
+
const TOP_ITEM_CURRENT_CLASS =
|
|
67
|
+
'rounded-b-none bg-gradient-to-b from-transparent to-ods-accent/10 text-ods-text-primary after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:bg-ods-accent';
|
|
68
|
+
|
|
69
|
+
/** A top-level item's optional glyph (`NavMenu.iconName`), before its label. */
|
|
70
|
+
const menuIcon = (menu: NavMenu) =>
|
|
71
|
+
menu.iconName ? <EntityIcon icon={{ name: menu.iconName }} size={20} className="size-5 shrink-0" /> : null;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The site header of every platform, drawn from one `SiteNav`: logo, the
|
|
75
|
+
* menus left-aligned after it, then the Mingo AI launcher, Sign in, the host's
|
|
76
|
+
* actions, the primary CTA (the only button) and the trailing cells. A
|
|
77
|
+
* platform differs only in the data and the slots it passes.
|
|
78
|
+
*
|
|
79
|
+
* Below `lg` the menus and Sign in leave the bar (they live in
|
|
80
|
+
* `MobileNavSheet`); the host's actions, the CTA and the launcher stay.
|
|
81
|
+
*/
|
|
82
|
+
export function SiteHeader({
|
|
83
|
+
nav,
|
|
84
|
+
pathname,
|
|
85
|
+
logo,
|
|
86
|
+
logoHref,
|
|
87
|
+
renderLink = defaultRenderSiteNavLink,
|
|
88
|
+
leading,
|
|
89
|
+
actions,
|
|
90
|
+
cta,
|
|
91
|
+
sideActions,
|
|
92
|
+
mingo,
|
|
93
|
+
mobile,
|
|
94
|
+
badges,
|
|
95
|
+
social,
|
|
96
|
+
autoHide = false,
|
|
97
|
+
backgroundClassName,
|
|
98
|
+
className,
|
|
99
|
+
style,
|
|
100
|
+
skipToContentId = 'main-content',
|
|
101
|
+
}: SiteHeaderProps) {
|
|
102
|
+
const [show, setShow] = useState(true);
|
|
103
|
+
// Not state: nothing renders the previous offset, and as `useState` it
|
|
104
|
+
// re-rendered the whole header on every scroll event just to store a number.
|
|
105
|
+
const lastScrollY = useRef(0);
|
|
106
|
+
|
|
107
|
+
const activeId = useActiveSection(nav.menus, pathname);
|
|
108
|
+
const { openId, close, getTriggerProps, getPanelProps } = useNavMenus({ pathname });
|
|
109
|
+
|
|
110
|
+
// The menu that was open before this one, kept during render (no effect, no
|
|
111
|
+
// late frame): it tells an opening mega menu which side its content comes from.
|
|
112
|
+
const [trail, setTrail] = useState<{ id: string | null; from: string | null }>({ id: null, from: null });
|
|
113
|
+
if (trail.id !== openId) setTrail({ id: openId, from: trail.id });
|
|
114
|
+
const previousId = trail.id === openId ? trail.from : trail.id;
|
|
115
|
+
const megaIds = nav.menus.filter(isMegaMenu).map(menu => menu.id);
|
|
116
|
+
const openMegaIndex = openId === null ? -1 : megaIds.indexOf(openId);
|
|
117
|
+
const previousMegaIndex = previousId === null ? -1 : megaIds.indexOf(previousId);
|
|
118
|
+
const megaMotion: NavPanelMotion =
|
|
119
|
+
openMegaIndex < 0 || previousMegaIndex < 0 ? 'open' : openMegaIndex > previousMegaIndex ? 'from-end' : 'from-start';
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
// Only add the scroll listener while auto-hide is on. Nothing to reset
|
|
123
|
+
// here: `show` is masked by `autoHide` where it is read (`headerShown`), so
|
|
124
|
+
// turning auto-hide off can never leave the header stuck off-screen.
|
|
125
|
+
if (!autoHide) return undefined;
|
|
126
|
+
|
|
127
|
+
const handleScroll = () => {
|
|
128
|
+
const currentScrollY = window.scrollY;
|
|
129
|
+
const prevScrollY = lastScrollY.current;
|
|
130
|
+
lastScrollY.current = currentScrollY;
|
|
131
|
+
|
|
132
|
+
if (currentScrollY > prevScrollY && currentScrollY > 50) setShow(false);
|
|
133
|
+
else if (currentScrollY < prevScrollY || currentScrollY <= 10) setShow(true);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
137
|
+
return () => window.removeEventListener('scroll', handleScroll);
|
|
138
|
+
}, [autoHide]);
|
|
139
|
+
|
|
140
|
+
// An open menu holds the header in place: hiding the bar would take the
|
|
141
|
+
// panel the visitor is reading with it.
|
|
142
|
+
const headerShown = !autoHide || show || openId !== null;
|
|
143
|
+
|
|
144
|
+
const renderMenu = (menu: NavMenu) => {
|
|
145
|
+
const current = menu.id === activeId;
|
|
146
|
+
const hasPanel = !!menu.columns?.length || !!menu.features?.length || !!menu.sideLinks?.length;
|
|
147
|
+
|
|
148
|
+
if (!hasPanel) {
|
|
149
|
+
if (!menu.href) return null;
|
|
150
|
+
return (
|
|
151
|
+
<div key={menu.id} className="flex">
|
|
152
|
+
<Button
|
|
153
|
+
asChild
|
|
154
|
+
variant="transparent"
|
|
155
|
+
size="wrap"
|
|
156
|
+
font="regular"
|
|
157
|
+
className={cn(TOP_ITEM_CLASS, NAV_FOCUS_CLASS, current && TOP_ITEM_CURRENT_CLASS)}
|
|
158
|
+
>
|
|
159
|
+
{renderLink({
|
|
160
|
+
link: { href: menu.href },
|
|
161
|
+
'aria-current': current ? 'page' : undefined,
|
|
162
|
+
children: (
|
|
163
|
+
<>
|
|
164
|
+
{menuIcon(menu)}
|
|
165
|
+
{menu.label}
|
|
166
|
+
</>
|
|
167
|
+
),
|
|
168
|
+
})}
|
|
169
|
+
</Button>
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const open = openId === menu.id;
|
|
175
|
+
return (
|
|
176
|
+
// A dropdown is anchored to its trigger (`relative`); a mega menu to the
|
|
177
|
+
// bar itself, so its wrapper stays unpositioned.
|
|
178
|
+
<div key={menu.id} className={cn('flex', !isMegaMenu(menu) && 'relative')}>
|
|
179
|
+
<Button
|
|
180
|
+
type="button"
|
|
181
|
+
variant="transparent"
|
|
182
|
+
size="wrap"
|
|
183
|
+
font="regular"
|
|
184
|
+
{...getTriggerProps(menu.id)}
|
|
185
|
+
aria-current={current ? 'page' : undefined}
|
|
186
|
+
className={cn(
|
|
187
|
+
TOP_ITEM_CLASS,
|
|
188
|
+
NAV_FOCUS_CLASS,
|
|
189
|
+
open && 'bg-ods-bg-hover text-ods-text-primary',
|
|
190
|
+
current && TOP_ITEM_CURRENT_CLASS,
|
|
191
|
+
)}
|
|
192
|
+
>
|
|
193
|
+
{menuIcon(menu)}
|
|
194
|
+
{menu.label}
|
|
195
|
+
<Chevron02DownIcon
|
|
196
|
+
aria-hidden="true"
|
|
197
|
+
// `!`: the Button sizes every glyph inside it at 20px; the chevron is 16.
|
|
198
|
+
className={cn('!h-4 !w-4 transition-transform duration-150', open && 'rotate-180')}
|
|
199
|
+
/>
|
|
200
|
+
</Button>
|
|
201
|
+
<NavPanel
|
|
202
|
+
{...getPanelProps(menu.id)}
|
|
203
|
+
menu={menu}
|
|
204
|
+
open={open}
|
|
205
|
+
motion={open ? megaMotion : undefined}
|
|
206
|
+
handoff={openMegaIndex >= 0}
|
|
207
|
+
renderLink={renderLink}
|
|
208
|
+
badges={badges}
|
|
209
|
+
social={social}
|
|
210
|
+
onNavigate={close}
|
|
211
|
+
/>
|
|
212
|
+
</div>
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const primaryCta =
|
|
217
|
+
typeof nav.primaryCta === 'object' ? (
|
|
218
|
+
<Button variant="accent" href={nav.primaryCta.href}>
|
|
219
|
+
{nav.primaryCta.label}
|
|
220
|
+
</Button>
|
|
221
|
+
) : nav.primaryCta === 'none' ? null : (
|
|
222
|
+
(cta ?? null)
|
|
223
|
+
);
|
|
224
|
+
const hasRight = !!mingo || !!nav.signIn || !!actions || !!primaryCta;
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<div
|
|
228
|
+
// Hook point for page-scoped header CSS (a full-screen deck hides the bar).
|
|
229
|
+
data-site-header=""
|
|
230
|
+
className="sticky top-0 z-[50] w-full transition-transform duration-300 ease-in-out"
|
|
231
|
+
style={{ transform: headerShown ? 'translateY(0)' : 'translateY(-100%)' }}
|
|
232
|
+
>
|
|
233
|
+
{/* First tab stop of the page; visible only while focused. */}
|
|
234
|
+
<Link
|
|
235
|
+
href={`#${skipToContentId}`}
|
|
236
|
+
className={cn(
|
|
237
|
+
'sr-only left-[var(--spacing-system-lf)] top-3 z-[70] rounded-md bg-ods-text-primary px-[var(--spacing-system-mf)] py-[var(--spacing-system-xsf)] text-ods-bg text-h6 focus:not-sr-only focus:absolute',
|
|
238
|
+
NAV_FOCUS_CLASS,
|
|
239
|
+
)}
|
|
240
|
+
>
|
|
241
|
+
Skip to content
|
|
242
|
+
</Link>
|
|
243
|
+
{/* Unified ODS top-navigation shell (Figma 2797-5978), cell model with
|
|
244
|
+
per-cell dividers. NOTE: no `backdrop-blur` anywhere in this bar.
|
|
245
|
+
Every platform ships an OPAQUE header background, so a
|
|
246
|
+
backdrop-filter would blur a backdrop that is then fully painted
|
|
247
|
+
over: zero visual effect, but the browser still re-rasterizes the
|
|
248
|
+
strip behind this sticky bar every scroll frame and content flickers
|
|
249
|
+
as it passes under the header. A translucent "glass" header needs
|
|
250
|
+
the blur and a translucent `backgroundClassName` together. */}
|
|
251
|
+
<TopNavigation
|
|
252
|
+
// `relative` anchors a mega menu to the bar: it opens full width
|
|
253
|
+
// right under it.
|
|
254
|
+
className={cn('relative', className)}
|
|
255
|
+
style={style}
|
|
256
|
+
backgroundClassName={backgroundClassName}
|
|
257
|
+
centerBreakpoint="lg"
|
|
258
|
+
size="big"
|
|
259
|
+
leading={
|
|
260
|
+
<>
|
|
261
|
+
{leading}
|
|
262
|
+
{/* Menu toggle: a leading cell, banded with the menus' breakpoint
|
|
263
|
+
(`lg`) so the desktop menus and the toggle never co-show. */}
|
|
264
|
+
{mobile && (
|
|
265
|
+
<HeaderButton
|
|
266
|
+
className="border-r border-ods-border lg:hidden"
|
|
267
|
+
onClick={mobile.onToggle}
|
|
268
|
+
isActive={mobile.isOpen}
|
|
269
|
+
aria-label={mobile.isOpen ? 'Close menu' : 'Open menu'}
|
|
270
|
+
aria-expanded={mobile.isOpen}
|
|
271
|
+
// Conditional: the sheet unmounts when closed, so an
|
|
272
|
+
// unconditional reference would dangle (axe aria-valid-attr-value).
|
|
273
|
+
aria-controls={mobile.isOpen ? (mobile.controlsId ?? MOBILE_NAV_SHEET_ID) : undefined}
|
|
274
|
+
icon={mobile.isOpen ? <XmarkIcon className="h-6 w-6" /> : <Menu01Icon className="h-6 w-6" />}
|
|
275
|
+
/>
|
|
276
|
+
)}
|
|
277
|
+
</>
|
|
278
|
+
}
|
|
279
|
+
logo={
|
|
280
|
+
logoHref
|
|
281
|
+
? renderLink({
|
|
282
|
+
link: { href: logoHref },
|
|
283
|
+
className: cn(
|
|
284
|
+
'flex min-w-0 items-center rounded-md transition-opacity duration-200 hover:opacity-80',
|
|
285
|
+
NAV_FOCUS_CLASS,
|
|
286
|
+
),
|
|
287
|
+
'aria-label': nav.brand.name,
|
|
288
|
+
children: logo,
|
|
289
|
+
})
|
|
290
|
+
: logo
|
|
291
|
+
}
|
|
292
|
+
// Big-bar rule (Figma 2936-6812): a fixed 24px left inset on the logo
|
|
293
|
+
// zone at every breakpoint, which also reads as the gap between a
|
|
294
|
+
// leading cell and the logo. `shrink` lets the logo, never the CTA,
|
|
295
|
+
// give way on the narrowest phones.
|
|
296
|
+
logoClassName="shrink pl-[var(--spacing-system-lf)] md:pl-[var(--spacing-system-lf)] lg:pl-[var(--spacing-system-lf)]"
|
|
297
|
+
center={
|
|
298
|
+
nav.menus.length > 0 ? (
|
|
299
|
+
<nav aria-label="Main" className="flex items-center gap-[var(--spacing-system-xxs)]">
|
|
300
|
+
{nav.menus.map(renderMenu)}
|
|
301
|
+
</nav>
|
|
302
|
+
) : undefined
|
|
303
|
+
}
|
|
304
|
+
centerClassName="justify-start pl-[var(--spacing-system-xlf)]"
|
|
305
|
+
cta={
|
|
306
|
+
hasRight ? (
|
|
307
|
+
<>
|
|
308
|
+
{mingo && (
|
|
309
|
+
<MingoAiButton
|
|
310
|
+
source={mingo.source}
|
|
311
|
+
icon={mingo.icon}
|
|
312
|
+
label={mingo.label}
|
|
313
|
+
shortcutHint={mingo.shortcutHint}
|
|
314
|
+
/>
|
|
315
|
+
)}
|
|
316
|
+
{nav.signIn && (
|
|
317
|
+
<div className="hidden lg:flex">
|
|
318
|
+
<Button
|
|
319
|
+
asChild
|
|
320
|
+
variant="transparent"
|
|
321
|
+
size="wrap"
|
|
322
|
+
font="regular"
|
|
323
|
+
className={cn(TOP_ITEM_CLASS, NAV_FOCUS_CLASS)}
|
|
324
|
+
>
|
|
325
|
+
{renderLink({ link: nav.signIn, children: nav.signIn.label })}
|
|
326
|
+
</Button>
|
|
327
|
+
</div>
|
|
328
|
+
)}
|
|
329
|
+
{actions}
|
|
330
|
+
{primaryCta}
|
|
331
|
+
</>
|
|
332
|
+
) : undefined
|
|
333
|
+
}
|
|
334
|
+
ctaClassName="gap-[var(--spacing-system-xsf)]"
|
|
335
|
+
sideActions={sideActions}
|
|
336
|
+
/>
|
|
337
|
+
</div>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import Link from '../../embed-shims/next-link';
|
|
3
|
+
import type { NavLink } from '../../types/navigation';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* How a host renders one navigation link (Next `Link`, a unified-navigation
|
|
7
|
+
* anchor). Every site navigation component takes one; omitted, links go
|
|
8
|
+
* through {@link defaultRenderSiteNavLink}.
|
|
9
|
+
*/
|
|
10
|
+
export type SiteNavLinkRenderer = (props: {
|
|
11
|
+
link: Pick<NavLink, 'href' | 'external'>;
|
|
12
|
+
className?: string;
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
15
|
+
'aria-current'?: 'page';
|
|
16
|
+
'aria-label'?: string;
|
|
17
|
+
}) => React.ReactNode;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The default link: the library's `Link` shim (a plain `<a>`, or the host's
|
|
21
|
+
* registered router link, so internal links soft-navigate), opened in a new
|
|
22
|
+
* tab for a link that leaves the site.
|
|
23
|
+
*/
|
|
24
|
+
export const defaultRenderSiteNavLink: SiteNavLinkRenderer = ({ link, children, ...rest }) =>
|
|
25
|
+
link.external ? (
|
|
26
|
+
<Link href={link.href} target="_blank" rel="noopener noreferrer" {...rest}>
|
|
27
|
+
{children}
|
|
28
|
+
</Link>
|
|
29
|
+
) : (
|
|
30
|
+
<Link href={link.href} {...rest}>
|
|
31
|
+
{children}
|
|
32
|
+
</Link>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/** A link's label, with its `{count}` token filled from `link.count`. */
|
|
36
|
+
export function navLinkLabel(link: Pick<NavLink, 'label' | 'count'>): string {
|
|
37
|
+
return link.count === undefined ? link.label : link.label.replace('{count}', String(link.count));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Focus ring shared by every navigation link and trigger. */
|
|
41
|
+
export const NAV_FOCUS_CLASS = 'outline-none focus-visible:ring-2 focus-visible:ring-ods-accent';
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* TicketAlertsButton — the unified header affordance for support-ticket
|
|
5
|
-
* unread indication. Mounted by BOTH header shells (
|
|
6
|
-
* `
|
|
5
|
+
* unread indication. Mounted by BOTH header shells (the `SiteHeader` through its
|
|
6
|
+
* `sideActions` slot, console `AppHeader` via `showTicketAlerts`).
|
|
7
7
|
*
|
|
8
8
|
* ATTENTION-ONLY element, deliberately unlike the always-on header cells:
|
|
9
9
|
* - renders NOTHING unless there are unread support replies (and a
|
|
@@ -59,7 +59,7 @@ export interface TopNavigationProps extends React.HTMLAttributes<HTMLElement> {
|
|
|
59
59
|
sideActions?: React.ReactNode;
|
|
60
60
|
/** Opaque ODS background class. Defaults to `bg-ods-card`. Keep it opaque —
|
|
61
61
|
* translucent backgrounds under a sticky bar need a deliberate
|
|
62
|
-
* backdrop-blur treatment (see the note in `header.tsx`). */
|
|
62
|
+
* backdrop-blur treatment (see the note in `site-header.tsx`). */
|
|
63
63
|
backgroundClassName?: string;
|
|
64
64
|
/** Top border on mobile (the ODS spec bar shows it below md). Default true. */
|
|
65
65
|
mobileTopBorder?: boolean;
|
|
@@ -73,7 +73,7 @@ const hasContent = (node: React.ReactNode): boolean => node !== null && node !==
|
|
|
73
73
|
/**
|
|
74
74
|
* Unified ODS top-navigation bar (Figma `[UPD] top-navigation`, node
|
|
75
75
|
* 2797-5978): the single 48px/56px (mobile / md+) cell-based header shell
|
|
76
|
-
* shared by the console `AppHeader` and the
|
|
76
|
+
* shared by the console `AppHeader` and the `SiteHeader` across all
|
|
77
77
|
* platforms.
|
|
78
78
|
*
|
|
79
79
|
* The shell owns the bar geometry only — height, borders, background, and the
|
|
@@ -9,6 +9,7 @@ import type React from 'react';
|
|
|
9
9
|
import type { ToolType } from '../../types/tool.types';
|
|
10
10
|
import { cn } from '../../utils/cn';
|
|
11
11
|
import { getToolLabel } from '../../utils/tool-utils';
|
|
12
|
+
import { NavLinkAnchorViaRuntime } from '../chat/nav-link-anchor-via-runtime';
|
|
12
13
|
import { ToolIcon } from '../tool-icon';
|
|
13
14
|
|
|
14
15
|
export type { ToolType } from '../../types/tool.types';
|
|
@@ -31,6 +32,12 @@ export interface ToolBadgeProps {
|
|
|
31
32
|
* link that opens it in a new tab; without it the badge is plain text.
|
|
32
33
|
*/
|
|
33
34
|
href?: string | null;
|
|
35
|
+
/**
|
|
36
|
+
* The platform `href` is on, by name, when it is one of the host's own
|
|
37
|
+
* platforms. The badge then opens through the shared navigation rule (the
|
|
38
|
+
* one chat cards use); the host must mount the chat runtime.
|
|
39
|
+
*/
|
|
40
|
+
targetPlatform?: string | null;
|
|
34
41
|
/** Additional CSS classes */
|
|
35
42
|
className?: string;
|
|
36
43
|
iconClassName?: string;
|
|
@@ -47,6 +54,7 @@ export const ToolBadge: React.FC<ToolBadgeProps> = ({
|
|
|
47
54
|
icon,
|
|
48
55
|
variant = 'inline',
|
|
49
56
|
href,
|
|
57
|
+
targetPlatform,
|
|
50
58
|
className,
|
|
51
59
|
iconClassName,
|
|
52
60
|
}) => {
|
|
@@ -55,7 +63,16 @@ export const ToolBadge: React.FC<ToolBadgeProps> = ({
|
|
|
55
63
|
|
|
56
64
|
// One rule for both variants: with an `href` the badge is a link.
|
|
57
65
|
const linked = (node: React.ReactElement, linkClassName: string) =>
|
|
58
|
-
href ? (
|
|
66
|
+
href && targetPlatform ? (
|
|
67
|
+
<NavLinkAnchorViaRuntime
|
|
68
|
+
href={href}
|
|
69
|
+
targetPlatform={targetPlatform}
|
|
70
|
+
title={text || undefined}
|
|
71
|
+
className={linkClassName}
|
|
72
|
+
>
|
|
73
|
+
{node}
|
|
74
|
+
</NavLinkAnchorViaRuntime>
|
|
75
|
+
) : href ? (
|
|
59
76
|
<a href={href} target="_blank" rel="noopener noreferrer" title={text || undefined} className={linkClassName}>
|
|
60
77
|
{node}
|
|
61
78
|
</a>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { ExternalLink } from 'lucide-react';
|
|
4
4
|
import React from 'react';
|
|
5
|
+
import { useNavLinkViaRuntime } from '../chat/nav-link-anchor-via-runtime';
|
|
5
6
|
import { Button } from './button';
|
|
6
7
|
|
|
7
8
|
export interface BrandAssociationItem {
|
|
@@ -10,6 +11,13 @@ export interface BrandAssociationItem {
|
|
|
10
11
|
description: string;
|
|
11
12
|
buttonText: string;
|
|
12
13
|
link: string;
|
|
14
|
+
/**
|
|
15
|
+
* The platform `link` leads to, by name, when it is another of the host's
|
|
16
|
+
* own platforms. The button then opens it through the shared navigation rule
|
|
17
|
+
* (the one chat cards use); the host must mount the chat runtime. Omitted, it
|
|
18
|
+
* is a plain outside link in a new tab.
|
|
19
|
+
*/
|
|
20
|
+
targetPlatform?: string | null;
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
export interface BrandAssociationCardProps {
|
|
@@ -17,6 +25,16 @@ export interface BrandAssociationCardProps {
|
|
|
17
25
|
className?: string;
|
|
18
26
|
}
|
|
19
27
|
|
|
28
|
+
/** The button to a NAMED platform: the shared navigation rule decides how it opens. */
|
|
29
|
+
function PlatformBrowseButton({ item }: { item: BrandAssociationItem }) {
|
|
30
|
+
const linkProps = useNavLinkViaRuntime({ href: item.link, targetPlatform: item.targetPlatform });
|
|
31
|
+
return (
|
|
32
|
+
<Button variant="outline" linkProps={linkProps} rightIcon={<ExternalLink className="h-4 w-4" />}>
|
|
33
|
+
Browse {item.buttonText}
|
|
34
|
+
</Button>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
20
38
|
export function BrandAssociationCard({ item, className = '' }: BrandAssociationCardProps) {
|
|
21
39
|
// Helper function to render icon - handle both React elements and components
|
|
22
40
|
const renderIcon = () => {
|
|
@@ -43,9 +61,13 @@ export function BrandAssociationCard({ item, className = '' }: BrandAssociationC
|
|
|
43
61
|
<p className="text-ods-text-secondary text-h6">{item.description}</p>
|
|
44
62
|
|
|
45
63
|
{/* Browse Button */}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
{item.targetPlatform ? (
|
|
65
|
+
<PlatformBrowseButton item={item} />
|
|
66
|
+
) : (
|
|
67
|
+
<Button variant="outline" href={item.link} openInNewTab rightIcon={<ExternalLink className="h-4 w-4" />}>
|
|
68
|
+
Browse {item.buttonText}
|
|
69
|
+
</Button>
|
|
70
|
+
)}
|
|
49
71
|
</div>
|
|
50
72
|
</div>
|
|
51
73
|
);
|
package/src/hooks/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export * from './use-claude-mirror-src';
|
|
|
39
39
|
// Deep-link "scroll to URL hash" after data loads. Pairs with URL
|
|
40
40
|
// composers that emit `?<filter>=<id>#<prefix>-<id>` — the filter
|
|
41
41
|
// narrows the list, the hash scrolls the matching DOM id.
|
|
42
|
+
export * from './use-location-hash';
|
|
42
43
|
export * from './use-scroll-to-hash';
|
|
43
44
|
|
|
44
45
|
// Invisible bot-protection client primitive (honeypot ref + submit-timing).
|
package/src/hooks/ui/index.ts
CHANGED
|
@@ -31,3 +31,6 @@ export { usePreventScroll } from '@react-aria/overlays';
|
|
|
31
31
|
export * from './use-prefers-reduced-motion';
|
|
32
32
|
export * from './use-in-view';
|
|
33
33
|
export * from './use-autoplay';
|
|
34
|
+
export * from './use-active-section';
|
|
35
|
+
export * from './use-nav-menus';
|
|
36
|
+
export * from './use-visitor-os';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import type { NavMenu } from '../../types/navigation';
|
|
5
|
+
|
|
6
|
+
/** The path of an internal href, without its query or `#anchor`. `null` for an
|
|
7
|
+
* absolute URL: another site is never the current section. */
|
|
8
|
+
function pathOf(href: string | undefined): string | null {
|
|
9
|
+
if (!href || !href.startsWith('/') || href.startsWith('//')) return null;
|
|
10
|
+
const path = href.split(/[?#]/)[0];
|
|
11
|
+
return path.length > 1 ? path.replace(/\/+$/, '') : '/';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Boundary-aware prefix test: `/pricing` holds `/pricing` and `/pricing/x`,
|
|
15
|
+
* never `/pricing-old`; `/` holds only `/`. */
|
|
16
|
+
function prefixHolds(prefix: string, pathname: string): boolean {
|
|
17
|
+
if (prefix === '/') return pathname === '/';
|
|
18
|
+
return pathname === prefix || pathname.startsWith(`${prefix}/`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Pure rule behind {@link useActiveSection}: the id of the menu whose `match`
|
|
23
|
+
* prefixes (else its `href`) hold the pathname. The longest prefix wins, the
|
|
24
|
+
* first menu on a tie; `null` when none holds it.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveActiveSection(menus: readonly NavMenu[], pathname: string | null | undefined): string | null {
|
|
27
|
+
const current = pathOf(pathname ?? undefined);
|
|
28
|
+
if (!current) return null;
|
|
29
|
+
let best: { id: string; length: number } | null = null;
|
|
30
|
+
for (const menu of menus) {
|
|
31
|
+
const prefixes = menu.match?.length ? menu.match : [menu.href];
|
|
32
|
+
for (const raw of prefixes) {
|
|
33
|
+
const prefix = pathOf(raw);
|
|
34
|
+
if (!prefix || !prefixHolds(prefix, current)) continue;
|
|
35
|
+
if (!best || prefix.length > best.length) best = { id: menu.id, length: prefix.length };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return best?.id ?? null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The id of the top-level menu the current page belongs to, or `null`. */
|
|
42
|
+
export function useActiveSection(menus: readonly NavMenu[], pathname: string | null | undefined): string | null {
|
|
43
|
+
return useMemo(() => resolveActiveSection(menus, pathname), [menus, pathname]);
|
|
44
|
+
}
|