@claralight-design/abweb-navbar 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 没有用的安龙
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,457 @@
1
+ .header {
2
+ position: fixed;
3
+ top: 0;
4
+ left: 0;
5
+ right: 0;
6
+ width: 100vw;
7
+ margin: 0 auto;
8
+ display: flex;
9
+ justify-content: center;
10
+ box-sizing: border-box;
11
+ align-items: center;
12
+ z-index: 1000;
13
+ user-select: none;
14
+ pointer-events: auto;
15
+ corner-shape: unset;
16
+ min-height: 72px;
17
+ max-height: 72px;
18
+ }
19
+
20
+ .inner {
21
+ width: calc(100% - 12px);
22
+ max-width: calc(1200px - 12px);
23
+ position: relative;
24
+ display: grid;
25
+ grid-template-columns: auto minmax(0, 1fr) auto;
26
+ align-items: center;
27
+ overflow: hidden;
28
+ padding: 3px 6px;
29
+ border-radius: 48px;
30
+ gap: 12px;
31
+ transform: translateY(0);
32
+ transition: transform 0.35s cubic-bezier(0.18, 0.86, 0.34, 1);
33
+ z-index: 1000;
34
+ pointer-events: auto;
35
+ min-height: 56px;
36
+ max-height: 56px;
37
+ corner-shape: unset;
38
+ will-change: transform;
39
+ box-sizing: border-box;
40
+ }
41
+
42
+ .blurEffect {
43
+ position: absolute;
44
+ inset: -10px 0 auto;
45
+ height: 60px;
46
+ width: 120vw;
47
+ z-index: 0;
48
+ pointer-events: none;
49
+ background:
50
+ linear-gradient(to bottom,
51
+ var(--color-main-background) 10%,
52
+ transparent);
53
+ corner-shape: unset;
54
+ }
55
+
56
+ .column {
57
+ display: flex;
58
+ justify-content: end;
59
+ align-items: center;
60
+ min-width: 0;
61
+ overflow: hidden;
62
+ }
63
+
64
+ .left {
65
+ min-width: 40px;
66
+ order: 3;
67
+ }
68
+
69
+ .right {
70
+ gap: 8px;
71
+ }
72
+
73
+ .rightSlot {
74
+ display: inline-flex;
75
+ align-items: center;
76
+ justify-content: center;
77
+ min-width: 0;
78
+ }
79
+
80
+ .centerColumn {
81
+ min-width: 0;
82
+ display: flex;
83
+ align-items: center;
84
+ gap: 12px;
85
+ overflow: hidden;
86
+ }
87
+
88
+ .centerTrackWrapper {
89
+ min-width: 0;
90
+ overflow: hidden;
91
+ flex: 0 1 auto;
92
+ }
93
+
94
+ .track {
95
+ display: flex;
96
+ flex-direction: column;
97
+ will-change: transform;
98
+ transform: translate3d(0, 0, 0);
99
+ }
100
+
101
+ .slide {
102
+ min-height: 40px;
103
+ height: 40px;
104
+ display: inline-flex;
105
+ align-items: center;
106
+ justify-content: center;
107
+ gap: 10px;
108
+ }
109
+
110
+ .brandName {
111
+ color: var(--color-text);
112
+ font-size: 16px;
113
+ line-height: 1;
114
+ font-weight: 600;
115
+ white-space: nowrap;
116
+ }
117
+
118
+ .logo {
119
+ height: 16px;
120
+ width: auto;
121
+ display: block;
122
+ color: var(--color-text);
123
+ }
124
+
125
+ .logotypeWrapper {
126
+ display: inline-flex;
127
+ align-items: center;
128
+ justify-content: center;
129
+ padding: 4px 8px;
130
+ border-radius: 12px;
131
+ transition: transform 0.25s ease, opacity 0.25s ease;
132
+ color: inherit;
133
+ text-decoration: none;
134
+ white-space: nowrap;
135
+ }
136
+
137
+ .logotypeWrapper:hover {
138
+ transform: translateY(-1px);
139
+ opacity: 0.92;
140
+ }
141
+
142
+ .breadcrumb {
143
+ display: inline-flex;
144
+ align-items: center;
145
+ justify-content: center;
146
+ gap: 6px;
147
+ padding: 4px 0;
148
+ white-space: nowrap;
149
+ min-width: 0;
150
+ }
151
+
152
+ .title {
153
+ margin: 0;
154
+ font-size: 18px;
155
+ line-height: 20px;
156
+ font-weight: 500;
157
+ letter-spacing: 0.01em;
158
+ color: var(--color-text);
159
+ margin-block-end: 0 !important;
160
+ white-space: nowrap;
161
+ }
162
+
163
+ .slash {
164
+ opacity: 0.5;
165
+ font-size: 16px;
166
+ font-weight: 500;
167
+ }
168
+
169
+ .iconButton {
170
+ width: 40px;
171
+ height: 40px;
172
+ border-radius: 999px;
173
+ border: none;
174
+ background: transparent;
175
+ color: var(--color-text);
176
+ display: inline-flex;
177
+ align-items: center;
178
+ justify-content: center;
179
+ box-shadow: none;
180
+ cursor: pointer;
181
+ transition:
182
+ transform 0.15s ease,
183
+ background 0.2s ease,
184
+ color 0.2s ease;
185
+ corner-shape: unset;
186
+ padding: 0;
187
+ }
188
+
189
+ .iconButton:hover {
190
+ background: color-mix(in srgb, var(--color-text) 10%, transparent);
191
+ }
192
+
193
+ .iconButton:active {
194
+ transform: scale(0.9);
195
+ }
196
+
197
+ .desktopNav {
198
+ display: none;
199
+ min-width: 0;
200
+ margin-left: auto;
201
+ overflow-x: auto;
202
+ scrollbar-width: none;
203
+ }
204
+
205
+ .desktopNav::-webkit-scrollbar {
206
+ display: none;
207
+ }
208
+
209
+ .navList {
210
+ display: inline-flex;
211
+ align-items: center;
212
+ gap: 4px;
213
+ min-width: max-content;
214
+ }
215
+
216
+ .navItem {
217
+ display: inline-flex;
218
+ }
219
+
220
+ .navLink {
221
+ min-height: 36px;
222
+ padding: 0 12px;
223
+ border: none;
224
+ border-radius: 999px;
225
+ background: transparent;
226
+ color: color-mix(in srgb, var(--color-text) 72%, transparent);
227
+ display: inline-flex;
228
+ align-items: center;
229
+ justify-content: center;
230
+ text-decoration: none;
231
+ cursor: pointer;
232
+ transition:
233
+ background 0.2s ease,
234
+ color 0.2s ease,
235
+ transform 0.15s ease;
236
+ white-space: nowrap;
237
+ font-family: inherit;
238
+ font-size: 14px;
239
+ font-weight: 500;
240
+ }
241
+
242
+ .navLink:hover {
243
+ background: color-mix(in srgb, var(--color-text) 8%, transparent);
244
+ color: var(--color-text);
245
+ }
246
+
247
+ .navLink:active {
248
+ transform: scale(0.96);
249
+ }
250
+
251
+ .navLinkActive {
252
+ color: var(--color-text);
253
+ background: color-mix(in srgb, var(--color-text) 10%, transparent);
254
+ }
255
+
256
+ .desktopLabel {
257
+ display: inline-flex;
258
+ align-items: center;
259
+ min-width: 0;
260
+ }
261
+
262
+ .desktopLabel svg {
263
+ max-height: 12px;
264
+ }
265
+
266
+ .mobileMenu {
267
+ display: inline-flex;
268
+ }
269
+
270
+ .menuOverlay {
271
+ position: fixed;
272
+ inset: 0;
273
+ z-index: 1001;
274
+ background: rgba(0, 0, 0, 0.52);
275
+ -webkit-backdrop-filter: blur(6px);
276
+ backdrop-filter: blur(6px);
277
+ }
278
+
279
+ .menuDrawerContent {
280
+ position: fixed;
281
+ inset: 0;
282
+ z-index: 1002;
283
+ display: flex;
284
+ flex-direction: column;
285
+ align-items: center;
286
+ justify-content: center;
287
+ gap: 8px;
288
+ outline: none;
289
+ overflow: hidden;
290
+ }
291
+
292
+ .menuDrawerInner {
293
+ width: 100%;
294
+ max-width: 648px;
295
+ height: 100%;
296
+ display: flex;
297
+ flex-direction: column;
298
+ justify-content: center;
299
+ align-items: center;
300
+ gap: 1px;
301
+ padding: clamp(3rem, 6vw, 4.5rem) clamp(1.5rem, 4vw, 2.75rem) clamp(4rem, 8vw, 6rem);
302
+ box-sizing: border-box;
303
+ }
304
+
305
+ .menuDrawerHandle {
306
+ width: 64px;
307
+ height: 6px;
308
+ border-radius: 999px;
309
+ background: color-mix(in srgb, var(--color-text) 30%, transparent);
310
+ margin: 0 auto 20px;
311
+ opacity: 0.3;
312
+ flex-shrink: 0;
313
+ }
314
+
315
+ .menuDrawerHeader {
316
+ width: 100%;
317
+ position: relative;
318
+ }
319
+
320
+ .menuTitle {
321
+ margin: 0;
322
+ font-family: var(--font-family-serif);
323
+ font-size: 44px;
324
+ line-height: 1.025;
325
+ font-weight: 400;
326
+ letter-spacing: -0.25px;
327
+ color: var(--color-text);
328
+ text-align: center;
329
+ }
330
+
331
+ .menuCloseButton {
332
+ position: absolute;
333
+ right: 0;
334
+ top: 50%;
335
+ transform: translateY(-50%);
336
+ }
337
+
338
+ .menuNav {
339
+ width: 100%;
340
+ display: flex;
341
+ flex-direction: column;
342
+ gap: 11px;
343
+ overflow-y: auto;
344
+ padding: 0;
345
+ }
346
+
347
+ .menuLink {
348
+ width: 100%;
349
+ display: inline-flex;
350
+ align-items: center;
351
+ justify-content: center;
352
+ min-height: 72px;
353
+ height: 72px;
354
+ padding: 11px 18px 11px 16px;
355
+ border: none;
356
+ border-radius: calc(var(--radius-root) * 1.55);
357
+ background: transparent;
358
+ color: color-mix(in srgb, var(--color-text) 75%, transparent);
359
+ text-decoration: none;
360
+ box-sizing: border-box;
361
+ gap: 12px;
362
+ user-select: none;
363
+ transition: background 0.2s ease-out, opacity 0.2s ease, transform 0.15s ease;
364
+ font-size: 30px;
365
+ font-weight: 600;
366
+ cursor: pointer;
367
+ font-family: inherit;
368
+ }
369
+
370
+ .menuLink:hover {
371
+ color: var(--color-text);
372
+ }
373
+
374
+ .menuItemMarker {
375
+ display: inline-flex;
376
+ align-items: center;
377
+ justify-content: center;
378
+ width: 16px;
379
+ opacity: 0;
380
+ transform: translateX(-10px);
381
+ transition: transform 0.25s ease, opacity 0.25s ease;
382
+ }
383
+
384
+ .menuLink:hover .menuItemMarker,
385
+ .menuLinkActive .menuItemMarker {
386
+ opacity: 1;
387
+ transform: translateX(0);
388
+ }
389
+
390
+ .menuLabel {
391
+ display: inline-flex;
392
+ align-items: center;
393
+ min-width: 0;
394
+ }
395
+
396
+ .menuLink:active {
397
+ transform: scale(0.95);
398
+ opacity: 0.75;
399
+ }
400
+
401
+ .menuLinkActive {
402
+ color: var(--color-text);
403
+ }
404
+
405
+ .left .slide,
406
+ .right .slide {
407
+ width: 40px;
408
+ }
409
+
410
+ @media (min-width: 960px) {
411
+ .desktopNav {
412
+ display: flex;
413
+ }
414
+
415
+ .mobileMenu {
416
+ display: none;
417
+ }
418
+ }
419
+
420
+ @media (max-width: 959px) {
421
+ .inner {
422
+ grid-template-columns: auto minmax(0, 1fr) auto auto;
423
+ }
424
+
425
+ .slide {
426
+ height: 36px;
427
+ }
428
+
429
+ .breadcrumb {
430
+ padding: 4px 0;
431
+ gap: 4px;
432
+ }
433
+
434
+ .title {
435
+ font-size: 14px;
436
+ }
437
+
438
+ .menuDrawerInner {
439
+ padding: 3rem 1.25rem 4.5rem;
440
+ }
441
+
442
+ .menuTitle {
443
+ font-size: 36px;
444
+ }
445
+ }
446
+
447
+ @media (prefers-reduced-motion: reduce) {
448
+ .inner,
449
+ .track,
450
+ .iconButton,
451
+ .logotypeWrapper,
452
+ .navLink,
453
+ .menuLink,
454
+ .menuItemMarker {
455
+ transition: none;
456
+ }
457
+ }
package/NavHeader.tsx ADDED
@@ -0,0 +1,530 @@
1
+ import React, { useEffect, useMemo, useRef, useState } from 'react'
2
+ import styles from './NavHeader.module.css'
3
+ import { ArrowLeftIcon, OptionIcon, XIcon } from '@phosphor-icons/react'
4
+ import { Drawer } from 'vaul'
5
+ import BlurEffect from 'react-progressive-blur'
6
+
7
+ export type NavHeaderLabels = {
8
+ menu: string
9
+ close: string
10
+ back: string
11
+ }
12
+
13
+ export type NavHeaderItem = {
14
+ id?: string
15
+ label?: React.ReactNode
16
+ ariaLabel: string
17
+ href?: string
18
+ external?: boolean
19
+ active?: boolean
20
+ matchPath?: string
21
+ onClick?: (
22
+ event: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>
23
+ ) => void
24
+ target?: React.HTMLAttributeAnchorTarget
25
+ rel?: string
26
+ }
27
+
28
+ export type NavHeaderProps = {
29
+ pageTitle?: string
30
+ secPageTitle?: string
31
+ currentPath?: string
32
+ variant?: 'default' | 'docs' | (string & {})
33
+ showHeaderBlur?: boolean
34
+ navItems?: NavHeaderItem[]
35
+ leftSlot?: React.ReactNode
36
+ rightSlot?: React.ReactNode
37
+ logo?: React.ReactNode
38
+ brandName?: string
39
+ homeHref?: string
40
+ logoAriaLabel?: string
41
+ labels?: Partial<NavHeaderLabels>
42
+ className?: string
43
+ scrollTransitionDistance?: number
44
+ onBack?: () => void
45
+ }
46
+
47
+ type HeaderState = 'home' | 'level1' | 'level2'
48
+ type LeftState = 'slot' | 'back'
49
+
50
+ const DEFAULT_LABELS: NavHeaderLabels = {
51
+ menu: '菜单',
52
+ close: '关闭',
53
+ back: '返回'
54
+ }
55
+
56
+ const normalizePath = (path: string): string => {
57
+ if (!path) return '/'
58
+ const cleanPath = path.split('?')[0]?.split('#')[0] ?? '/'
59
+ const withLeading = cleanPath.startsWith('/') ? cleanPath : `/${cleanPath}`
60
+ if (withLeading === '/') return '/'
61
+ return withLeading.endsWith('/') ? withLeading.slice(0, -1) : withLeading
62
+ }
63
+
64
+ const isMenuItemActive = (currentPath: string, itemPath: string): boolean => {
65
+ const normalizedCurrent = normalizePath(currentPath)
66
+ const normalizedItem = normalizePath(itemPath)
67
+
68
+ if (normalizedItem === '/') {
69
+ return normalizedCurrent === '/'
70
+ }
71
+
72
+ return (
73
+ normalizedCurrent === normalizedItem ||
74
+ normalizedCurrent.startsWith(`${normalizedItem}/`)
75
+ )
76
+ }
77
+
78
+ const useHeaderStates = (pageTitle?: string, secPageTitle?: string) => {
79
+ return useMemo<HeaderState[]>(() => {
80
+ if (!pageTitle && !secPageTitle) {
81
+ return ['home']
82
+ }
83
+
84
+ if (!pageTitle && secPageTitle) {
85
+ return ['home', 'level1']
86
+ }
87
+
88
+ if (pageTitle && !secPageTitle) {
89
+ return ['home', 'level1']
90
+ }
91
+
92
+ return ['level1', 'level2']
93
+ }, [pageTitle, secPageTitle])
94
+ }
95
+
96
+ const useLeftStates = (leftSlot?: React.ReactNode, secPageTitle?: string) => {
97
+ return useMemo<LeftState[]>(() => {
98
+ const states: LeftState[] = []
99
+
100
+ if (leftSlot) {
101
+ states.push('slot')
102
+ }
103
+
104
+ if (secPageTitle) {
105
+ states.push('back')
106
+ }
107
+
108
+ return states
109
+ }, [leftSlot, secPageTitle])
110
+ }
111
+
112
+ const cx = (...classNames: Array<string | false | null | undefined>) =>
113
+ classNames.filter(Boolean).join(' ')
114
+
115
+ const renderItemLabel = (item: NavHeaderItem) => item.label ?? item.ariaLabel
116
+
117
+ const renderDesktopItem = (
118
+ item: NavHeaderItem,
119
+ className: string,
120
+ isActive: boolean
121
+ ) => {
122
+ const resolvedClassName = isActive
123
+ ? `${className} ${styles.navLinkActive}`
124
+ : className
125
+
126
+ if (item.href) {
127
+ return (
128
+ <a
129
+ href={item.href}
130
+ className={resolvedClassName}
131
+ aria-label={item.ariaLabel}
132
+ onClick={item.onClick}
133
+ target={item.external ? item.target ?? '_blank' : item.target}
134
+ rel={item.external ? item.rel ?? 'noreferrer' : item.rel}
135
+ >
136
+ <span className={styles.desktopLabel}>{renderItemLabel(item)}</span>
137
+ </a>
138
+ )
139
+ }
140
+
141
+ return (
142
+ <button
143
+ type='button'
144
+ className={resolvedClassName}
145
+ aria-label={item.ariaLabel}
146
+ onClick={item.onClick}
147
+ >
148
+ <span className={styles.desktopLabel}>{renderItemLabel(item)}</span>
149
+ </button>
150
+ )
151
+ }
152
+
153
+ const renderMobileItem = (
154
+ item: NavHeaderItem,
155
+ className: string,
156
+ isActive: boolean
157
+ ) => {
158
+ const resolvedClassName = isActive
159
+ ? `${className} ${styles.menuLinkActive}`
160
+ : className
161
+
162
+ const content = (
163
+ <>
164
+ <span aria-hidden className={styles.menuItemMarker}>
165
+ /
166
+ </span>
167
+ <span className={styles.menuLabel}>{renderItemLabel(item)}</span>
168
+ </>
169
+ )
170
+
171
+ if (item.href) {
172
+ return (
173
+ <a
174
+ href={item.href}
175
+ className={resolvedClassName}
176
+ aria-label={item.ariaLabel}
177
+ onClick={item.onClick}
178
+ target={item.external ? item.target ?? '_blank' : item.target}
179
+ rel={item.external ? item.rel ?? 'noreferrer' : item.rel}
180
+ >
181
+ {content}
182
+ </a>
183
+ )
184
+ }
185
+
186
+ return (
187
+ <button
188
+ type='button'
189
+ className={resolvedClassName}
190
+ aria-label={item.ariaLabel}
191
+ onClick={item.onClick}
192
+ >
193
+ {content}
194
+ </button>
195
+ )
196
+ }
197
+
198
+ const NavHeader: React.FC<NavHeaderProps> = ({
199
+ pageTitle,
200
+ secPageTitle,
201
+ currentPath = '/',
202
+ variant = 'default',
203
+ showHeaderBlur = true,
204
+ navItems = [],
205
+ leftSlot,
206
+ rightSlot,
207
+ logo,
208
+ brandName = 'Brand',
209
+ homeHref = '/',
210
+ logoAriaLabel,
211
+ labels,
212
+ className,
213
+ scrollTransitionDistance = 72,
214
+ onBack
215
+ }) => {
216
+ const leftTrackRef = useRef<HTMLDivElement>(null)
217
+ const centerTrackRef = useRef<HTMLDivElement>(null)
218
+ const [menuOpen, setMenuOpen] = useState(false)
219
+
220
+ const resolvedLabels = { ...DEFAULT_LABELS, ...labels }
221
+ const states = useHeaderStates(pageTitle, secPageTitle)
222
+ const leftStates = useLeftStates(leftSlot, secPageTitle)
223
+ const hasTransition = states.length > 1
224
+ const hasNavItems = navItems.length > 0
225
+ const resolvedLogoAriaLabel = logoAriaLabel ?? brandName
226
+
227
+ useEffect(() => {
228
+ if (typeof window === 'undefined') return
229
+
230
+ const leftTrack = leftTrackRef.current
231
+ const centerTrack = centerTrackRef.current
232
+ const animatableTracks = [
233
+ leftStates.length > 1 ? leftTrack : null,
234
+ states.length > 1 ? centerTrack : null
235
+ ].filter(Boolean) as HTMLDivElement[]
236
+
237
+ if (!animatableTracks.length) return
238
+
239
+ let slideHeight = 0
240
+ let centerOffset = 0
241
+ let leftOffset = 0
242
+ let rafId = 0
243
+ let nextProgress = 0
244
+ let lastProgress = -1
245
+
246
+ const refreshOffsets = () => {
247
+ const el =
248
+ centerTrack?.querySelector<HTMLElement>('[data-slide]') ??
249
+ leftTrack?.querySelector<HTMLElement>('[data-slide]')
250
+ slideHeight = el?.offsetHeight ?? 0
251
+ centerOffset = hasTransition ? -(states.length - 1) * slideHeight : 0
252
+ leftOffset =
253
+ leftStates.length > 1 ? -((leftStates.length - 1) * slideHeight) : 0
254
+ }
255
+
256
+ const applyProgress = (progress: number) => {
257
+ if (leftTrack && leftStates.length > 1) {
258
+ leftTrack.style.transform = `translate3d(0, ${leftOffset * progress}px, 0)`
259
+ }
260
+
261
+ if (centerTrack && hasTransition) {
262
+ centerTrack.style.transform = `translate3d(0, ${centerOffset * progress}px, 0)`
263
+ }
264
+ }
265
+
266
+ const queueApply = (progress: number) => {
267
+ nextProgress = progress
268
+ if (rafId) return
269
+
270
+ rafId = window.requestAnimationFrame(() => {
271
+ rafId = 0
272
+ if (nextProgress === lastProgress) return
273
+ lastProgress = nextProgress
274
+ applyProgress(nextProgress)
275
+ })
276
+ }
277
+
278
+ const syncFromScroll = () => {
279
+ if (!slideHeight) refreshOffsets()
280
+ if (!slideHeight || (!hasTransition && leftStates.length <= 1)) return
281
+ const progress = Math.max(
282
+ 0,
283
+ Math.min(1, window.scrollY / Math.max(scrollTransitionDistance, 1))
284
+ )
285
+ queueApply(progress)
286
+ }
287
+
288
+ refreshOffsets()
289
+ syncFromScroll()
290
+
291
+ window.addEventListener('scroll', syncFromScroll, { passive: true })
292
+
293
+ const ro = new ResizeObserver(() => {
294
+ refreshOffsets()
295
+ syncFromScroll()
296
+ })
297
+
298
+ animatableTracks.forEach((track) => ro.observe(track))
299
+
300
+ return () => {
301
+ if (rafId) window.cancelAnimationFrame(rafId)
302
+ window.removeEventListener('scroll', syncFromScroll)
303
+ ro.disconnect()
304
+ if (leftTrack) leftTrack.style.transform = ''
305
+ if (centerTrack) centerTrack.style.transform = ''
306
+ }
307
+ }, [hasTransition, leftStates.length, scrollTransitionDistance, states])
308
+
309
+ const handleBack = () => {
310
+ if (typeof window === 'undefined') return
311
+
312
+ if (onBack) {
313
+ onBack()
314
+ return
315
+ }
316
+
317
+ if (window.history.length > 1) {
318
+ window.history.back()
319
+ return
320
+ }
321
+
322
+ window.location.href = homeHref
323
+ }
324
+
325
+ const brandContent = logo ?? <span className={styles.brandName}>{brandName}</span>
326
+
327
+ return (
328
+ <div
329
+ className={cx(styles.header, className)}
330
+ data-nav-header
331
+ data-variant={variant}
332
+ >
333
+ {showHeaderBlur && <BlurEffect className={styles.blurEffect} position="top" intensity={100} aria-hidden />}
334
+ <header className={styles.inner}>
335
+ {hasNavItems && (
336
+ <div className={styles.mobileMenu}>
337
+ <Drawer.Root
338
+ open={menuOpen}
339
+ onOpenChange={setMenuOpen}
340
+ shouldScaleBackground
341
+ disablePreventScroll={false}
342
+ direction='top'
343
+ >
344
+ <Drawer.Trigger asChild>
345
+ <button
346
+ type='button'
347
+ className={styles.iconButton}
348
+ aria-label={resolvedLabels.menu}
349
+ >
350
+ <OptionIcon size={18} weight='bold' />
351
+ </button>
352
+ </Drawer.Trigger>
353
+
354
+ <Drawer.Portal>
355
+ <Drawer.Overlay className={styles.menuOverlay} />
356
+ <Drawer.Content className={styles.menuDrawerContent}>
357
+ <div className={styles.menuDrawerInner}>
358
+ <div className={styles.menuDrawerHeader}>
359
+ <Drawer.Title className={styles.menuTitle}>
360
+ {resolvedLabels.menu}
361
+ </Drawer.Title>
362
+ <Drawer.Close asChild>
363
+ <button
364
+ type='button'
365
+ className={cx(
366
+ styles.iconButton,
367
+ styles.menuCloseButton
368
+ )}
369
+ aria-label={resolvedLabels.close}
370
+ >
371
+ <XIcon size={18} weight='bold' />
372
+ </button>
373
+ </Drawer.Close>
374
+ </div>
375
+
376
+ <nav
377
+ className={styles.menuNav}
378
+ aria-label={resolvedLabels.menu}
379
+ >
380
+ {navItems.map((item) => {
381
+ const key =
382
+ item.id ??
383
+ item.href ??
384
+ item.ariaLabel
385
+ const isActive =
386
+ item.active ??
387
+ Boolean(
388
+ item.href &&
389
+ !item.external &&
390
+ isMenuItemActive(
391
+ currentPath,
392
+ item.matchPath ??
393
+ item.href
394
+ )
395
+ )
396
+
397
+ return (
398
+ <Drawer.Close asChild key={key}>
399
+ {renderMobileItem(
400
+ item,
401
+ styles.menuLink,
402
+ isActive
403
+ )}
404
+ </Drawer.Close>
405
+ )
406
+ })}
407
+ </nav>
408
+ </div>
409
+
410
+ <div
411
+ aria-hidden
412
+ className={styles.menuDrawerHandle}
413
+ />
414
+ </Drawer.Content>
415
+ </Drawer.Portal>
416
+ </Drawer.Root>
417
+ </div>
418
+ )}
419
+ <div className={cx(styles.column, styles.left)}>
420
+ <div className={styles.track} ref={leftTrackRef}>
421
+ {leftStates.map((state, index) => (
422
+ <div
423
+ className={styles.slide}
424
+ data-slide
425
+ key={`left-${state}-${index}`}
426
+ >
427
+ {state === 'back' ? (
428
+ <button
429
+ type='button'
430
+ className={styles.iconButton}
431
+ onClick={handleBack}
432
+ aria-label={resolvedLabels.back}
433
+ >
434
+ <ArrowLeftIcon size={18} weight='bold' />
435
+ </button>
436
+ ) : (
437
+ leftSlot
438
+ )}
439
+ </div>
440
+ ))}
441
+ </div>
442
+ </div>
443
+
444
+ <div className={styles.centerColumn}>
445
+ <div className={styles.centerTrackWrapper}>
446
+ <div className={styles.track} ref={centerTrackRef}>
447
+ {states.map((state, index) => (
448
+ <div
449
+ className={styles.slide}
450
+ data-slide
451
+ key={`center-${state}-${index}`}
452
+ >
453
+ {state === 'home' && (
454
+ <a
455
+ className={styles.logotypeWrapper}
456
+ href={homeHref}
457
+ aria-label={resolvedLogoAriaLabel}
458
+ >
459
+ {brandContent}
460
+ </a>
461
+ )}
462
+
463
+ {state === 'level1' && (
464
+ <div className={styles.breadcrumb}>
465
+ <p className={styles.title}>
466
+ {pageTitle ?? secPageTitle}
467
+ </p>
468
+ </div>
469
+ )}
470
+
471
+ {state === 'level2' && (
472
+ <div className={styles.breadcrumb}>
473
+ {pageTitle && (
474
+ <>
475
+ <p className={styles.title}>
476
+ {pageTitle}
477
+ </p>
478
+ <span className={styles.slash}>/</span>
479
+ </>
480
+ )}
481
+ <p className={styles.title}>{secPageTitle}</p>
482
+ </div>
483
+ )}
484
+ </div>
485
+ ))}
486
+ </div>
487
+ </div>
488
+
489
+ {hasNavItems && (
490
+ <nav
491
+ className={styles.desktopNav}
492
+ aria-label={resolvedLabels.menu}
493
+ >
494
+ <div className={styles.navList}>
495
+ {navItems.map((item) => {
496
+ const key = item.id ?? item.href ?? item.ariaLabel
497
+ const isActive =
498
+ item.active ??
499
+ Boolean(
500
+ item.href &&
501
+ !item.external &&
502
+ isMenuItemActive(
503
+ currentPath,
504
+ item.matchPath ?? item.href
505
+ )
506
+ )
507
+
508
+ return (
509
+ <div className={styles.navItem} key={key}>
510
+ {renderDesktopItem(
511
+ item,
512
+ styles.navLink,
513
+ isActive
514
+ )}
515
+ </div>
516
+ )
517
+ })}
518
+ </div>
519
+ </nav>
520
+ )}
521
+ </div>
522
+ <div className={cx(styles.column, styles.right)}>
523
+ {rightSlot && <div className={styles.rightSlot}>{rightSlot}</div>}
524
+ </div>
525
+ </header>
526
+ </div>
527
+ )
528
+ }
529
+
530
+ export default NavHeader
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # AstroBox-WebNavbar
2
+ A react components for AstroBox websites.
3
+
4
+ note: The Demo is built by AI
package/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { default } from './NavHeader'
2
+ export { default as NavHeader } from './NavHeader'
3
+ export type {
4
+ NavHeaderItem,
5
+ NavHeaderLabels,
6
+ NavHeaderProps
7
+ } from './NavHeader'
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@claralight-design/abweb-navbar",
3
+ "version": "0.1.0",
4
+ "description": "A react components for AstroBox websites.",
5
+ "scripts": {
6
+ "dev": "vite",
7
+ "build": "vite build"
8
+ },
9
+ "type": "module",
10
+ "main": "./index.ts",
11
+ "module": "./index.ts",
12
+ "types": "./index.ts",
13
+ "exports": {
14
+ ".": "./index.ts"
15
+ },
16
+ "files": [
17
+ "index.ts",
18
+ "NavHeader.tsx",
19
+ "NavHeader.module.css"
20
+ ],
21
+ "sideEffects": [
22
+ "./NavHeader.module.css"
23
+ ],
24
+ "peerDependencies": {
25
+ "react": "^18.2.0 || ^19.0.0",
26
+ "react-dom": "^18.2.0 || ^19.0.0"
27
+ },
28
+ "dependencies": {
29
+ "@phosphor-icons/react": "^2.1.7",
30
+ "react-progressive-blur": "^1.0.6",
31
+ "vaul": "^1.1.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/react": "^19.1.4",
35
+ "@types/react-dom": "^19.1.5",
36
+ "@vitejs/plugin-react": "^4.7.0",
37
+ "react": "^19.1.0",
38
+ "react-dom": "^19.1.0",
39
+ "typescript": "^5.8.3",
40
+ "vite": "^7.3.3"
41
+ }
42
+ }