@whity/ui 0.5.0 → 1.0.1
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 +107 -107
- package/package.json +223 -192
- package/src/access-denied.stories.tsx +179 -179
- package/src/access-denied.tsx +305 -305
- package/src/action-proposal.tsx +338 -302
- package/src/actor-chip.tsx +71 -71
- package/src/agent-activity.tsx +163 -163
- package/src/agent-collaboration.stories.tsx +156 -156
- package/src/agent-run-status.tsx +196 -196
- package/src/alert-dialog.stories.tsx +45 -45
- package/src/alert-dialog.tsx +147 -147
- package/src/alert.stories.tsx +91 -91
- package/src/alert.tsx +89 -89
- package/src/app-sidebar.stories.tsx +195 -195
- package/src/app-sidebar.tsx +604 -500
- package/src/approval-queue.tsx +109 -108
- package/src/audience-group-picker.stories.tsx +198 -198
- package/src/audience-group-picker.tsx +362 -362
- package/src/audience-people-picker.stories.tsx +102 -102
- package/src/audience-people-picker.tsx +279 -279
- package/src/avatar-pattern.ts +138 -0
- package/src/avatar.tsx +125 -83
- package/src/badge.stories.tsx +105 -105
- package/src/badge.tsx +68 -68
- package/src/beta-warning.stories.tsx +79 -79
- package/src/beta-warning.tsx +189 -189
- package/src/bilingual-input.stories.tsx +82 -82
- package/src/bilingual-input.tsx +188 -183
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -51
- package/src/breadcrumb.tsx +90 -90
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -87
- package/src/button.tsx +125 -118
- package/src/card.stories.tsx +423 -423
- package/src/card.tsx +180 -180
- package/src/chart.stories.tsx +66 -66
- package/src/chart.tsx +228 -228
- package/src/checkbox.stories.tsx +62 -62
- package/src/checkbox.tsx +54 -54
- package/src/collapsible.stories.tsx +48 -48
- package/src/collapsible.tsx +34 -34
- package/src/color-card.stories.tsx +61 -61
- package/src/color-card.tsx +270 -270
- package/src/color-picker.stories.tsx +65 -65
- package/src/color-picker.tsx +425 -425
- package/src/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +399 -306
- package/src/confirm-action.tsx +98 -0
- package/src/copy-block.stories.tsx +38 -38
- package/src/copy-block.tsx +85 -85
- package/src/data-table.stories.tsx +200 -200
- package/src/data-table.tsx +1687 -1106
- package/src/date-picker.stories.tsx +61 -61
- package/src/date-picker.tsx +457 -422
- package/src/design-cards.stories.tsx +551 -458
- package/src/dialog.stories.tsx +48 -48
- package/src/dialog.tsx +179 -166
- package/src/display-preferences.tsx +59 -0
- package/src/documents/barcode-svg.stories.tsx +72 -72
- package/src/documents/barcode-svg.tsx +79 -79
- package/src/dropdown-menu.stories.tsx +77 -77
- package/src/dropdown-menu.tsx +271 -271
- package/src/editor/agent-panel.tsx +222 -0
- package/src/editor/agents.stories.tsx +81 -0
- package/src/editor/agents.ts +55 -0
- package/src/editor/behaviour.ts +279 -279
- package/src/editor/block-ids.ts +44 -44
- package/src/editor/block-list.tsx +104 -101
- package/src/editor/block-toolbar.tsx +490 -477
- package/src/editor/bubble.tsx +119 -93
- package/src/editor/catalogue.ts +169 -103
- package/src/editor/collab-rail.tsx +746 -746
- package/src/editor/collab.stories.tsx +207 -207
- package/src/editor/collab.ts +87 -87
- package/src/editor/contract.ts +476 -408
- package/src/editor/convert.ts +414 -362
- package/src/editor/doc-editor.stories.tsx +98 -98
- package/src/editor/doc-editor.tsx +1492 -1287
- package/src/editor/editor.css +636 -536
- package/src/editor/extensions.ts +86 -86
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -107
- package/src/editor/fields.ts +100 -100
- package/src/editor/gutter.tsx +443 -367
- package/src/editor/index.ts +23 -22
- package/src/editor/label-sheet.tsx +289 -289
- package/src/editor/labels.ts +394 -310
- package/src/editor/link-tools.tsx +141 -141
- package/src/editor/node-views.tsx +461 -450
- package/src/editor/page-view.tsx +372 -353
- package/src/editor/phone.tsx +310 -0
- package/src/editor/plugin-block-view.tsx +230 -0
- package/src/editor/plugin-blocks.stories.tsx +96 -0
- package/src/editor/plugin-blocks.ts +52 -0
- package/src/editor/publish-check.tsx +201 -182
- package/src/editor/rich-blocks.stories.tsx +146 -146
- package/src/editor/sample.ts +40 -40
- package/src/editor/save-block-dialog.tsx +141 -0
- package/src/editor/saved-block-view.tsx +205 -0
- package/src/editor/saved-blocks.stories.tsx +105 -0
- package/src/editor/saved-parts.ts +192 -0
- package/src/editor/schema-rich.ts +156 -150
- package/src/editor/schema.ts +368 -315
- package/src/editor/services.tsx +205 -127
- package/src/editor/slash.ts +64 -64
- package/src/editor/suggesting.ts +372 -372
- package/src/editor/suggestions.ts +763 -763
- package/src/editor/table-keys.ts +66 -66
- package/src/editor/templates.stories.tsx +324 -324
- package/src/editor/toolbar.tsx +364 -358
- package/src/empty-state.stories.tsx +51 -51
- package/src/empty-state.tsx +126 -100
- package/src/empty-state.usage-notes.md +30 -30
- package/src/form.stories.tsx +112 -112
- package/src/form.tsx +176 -176
- package/src/globals.css +20 -20
- package/src/icon-button.tsx +85 -85
- package/src/icon-map.ts +335 -244
- package/src/icon.tsx +41 -41
- package/src/index.ts +92 -67
- package/src/input.stories.tsx +157 -157
- package/src/input.tsx +768 -759
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -29
- package/src/locked-screen.tsx +75 -61
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -0
- package/src/mark.tsx +62 -62
- package/src/math-text.stories.tsx +33 -33
- package/src/math-text.tsx +43 -43
- package/src/menu-bar.stories.tsx +198 -198
- package/src/menu-bar.tsx +373 -373
- package/src/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -230
- package/src/money/money-input.tsx +131 -0
- package/src/money/money.tsx +33 -0
- package/src/open-on-computer.tsx +150 -0
- package/src/otp-input.tsx +161 -0
- package/src/page-header.stories.tsx +95 -95
- package/src/page-header.tsx +122 -122
- package/src/page-shell.stories.tsx +42 -42
- package/src/page-shell.tsx +32 -32
- package/src/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -45
- package/src/pagination.tsx +98 -98
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-input.tsx +252 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -180
- package/src/plugin-card.tsx +931 -848
- package/src/popover.stories.tsx +48 -48
- package/src/popover.tsx +55 -55
- package/src/radio-group.stories.tsx +26 -26
- package/src/radio-group.tsx +44 -44
- package/src/role-summary.stories.tsx +143 -0
- package/src/role-summary.tsx +120 -0
- package/src/route-flow/editor.tsx +1087 -1014
- package/src/route-flow/model.ts +771 -716
- package/src/save-bar.tsx +94 -0
- package/src/scope-grant.tsx +139 -139
- package/src/screen-too-small.stories.tsx +61 -61
- package/src/screen-too-small.tsx +104 -104
- package/src/search-field.tsx +65 -0
- package/src/select.stories.tsx +44 -44
- package/src/select.tsx +197 -197
- package/src/separator.stories.tsx +34 -34
- package/src/separator.tsx +34 -34
- package/src/sheet.stories.tsx +49 -49
- package/src/sheet.tsx +168 -168
- package/src/skeleton.stories.tsx +28 -28
- package/src/skeleton.tsx +19 -19
- package/src/slider.stories.tsx +78 -78
- package/src/slider.tsx +300 -300
- package/src/spinner.stories.tsx +33 -33
- package/src/spinner.tsx +55 -55
- package/src/stepper.tsx +85 -0
- package/src/switch.stories.tsx +42 -42
- package/src/switch.tsx +41 -41
- package/src/switcher.stories.tsx +111 -111
- package/src/switcher.tsx +131 -131
- package/src/system-state.tsx +55 -0
- package/src/table.stories.tsx +48 -48
- package/src/table.tsx +121 -121
- package/src/tabs.stories.tsx +74 -74
- package/src/tabs.tsx +90 -90
- package/src/tag-input.stories.tsx +67 -67
- package/src/tag-input.tsx +117 -117
- package/src/tenant-logo.tsx +63 -63
- package/src/tenant-switcher.stories.tsx +38 -38
- package/src/tenant-switcher.tsx +185 -164
- package/src/textarea.stories.tsx +27 -27
- package/src/textarea.tsx +18 -18
- package/src/theme-mode.ts +74 -52
- package/src/time-grid.tsx +163 -0
- package/src/time-picker.stories.tsx +62 -62
- package/src/time-picker.tsx +616 -615
- package/src/toggle-group.tsx +139 -138
- package/src/tooltip.stories.tsx +43 -43
- package/src/tooltip.tsx +73 -73
- package/src/top-nav.stories.tsx +58 -58
- package/src/top-nav.tsx +324 -324
- package/src/undo-bar.tsx +107 -107
- package/src/utils.ts +45 -45
- package/src/view-toggle.stories.tsx +84 -84
- package/src/view-toggle.tsx +111 -110
package/src/app-sidebar.tsx
CHANGED
|
@@ -1,500 +1,604 @@
|
|
|
1
|
-
import * as React from "react"
|
|
2
|
-
import {
|
|
3
|
-
IconChevronDown,
|
|
4
|
-
IconChevronLeft,
|
|
5
|
-
IconChevronRight,
|
|
6
|
-
IconMenu2,
|
|
7
|
-
IconSearch,
|
|
8
|
-
IconX,
|
|
9
|
-
} from "@tabler/icons-react"
|
|
10
|
-
|
|
11
|
-
import { cn } from "./utils"
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* PRESENTATIONAL app-shell sidebar only — a controlled, data-driven nav
|
|
15
|
-
* chrome. Fetching nav items (RBAC/tenant-filtered), branding, tenant/team
|
|
16
|
-
* switching, and theme/direction toggles belong to the app-specific
|
|
17
|
-
* composed wrapper (e.g. web/components/sidebar.tsx's `Sidebar`), which
|
|
18
|
-
* renders this component and passes it `groups` + slot content — the same
|
|
19
|
-
* split Breadcrumb already draws between itself and route-derived crumbs.
|
|
20
|
-
*
|
|
21
|
-
* Multi-tenant + multi-team: `tenantSwitcher` and `teamSwitcher` are
|
|
22
|
-
* independent optional slots (see each prop's doc below) built from the
|
|
23
|
-
* shared `Switcher` primitive — a user might have many tenants and no
|
|
24
|
-
* teams, one tenant and many teams, both, or neither; which nav `groups`
|
|
25
|
-
* to pass is entirely the composed caller's decision (e.g. re-fetch/swap
|
|
26
|
-
* `groups` when the active team changes), this component has no concept
|
|
27
|
-
* of "tenant" or "team" itself.
|
|
28
|
-
*
|
|
29
|
-
* PLATFORM NOTE: `groups`/`items` are plain data (label + href + optional
|
|
30
|
-
* icon) — the same shape a Flutter or Tauri-native nav rail would consume;
|
|
31
|
-
* this component owns only the desktop-web collapse/expand + mobile
|
|
32
|
-
* slide-over chrome around that data.
|
|
33
|
-
*
|
|
34
|
-
* I18N: every user-visible string is a prop with an English default, and
|
|
35
|
-
* nothing here imports a translator — the composed wrapper passes already
|
|
36
|
-
* translated text, so the same component serves a client with no i18n layer
|
|
37
|
-
* and one with a full catalogue.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
export interface AppSidebarNavItem {
|
|
41
|
-
id: string
|
|
42
|
-
label: string
|
|
43
|
-
href: string
|
|
44
|
-
icon?: React.ReactNode
|
|
45
|
-
/** Marks the item as the current page (styling only — routing is the caller's job). */
|
|
46
|
-
active?: boolean
|
|
47
|
-
/**
|
|
48
|
-
* Things waiting for the person (Inbox, Approvals). A pill beside the label;
|
|
49
|
-
* in the rail, a dot on the icon (AppShellCollapsed). Zero or absent shows nothing.
|
|
50
|
-
*/
|
|
51
|
-
count?: number
|
|
52
|
-
/** Accessible text for the count, e.g. "3 waiting". Defaults to the number. */
|
|
53
|
-
countLabel?: string
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface AppSidebarNavGroup {
|
|
57
|
-
id: string
|
|
58
|
-
/**
|
|
59
|
-
* Optional group heading, hidden entirely when the sidebar is collapsed.
|
|
60
|
-
* A group WITHOUT a label is never collapsible — there is no header to
|
|
61
|
-
* click — so its items always render. Use that for a short trailing set
|
|
62
|
-
* that must stay reachable regardless of collapse state.
|
|
63
|
-
*/
|
|
64
|
-
label?: string
|
|
65
|
-
items: AppSidebarNavItem[]
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface AppSidebarProps {
|
|
69
|
-
/** Branding/logo slot, rendered above the switchers/nav. */
|
|
70
|
-
header?: React.ReactNode
|
|
71
|
-
/**
|
|
72
|
-
* Optional tenant-switcher slot (e.g. built from the shared `Switcher`
|
|
73
|
-
* primitive). A multi-tenant client renders one here; a single-tenant
|
|
74
|
-
* client omits it entirely — this component has no opinion on tenants.
|
|
75
|
-
* If provided, keep it in sync with `collapsed` (pass this same prop's
|
|
76
|
-
* value to the `Switcher`/custom control you render here) so it matches
|
|
77
|
-
* the sidebar's icon-only state.
|
|
78
|
-
*/
|
|
79
|
-
tenantSwitcher?: React.ReactNode
|
|
80
|
-
/**
|
|
81
|
-
* Optional team-switcher slot, independent of `tenantSwitcher` — a user
|
|
82
|
-
* may have many teams and one tenant (show only this), many tenants and
|
|
83
|
-
* no teams (show only that), both, or neither. Whether to render either
|
|
84
|
-
* slot at all is entirely the composed caller's call; this component
|
|
85
|
-
* just reserves the layout position and stacks whatever it's given.
|
|
86
|
-
*/
|
|
87
|
-
teamSwitcher?: React.ReactNode
|
|
88
|
-
groups: AppSidebarNavGroup[]
|
|
89
|
-
/** User menu / theme toggle slot, rendered below the nav. */
|
|
90
|
-
footer?: React.ReactNode
|
|
91
|
-
/** Controlled collapsed (icon-only) state. Uncontrolled if omitted. */
|
|
92
|
-
collapsed?: boolean
|
|
93
|
-
/** Called when the user clicks the collapse toggle. */
|
|
94
|
-
onCollapsedChange?: (collapsed: boolean) => void
|
|
95
|
-
/** Controlled mobile open state. Uncontrolled if omitted. */
|
|
96
|
-
mobileOpen?: boolean
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const [
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
React.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
)
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
}
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import {
|
|
3
|
+
IconChevronDown,
|
|
4
|
+
IconChevronLeft,
|
|
5
|
+
IconChevronRight,
|
|
6
|
+
IconMenu2,
|
|
7
|
+
IconSearch,
|
|
8
|
+
IconX,
|
|
9
|
+
} from "@tabler/icons-react"
|
|
10
|
+
|
|
11
|
+
import { cn } from "./utils"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* PRESENTATIONAL app-shell sidebar only — a controlled, data-driven nav
|
|
15
|
+
* chrome. Fetching nav items (RBAC/tenant-filtered), branding, tenant/team
|
|
16
|
+
* switching, and theme/direction toggles belong to the app-specific
|
|
17
|
+
* composed wrapper (e.g. web/components/sidebar.tsx's `Sidebar`), which
|
|
18
|
+
* renders this component and passes it `groups` + slot content — the same
|
|
19
|
+
* split Breadcrumb already draws between itself and route-derived crumbs.
|
|
20
|
+
*
|
|
21
|
+
* Multi-tenant + multi-team: `tenantSwitcher` and `teamSwitcher` are
|
|
22
|
+
* independent optional slots (see each prop's doc below) built from the
|
|
23
|
+
* shared `Switcher` primitive — a user might have many tenants and no
|
|
24
|
+
* teams, one tenant and many teams, both, or neither; which nav `groups`
|
|
25
|
+
* to pass is entirely the composed caller's decision (e.g. re-fetch/swap
|
|
26
|
+
* `groups` when the active team changes), this component has no concept
|
|
27
|
+
* of "tenant" or "team" itself.
|
|
28
|
+
*
|
|
29
|
+
* PLATFORM NOTE: `groups`/`items` are plain data (label + href + optional
|
|
30
|
+
* icon) — the same shape a Flutter or Tauri-native nav rail would consume;
|
|
31
|
+
* this component owns only the desktop-web collapse/expand + mobile
|
|
32
|
+
* slide-over chrome around that data.
|
|
33
|
+
*
|
|
34
|
+
* I18N: every user-visible string is a prop with an English default, and
|
|
35
|
+
* nothing here imports a translator — the composed wrapper passes already
|
|
36
|
+
* translated text, so the same component serves a client with no i18n layer
|
|
37
|
+
* and one with a full catalogue.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
export interface AppSidebarNavItem {
|
|
41
|
+
id: string
|
|
42
|
+
label: string
|
|
43
|
+
href: string
|
|
44
|
+
icon?: React.ReactNode
|
|
45
|
+
/** Marks the item as the current page (styling only — routing is the caller's job). */
|
|
46
|
+
active?: boolean
|
|
47
|
+
/**
|
|
48
|
+
* Things waiting for the person (Inbox, Approvals). A pill beside the label;
|
|
49
|
+
* in the rail, a dot on the icon (AppShellCollapsed). Zero or absent shows nothing.
|
|
50
|
+
*/
|
|
51
|
+
count?: number
|
|
52
|
+
/** Accessible text for the count, e.g. "3 waiting". Defaults to the number. */
|
|
53
|
+
countLabel?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface AppSidebarNavGroup {
|
|
57
|
+
id: string
|
|
58
|
+
/**
|
|
59
|
+
* Optional group heading, hidden entirely when the sidebar is collapsed.
|
|
60
|
+
* A group WITHOUT a label is never collapsible — there is no header to
|
|
61
|
+
* click — so its items always render. Use that for a short trailing set
|
|
62
|
+
* that must stay reachable regardless of collapse state.
|
|
63
|
+
*/
|
|
64
|
+
label?: string
|
|
65
|
+
items: AppSidebarNavItem[]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface AppSidebarProps {
|
|
69
|
+
/** Branding/logo slot, rendered above the switchers/nav. */
|
|
70
|
+
header?: React.ReactNode
|
|
71
|
+
/**
|
|
72
|
+
* Optional tenant-switcher slot (e.g. built from the shared `Switcher`
|
|
73
|
+
* primitive). A multi-tenant client renders one here; a single-tenant
|
|
74
|
+
* client omits it entirely — this component has no opinion on tenants.
|
|
75
|
+
* If provided, keep it in sync with `collapsed` (pass this same prop's
|
|
76
|
+
* value to the `Switcher`/custom control you render here) so it matches
|
|
77
|
+
* the sidebar's icon-only state.
|
|
78
|
+
*/
|
|
79
|
+
tenantSwitcher?: React.ReactNode
|
|
80
|
+
/**
|
|
81
|
+
* Optional team-switcher slot, independent of `tenantSwitcher` — a user
|
|
82
|
+
* may have many teams and one tenant (show only this), many tenants and
|
|
83
|
+
* no teams (show only that), both, or neither. Whether to render either
|
|
84
|
+
* slot at all is entirely the composed caller's call; this component
|
|
85
|
+
* just reserves the layout position and stacks whatever it's given.
|
|
86
|
+
*/
|
|
87
|
+
teamSwitcher?: React.ReactNode
|
|
88
|
+
groups: AppSidebarNavGroup[]
|
|
89
|
+
/** User menu / theme toggle slot, rendered below the nav. */
|
|
90
|
+
footer?: React.ReactNode
|
|
91
|
+
/** Controlled collapsed (icon-only) state. Uncontrolled if omitted. */
|
|
92
|
+
collapsed?: boolean
|
|
93
|
+
/** Called when the user clicks the collapse toggle. */
|
|
94
|
+
onCollapsedChange?: (collapsed: boolean) => void
|
|
95
|
+
/** Controlled mobile open state. Uncontrolled if omitted. */
|
|
96
|
+
mobileOpen?: boolean
|
|
97
|
+
/**
|
|
98
|
+
* Under 640px the host shows the phone tab bar (`PwNav`, `PhoneTabBar`)
|
|
99
|
+
* instead: the drawer and its open button leave the phone layout, and More
|
|
100
|
+
* lists the same groups. 640–767px keeps the drawer, 768–1023px the rail.
|
|
101
|
+
*/
|
|
102
|
+
phoneTabBar?: boolean
|
|
103
|
+
/**
|
|
104
|
+
* Groups pinned at the foot, above `footer`, outside the scrolling list
|
|
105
|
+
* (`PwShortSidebar`, PW.10): on a short window Settings stays put with the
|
|
106
|
+
* account row while only the links between them scroll.
|
|
107
|
+
*/
|
|
108
|
+
pinnedGroupIds?: readonly string[]
|
|
109
|
+
onMobileOpenChange?: (open: boolean) => void
|
|
110
|
+
/** Custom link component (e.g. Next.js <Link>) — defaults to a plain <a>. */
|
|
111
|
+
linkComponent?: React.ElementType
|
|
112
|
+
/**
|
|
113
|
+
* Turn group headings into disclosure buttons. Groups the user has not
|
|
114
|
+
* opened render their items HIDDEN rather than unmounted — see the
|
|
115
|
+
* `hidden` attribute in the group body below for why that distinction is
|
|
116
|
+
* load-bearing.
|
|
117
|
+
*/
|
|
118
|
+
collapsibleGroups?: boolean
|
|
119
|
+
/**
|
|
120
|
+
* Controlled set of open group ids. Uncontrolled if omitted, in which
|
|
121
|
+
* case exactly one group starts open: the one holding the active item
|
|
122
|
+
* (falling back to the first group when nothing is active). Navigating to
|
|
123
|
+
* another group's page opens that group, without closing anything the
|
|
124
|
+
* user opened by hand.
|
|
125
|
+
*/
|
|
126
|
+
expandedGroupIds?: readonly string[]
|
|
127
|
+
onExpandedGroupsChange?: (expanded: readonly string[]) => void
|
|
128
|
+
/** Render a filter box above the nav that narrows items by label. */
|
|
129
|
+
searchable?: boolean
|
|
130
|
+
/** Controlled search query. Uncontrolled if omitted. */
|
|
131
|
+
searchValue?: string
|
|
132
|
+
onSearchChange?: (value: string) => void
|
|
133
|
+
/** Placeholder AND accessible name for the filter box. Defaults to "Search". */
|
|
134
|
+
searchPlaceholder?: string
|
|
135
|
+
/** Accessible name for the button that empties the filter box. */
|
|
136
|
+
clearSearchLabel?: string
|
|
137
|
+
/** Shown in place of the nav when a query matches no item. */
|
|
138
|
+
searchNoResultsLabel?: string
|
|
139
|
+
/** Accessible name for the navigation landmark. Defaults to "Main". */
|
|
140
|
+
navLabel?: string
|
|
141
|
+
/** Accessible name for the button that opens the mobile drawer. */
|
|
142
|
+
openNavLabel?: string
|
|
143
|
+
/** Accessible name for the button that closes the mobile drawer. */
|
|
144
|
+
closeNavLabel?: string
|
|
145
|
+
/** Text of the collapse toggle. Defaults to "Collapse". */
|
|
146
|
+
collapseLabel?: string
|
|
147
|
+
/**
|
|
148
|
+
* Accessible names for the collapse toggle in each direction. Separate
|
|
149
|
+
* from `collapseLabel`, which is the visible text beside the icon.
|
|
150
|
+
*/
|
|
151
|
+
collapseAriaLabel?: string
|
|
152
|
+
expandAriaLabel?: string
|
|
153
|
+
className?: string
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* True between 768 and 1023px, where the sidebar is the 56px rail whatever the
|
|
158
|
+
* collapse toggle says (register 4.5). Below 768 it is the drawer; from 1024
|
|
159
|
+
* the person's own choice applies. Exported so the composed wrapper can size
|
|
160
|
+
* its own slot content (logo, switcher, footer) to the same state.
|
|
161
|
+
*/
|
|
162
|
+
export function useForcedRail(): boolean {
|
|
163
|
+
const [forced, setForced] = React.useState(false)
|
|
164
|
+
React.useEffect(() => {
|
|
165
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return
|
|
166
|
+
const query = window.matchMedia("(min-width: 768px) and (max-width: 1023.98px)")
|
|
167
|
+
const update = () => setForced(query.matches)
|
|
168
|
+
update()
|
|
169
|
+
query.addEventListener?.("change", update)
|
|
170
|
+
return () => query.removeEventListener?.("change", update)
|
|
171
|
+
}, [])
|
|
172
|
+
return forced
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Case-insensitive substring match, tolerant of surrounding whitespace. */
|
|
176
|
+
/**
|
|
177
|
+
* True below 768px, where the sidebar is an off-canvas drawer. A closed
|
|
178
|
+
* drawer is only moved off the screen, so it must also be made inert or its
|
|
179
|
+
* links stay in the tab order and in a screen reader's reading order.
|
|
180
|
+
*/
|
|
181
|
+
function usePhoneDrawer(): boolean {
|
|
182
|
+
const [phone, setPhone] = React.useState(false)
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return
|
|
185
|
+
const query = window.matchMedia("(max-width: 767.98px)")
|
|
186
|
+
const update = () => setPhone(query.matches)
|
|
187
|
+
update()
|
|
188
|
+
query.addEventListener?.("change", update)
|
|
189
|
+
return () => query.removeEventListener?.("change", update)
|
|
190
|
+
}, [])
|
|
191
|
+
return phone
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function matches(label: string, normalizedQuery: string): boolean {
|
|
195
|
+
return label.toLocaleLowerCase().includes(normalizedQuery)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export function AppSidebar({
|
|
199
|
+
header,
|
|
200
|
+
tenantSwitcher,
|
|
201
|
+
teamSwitcher,
|
|
202
|
+
groups,
|
|
203
|
+
footer,
|
|
204
|
+
collapsed: collapsedProp,
|
|
205
|
+
onCollapsedChange,
|
|
206
|
+
mobileOpen: mobileOpenProp,
|
|
207
|
+
phoneTabBar = false,
|
|
208
|
+
pinnedGroupIds,
|
|
209
|
+
onMobileOpenChange,
|
|
210
|
+
linkComponent,
|
|
211
|
+
collapsibleGroups = false,
|
|
212
|
+
expandedGroupIds,
|
|
213
|
+
onExpandedGroupsChange,
|
|
214
|
+
searchable = false,
|
|
215
|
+
searchValue,
|
|
216
|
+
onSearchChange,
|
|
217
|
+
searchPlaceholder = "Search",
|
|
218
|
+
clearSearchLabel = "Clear search",
|
|
219
|
+
searchNoResultsLabel = "No matching pages",
|
|
220
|
+
navLabel = "Main",
|
|
221
|
+
openNavLabel = "Open navigation",
|
|
222
|
+
closeNavLabel = "Close navigation",
|
|
223
|
+
collapseLabel = "Collapse",
|
|
224
|
+
collapseAriaLabel = "Collapse sidebar",
|
|
225
|
+
expandAriaLabel = "Expand sidebar",
|
|
226
|
+
className,
|
|
227
|
+
}: AppSidebarProps) {
|
|
228
|
+
const [collapsedState, setCollapsedState] = React.useState(false)
|
|
229
|
+
const forcedRail = useForcedRail()
|
|
230
|
+
const collapsed = (forcedRail && !(mobileOpenProp ?? false)) || (collapsedProp ?? collapsedState)
|
|
231
|
+
const setCollapsed = (next: boolean) => {
|
|
232
|
+
setCollapsedState(next)
|
|
233
|
+
onCollapsedChange?.(next)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const [mobileOpenState, setMobileOpenState] = React.useState(false)
|
|
237
|
+
const mobileOpen = mobileOpenProp ?? mobileOpenState
|
|
238
|
+
const phoneDrawer = usePhoneDrawer()
|
|
239
|
+
const setMobileOpen = (next: boolean) => {
|
|
240
|
+
setMobileOpenState(next)
|
|
241
|
+
onMobileOpenChange?.(next)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// The drawer is modal on a phone (a scrim covers the page), so Escape
|
|
245
|
+
// closes it like every other modal layer.
|
|
246
|
+
React.useEffect(() => {
|
|
247
|
+
if (!mobileOpen) return
|
|
248
|
+
const onKey = (event: KeyboardEvent) => {
|
|
249
|
+
if (event.key === "Escape") setMobileOpen(false)
|
|
250
|
+
}
|
|
251
|
+
window.addEventListener("keydown", onKey)
|
|
252
|
+
return () => window.removeEventListener("keydown", onKey)
|
|
253
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
|
+
}, [mobileOpen])
|
|
255
|
+
|
|
256
|
+
const [queryState, setQueryState] = React.useState("")
|
|
257
|
+
const query = searchValue ?? queryState
|
|
258
|
+
const setQuery = (next: string) => {
|
|
259
|
+
if (searchValue === undefined) setQueryState(next)
|
|
260
|
+
onSearchChange?.(next)
|
|
261
|
+
}
|
|
262
|
+
const normalizedQuery = query.trim().toLocaleLowerCase()
|
|
263
|
+
const searching = normalizedQuery !== ""
|
|
264
|
+
|
|
265
|
+
// The group holding the current page, which is what starts open. Falls back
|
|
266
|
+
// to the first group so an unmatched route (a detail page no nav item owns)
|
|
267
|
+
// still shows something rather than a stack of closed headers.
|
|
268
|
+
const openByDefaultGroupId = React.useMemo(() => {
|
|
269
|
+
const active = groups.find((group) => group.items.some((item) => item.active))
|
|
270
|
+
return active?.id ?? groups[0]?.id ?? null
|
|
271
|
+
}, [groups])
|
|
272
|
+
|
|
273
|
+
const [expandedState, setExpandedState] = React.useState<readonly string[]>([])
|
|
274
|
+
const expanded = expandedGroupIds ?? expandedState
|
|
275
|
+
|
|
276
|
+
// `groups` typically arrives empty on first render and fills in after the
|
|
277
|
+
// nav fetch resolves, so the default cannot be computed in useState's
|
|
278
|
+
// initializer — it has to react to the id appearing. Keyed on the id alone:
|
|
279
|
+
// a group the user opened by hand survives navigation within it, and only a
|
|
280
|
+
// move to a DIFFERENT group re-narrows the sidebar to that one.
|
|
281
|
+
React.useEffect(() => {
|
|
282
|
+
if (expandedGroupIds !== undefined) return
|
|
283
|
+
if (openByDefaultGroupId === null) return
|
|
284
|
+
// Only the current group stays open (section 21): moving to another group
|
|
285
|
+
// folds the rest.
|
|
286
|
+
setExpandedState([openByDefaultGroupId])
|
|
287
|
+
}, [openByDefaultGroupId, expandedGroupIds])
|
|
288
|
+
|
|
289
|
+
const toggleGroup = (id: string) => {
|
|
290
|
+
// Opening a group folds the others; only the current group stays open.
|
|
291
|
+
const next = expanded.includes(id) ? expanded.filter((groupId) => groupId !== id) : [id]
|
|
292
|
+
if (expandedGroupIds === undefined) setExpandedState(next)
|
|
293
|
+
onExpandedGroupsChange?.(next)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const Link = linkComponent ?? "a"
|
|
297
|
+
|
|
298
|
+
// While a query is active the disclosure state is bypassed entirely: the
|
|
299
|
+
// point of the box is to reach an item without knowing which group holds
|
|
300
|
+
// it. Groups with no match drop out so the result list stays short.
|
|
301
|
+
const pinned = React.useMemo(
|
|
302
|
+
() => (searching ? [] : groups.filter((group) => pinnedGroupIds?.includes(group.id))),
|
|
303
|
+
[groups, pinnedGroupIds, searching]
|
|
304
|
+
)
|
|
305
|
+
const rendered = React.useMemo(() => {
|
|
306
|
+
if (!searching) {
|
|
307
|
+
return groups
|
|
308
|
+
.filter((group) => !pinnedGroupIds?.includes(group.id))
|
|
309
|
+
.map((group) => ({ group, items: group.items }))
|
|
310
|
+
}
|
|
311
|
+
return groups
|
|
312
|
+
.map((group) => ({
|
|
313
|
+
group,
|
|
314
|
+
items: group.items.filter((item) => matches(item.label, normalizedQuery)),
|
|
315
|
+
}))
|
|
316
|
+
.filter((entry) => entry.items.length > 0)
|
|
317
|
+
}, [groups, searching, normalizedQuery, pinnedGroupIds])
|
|
318
|
+
|
|
319
|
+
// A group is open when it cannot be closed (no header to click, or the
|
|
320
|
+
// feature is off), when the icon rail hides the headers anyway, while a
|
|
321
|
+
// query is bypassing disclosure, or when the user/default opened it.
|
|
322
|
+
const isGroupOpen = (group: AppSidebarNavGroup): boolean =>
|
|
323
|
+
!collapsibleGroups ||
|
|
324
|
+
!group.label ||
|
|
325
|
+
collapsed ||
|
|
326
|
+
searching ||
|
|
327
|
+
expanded.includes(group.id)
|
|
328
|
+
|
|
329
|
+
const renderItem = (item: AppSidebarNavItem) => {
|
|
330
|
+
const count = item.count && item.count > 0 ? item.count : 0
|
|
331
|
+
const countText = item.countLabel ?? String(count)
|
|
332
|
+
return (
|
|
333
|
+
<Link
|
|
334
|
+
key={item.id}
|
|
335
|
+
href={item.href}
|
|
336
|
+
aria-current={item.active ? "page" : undefined}
|
|
337
|
+
title={collapsed ? item.label : undefined}
|
|
338
|
+
aria-label={collapsed && count > 0 ? `${item.label}, ${countText}` : undefined}
|
|
339
|
+
className={cn(
|
|
340
|
+
"relative flex items-center gap-2.5 rounded-md px-2 py-[7px] text-sm font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring max-md:min-h-11",
|
|
341
|
+
item.active
|
|
342
|
+
? "bg-sidebar-primary text-sidebar-primary-foreground"
|
|
343
|
+
: "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
344
|
+
collapsed && "mx-auto h-9 w-10 justify-center px-0 py-0"
|
|
345
|
+
)}
|
|
346
|
+
>
|
|
347
|
+
{item.icon && <span className="shrink-0 [&_svg]:size-5">{item.icon}</span>}
|
|
348
|
+
{!collapsed && <span className="min-w-0 flex-1 truncate">{item.label}</span>}
|
|
349
|
+
{count > 0 && !collapsed && (
|
|
350
|
+
<span
|
|
351
|
+
data-slot="app-sidebar-count"
|
|
352
|
+
className="rounded-full bg-primary px-1.5 py-px text-xs leading-4 font-semibold text-primary-foreground tabular-nums"
|
|
353
|
+
>
|
|
354
|
+
<span aria-hidden="true">{count}</span>
|
|
355
|
+
<span className="sr-only">{countText}</span>
|
|
356
|
+
</span>
|
|
357
|
+
)}
|
|
358
|
+
{count > 0 && collapsed && (
|
|
359
|
+
<span
|
|
360
|
+
data-slot="app-sidebar-count-dot"
|
|
361
|
+
aria-hidden="true"
|
|
362
|
+
className="absolute end-2 top-[7px] size-[7px] rounded-full bg-primary ring-2 ring-sidebar"
|
|
363
|
+
/>
|
|
364
|
+
)}
|
|
365
|
+
</Link>
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Only the links scroll (PwShortSidebar, PW.10, WHIT-827): the logo and
|
|
370
|
+
// switchers at the top and the pinned groups and footer at the bottom stay
|
|
371
|
+
// put on any window height. A soft fade at either end says there is more;
|
|
372
|
+
// once scrolled, a line appears under the top. The current page is scrolled
|
|
373
|
+
// into view when the page opens.
|
|
374
|
+
const navRef = React.useRef<HTMLElement>(null)
|
|
375
|
+
const [edges, setEdges] = React.useState({ top: true, bottom: true })
|
|
376
|
+
const measure = React.useCallback(() => {
|
|
377
|
+
const el = navRef.current
|
|
378
|
+
if (!el) return
|
|
379
|
+
const top = el.scrollTop <= 1
|
|
380
|
+
const bottom = el.scrollTop + el.clientHeight >= el.scrollHeight - 1
|
|
381
|
+
setEdges((prev) => (prev.top === top && prev.bottom === bottom ? prev : { top, bottom }))
|
|
382
|
+
}, [])
|
|
383
|
+
const activeId = React.useMemo(
|
|
384
|
+
() => groups.flatMap((group) => group.items).find((item) => item.active)?.id,
|
|
385
|
+
[groups]
|
|
386
|
+
)
|
|
387
|
+
React.useEffect(() => {
|
|
388
|
+
const el = navRef.current
|
|
389
|
+
if (!el) return
|
|
390
|
+
el.querySelector<HTMLElement>('[aria-current="page"]')?.scrollIntoView?.({ block: "nearest" })
|
|
391
|
+
measure()
|
|
392
|
+
if (typeof ResizeObserver === "undefined") return
|
|
393
|
+
const observer = new ResizeObserver(measure)
|
|
394
|
+
observer.observe(el)
|
|
395
|
+
return () => observer.disconnect()
|
|
396
|
+
}, [activeId, measure, expanded, collapsed])
|
|
397
|
+
|
|
398
|
+
const nav = (
|
|
399
|
+
<div className={cn("relative flex min-h-0 flex-1 flex-col", !edges.top && "border-t border-sidebar-border")}>
|
|
400
|
+
<nav
|
|
401
|
+
ref={navRef}
|
|
402
|
+
onScroll={measure}
|
|
403
|
+
data-slot="app-sidebar-nav"
|
|
404
|
+
aria-label={navLabel}
|
|
405
|
+
className={cn("min-h-0 flex-1 space-y-3 overflow-x-hidden overflow-y-auto overscroll-contain px-3 py-3", collapsed && "px-2")}
|
|
406
|
+
>
|
|
407
|
+
{rendered.map(({ group, items }, index) => {
|
|
408
|
+
const open = isGroupOpen(group)
|
|
409
|
+
const showHeading = Boolean(group.label) && !collapsed
|
|
410
|
+
const isDisclosure = showHeading && collapsibleGroups && !searching
|
|
411
|
+
const bodyId = `app-sidebar-group-${group.id}`
|
|
412
|
+
|
|
413
|
+
return (
|
|
414
|
+
<div
|
|
415
|
+
key={group.id}
|
|
416
|
+
data-slot="app-sidebar-group"
|
|
417
|
+
className={cn("grid gap-px", collapsed && index > 0 && "border-t border-sidebar-border pt-2")}
|
|
418
|
+
>
|
|
419
|
+
{showHeading && isDisclosure && (
|
|
420
|
+
<button
|
|
421
|
+
type="button"
|
|
422
|
+
data-slot="app-sidebar-group-toggle"
|
|
423
|
+
data-group-id={group.id}
|
|
424
|
+
aria-expanded={open}
|
|
425
|
+
aria-controls={bodyId}
|
|
426
|
+
onClick={() => toggleGroup(group.id)}
|
|
427
|
+
className="flex min-h-8 w-full items-center gap-1 rounded-md px-2 py-1 max-md:min-h-11 text-xs font-medium text-muted-foreground outline-none hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-ring"
|
|
428
|
+
>
|
|
429
|
+
{open ? (
|
|
430
|
+
<IconChevronDown className="size-3 shrink-0" />
|
|
431
|
+
) : (
|
|
432
|
+
<IconChevronRight className="size-3 shrink-0 rtl:rotate-180" />
|
|
433
|
+
)}
|
|
434
|
+
<span className="truncate">{group.label}</span>
|
|
435
|
+
</button>
|
|
436
|
+
)}
|
|
437
|
+
{showHeading && !isDisclosure && (
|
|
438
|
+
<div className="px-2 py-1 text-xs font-medium text-muted-foreground">
|
|
439
|
+
{group.label}
|
|
440
|
+
</div>
|
|
441
|
+
)}
|
|
442
|
+
{/*
|
|
443
|
+
A closed group's items are HIDDEN, not unmounted.
|
|
444
|
+
|
|
445
|
+
`hidden` is the correct disclosure semantic — collapsed content
|
|
446
|
+
must leave the accessibility tree, or a screen reader announces
|
|
447
|
+
links the sighted user cannot see. It follows that a role/name
|
|
448
|
+
query cannot find an item in a closed group, in Playwright as
|
|
449
|
+
much as in Testing Library.
|
|
450
|
+
|
|
451
|
+
Keeping them mounted is still deliberate: a DOM/CSS query can
|
|
452
|
+
tell "this group is closed" (present, hidden) from "RBAC removed
|
|
453
|
+
this link for this role" (absent). Unmounting would collapse
|
|
454
|
+
both into "absent", and any suite asserting absence as proof of
|
|
455
|
+
permission filtering would keep passing after that filtering
|
|
456
|
+
broke. Either query by CSS or open the group first.
|
|
457
|
+
*/}
|
|
458
|
+
<div id={bodyId} hidden={!open} className="grid gap-px">
|
|
459
|
+
{items.map(renderItem)}
|
|
460
|
+
</div>
|
|
461
|
+
</div>
|
|
462
|
+
)
|
|
463
|
+
})}
|
|
464
|
+
{searching && rendered.length === 0 && (
|
|
465
|
+
<p data-slot="app-sidebar-no-results" className="px-2 py-1 text-xs/relaxed text-muted-foreground">
|
|
466
|
+
{searchNoResultsLabel}
|
|
467
|
+
</p>
|
|
468
|
+
)}
|
|
469
|
+
</nav>
|
|
470
|
+
{!edges.top && (
|
|
471
|
+
<div aria-hidden="true" data-slot="app-sidebar-fade-top" className="pointer-events-none absolute inset-x-0 top-0 h-6 bg-gradient-to-b from-sidebar to-transparent" />
|
|
472
|
+
)}
|
|
473
|
+
{!edges.bottom && (
|
|
474
|
+
<div aria-hidden="true" data-slot="app-sidebar-fade-bottom" className="pointer-events-none absolute inset-x-0 bottom-0 h-6 bg-gradient-to-t from-sidebar to-transparent" />
|
|
475
|
+
)}
|
|
476
|
+
</div>
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
const pinnedSection = pinned.length > 0 && (
|
|
480
|
+
<div data-slot="app-sidebar-pinned" className={cn("grid shrink-0 gap-px border-t border-sidebar-border px-3 py-2", collapsed && "px-2")}>
|
|
481
|
+
{pinned.flatMap((group) => group.items).map(renderItem)}
|
|
482
|
+
</div>
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
// Hidden in the icon rail: a 4rem-wide column has nowhere to put a text
|
|
486
|
+
// field, and the collapse toggle is right there to widen it again.
|
|
487
|
+
const search = searchable && !collapsed && (
|
|
488
|
+
<div className="shrink-0 px-2.5 pt-2.5">
|
|
489
|
+
<div className="relative flex items-center">
|
|
490
|
+
<IconSearch className="pointer-events-none absolute start-2 size-3.5 text-muted-foreground" />
|
|
491
|
+
<input
|
|
492
|
+
type="search"
|
|
493
|
+
data-slot="app-sidebar-search"
|
|
494
|
+
value={query}
|
|
495
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
496
|
+
onKeyDown={(event) => {
|
|
497
|
+
if (event.key === "Escape") setQuery("")
|
|
498
|
+
}}
|
|
499
|
+
placeholder={searchPlaceholder}
|
|
500
|
+
aria-label={searchPlaceholder}
|
|
501
|
+
className="h-8 w-full rounded-md border border-sidebar-border bg-background/50 ps-7 pe-7 max-md:h-11 max-md:text-sm text-xs/relaxed text-sidebar-foreground outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 [&::-webkit-search-cancel-button]:hidden"
|
|
502
|
+
/>
|
|
503
|
+
{query !== "" && (
|
|
504
|
+
<button
|
|
505
|
+
type="button"
|
|
506
|
+
aria-label={clearSearchLabel}
|
|
507
|
+
onClick={() => setQuery("")}
|
|
508
|
+
className="absolute end-1 flex size-6 items-center justify-center rounded-md text-sidebar-foreground/70 outline-none hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-ring/30"
|
|
509
|
+
>
|
|
510
|
+
<IconX className="size-3.5" />
|
|
511
|
+
</button>
|
|
512
|
+
)}
|
|
513
|
+
</div>
|
|
514
|
+
</div>
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
return (
|
|
518
|
+
<>
|
|
519
|
+
{/* Mobile trigger — shown only below the md breakpoint; the sidebar
|
|
520
|
+
itself is fixed off-canvas until toggled open. */}
|
|
521
|
+
<button
|
|
522
|
+
type="button"
|
|
523
|
+
aria-label={openNavLabel}
|
|
524
|
+
onClick={() => setMobileOpen(true)}
|
|
525
|
+
className={cn(
|
|
526
|
+
"fixed start-3 top-[calc(0.75rem+env(safe-area-inset-top))] z-40 flex size-11 items-center justify-center rounded-control-lg border border-border bg-card outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 md:hidden",
|
|
527
|
+
phoneTabBar && "max-sm:hidden"
|
|
528
|
+
)}
|
|
529
|
+
>
|
|
530
|
+
<IconMenu2 className="size-5" />
|
|
531
|
+
</button>
|
|
532
|
+
|
|
533
|
+
{mobileOpen && (
|
|
534
|
+
<div
|
|
535
|
+
aria-hidden="true"
|
|
536
|
+
onClick={() => setMobileOpen(false)}
|
|
537
|
+
className="fixed inset-0 z-40 bg-overlay md:hidden"
|
|
538
|
+
/>
|
|
539
|
+
)}
|
|
540
|
+
|
|
541
|
+
<aside
|
|
542
|
+
data-slot="app-sidebar"
|
|
543
|
+
data-collapsed={collapsed || undefined}
|
|
544
|
+
inert={phoneDrawer && !mobileOpen ? true : undefined}
|
|
545
|
+
className={cn(
|
|
546
|
+
"fixed inset-y-0 start-0 z-50 flex h-dvh overflow-hidden w-[min(85vw,20rem)] -translate-x-full flex-col border-e border-sidebar-border bg-sidebar pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] text-sidebar-foreground transition-all duration-200 rtl:translate-x-full md:w-60 md:pt-0 md:pb-0",
|
|
547
|
+
mobileOpen && "translate-x-0 rtl:translate-x-0",
|
|
548
|
+
"md:sticky md:top-0 md:z-auto md:h-auto md:self-stretch md:shrink-0 md:translate-x-0 rtl:md:translate-x-0",
|
|
549
|
+
collapsed && "md:w-14",
|
|
550
|
+
phoneTabBar && "max-sm:hidden",
|
|
551
|
+
className
|
|
552
|
+
)}
|
|
553
|
+
>
|
|
554
|
+
<button
|
|
555
|
+
type="button"
|
|
556
|
+
aria-label={closeNavLabel}
|
|
557
|
+
onClick={() => setMobileOpen(false)}
|
|
558
|
+
className="absolute end-2 top-[calc(0.5rem+env(safe-area-inset-top))] z-20 flex size-11 items-center justify-center rounded-control-lg text-sidebar-foreground/70 outline-none hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-ring/30 md:hidden"
|
|
559
|
+
>
|
|
560
|
+
<IconX className="size-5" />
|
|
561
|
+
</button>
|
|
562
|
+
|
|
563
|
+
{(header || tenantSwitcher || teamSwitcher) && (
|
|
564
|
+
<div className={cn("flex shrink-0 flex-col gap-3 px-3 pt-4 pe-14 md:pe-3", collapsed && "items-center md:px-2")}>
|
|
565
|
+
{header && <div className="px-1.5 pt-0.5 pb-1.5">{header}</div>}
|
|
566
|
+
{(tenantSwitcher || teamSwitcher) && (
|
|
567
|
+
<div className="flex flex-col gap-1.5">
|
|
568
|
+
{tenantSwitcher}
|
|
569
|
+
{teamSwitcher}
|
|
570
|
+
</div>
|
|
571
|
+
)}
|
|
572
|
+
</div>
|
|
573
|
+
)}
|
|
574
|
+
|
|
575
|
+
{search}
|
|
576
|
+
|
|
577
|
+
{nav}
|
|
578
|
+
|
|
579
|
+
{pinnedSection}
|
|
580
|
+
|
|
581
|
+
<button
|
|
582
|
+
type="button"
|
|
583
|
+
aria-label={collapsed ? expandAriaLabel : collapseAriaLabel}
|
|
584
|
+
onClick={() => setCollapsed(!collapsed)}
|
|
585
|
+
className={cn(
|
|
586
|
+
"hidden shrink-0 items-center justify-center gap-1.5 border-t border-sidebar-border px-3 py-2 text-xs text-muted-foreground outline-none hover:bg-sidebar-accent focus-visible:ring-2 focus-visible:ring-ring",
|
|
587
|
+
!forcedRail && "md:flex"
|
|
588
|
+
)}
|
|
589
|
+
>
|
|
590
|
+
{collapsed ? (
|
|
591
|
+
<IconChevronRight className="size-3.5 rtl:rotate-180" />
|
|
592
|
+
) : (
|
|
593
|
+
<>
|
|
594
|
+
<IconChevronLeft className="size-3.5 rtl:rotate-180" />
|
|
595
|
+
<span>{collapseLabel}</span>
|
|
596
|
+
</>
|
|
597
|
+
)}
|
|
598
|
+
</button>
|
|
599
|
+
|
|
600
|
+
{footer && <div className="shrink-0 border-t border-sidebar-border px-3 py-3">{footer}</div>}
|
|
601
|
+
</aside>
|
|
602
|
+
</>
|
|
603
|
+
)
|
|
604
|
+
}
|