@hyperpackai/hyperui 0.2.0 → 0.3.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/README.md +13 -0
- package/dist/components/Accordion/index.d.ts +6 -0
- package/dist/components/Accordion/index.d.ts.map +1 -1
- package/dist/components/Accordion/index.js +65 -9
- package/dist/components/Autocomplete/index.d.ts +12 -2
- package/dist/components/Autocomplete/index.d.ts.map +1 -1
- package/dist/components/Autocomplete/index.js +148 -24
- package/dist/components/Backdrop/index.d.ts +2 -1
- package/dist/components/Backdrop/index.d.ts.map +1 -1
- package/dist/components/Backdrop/index.js +6 -3
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Checkbox/index.d.ts.map +1 -1
- package/dist/components/Checkbox/index.js +6 -2
- package/dist/components/DashboardLayout/index.d.ts +13 -0
- package/dist/components/DashboardLayout/index.d.ts.map +1 -1
- package/dist/components/DashboardLayout/index.js +50 -7
- package/dist/components/DataTable/index.d.ts +43 -0
- package/dist/components/DataTable/index.d.ts.map +1 -1
- package/dist/components/DataTable/index.js +126 -21
- package/dist/components/Dialog/index.d.ts +9 -3
- package/dist/components/Dialog/index.d.ts.map +1 -1
- package/dist/components/Dialog/index.js +46 -30
- package/dist/components/Drawer/index.d.ts +11 -3
- package/dist/components/Drawer/index.d.ts.map +1 -1
- package/dist/components/Drawer/index.js +66 -11
- package/dist/components/DropdownMenu/index.d.ts +5 -3
- package/dist/components/DropdownMenu/index.d.ts.map +1 -1
- package/dist/components/DropdownMenu/index.js +56 -13
- package/dist/components/FocusTrap/index.d.ts.map +1 -1
- package/dist/components/FocusTrap/index.js +34 -32
- package/dist/components/Input/index.d.ts +2 -0
- package/dist/components/Input/index.d.ts.map +1 -1
- package/dist/components/Input/index.js +18 -4
- package/dist/components/Menu/index.d.ts +6 -2
- package/dist/components/Menu/index.d.ts.map +1 -1
- package/dist/components/Menu/index.js +50 -15
- package/dist/components/Modal/index.d.ts +3 -1
- package/dist/components/Modal/index.d.ts.map +1 -1
- package/dist/components/Modal/index.js +27 -9
- package/dist/components/NestedNavbar/index.d.ts +33 -0
- package/dist/components/NestedNavbar/index.d.ts.map +1 -0
- package/dist/components/NestedNavbar/index.js +435 -0
- package/dist/components/NestedSidebar/index.d.ts +48 -0
- package/dist/components/NestedSidebar/index.d.ts.map +1 -0
- package/dist/components/NestedSidebar/index.js +368 -0
- package/dist/components/Popover/index.d.ts +11 -3
- package/dist/components/Popover/index.d.ts.map +1 -1
- package/dist/components/Popover/index.js +45 -9
- package/dist/components/Radio/index.d.ts +26 -1
- package/dist/components/Radio/index.d.ts.map +1 -1
- package/dist/components/Radio/index.js +61 -2
- package/dist/components/Select/index.d.ts +5 -0
- package/dist/components/Select/index.d.ts.map +1 -1
- package/dist/components/Select/index.js +22 -5
- package/dist/components/Sheet/index.d.ts +9 -3
- package/dist/components/Sheet/index.d.ts.map +1 -1
- package/dist/components/Sheet/index.js +48 -23
- package/dist/components/Sidebar/index.d.ts +20 -1
- package/dist/components/Sidebar/index.d.ts.map +1 -1
- package/dist/components/Sidebar/index.js +285 -8
- package/dist/components/SpeedDial/index.d.ts +10 -0
- package/dist/components/SpeedDial/index.d.ts.map +1 -1
- package/dist/components/SpeedDial/index.js +61 -11
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/index.d.ts.map +1 -1
- package/dist/components/Switch/index.js +6 -2
- package/dist/components/Tabs/index.d.ts +3 -0
- package/dist/components/Tabs/index.d.ts.map +1 -1
- package/dist/components/Tabs/index.js +47 -8
- package/dist/components/TextField/index.d.ts +2 -0
- package/dist/components/TextField/index.d.ts.map +1 -1
- package/dist/components/TextField/index.js +12 -4
- package/dist/components/Textarea/index.d.ts +5 -0
- package/dist/components/Textarea/index.d.ts.map +1 -1
- package/dist/components/Textarea/index.js +21 -4
- package/dist/components/Transition/index.d.ts +14 -0
- package/dist/components/Transition/index.d.ts.map +1 -0
- package/dist/components/Transition/index.js +49 -0
- package/dist/components/TransitionGroup/index.d.ts +16 -0
- package/dist/components/TransitionGroup/index.d.ts.map +1 -0
- package/dist/components/TransitionGroup/index.js +95 -0
- package/dist/components/data.d.ts +81 -16
- package/dist/components/data.d.ts.map +1 -1
- package/dist/components/data.js +163 -31
- package/dist/components/enterprise.d.ts +85 -26
- package/dist/components/enterprise.d.ts.map +1 -1
- package/dist/components/enterprise.js +211 -36
- package/dist/components/index.d.ts +21 -13
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +7 -2
- package/dist/portal.d.ts.map +1 -1
- package/dist/portal.js +3 -0
- package/dist/theme/index.d.ts +5 -6
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +30 -0
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +11 -0
- package/package.json +6 -1
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { onCleanup, signal } from "@hyperpackai/hyperion";
|
|
2
|
+
import { injectCSS, cn, h } from "../../theme/index.js";
|
|
3
|
+
import { FocusTrap } from "../FocusTrap/index.js";
|
|
4
|
+
let navbarCounter = 0;
|
|
5
|
+
const NESTED_NAVBAR_CSS = `
|
|
6
|
+
/* ── Base ───────────────────────────────────────────────────────────── */
|
|
7
|
+
.hu-nested-navbar {
|
|
8
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
9
|
+
gap: var(--hu-space-4); padding: 0 var(--hu-space-6); min-height: 60px;
|
|
10
|
+
border-bottom: 1px solid color-mix(in srgb, var(--hu-border) 82%, transparent);
|
|
11
|
+
position: sticky; top: 0; z-index: var(--hu-z-sticky);
|
|
12
|
+
backdrop-filter: blur(12px);
|
|
13
|
+
background: color-mix(in srgb, var(--hu-bg) 88%, transparent);
|
|
14
|
+
box-shadow: var(--hu-shadow-xs);
|
|
15
|
+
overflow: visible;
|
|
16
|
+
}
|
|
17
|
+
.hu-nested-navbar__brand {
|
|
18
|
+
display: flex; align-items: center; gap: var(--hu-space-3); min-width: max-content;
|
|
19
|
+
text-decoration: none; color: var(--hu-text);
|
|
20
|
+
font-weight: var(--hu-font-weight-bold); font-size: var(--hu-font-size-md);
|
|
21
|
+
}
|
|
22
|
+
.hu-nested-navbar__end { display: flex; align-items: center; gap: var(--hu-space-2); min-width: max-content; }
|
|
23
|
+
.hu-nested-navbar__actions { display: flex; align-items: center; gap: var(--hu-space-2); }
|
|
24
|
+
|
|
25
|
+
/* ── Desktop Nav ────────────────────────────────────────────────────── */
|
|
26
|
+
.hu-nested-navbar__nav { display: flex; align-items: center; gap: var(--hu-space-1); flex: 1; min-width: 0; overflow: visible; padding: 0 var(--hu-space-2); }
|
|
27
|
+
.hu-nested-navbar__item { position: relative; }
|
|
28
|
+
.hu-nested-navbar__item:not([data-open="true"]) [data-hu-nn-dropdown-panel] { display: none !important; }
|
|
29
|
+
.hu-nested-navbar__link,
|
|
30
|
+
.hu-nested-navbar__trigger {
|
|
31
|
+
display: inline-flex; align-items: center; gap: 4px;
|
|
32
|
+
padding: 7px 12px; border-radius: var(--hu-radius-md);
|
|
33
|
+
font-size: var(--hu-font-size-sm); font-weight: var(--hu-font-weight-medium);
|
|
34
|
+
color: var(--hu-text-2); text-decoration: none; white-space: nowrap;
|
|
35
|
+
border: none; background: transparent; cursor: pointer;
|
|
36
|
+
font-family: inherit; font-size: inherit;
|
|
37
|
+
transition: background var(--hu-duration) var(--hu-ease), color var(--hu-duration) var(--hu-ease);
|
|
38
|
+
}
|
|
39
|
+
.hu-nested-navbar__link:hover,
|
|
40
|
+
.hu-nested-navbar__trigger:hover { color: var(--hu-text); background: var(--hu-bg-3); }
|
|
41
|
+
.hu-nested-navbar__link:focus-visible,
|
|
42
|
+
.hu-nested-navbar__trigger:focus-visible { outline: 2px solid var(--hu-primary); outline-offset: 2px; }
|
|
43
|
+
.hu-nested-navbar__link--active,
|
|
44
|
+
.hu-nested-navbar__trigger--active {
|
|
45
|
+
color: var(--hu-primary); background: var(--hu-primary-bg);
|
|
46
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hu-primary) 20%, transparent);
|
|
47
|
+
}
|
|
48
|
+
.hu-nested-navbar__chevron {
|
|
49
|
+
width: 14px; height: 14px; flex-shrink: 0;
|
|
50
|
+
transition: transform var(--hu-duration) var(--hu-ease);
|
|
51
|
+
}
|
|
52
|
+
.hu-nested-navbar__trigger[aria-expanded="true"] .hu-nested-navbar__chevron { transform: rotate(180deg); }
|
|
53
|
+
|
|
54
|
+
/* ── Desktop Dropdown ───────────────────────────────────────────────── */
|
|
55
|
+
.hu-nested-navbar__dropdown {
|
|
56
|
+
position: absolute; top: calc(100% + 6px); left: 0;
|
|
57
|
+
min-width: 220px; max-width: 320px;
|
|
58
|
+
background: var(--hu-bg); border: 1px solid var(--hu-border);
|
|
59
|
+
border-radius: var(--hu-radius-lg); box-shadow: var(--hu-shadow-lg);
|
|
60
|
+
padding: var(--hu-space-2); z-index: var(--hu-z-dropdown);
|
|
61
|
+
animation: hu-nn-dropdown-in var(--hu-duration-fast) var(--hu-ease-out);
|
|
62
|
+
}
|
|
63
|
+
@keyframes hu-nn-dropdown-in {
|
|
64
|
+
from { opacity: 0; transform: translateY(-6px); }
|
|
65
|
+
to { opacity: 1; transform: translateY(0); }
|
|
66
|
+
}
|
|
67
|
+
.hu-nested-navbar__child {
|
|
68
|
+
display: flex; align-items: flex-start; gap: var(--hu-space-3);
|
|
69
|
+
padding: var(--hu-space-2) var(--hu-space-3); border-radius: var(--hu-radius-md);
|
|
70
|
+
text-decoration: none; color: var(--hu-text-2); width: 100%;
|
|
71
|
+
transition: background var(--hu-duration) var(--hu-ease), color var(--hu-duration) var(--hu-ease);
|
|
72
|
+
}
|
|
73
|
+
.hu-nested-navbar__child:hover { background: var(--hu-bg-3); color: var(--hu-text); }
|
|
74
|
+
.hu-nested-navbar__child:focus-visible { outline: 2px solid var(--hu-primary); outline-offset: 2px; }
|
|
75
|
+
.hu-nested-navbar__child--active { color: var(--hu-primary); background: var(--hu-primary-bg); }
|
|
76
|
+
.hu-nested-navbar__child-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; color: var(--hu-text-3); }
|
|
77
|
+
.hu-nested-navbar__child-body { min-width: 0; }
|
|
78
|
+
.hu-nested-navbar__child-label { font-size: var(--hu-font-size-sm); font-weight: var(--hu-font-weight-medium); color: inherit; line-height: 1.3; }
|
|
79
|
+
.hu-nested-navbar__child-desc { font-size: var(--hu-font-size-xs); color: var(--hu-text-3); margin-top: 2px; line-height: 1.4; }
|
|
80
|
+
|
|
81
|
+
/* ── Mobile Toggle ──────────────────────────────────────────────────── */
|
|
82
|
+
.hu-nested-navbar__toggle {
|
|
83
|
+
display: none; align-items: center; justify-content: center;
|
|
84
|
+
width: 40px; height: 40px; padding: 0; flex-shrink: 0;
|
|
85
|
+
background: transparent; border: 1px solid var(--hu-border);
|
|
86
|
+
border-radius: var(--hu-radius-md); cursor: pointer; color: var(--hu-text-2);
|
|
87
|
+
transition: background var(--hu-duration) var(--hu-ease), color var(--hu-duration) var(--hu-ease);
|
|
88
|
+
}
|
|
89
|
+
.hu-nested-navbar__toggle:hover { background: var(--hu-bg-3); color: var(--hu-text); }
|
|
90
|
+
.hu-nested-navbar__toggle:focus-visible { outline: 2px solid var(--hu-primary); outline-offset: 2px; }
|
|
91
|
+
|
|
92
|
+
/* ── Mobile Backdrop ────────────────────────────────────────────────── */
|
|
93
|
+
.hu-nested-navbar__backdrop {
|
|
94
|
+
position: fixed; inset: 0; z-index: var(--hu-z-backdrop);
|
|
95
|
+
background: var(--hu-overlay);
|
|
96
|
+
animation: hu-nn-fade-in var(--hu-duration-fast) var(--hu-ease);
|
|
97
|
+
}
|
|
98
|
+
.hu-nested-navbar__mobile-overlay[hidden] { display: none !important; }
|
|
99
|
+
@keyframes hu-nn-fade-in { from { opacity: 0; } to { opacity: 1; } }
|
|
100
|
+
|
|
101
|
+
/* ── Mobile Drawer ──────────────────────────────────────────────────── */
|
|
102
|
+
.hu-nested-navbar__drawer {
|
|
103
|
+
position: fixed; inset-y: 0; left: 0; z-index: var(--hu-z-modal);
|
|
104
|
+
width: min(82vw, 320px);
|
|
105
|
+
display: flex; flex-direction: column;
|
|
106
|
+
background: var(--hu-bg); border-right: 1px solid var(--hu-border);
|
|
107
|
+
box-shadow: var(--hu-shadow-xl);
|
|
108
|
+
animation: hu-nn-drawer-in var(--hu-duration-slow) var(--hu-ease-out);
|
|
109
|
+
}
|
|
110
|
+
@keyframes hu-nn-drawer-in { from { transform: translateX(-100%); } to { transform: translateX(0); } }
|
|
111
|
+
.hu-nested-navbar__drawer-header {
|
|
112
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
113
|
+
padding: var(--hu-space-3) var(--hu-space-4); min-height: 60px;
|
|
114
|
+
border-bottom: 1px solid var(--hu-border);
|
|
115
|
+
}
|
|
116
|
+
.hu-nested-navbar__drawer-brand {
|
|
117
|
+
display: flex; align-items: center; gap: var(--hu-space-3);
|
|
118
|
+
text-decoration: none; color: var(--hu-text);
|
|
119
|
+
font-weight: var(--hu-font-weight-bold); font-size: var(--hu-font-size-md);
|
|
120
|
+
}
|
|
121
|
+
.hu-nested-navbar__drawer-close {
|
|
122
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
123
|
+
width: 36px; height: 36px; padding: 0; flex-shrink: 0;
|
|
124
|
+
background: var(--hu-bg); border: 1px solid var(--hu-border);
|
|
125
|
+
border-radius: var(--hu-radius-md); cursor: pointer; color: var(--hu-text-2);
|
|
126
|
+
}
|
|
127
|
+
.hu-nested-navbar__drawer-close:hover { background: var(--hu-bg-3); color: var(--hu-text); }
|
|
128
|
+
.hu-nested-navbar__drawer-close:focus-visible { outline: 2px solid var(--hu-primary); outline-offset: 2px; }
|
|
129
|
+
.hu-nested-navbar__drawer-body { flex: 1; overflow-y: auto; padding: var(--hu-space-2); }
|
|
130
|
+
|
|
131
|
+
/* Accordion in drawer / sheet */
|
|
132
|
+
.hu-nested-navbar__mob-link {
|
|
133
|
+
display: flex; align-items: center; gap: var(--hu-space-3);
|
|
134
|
+
min-height: 48px; padding: 10px var(--hu-space-3);
|
|
135
|
+
border-radius: var(--hu-radius-md); font-size: var(--hu-font-size-sm);
|
|
136
|
+
font-weight: var(--hu-font-weight-medium); color: var(--hu-text-2);
|
|
137
|
+
text-decoration: none; transition: background var(--hu-duration) var(--hu-ease), color var(--hu-duration) var(--hu-ease);
|
|
138
|
+
}
|
|
139
|
+
.hu-nested-navbar__mob-link:hover { background: var(--hu-bg-3); color: var(--hu-text); }
|
|
140
|
+
.hu-nested-navbar__mob-link--active { color: var(--hu-primary); background: var(--hu-primary-bg); }
|
|
141
|
+
.hu-nested-navbar__acc-trigger {
|
|
142
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
143
|
+
width: 100%; min-height: 48px; padding: 10px var(--hu-space-3);
|
|
144
|
+
background: transparent; border: none; border-radius: var(--hu-radius-md);
|
|
145
|
+
font-family: inherit; font-size: var(--hu-font-size-sm);
|
|
146
|
+
font-weight: var(--hu-font-weight-medium); color: var(--hu-text-2);
|
|
147
|
+
cursor: pointer; text-align: left;
|
|
148
|
+
transition: background var(--hu-duration) var(--hu-ease), color var(--hu-duration) var(--hu-ease);
|
|
149
|
+
}
|
|
150
|
+
.hu-nested-navbar__acc-trigger:hover { background: var(--hu-bg-3); color: var(--hu-text); }
|
|
151
|
+
.hu-nested-navbar__acc-trigger--active { color: var(--hu-primary); }
|
|
152
|
+
.hu-nested-navbar__acc-trigger:focus-visible { outline: 2px solid var(--hu-primary); outline-offset: 2px; }
|
|
153
|
+
.hu-nested-navbar__acc-chevron {
|
|
154
|
+
width: 16px; height: 16px; flex-shrink: 0;
|
|
155
|
+
transition: transform var(--hu-duration) var(--hu-ease);
|
|
156
|
+
}
|
|
157
|
+
.hu-nested-navbar__acc-trigger[aria-expanded="true"] .hu-nested-navbar__acc-chevron { transform: rotate(180deg); }
|
|
158
|
+
.hu-nested-navbar__acc-content { padding-left: var(--hu-space-3); }
|
|
159
|
+
.hu-nested-navbar__acc-item:not([data-expanded="true"]) .hu-nested-navbar__acc-content { display: none !important; }
|
|
160
|
+
.hu-nested-navbar__acc-child {
|
|
161
|
+
display: flex; align-items: center; gap: var(--hu-space-2);
|
|
162
|
+
min-height: 40px; padding: 8px var(--hu-space-3);
|
|
163
|
+
border-radius: var(--hu-radius-md); font-size: var(--hu-font-size-sm);
|
|
164
|
+
color: var(--hu-text-2); text-decoration: none;
|
|
165
|
+
transition: background var(--hu-duration) var(--hu-ease), color var(--hu-duration) var(--hu-ease);
|
|
166
|
+
}
|
|
167
|
+
.hu-nested-navbar__acc-child:hover { background: var(--hu-bg-3); color: var(--hu-text); }
|
|
168
|
+
.hu-nested-navbar__acc-child--active { color: var(--hu-primary); background: var(--hu-primary-bg); }
|
|
169
|
+
|
|
170
|
+
/* ── Mobile Bottom Sheet ────────────────────────────────────────────── */
|
|
171
|
+
.hu-nested-navbar__sheet {
|
|
172
|
+
position: fixed; inset-x: 0; bottom: 0; z-index: var(--hu-z-modal);
|
|
173
|
+
max-height: 85vh; display: flex; flex-direction: column;
|
|
174
|
+
background: var(--hu-bg);
|
|
175
|
+
border-top: 1px solid var(--hu-border);
|
|
176
|
+
border-radius: var(--hu-radius-xl) var(--hu-radius-xl) 0 0;
|
|
177
|
+
box-shadow: var(--hu-shadow-xl);
|
|
178
|
+
animation: hu-nn-sheet-in var(--hu-duration-slow) var(--hu-ease-out);
|
|
179
|
+
}
|
|
180
|
+
@keyframes hu-nn-sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
|
|
181
|
+
.hu-nested-navbar__sheet-handle {
|
|
182
|
+
width: 36px; height: 4px; border-radius: 2px;
|
|
183
|
+
background: var(--hu-border); margin: var(--hu-space-3) auto var(--hu-space-1); flex-shrink: 0;
|
|
184
|
+
}
|
|
185
|
+
.hu-nested-navbar__sheet-header {
|
|
186
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
187
|
+
padding: var(--hu-space-2) var(--hu-space-4) var(--hu-space-3);
|
|
188
|
+
border-bottom: 1px solid var(--hu-border);
|
|
189
|
+
}
|
|
190
|
+
.hu-nested-navbar__sheet-title { font-weight: var(--hu-font-weight-semibold); color: var(--hu-text); font-size: var(--hu-font-size-md); }
|
|
191
|
+
.hu-nested-navbar__sheet-close {
|
|
192
|
+
display: inline-flex; align-items: center; justify-content: center;
|
|
193
|
+
width: 34px; height: 34px; padding: 0;
|
|
194
|
+
background: var(--hu-bg); border: 1px solid var(--hu-border);
|
|
195
|
+
border-radius: var(--hu-radius-md); cursor: pointer; color: var(--hu-text-2);
|
|
196
|
+
}
|
|
197
|
+
.hu-nested-navbar__sheet-close:hover { background: var(--hu-bg-3); color: var(--hu-text); }
|
|
198
|
+
.hu-nested-navbar__sheet-close:focus-visible { outline: 2px solid var(--hu-primary); outline-offset: 2px; }
|
|
199
|
+
.hu-nested-navbar__sheet-body { flex: 1; overflow-y: auto; padding: var(--hu-space-2); }
|
|
200
|
+
|
|
201
|
+
/* ── Responsive Breakpoint ──────────────────────────────────────────── */
|
|
202
|
+
@media (max-width: 768px) {
|
|
203
|
+
.hu-nested-navbar__nav { display: none; }
|
|
204
|
+
.hu-nested-navbar__toggle { display: inline-flex; }
|
|
205
|
+
}
|
|
206
|
+
`;
|
|
207
|
+
function isActive(a) {
|
|
208
|
+
return typeof a === "function" ? a() : (a ?? false);
|
|
209
|
+
}
|
|
210
|
+
const navbarState = new Map();
|
|
211
|
+
function getNavbarState(key) {
|
|
212
|
+
let state = navbarState.get(key);
|
|
213
|
+
if (!state) {
|
|
214
|
+
state = {
|
|
215
|
+
openDropdown: signal(null),
|
|
216
|
+
mobileOpen: signal(false),
|
|
217
|
+
expandedItems: signal(new Set())
|
|
218
|
+
};
|
|
219
|
+
navbarState.set(key, state);
|
|
220
|
+
}
|
|
221
|
+
return state;
|
|
222
|
+
}
|
|
223
|
+
function getNavbarKey(props, items) {
|
|
224
|
+
return props.id ?? props.class ?? props.mobileTitle ?? items.map((item) => item.label).join("|") ?? `navbar-${navbarCounter + 1}`;
|
|
225
|
+
}
|
|
226
|
+
// ── SVG helpers ───────────────────────────────────────────────────────────────
|
|
227
|
+
const chevronDown = h("svg", { class: "hu-nested-navbar__chevron", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true" }, h("path", { d: "M4 6l4 4 4-4" }));
|
|
228
|
+
const chevronDown16 = h("svg", { class: "hu-nested-navbar__acc-chevron", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true" }, h("path", { d: "M4 6l4 4 4-4" }));
|
|
229
|
+
const closeIcon = h("svg", { viewBox: "0 0 16 16", width: "16", height: "16", fill: "none", stroke: "currentColor", "stroke-width": "2", "aria-hidden": "true" }, h("path", { d: "M2 2l12 12M14 2L2 14" }));
|
|
230
|
+
const menuIcon = h("svg", { viewBox: "0 0 20 20", width: "18", height: "18", fill: "none", stroke: "currentColor", "stroke-width": "1.75", "aria-hidden": "true" }, h("path", { d: "M3 5h14M3 10h14M3 15h14" }));
|
|
231
|
+
// ── Component ─────────────────────────────────────────────────────────────────
|
|
232
|
+
export function NestedNavbar(props) {
|
|
233
|
+
injectCSS("hu-nested-navbar", NESTED_NAVBAR_CSS);
|
|
234
|
+
const { items = [], mobileVariant = "drawer" } = props;
|
|
235
|
+
const instanceKey = getNavbarKey(props, items);
|
|
236
|
+
const id = props.id ?? `hu-nn-${++navbarCounter}`;
|
|
237
|
+
const { openDropdown, mobileOpen, expandedItems } = getNavbarState(instanceKey);
|
|
238
|
+
if (typeof document !== "undefined" && typeof document.addEventListener === "function") {
|
|
239
|
+
const closeOnOutsideClick = (event) => {
|
|
240
|
+
if (!openDropdown.value)
|
|
241
|
+
return;
|
|
242
|
+
const target = event.target;
|
|
243
|
+
if (target?.closest(".hu-nested-navbar__item[data-hu-nn-dropdown]"))
|
|
244
|
+
return;
|
|
245
|
+
closeDropdown();
|
|
246
|
+
};
|
|
247
|
+
document.addEventListener("click", closeOnOutsideClick);
|
|
248
|
+
onCleanup(() => document.removeEventListener("click", closeOnOutsideClick));
|
|
249
|
+
}
|
|
250
|
+
const syncDesktopDropdowns = (activeItem, open) => {
|
|
251
|
+
if (typeof document === "undefined")
|
|
252
|
+
return;
|
|
253
|
+
const root = activeItem?.closest(".hu-nested-navbar")
|
|
254
|
+
?? (typeof document.getElementById === "function" ? document.getElementById(id) : null);
|
|
255
|
+
const dropdownItems = root?.querySelectorAll(".hu-nested-navbar__item[data-hu-nn-dropdown]");
|
|
256
|
+
dropdownItems?.forEach((itemEl) => {
|
|
257
|
+
const isOpen = open && itemEl === activeItem;
|
|
258
|
+
itemEl.dataset.open = String(isOpen);
|
|
259
|
+
itemEl.querySelector(".hu-nested-navbar__trigger")?.setAttribute("aria-expanded", String(isOpen));
|
|
260
|
+
itemEl.querySelectorAll("[data-hu-nn-dropdown-panel]").forEach((panel) => {
|
|
261
|
+
panel.hidden = !isOpen;
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
const closeDropdown = () => {
|
|
266
|
+
openDropdown.value = null;
|
|
267
|
+
syncDesktopDropdowns(null, false);
|
|
268
|
+
};
|
|
269
|
+
const syncMobile = (open) => {
|
|
270
|
+
if (typeof document === "undefined")
|
|
271
|
+
return;
|
|
272
|
+
if (typeof document.querySelector !== "function")
|
|
273
|
+
return;
|
|
274
|
+
const root = document.querySelector(`[data-hu-nn-root="${id}"]`);
|
|
275
|
+
root?.querySelector(".hu-nested-navbar__toggle")?.setAttribute("aria-expanded", String(open));
|
|
276
|
+
const overlay = root?.querySelector(".hu-nested-navbar__mobile-overlay");
|
|
277
|
+
if (overlay) {
|
|
278
|
+
overlay.hidden = !open;
|
|
279
|
+
overlay.dataset.open = String(open);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const setMobileOpen = (open) => {
|
|
283
|
+
mobileOpen.value = open;
|
|
284
|
+
syncMobile(open);
|
|
285
|
+
};
|
|
286
|
+
const closeMobile = () => { setMobileOpen(false); };
|
|
287
|
+
const handleLinkClick = (event, onClick, onClose) => {
|
|
288
|
+
onClick?.(event);
|
|
289
|
+
onClose?.();
|
|
290
|
+
};
|
|
291
|
+
const setDropdownOpen = (event, key, open) => {
|
|
292
|
+
const itemEl = event ? event.currentTarget.closest(".hu-nested-navbar__item") : null;
|
|
293
|
+
openDropdown.value = open ? key : null;
|
|
294
|
+
syncDesktopDropdowns(itemEl, open);
|
|
295
|
+
};
|
|
296
|
+
const toggleDropdown = (event, key) => {
|
|
297
|
+
const itemEl = event ? event.currentTarget.closest(".hu-nested-navbar__item") : null;
|
|
298
|
+
const isOpen = itemEl?.dataset.open === "true" || openDropdown.value === key;
|
|
299
|
+
openDropdown.value = isOpen ? null : key;
|
|
300
|
+
syncDesktopDropdowns(itemEl, !isOpen);
|
|
301
|
+
};
|
|
302
|
+
const syncMobileAccordion = (itemEl, expanded) => {
|
|
303
|
+
itemEl?.setAttribute("data-expanded", String(expanded));
|
|
304
|
+
itemEl?.querySelector(".hu-nested-navbar__acc-trigger")?.setAttribute("aria-expanded", String(expanded));
|
|
305
|
+
itemEl?.querySelectorAll(".hu-nested-navbar__acc-content").forEach((panel) => {
|
|
306
|
+
panel.hidden = !expanded;
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
const toggleAccordion = (event, key) => {
|
|
310
|
+
const next = new Set(expandedItems.value);
|
|
311
|
+
const itemEl = event ? event.currentTarget.closest(".hu-nested-navbar__acc-item") : null;
|
|
312
|
+
const expanded = !(itemEl?.dataset.expanded === "true" || next.has(key));
|
|
313
|
+
if (expanded)
|
|
314
|
+
next.add(key);
|
|
315
|
+
else
|
|
316
|
+
next.delete(key);
|
|
317
|
+
expandedItems.value = next;
|
|
318
|
+
syncMobileAccordion(itemEl, expanded);
|
|
319
|
+
};
|
|
320
|
+
// ── Desktop nav items ──────────────────────────────────────────────────────
|
|
321
|
+
const renderDesktopItems = () => items.map((item, i) => {
|
|
322
|
+
const key = item.id ?? item.label + i;
|
|
323
|
+
if (!item.children?.length) {
|
|
324
|
+
return h("div", { key, class: "hu-nested-navbar__item" }, h("a", {
|
|
325
|
+
href: item.href ?? "#",
|
|
326
|
+
class: () => cn("hu-nested-navbar__link", isActive(item.active) && "hu-nested-navbar__link--active"),
|
|
327
|
+
onClick: (event) => handleLinkClick(event, item.onClick),
|
|
328
|
+
}, item.label));
|
|
329
|
+
}
|
|
330
|
+
return h("div", {
|
|
331
|
+
key,
|
|
332
|
+
class: "hu-nested-navbar__item",
|
|
333
|
+
"data-hu-nn-dropdown": key,
|
|
334
|
+
}, h("button", {
|
|
335
|
+
type: "button",
|
|
336
|
+
class: () => cn("hu-nested-navbar__trigger", isActive(item.active) && "hu-nested-navbar__trigger--active"),
|
|
337
|
+
"aria-haspopup": "true",
|
|
338
|
+
"aria-expanded": () => String(openDropdown.value === key),
|
|
339
|
+
onKeydown: (event) => {
|
|
340
|
+
if (event.key === "Enter" || event.key === " " || event.key === "ArrowDown") {
|
|
341
|
+
event.preventDefault();
|
|
342
|
+
setDropdownOpen(event, key, true);
|
|
343
|
+
}
|
|
344
|
+
if (event.key === "Escape") {
|
|
345
|
+
event.preventDefault();
|
|
346
|
+
setDropdownOpen(event, key, false);
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
onClick: (event) => toggleDropdown(event, key),
|
|
350
|
+
}, item.label, chevronDown), h("div", {
|
|
351
|
+
hidden: () => openDropdown.value !== key,
|
|
352
|
+
"data-hu-nn-dropdown-panel": "layer"
|
|
353
|
+
}, h("div", {
|
|
354
|
+
class: "hu-nested-navbar__dropdown",
|
|
355
|
+
role: "menu",
|
|
356
|
+
hidden: () => openDropdown.value !== key,
|
|
357
|
+
"data-hu-nn-dropdown-panel": "menu"
|
|
358
|
+
}, ...item.children.map((child) => h("a", {
|
|
359
|
+
key: child.href,
|
|
360
|
+
href: child.href,
|
|
361
|
+
class: () => cn("hu-nested-navbar__child", isActive(child.active) && "hu-nested-navbar__child--active"),
|
|
362
|
+
role: "menuitem",
|
|
363
|
+
onClick: (event) => handleLinkClick(event, child.onClick, closeDropdown),
|
|
364
|
+
}, child.icon && h("span", { class: "hu-nested-navbar__child-icon", "aria-hidden": "true" }, child.icon), h("span", { class: "hu-nested-navbar__child-body" }, h("span", { class: "hu-nested-navbar__child-label" }, child.label), child.description && h("span", { class: "hu-nested-navbar__child-desc" }, child.description)))))));
|
|
365
|
+
});
|
|
366
|
+
// ── Mobile accordion menu items ────────────────────────────────────────────
|
|
367
|
+
const renderMobileItems = (onClose) => items.map((item, i) => {
|
|
368
|
+
const key = item.id ?? item.label + i;
|
|
369
|
+
if (!item.children?.length) {
|
|
370
|
+
return h("a", {
|
|
371
|
+
key,
|
|
372
|
+
href: item.href ?? "#",
|
|
373
|
+
class: () => cn("hu-nested-navbar__mob-link", isActive(item.active) && "hu-nested-navbar__mob-link--active"),
|
|
374
|
+
onClick: (event) => handleLinkClick(event, item.onClick, onClose),
|
|
375
|
+
}, item.label);
|
|
376
|
+
}
|
|
377
|
+
const isExpanded = () => expandedItems.value.has(key);
|
|
378
|
+
return h("div", {
|
|
379
|
+
key,
|
|
380
|
+
class: "hu-nested-navbar__acc-item",
|
|
381
|
+
"data-expanded": () => String(isExpanded())
|
|
382
|
+
}, h("button", {
|
|
383
|
+
type: "button",
|
|
384
|
+
class: () => cn("hu-nested-navbar__acc-trigger", isActive(item.active) && "hu-nested-navbar__acc-trigger--active"),
|
|
385
|
+
"aria-expanded": () => String(isExpanded()),
|
|
386
|
+
onClick: (event) => toggleAccordion(event, key),
|
|
387
|
+
}, item.label, chevronDown16), h("div", {
|
|
388
|
+
class: "hu-nested-navbar__acc-content",
|
|
389
|
+
hidden: () => !isExpanded()
|
|
390
|
+
}, ...item.children.map((child) => h("a", {
|
|
391
|
+
key: child.href,
|
|
392
|
+
href: child.href,
|
|
393
|
+
class: () => cn("hu-nested-navbar__acc-child", isActive(child.active) && "hu-nested-navbar__acc-child--active"),
|
|
394
|
+
onClick: (event) => handleLinkClick(event, child.onClick, onClose),
|
|
395
|
+
}, child.label))));
|
|
396
|
+
});
|
|
397
|
+
// ── Mobile overlay ─────────────────────────────────────────────────────────
|
|
398
|
+
const renderMobileOverlay = () => {
|
|
399
|
+
const title = props.mobileTitle ?? "Menu";
|
|
400
|
+
const body = h("div", { class: mobileVariant === "bottom-sheet" ? "hu-nested-navbar__sheet-body" : "hu-nested-navbar__drawer-body" }, ...renderMobileItems(closeMobile));
|
|
401
|
+
const closeBtn = (cls) => h("button", {
|
|
402
|
+
type: "button",
|
|
403
|
+
class: cls,
|
|
404
|
+
"aria-label": "Close menu",
|
|
405
|
+
onClick: closeMobile,
|
|
406
|
+
}, closeIcon);
|
|
407
|
+
const overlay = mobileVariant === "bottom-sheet"
|
|
408
|
+
? h("div", { class: "hu-nested-navbar__sheet", role: "dialog", "aria-modal": "true", "aria-label": title }, h("div", { class: "hu-nested-navbar__sheet-handle" }), h("div", { class: "hu-nested-navbar__sheet-header" }, h("span", { class: "hu-nested-navbar__sheet-title" }, title), closeBtn("hu-nested-navbar__sheet-close")), body)
|
|
409
|
+
: h("aside", { class: "hu-nested-navbar__drawer", role: "dialog", "aria-modal": "true", "aria-label": title }, h("div", { class: "hu-nested-navbar__drawer-header" }, props.brand
|
|
410
|
+
? h("a", {
|
|
411
|
+
href: props.brandHref ?? "/",
|
|
412
|
+
class: "hu-nested-navbar__drawer-brand",
|
|
413
|
+
onClick: (event) => handleLinkClick(event, props.onBrandClick, closeMobile)
|
|
414
|
+
}, props.brand)
|
|
415
|
+
: h("span", { class: "hu-nested-navbar__drawer-brand" }, title), closeBtn("hu-nested-navbar__drawer-close")), body);
|
|
416
|
+
return h("div", {
|
|
417
|
+
class: "hu-nested-navbar__mobile-overlay",
|
|
418
|
+
hidden: () => !mobileOpen.value,
|
|
419
|
+
"data-open": () => String(mobileOpen.value)
|
|
420
|
+
}, h("div", { class: "hu-nested-navbar__backdrop", onClick: closeMobile, "aria-hidden": "true" }), FocusTrap({ active: true, restoreFocus: true, autoFocus: true, onEscape: closeMobile, children: overlay }));
|
|
421
|
+
};
|
|
422
|
+
// ── Root VNode ─────────────────────────────────────────────────────────────
|
|
423
|
+
return h("div", { style: "display:contents;", "data-hu-nn-root": id }, h("header", { class: cn("hu-nested-navbar", props.class), id }, props.brand && h("a", {
|
|
424
|
+
href: props.brandHref ?? "/",
|
|
425
|
+
class: "hu-nested-navbar__brand",
|
|
426
|
+
onClick: props.onBrandClick
|
|
427
|
+
}, props.brand), h("nav", { class: "hu-nested-navbar__nav", "aria-label": "Main navigation" }, ...renderDesktopItems()), h("div", { class: "hu-nested-navbar__end" }, props.actions && h("div", { class: "hu-nested-navbar__actions" }, props.actions), h("button", {
|
|
428
|
+
type: "button",
|
|
429
|
+
class: "hu-nested-navbar__toggle",
|
|
430
|
+
"aria-label": "Open menu",
|
|
431
|
+
"aria-expanded": () => String(mobileOpen.value),
|
|
432
|
+
"aria-haspopup": "dialog",
|
|
433
|
+
onClick: () => { setMobileOpen(true); },
|
|
434
|
+
}, menuIcon))), renderMobileOverlay);
|
|
435
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type Signal } from "@hyperpackai/hyperion";
|
|
2
|
+
import { type VNode } from "../../theme/index.js";
|
|
3
|
+
export interface NestedSidebarChildItem {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
href?: string;
|
|
7
|
+
icon?: unknown;
|
|
8
|
+
active?: boolean | Signal<boolean> | (() => boolean);
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface NestedSidebarItem {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
icon?: unknown;
|
|
15
|
+
badge?: unknown;
|
|
16
|
+
href?: string;
|
|
17
|
+
active?: boolean | Signal<boolean> | (() => boolean);
|
|
18
|
+
onClick?: () => void;
|
|
19
|
+
children?: NestedSidebarChildItem[];
|
|
20
|
+
defaultExpanded?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface NestedSidebarSection {
|
|
23
|
+
label?: string;
|
|
24
|
+
items: NestedSidebarItem[];
|
|
25
|
+
}
|
|
26
|
+
export type NestedSidebarMobileVariant = "drawer" | "bottom-sheet";
|
|
27
|
+
export type NestedSidebarPosition = "static" | "sticky" | "fixed";
|
|
28
|
+
export interface NestedSidebarProps {
|
|
29
|
+
id?: string;
|
|
30
|
+
header?: unknown;
|
|
31
|
+
sections: NestedSidebarSection[];
|
|
32
|
+
footer?: unknown;
|
|
33
|
+
width?: "sm" | "md" | "lg";
|
|
34
|
+
position?: NestedSidebarPosition;
|
|
35
|
+
topOffset?: string | number;
|
|
36
|
+
height?: string | number;
|
|
37
|
+
responsive?: boolean;
|
|
38
|
+
mobileVariant?: NestedSidebarMobileVariant;
|
|
39
|
+
menuLabel?: string;
|
|
40
|
+
menuIcon?: unknown;
|
|
41
|
+
drawerTitle?: string;
|
|
42
|
+
open?: boolean | Signal<boolean>;
|
|
43
|
+
defaultOpen?: boolean;
|
|
44
|
+
onOpenChange?: (open: boolean) => void;
|
|
45
|
+
class?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function NestedSidebar(props: NestedSidebarProps): VNode;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/NestedSidebar/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAoB,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAqMpE,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACpC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B;AAED,MAAM,MAAM,0BAA0B,GAAG,QAAQ,GAAG,cAAc,CAAC;AACnE,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElE,MAAM,WAAW,kBAAkB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,oBAAoB,EAAE,CAAC;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA4ED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,KAAK,CAuM9D"}
|