@whity/ui 0.0.0-stage → 0.5.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 +107 -3
- package/package.json +192 -6
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +302 -0
- package/src/actor-chip.tsx +71 -0
- package/src/agent-activity.tsx +163 -0
- package/src/agent-collaboration.stories.tsx +156 -0
- package/src/agent-run-status.tsx +196 -0
- package/src/alert-dialog.stories.tsx +45 -0
- package/src/alert-dialog.tsx +147 -0
- package/src/alert.stories.tsx +91 -0
- package/src/alert.tsx +89 -0
- package/src/app-sidebar.stories.tsx +195 -0
- package/src/app-sidebar.tsx +500 -0
- package/src/approval-queue.tsx +108 -0
- package/src/audience-group-picker.stories.tsx +198 -0
- package/src/audience-group-picker.tsx +362 -0
- package/src/audience-people-picker.stories.tsx +102 -0
- package/src/audience-people-picker.tsx +279 -0
- package/src/avatar.tsx +83 -0
- package/src/badge.stories.tsx +105 -0
- package/src/badge.tsx +68 -0
- package/src/beta-warning.stories.tsx +79 -0
- package/src/beta-warning.tsx +189 -0
- package/src/bilingual-input.stories.tsx +82 -0
- package/src/bilingual-input.tsx +183 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +118 -0
- package/src/card.stories.tsx +423 -0
- package/src/card.tsx +180 -0
- package/src/chart.stories.tsx +66 -0
- package/src/chart.tsx +228 -0
- package/src/checkbox.stories.tsx +62 -0
- package/src/checkbox.tsx +54 -0
- package/src/collapsible.stories.tsx +48 -0
- package/src/collapsible.tsx +34 -0
- package/src/color-card.stories.tsx +61 -0
- package/src/color-card.tsx +270 -0
- package/src/color-picker.stories.tsx +65 -0
- package/src/color-picker.tsx +425 -0
- package/src/command-palette.tsx +306 -0
- package/src/copy-block.stories.tsx +38 -0
- package/src/copy-block.tsx +85 -0
- package/src/data-table.stories.tsx +200 -0
- package/src/data-table.tsx +1106 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +422 -0
- package/src/design-cards.stories.tsx +458 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +166 -0
- package/src/documents/barcode-svg.stories.tsx +72 -0
- package/src/documents/barcode-svg.tsx +79 -0
- package/src/dropdown-menu.stories.tsx +77 -0
- package/src/dropdown-menu.tsx +271 -0
- package/src/editor/behaviour.ts +279 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +101 -0
- package/src/editor/block-toolbar.tsx +477 -0
- package/src/editor/bubble.tsx +93 -0
- package/src/editor/catalogue.ts +103 -0
- package/src/editor/collab-rail.tsx +746 -0
- package/src/editor/collab.stories.tsx +207 -0
- package/src/editor/collab.ts +87 -0
- package/src/editor/contract.ts +408 -0
- package/src/editor/convert.ts +362 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1287 -0
- package/src/editor/editor.css +536 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-picker.tsx +107 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +367 -0
- package/src/editor/index.ts +22 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +310 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +450 -0
- package/src/editor/page-view.tsx +353 -0
- package/src/editor/publish-check.tsx +182 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- package/src/editor/schema-rich.ts +150 -0
- package/src/editor/schema.ts +315 -0
- package/src/editor/services.tsx +127 -0
- package/src/editor/slash.ts +64 -0
- package/src/editor/suggesting.ts +372 -0
- package/src/editor/suggestions.ts +763 -0
- package/src/editor/table-keys.ts +66 -0
- package/src/editor/templates.stories.tsx +324 -0
- package/src/editor/toolbar.tsx +358 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +100 -0
- package/src/empty-state.usage-notes.md +30 -0
- package/src/form.stories.tsx +112 -0
- package/src/form.tsx +176 -0
- package/src/globals.css +20 -0
- package/src/icon-button.tsx +85 -0
- package/src/icon-map.ts +244 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +67 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +759 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +61 -0
- package/src/mark.tsx +62 -0
- package/src/math-text.stories.tsx +33 -0
- package/src/math-text.tsx +43 -0
- package/src/menu-bar.stories.tsx +198 -0
- package/src/menu-bar.tsx +373 -0
- package/src/money/currency.ts +230 -0
- package/src/page-header.stories.tsx +95 -0
- package/src/page-header.tsx +122 -0
- package/src/page-shell.stories.tsx +42 -0
- package/src/page-shell.tsx +32 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- package/src/plugin-card.stories.tsx +180 -0
- package/src/plugin-card.tsx +848 -0
- package/src/popover.stories.tsx +48 -0
- package/src/popover.tsx +55 -0
- package/src/radio-group.stories.tsx +26 -0
- package/src/radio-group.tsx +44 -0
- package/src/route-flow/editor.tsx +1014 -0
- package/src/route-flow/model.ts +716 -0
- package/src/scope-grant.tsx +139 -0
- package/src/screen-too-small.stories.tsx +61 -0
- package/src/screen-too-small.tsx +104 -0
- package/src/select.stories.tsx +44 -0
- package/src/select.tsx +197 -0
- package/src/separator.stories.tsx +34 -0
- package/src/separator.tsx +34 -0
- package/src/sheet.stories.tsx +49 -0
- package/src/sheet.tsx +168 -0
- package/src/skeleton.stories.tsx +28 -0
- package/src/skeleton.tsx +19 -0
- package/src/slider.stories.tsx +78 -0
- package/src/slider.tsx +300 -0
- package/src/spinner.stories.tsx +33 -0
- package/src/spinner.tsx +55 -0
- package/src/switch.stories.tsx +42 -0
- package/src/switch.tsx +41 -0
- package/src/switcher.stories.tsx +111 -0
- package/src/switcher.tsx +131 -0
- package/src/table.stories.tsx +48 -0
- package/src/table.tsx +121 -0
- package/src/tabs.stories.tsx +74 -0
- package/src/tabs.tsx +90 -0
- package/src/tag-input.stories.tsx +67 -0
- package/src/tag-input.tsx +117 -0
- package/src/tenant-logo.tsx +63 -0
- package/src/tenant-switcher.stories.tsx +38 -0
- package/src/tenant-switcher.tsx +164 -0
- package/src/textarea.stories.tsx +27 -0
- package/src/textarea.tsx +18 -0
- package/src/theme-mode.ts +52 -0
- package/src/time-picker.stories.tsx +62 -0
- package/src/time-picker.tsx +615 -0
- package/src/toggle-group.tsx +138 -0
- package/src/tooltip.stories.tsx +43 -0
- package/src/tooltip.tsx +73 -0
- package/src/top-nav.stories.tsx +58 -0
- package/src/top-nav.tsx +324 -0
- package/src/undo-bar.tsx +107 -0
- package/src/utils.ts +45 -0
- package/src/view-toggle.stories.tsx +84 -0
- package/src/view-toggle.tsx +110 -0
|
@@ -0,0 +1,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
|
+
onMobileOpenChange?: (open: boolean) => void
|
|
98
|
+
/** Custom link component (e.g. Next.js <Link>) — defaults to a plain <a>. */
|
|
99
|
+
linkComponent?: React.ElementType
|
|
100
|
+
/**
|
|
101
|
+
* Turn group headings into disclosure buttons. Groups the user has not
|
|
102
|
+
* opened render their items HIDDEN rather than unmounted — see the
|
|
103
|
+
* `hidden` attribute in the group body below for why that distinction is
|
|
104
|
+
* load-bearing.
|
|
105
|
+
*/
|
|
106
|
+
collapsibleGroups?: boolean
|
|
107
|
+
/**
|
|
108
|
+
* Controlled set of open group ids. Uncontrolled if omitted, in which
|
|
109
|
+
* case exactly one group starts open: the one holding the active item
|
|
110
|
+
* (falling back to the first group when nothing is active). Navigating to
|
|
111
|
+
* another group's page opens that group, without closing anything the
|
|
112
|
+
* user opened by hand.
|
|
113
|
+
*/
|
|
114
|
+
expandedGroupIds?: readonly string[]
|
|
115
|
+
onExpandedGroupsChange?: (expanded: readonly string[]) => void
|
|
116
|
+
/** Render a filter box above the nav that narrows items by label. */
|
|
117
|
+
searchable?: boolean
|
|
118
|
+
/** Controlled search query. Uncontrolled if omitted. */
|
|
119
|
+
searchValue?: string
|
|
120
|
+
onSearchChange?: (value: string) => void
|
|
121
|
+
/** Placeholder AND accessible name for the filter box. Defaults to "Search". */
|
|
122
|
+
searchPlaceholder?: string
|
|
123
|
+
/** Accessible name for the button that empties the filter box. */
|
|
124
|
+
clearSearchLabel?: string
|
|
125
|
+
/** Shown in place of the nav when a query matches no item. */
|
|
126
|
+
searchNoResultsLabel?: string
|
|
127
|
+
/** Accessible name for the navigation landmark. Defaults to "Main". */
|
|
128
|
+
navLabel?: string
|
|
129
|
+
/** Accessible name for the button that opens the mobile drawer. */
|
|
130
|
+
openNavLabel?: string
|
|
131
|
+
/** Accessible name for the button that closes the mobile drawer. */
|
|
132
|
+
closeNavLabel?: string
|
|
133
|
+
/** Text of the collapse toggle. Defaults to "Collapse". */
|
|
134
|
+
collapseLabel?: string
|
|
135
|
+
/**
|
|
136
|
+
* Accessible names for the collapse toggle in each direction. Separate
|
|
137
|
+
* from `collapseLabel`, which is the visible text beside the icon.
|
|
138
|
+
*/
|
|
139
|
+
collapseAriaLabel?: string
|
|
140
|
+
expandAriaLabel?: string
|
|
141
|
+
className?: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* True between 768 and 1023px, where the sidebar is the 56px rail whatever the
|
|
146
|
+
* collapse toggle says (register 4.5). Below 768 it is the drawer; from 1024
|
|
147
|
+
* the person's own choice applies. Exported so the composed wrapper can size
|
|
148
|
+
* its own slot content (logo, switcher, footer) to the same state.
|
|
149
|
+
*/
|
|
150
|
+
export function useForcedRail(): boolean {
|
|
151
|
+
const [forced, setForced] = React.useState(false)
|
|
152
|
+
React.useEffect(() => {
|
|
153
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return
|
|
154
|
+
const query = window.matchMedia("(min-width: 768px) and (max-width: 1023.98px)")
|
|
155
|
+
const update = () => setForced(query.matches)
|
|
156
|
+
update()
|
|
157
|
+
query.addEventListener?.("change", update)
|
|
158
|
+
return () => query.removeEventListener?.("change", update)
|
|
159
|
+
}, [])
|
|
160
|
+
return forced
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Case-insensitive substring match, tolerant of surrounding whitespace. */
|
|
164
|
+
function matches(label: string, normalizedQuery: string): boolean {
|
|
165
|
+
return label.toLocaleLowerCase().includes(normalizedQuery)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function AppSidebar({
|
|
169
|
+
header,
|
|
170
|
+
tenantSwitcher,
|
|
171
|
+
teamSwitcher,
|
|
172
|
+
groups,
|
|
173
|
+
footer,
|
|
174
|
+
collapsed: collapsedProp,
|
|
175
|
+
onCollapsedChange,
|
|
176
|
+
mobileOpen: mobileOpenProp,
|
|
177
|
+
onMobileOpenChange,
|
|
178
|
+
linkComponent,
|
|
179
|
+
collapsibleGroups = false,
|
|
180
|
+
expandedGroupIds,
|
|
181
|
+
onExpandedGroupsChange,
|
|
182
|
+
searchable = false,
|
|
183
|
+
searchValue,
|
|
184
|
+
onSearchChange,
|
|
185
|
+
searchPlaceholder = "Search",
|
|
186
|
+
clearSearchLabel = "Clear search",
|
|
187
|
+
searchNoResultsLabel = "No matching pages",
|
|
188
|
+
navLabel = "Main",
|
|
189
|
+
openNavLabel = "Open navigation",
|
|
190
|
+
closeNavLabel = "Close navigation",
|
|
191
|
+
collapseLabel = "Collapse",
|
|
192
|
+
collapseAriaLabel = "Collapse sidebar",
|
|
193
|
+
expandAriaLabel = "Expand sidebar",
|
|
194
|
+
className,
|
|
195
|
+
}: AppSidebarProps) {
|
|
196
|
+
const [collapsedState, setCollapsedState] = React.useState(false)
|
|
197
|
+
const forcedRail = useForcedRail()
|
|
198
|
+
const collapsed = (forcedRail && !(mobileOpenProp ?? false)) || (collapsedProp ?? collapsedState)
|
|
199
|
+
const setCollapsed = (next: boolean) => {
|
|
200
|
+
setCollapsedState(next)
|
|
201
|
+
onCollapsedChange?.(next)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const [mobileOpenState, setMobileOpenState] = React.useState(false)
|
|
205
|
+
const mobileOpen = mobileOpenProp ?? mobileOpenState
|
|
206
|
+
const setMobileOpen = (next: boolean) => {
|
|
207
|
+
setMobileOpenState(next)
|
|
208
|
+
onMobileOpenChange?.(next)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const [queryState, setQueryState] = React.useState("")
|
|
212
|
+
const query = searchValue ?? queryState
|
|
213
|
+
const setQuery = (next: string) => {
|
|
214
|
+
if (searchValue === undefined) setQueryState(next)
|
|
215
|
+
onSearchChange?.(next)
|
|
216
|
+
}
|
|
217
|
+
const normalizedQuery = query.trim().toLocaleLowerCase()
|
|
218
|
+
const searching = normalizedQuery !== ""
|
|
219
|
+
|
|
220
|
+
// The group holding the current page, which is what starts open. Falls back
|
|
221
|
+
// to the first group so an unmatched route (a detail page no nav item owns)
|
|
222
|
+
// still shows something rather than a stack of closed headers.
|
|
223
|
+
const openByDefaultGroupId = React.useMemo(() => {
|
|
224
|
+
const active = groups.find((group) => group.items.some((item) => item.active))
|
|
225
|
+
return active?.id ?? groups[0]?.id ?? null
|
|
226
|
+
}, [groups])
|
|
227
|
+
|
|
228
|
+
const [expandedState, setExpandedState] = React.useState<readonly string[]>([])
|
|
229
|
+
const expanded = expandedGroupIds ?? expandedState
|
|
230
|
+
|
|
231
|
+
// `groups` typically arrives empty on first render and fills in after the
|
|
232
|
+
// nav fetch resolves, so the default cannot be computed in useState's
|
|
233
|
+
// initializer — it has to react to the id appearing. Keyed on the id alone:
|
|
234
|
+
// a group the user opened by hand survives navigation within it, and only a
|
|
235
|
+
// move to a DIFFERENT group re-narrows the sidebar.
|
|
236
|
+
React.useEffect(() => {
|
|
237
|
+
if (expandedGroupIds !== undefined) return
|
|
238
|
+
if (openByDefaultGroupId === null) return
|
|
239
|
+
setExpandedState((prev) =>
|
|
240
|
+
prev.includes(openByDefaultGroupId) ? prev : [openByDefaultGroupId]
|
|
241
|
+
)
|
|
242
|
+
}, [openByDefaultGroupId, expandedGroupIds])
|
|
243
|
+
|
|
244
|
+
const toggleGroup = (id: string) => {
|
|
245
|
+
const next = expanded.includes(id)
|
|
246
|
+
? expanded.filter((groupId) => groupId !== id)
|
|
247
|
+
: [...expanded, id]
|
|
248
|
+
if (expandedGroupIds === undefined) setExpandedState(next)
|
|
249
|
+
onExpandedGroupsChange?.(next)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const Link = linkComponent ?? "a"
|
|
253
|
+
|
|
254
|
+
// While a query is active the disclosure state is bypassed entirely: the
|
|
255
|
+
// point of the box is to reach an item without knowing which group holds
|
|
256
|
+
// it. Groups with no match drop out so the result list stays short.
|
|
257
|
+
const rendered = React.useMemo(() => {
|
|
258
|
+
if (!searching) {
|
|
259
|
+
return groups.map((group) => ({ group, items: group.items }))
|
|
260
|
+
}
|
|
261
|
+
return groups
|
|
262
|
+
.map((group) => ({
|
|
263
|
+
group,
|
|
264
|
+
items: group.items.filter((item) => matches(item.label, normalizedQuery)),
|
|
265
|
+
}))
|
|
266
|
+
.filter((entry) => entry.items.length > 0)
|
|
267
|
+
}, [groups, searching, normalizedQuery])
|
|
268
|
+
|
|
269
|
+
// A group is open when it cannot be closed (no header to click, or the
|
|
270
|
+
// feature is off), when the icon rail hides the headers anyway, while a
|
|
271
|
+
// query is bypassing disclosure, or when the user/default opened it.
|
|
272
|
+
const isGroupOpen = (group: AppSidebarNavGroup): boolean =>
|
|
273
|
+
!collapsibleGroups ||
|
|
274
|
+
!group.label ||
|
|
275
|
+
collapsed ||
|
|
276
|
+
searching ||
|
|
277
|
+
expanded.includes(group.id)
|
|
278
|
+
|
|
279
|
+
const nav = (
|
|
280
|
+
<nav
|
|
281
|
+
data-slot="app-sidebar-nav"
|
|
282
|
+
aria-label={navLabel}
|
|
283
|
+
className={cn("flex-1 space-y-3 overflow-x-hidden overflow-y-auto px-3 py-3", collapsed && "px-2")}
|
|
284
|
+
>
|
|
285
|
+
{rendered.map(({ group, items }, index) => {
|
|
286
|
+
const open = isGroupOpen(group)
|
|
287
|
+
const showHeading = Boolean(group.label) && !collapsed
|
|
288
|
+
const isDisclosure = showHeading && collapsibleGroups && !searching
|
|
289
|
+
const bodyId = `app-sidebar-group-${group.id}`
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<div
|
|
293
|
+
key={group.id}
|
|
294
|
+
data-slot="app-sidebar-group"
|
|
295
|
+
className={cn("grid gap-px", collapsed && index > 0 && "border-t border-sidebar-border pt-2")}
|
|
296
|
+
>
|
|
297
|
+
{showHeading && isDisclosure && (
|
|
298
|
+
<button
|
|
299
|
+
type="button"
|
|
300
|
+
data-slot="app-sidebar-group-toggle"
|
|
301
|
+
data-group-id={group.id}
|
|
302
|
+
aria-expanded={open}
|
|
303
|
+
aria-controls={bodyId}
|
|
304
|
+
onClick={() => toggleGroup(group.id)}
|
|
305
|
+
className="flex w-full items-center gap-1 rounded-md px-2 py-1 text-[0.6875rem] font-semibold tracking-wider text-muted-foreground uppercase outline-none hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-ring"
|
|
306
|
+
>
|
|
307
|
+
{open ? (
|
|
308
|
+
<IconChevronDown className="size-3 shrink-0" />
|
|
309
|
+
) : (
|
|
310
|
+
<IconChevronRight className="size-3 shrink-0 rtl:rotate-180" />
|
|
311
|
+
)}
|
|
312
|
+
<span className="truncate">{group.label}</span>
|
|
313
|
+
</button>
|
|
314
|
+
)}
|
|
315
|
+
{showHeading && !isDisclosure && (
|
|
316
|
+
<div className="px-2 py-1 text-[0.6875rem] font-semibold tracking-wider text-muted-foreground uppercase">
|
|
317
|
+
{group.label}
|
|
318
|
+
</div>
|
|
319
|
+
)}
|
|
320
|
+
{/*
|
|
321
|
+
A closed group's items are HIDDEN, not unmounted.
|
|
322
|
+
|
|
323
|
+
`hidden` is the correct disclosure semantic — collapsed content
|
|
324
|
+
must leave the accessibility tree, or a screen reader announces
|
|
325
|
+
links the sighted user cannot see. It follows that a role/name
|
|
326
|
+
query cannot find an item in a closed group, in Playwright as
|
|
327
|
+
much as in Testing Library.
|
|
328
|
+
|
|
329
|
+
Keeping them mounted is still deliberate: a DOM/CSS query can
|
|
330
|
+
tell "this group is closed" (present, hidden) from "RBAC removed
|
|
331
|
+
this link for this role" (absent). Unmounting would collapse
|
|
332
|
+
both into "absent", and any suite asserting absence as proof of
|
|
333
|
+
permission filtering would keep passing after that filtering
|
|
334
|
+
broke. Either query by CSS or open the group first.
|
|
335
|
+
*/}
|
|
336
|
+
<div id={bodyId} hidden={!open} className="grid gap-px">
|
|
337
|
+
{items.map((item) => {
|
|
338
|
+
const count = item.count && item.count > 0 ? item.count : 0
|
|
339
|
+
const countText = item.countLabel ?? String(count)
|
|
340
|
+
return (
|
|
341
|
+
<Link
|
|
342
|
+
key={item.id}
|
|
343
|
+
href={item.href}
|
|
344
|
+
aria-current={item.active ? "page" : undefined}
|
|
345
|
+
title={collapsed ? item.label : undefined}
|
|
346
|
+
aria-label={collapsed && count > 0 ? `${item.label}, ${countText}` : undefined}
|
|
347
|
+
className={cn(
|
|
348
|
+
"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",
|
|
349
|
+
item.active
|
|
350
|
+
? "bg-sidebar-primary text-sidebar-primary-foreground"
|
|
351
|
+
: "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
352
|
+
collapsed && "mx-auto h-9 w-10 justify-center px-0 py-0"
|
|
353
|
+
)}
|
|
354
|
+
>
|
|
355
|
+
{item.icon && <span className="shrink-0 [&_svg]:size-5">{item.icon}</span>}
|
|
356
|
+
{!collapsed && <span className="min-w-0 flex-1 truncate">{item.label}</span>}
|
|
357
|
+
{count > 0 && !collapsed && (
|
|
358
|
+
<span
|
|
359
|
+
data-slot="app-sidebar-count"
|
|
360
|
+
className="rounded-full bg-primary px-1.5 py-px text-[0.6875rem] leading-4 font-semibold text-primary-foreground tabular-nums"
|
|
361
|
+
>
|
|
362
|
+
<span aria-hidden="true">{count}</span>
|
|
363
|
+
<span className="sr-only">{countText}</span>
|
|
364
|
+
</span>
|
|
365
|
+
)}
|
|
366
|
+
{count > 0 && collapsed && (
|
|
367
|
+
<span
|
|
368
|
+
data-slot="app-sidebar-count-dot"
|
|
369
|
+
aria-hidden="true"
|
|
370
|
+
className="absolute end-2 top-[7px] size-[7px] rounded-full bg-primary ring-2 ring-sidebar"
|
|
371
|
+
/>
|
|
372
|
+
)}
|
|
373
|
+
</Link>
|
|
374
|
+
)
|
|
375
|
+
})}
|
|
376
|
+
</div>
|
|
377
|
+
</div>
|
|
378
|
+
)
|
|
379
|
+
})}
|
|
380
|
+
{searching && rendered.length === 0 && (
|
|
381
|
+
<p data-slot="app-sidebar-no-results" className="px-2 py-1 text-xs/relaxed text-muted-foreground">
|
|
382
|
+
{searchNoResultsLabel}
|
|
383
|
+
</p>
|
|
384
|
+
)}
|
|
385
|
+
</nav>
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
// Hidden in the icon rail: a 4rem-wide column has nowhere to put a text
|
|
389
|
+
// field, and the collapse toggle is right there to widen it again.
|
|
390
|
+
const search = searchable && !collapsed && (
|
|
391
|
+
<div className="px-2.5 pt-2.5">
|
|
392
|
+
<div className="relative flex items-center">
|
|
393
|
+
<IconSearch className="pointer-events-none absolute start-2 size-3.5 text-muted-foreground" />
|
|
394
|
+
<input
|
|
395
|
+
type="search"
|
|
396
|
+
data-slot="app-sidebar-search"
|
|
397
|
+
value={query}
|
|
398
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
399
|
+
onKeyDown={(event) => {
|
|
400
|
+
if (event.key === "Escape") setQuery("")
|
|
401
|
+
}}
|
|
402
|
+
placeholder={searchPlaceholder}
|
|
403
|
+
aria-label={searchPlaceholder}
|
|
404
|
+
className="h-8 w-full rounded-md border border-sidebar-border bg-background/50 ps-7 pe-7 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"
|
|
405
|
+
/>
|
|
406
|
+
{query !== "" && (
|
|
407
|
+
<button
|
|
408
|
+
type="button"
|
|
409
|
+
aria-label={clearSearchLabel}
|
|
410
|
+
onClick={() => setQuery("")}
|
|
411
|
+
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"
|
|
412
|
+
>
|
|
413
|
+
<IconX className="size-3.5" />
|
|
414
|
+
</button>
|
|
415
|
+
)}
|
|
416
|
+
</div>
|
|
417
|
+
</div>
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
return (
|
|
421
|
+
<>
|
|
422
|
+
{/* Mobile trigger — shown only below the md breakpoint; the sidebar
|
|
423
|
+
itself is fixed off-canvas until toggled open. */}
|
|
424
|
+
<button
|
|
425
|
+
type="button"
|
|
426
|
+
aria-label={openNavLabel}
|
|
427
|
+
onClick={() => setMobileOpen(true)}
|
|
428
|
+
className="fixed start-3 top-3 z-40 flex size-8 items-center justify-center rounded-md border border-border bg-card outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 md:hidden"
|
|
429
|
+
>
|
|
430
|
+
<IconMenu2 className="size-4" />
|
|
431
|
+
</button>
|
|
432
|
+
|
|
433
|
+
{mobileOpen && (
|
|
434
|
+
<div
|
|
435
|
+
aria-hidden="true"
|
|
436
|
+
onClick={() => setMobileOpen(false)}
|
|
437
|
+
className="fixed inset-0 z-40 bg-foreground/20 md:hidden"
|
|
438
|
+
/>
|
|
439
|
+
)}
|
|
440
|
+
|
|
441
|
+
<aside
|
|
442
|
+
data-slot="app-sidebar"
|
|
443
|
+
data-collapsed={collapsed || undefined}
|
|
444
|
+
className={cn(
|
|
445
|
+
"fixed inset-y-0 start-0 z-50 flex h-screen w-60 -translate-x-full flex-col border-e border-sidebar-border bg-sidebar text-sidebar-foreground transition-all duration-200 rtl:translate-x-full",
|
|
446
|
+
mobileOpen && "translate-x-0 rtl:translate-x-0",
|
|
447
|
+
"md:sticky md:top-0 md:z-auto md:h-screen md:shrink-0 md:translate-x-0 rtl:md:translate-x-0",
|
|
448
|
+
collapsed && "md:w-14",
|
|
449
|
+
className
|
|
450
|
+
)}
|
|
451
|
+
>
|
|
452
|
+
<button
|
|
453
|
+
type="button"
|
|
454
|
+
aria-label={closeNavLabel}
|
|
455
|
+
onClick={() => setMobileOpen(false)}
|
|
456
|
+
className="absolute end-2 top-2.5 z-20 flex size-7 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 md:hidden"
|
|
457
|
+
>
|
|
458
|
+
<IconX className="size-4" />
|
|
459
|
+
</button>
|
|
460
|
+
|
|
461
|
+
{(header || tenantSwitcher || teamSwitcher) && (
|
|
462
|
+
<div className={cn("flex flex-col gap-3 px-3 pt-4 pe-10 md:pe-3", collapsed && "items-center md:px-2")}>
|
|
463
|
+
{header && <div className="px-1.5 pt-0.5 pb-1.5">{header}</div>}
|
|
464
|
+
{(tenantSwitcher || teamSwitcher) && (
|
|
465
|
+
<div className="flex flex-col gap-1.5">
|
|
466
|
+
{tenantSwitcher}
|
|
467
|
+
{teamSwitcher}
|
|
468
|
+
</div>
|
|
469
|
+
)}
|
|
470
|
+
</div>
|
|
471
|
+
)}
|
|
472
|
+
|
|
473
|
+
{search}
|
|
474
|
+
|
|
475
|
+
{nav}
|
|
476
|
+
|
|
477
|
+
<button
|
|
478
|
+
type="button"
|
|
479
|
+
aria-label={collapsed ? expandAriaLabel : collapseAriaLabel}
|
|
480
|
+
onClick={() => setCollapsed(!collapsed)}
|
|
481
|
+
className={cn(
|
|
482
|
+
"hidden 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",
|
|
483
|
+
!forcedRail && "md:flex"
|
|
484
|
+
)}
|
|
485
|
+
>
|
|
486
|
+
{collapsed ? (
|
|
487
|
+
<IconChevronRight className="size-3.5 rtl:rotate-180" />
|
|
488
|
+
) : (
|
|
489
|
+
<>
|
|
490
|
+
<IconChevronLeft className="size-3.5 rtl:rotate-180" />
|
|
491
|
+
<span>{collapseLabel}</span>
|
|
492
|
+
</>
|
|
493
|
+
)}
|
|
494
|
+
</button>
|
|
495
|
+
|
|
496
|
+
{footer && <div className="border-t border-sidebar-border px-3 py-3">{footer}</div>}
|
|
497
|
+
</aside>
|
|
498
|
+
</>
|
|
499
|
+
)
|
|
500
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { ActionProposal, type ActionProposalProps } from "./action-proposal"
|
|
4
|
+
import { Button } from "./button"
|
|
5
|
+
import { EmptyState } from "./empty-state"
|
|
6
|
+
import { Icon } from "./icon"
|
|
7
|
+
import { cn } from "./utils"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The approvals inbox, one request at a time (docs/design/components/
|
|
11
|
+
* ApprovalQueue; register 7.5b): "1 of 3 waiting · oldest first", Previous and
|
|
12
|
+
* Next, the current proposal, and the edges of the cards behind it. When
|
|
13
|
+
* nothing is left it says so.
|
|
14
|
+
*
|
|
15
|
+
* Controlled: the caller holds the list (oldest first), which one is shown,
|
|
16
|
+
* and what deciding does. Moving on after a decision is the caller's too, so
|
|
17
|
+
* the list can shrink only once the server has answered.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface ApprovalQueueItem extends ActionProposalProps {
|
|
21
|
+
id: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ApprovalQueueLabels {
|
|
25
|
+
/** `{index}` and `{count}`. */
|
|
26
|
+
position?: string
|
|
27
|
+
order?: string
|
|
28
|
+
previous?: string
|
|
29
|
+
next?: string
|
|
30
|
+
doneTitle?: string
|
|
31
|
+
doneDescription?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ApprovalQueueProps {
|
|
35
|
+
items: ApprovalQueueItem[]
|
|
36
|
+
currentId?: string
|
|
37
|
+
onCurrentChange: (id: string) => void
|
|
38
|
+
/** Accessible name of the section. */
|
|
39
|
+
label?: string
|
|
40
|
+
labels?: ApprovalQueueLabels
|
|
41
|
+
className?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const DEFAULT_LABELS: Required<ApprovalQueueLabels> = {
|
|
45
|
+
position: "{index} of {count} waiting",
|
|
46
|
+
order: "oldest first",
|
|
47
|
+
previous: "Previous",
|
|
48
|
+
next: "Next",
|
|
49
|
+
doneTitle: "All caught up",
|
|
50
|
+
doneDescription: "Nothing is waiting for you. New requests from agents appear here.",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function ApprovalQueue({ items, currentId, onCurrentChange, label = "Approvals", labels, className }: ApprovalQueueProps) {
|
|
54
|
+
const L = { ...DEFAULT_LABELS, ...labels }
|
|
55
|
+
const found = items.findIndex((item) => item.id === currentId)
|
|
56
|
+
const index = found >= 0 ? found : 0
|
|
57
|
+
const current = items[index]
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<section data-slot="approval-queue" aria-label={label} className={cn("grid max-w-[560px] gap-2", className)}>
|
|
61
|
+
{!current ? (
|
|
62
|
+
<EmptyState
|
|
63
|
+
icon={<Icon name="success" size={24} />}
|
|
64
|
+
title={L.doneTitle}
|
|
65
|
+
description={L.doneDescription}
|
|
66
|
+
/>
|
|
67
|
+
) : (
|
|
68
|
+
<>
|
|
69
|
+
<div className="flex items-center justify-between text-[0.8125rem] text-muted-foreground">
|
|
70
|
+
<span aria-live="polite">
|
|
71
|
+
{L.position.replace("{index}", String(index + 1)).replace("{count}", String(items.length))} · {L.order}
|
|
72
|
+
</span>
|
|
73
|
+
<span className="flex items-center gap-1">
|
|
74
|
+
<Button
|
|
75
|
+
variant="ghost"
|
|
76
|
+
size="sm"
|
|
77
|
+
disabled={index <= 0}
|
|
78
|
+
onClick={() => onCurrentChange(items[index - 1].id)}
|
|
79
|
+
>
|
|
80
|
+
<Icon name="chevron-left" size={16} className="rtl:-scale-x-100" />
|
|
81
|
+
{L.previous}
|
|
82
|
+
</Button>
|
|
83
|
+
<Button
|
|
84
|
+
variant="ghost"
|
|
85
|
+
size="sm"
|
|
86
|
+
disabled={index >= items.length - 1}
|
|
87
|
+
onClick={() => onCurrentChange(items[index + 1].id)}
|
|
88
|
+
>
|
|
89
|
+
{L.next}
|
|
90
|
+
<Icon name="chevron-right" size={16} className="rtl:-scale-x-100" />
|
|
91
|
+
</Button>
|
|
92
|
+
</span>
|
|
93
|
+
</div>
|
|
94
|
+
{/* key: a new card per proposal, so its "Show all" starts folded. */}
|
|
95
|
+
<ActionProposal key={current.id} {...current} />
|
|
96
|
+
{items.length > 1 && (
|
|
97
|
+
<div aria-hidden="true" className="relative mx-3 -mt-2 h-2 rounded-b-card border border-t-0 border-border bg-card" />
|
|
98
|
+
)}
|
|
99
|
+
{items.length > 2 && (
|
|
100
|
+
<div aria-hidden="true" className="relative mx-6 -mt-2 h-2 rounded-b-card border border-t-0 border-border bg-card" />
|
|
101
|
+
)}
|
|
102
|
+
</>
|
|
103
|
+
)}
|
|
104
|
+
</section>
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { ApprovalQueue }
|