@whity/ui 0.0.0-stage → 1.0.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 +106 -2
- package/package.json +219 -4
- package/src/access-denied.stories.tsx +179 -0
- package/src/access-denied.tsx +305 -0
- package/src/action-proposal.tsx +338 -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 +604 -0
- package/src/approval-queue.tsx +109 -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-pattern.ts +138 -0
- package/src/avatar.tsx +125 -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 +188 -0
- package/src/board.tsx +216 -0
- package/src/breadcrumb.stories.tsx +51 -0
- package/src/breadcrumb.tsx +90 -0
- package/src/built-on-whity.tsx +52 -0
- package/src/button.stories.tsx +87 -0
- package/src/button.tsx +123 -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/column-matcher.tsx +84 -0
- package/src/command-palette.tsx +398 -0
- package/src/confirm-action.tsx +98 -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 +1686 -0
- package/src/date-picker.stories.tsx +61 -0
- package/src/date-picker.tsx +456 -0
- package/src/design-cards.stories.tsx +551 -0
- package/src/dialog.stories.tsx +48 -0
- package/src/dialog.tsx +179 -0
- package/src/display-preferences.tsx +50 -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/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 -0
- package/src/editor/block-ids.ts +44 -0
- package/src/editor/block-list.tsx +104 -0
- package/src/editor/block-toolbar.tsx +490 -0
- package/src/editor/bubble.tsx +119 -0
- package/src/editor/catalogue.ts +169 -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 +476 -0
- package/src/editor/convert.ts +414 -0
- package/src/editor/doc-editor.stories.tsx +98 -0
- package/src/editor/doc-editor.tsx +1492 -0
- package/src/editor/editor.css +636 -0
- package/src/editor/extensions.ts +86 -0
- package/src/editor/field-bar.tsx +154 -0
- package/src/editor/field-picker.tsx +109 -0
- package/src/editor/fields.ts +100 -0
- package/src/editor/gutter.tsx +443 -0
- package/src/editor/index.ts +23 -0
- package/src/editor/label-sheet.tsx +289 -0
- package/src/editor/labels.ts +394 -0
- package/src/editor/link-tools.tsx +141 -0
- package/src/editor/node-views.tsx +461 -0
- package/src/editor/page-view.tsx +372 -0
- 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 -0
- package/src/editor/rich-blocks.stories.tsx +146 -0
- package/src/editor/sample.ts +40 -0
- 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 -0
- package/src/editor/schema.ts +368 -0
- package/src/editor/services.tsx +205 -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 +364 -0
- package/src/empty-state.stories.tsx +51 -0
- package/src/empty-state.tsx +126 -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 +335 -0
- package/src/icon.tsx +41 -0
- package/src/index.ts +90 -0
- package/src/input.stories.tsx +157 -0
- package/src/input.tsx +768 -0
- package/src/kpi-strip.tsx +47 -0
- package/src/localized-text.ts +76 -0
- package/src/locked-screen.stories.tsx +29 -0
- package/src/locked-screen.tsx +75 -0
- package/src/lockup.tsx +42 -0
- package/src/lottie.tsx +441 -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/message-thread.tsx +181 -0
- package/src/money/currency.ts +244 -0
- 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 -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/page-states.tsx +277 -0
- package/src/pagination.stories.tsx +45 -0
- package/src/pagination.tsx +98 -0
- package/src/paper-sheet.stories.tsx +88 -0
- package/src/paper-sheet.tsx +85 -0
- package/src/phone-tab-bar.tsx +152 -0
- package/src/plugin-card.stories.tsx +208 -0
- package/src/plugin-card.tsx +931 -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 +1087 -0
- package/src/route-flow/model.ts +771 -0
- package/src/save-bar.tsx +94 -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/search-field.tsx +65 -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/stepper.tsx +85 -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/system-state.tsx +55 -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-grid.tsx +163 -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,198 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
3
|
+
import { IconFilePlus, IconPrinter, IconTrash, IconTypography } from "@tabler/icons-react"
|
|
4
|
+
|
|
5
|
+
import { MenuBar, type MenuBarMenu } from "./menu-bar"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A live model: the toggles and the "last command" readout prove the menu bar is
|
|
9
|
+
* driven entirely by the `menus` array it's handed — every `checked` and
|
|
10
|
+
* `disabled` state below comes from this state, not from anything the menu bar
|
|
11
|
+
* keeps for itself.
|
|
12
|
+
*/
|
|
13
|
+
function Demo({
|
|
14
|
+
build,
|
|
15
|
+
}: {
|
|
16
|
+
build: (state: {
|
|
17
|
+
grid: boolean
|
|
18
|
+
setGrid: (v: boolean) => void
|
|
19
|
+
snap: boolean
|
|
20
|
+
setSnap: (v: boolean) => void
|
|
21
|
+
hasSelection: boolean
|
|
22
|
+
setHasSelection: (v: boolean) => void
|
|
23
|
+
run: (id: string) => void
|
|
24
|
+
}) => MenuBarMenu[]
|
|
25
|
+
}) {
|
|
26
|
+
const [grid, setGrid] = React.useState(true)
|
|
27
|
+
const [snap, setSnap] = React.useState(false)
|
|
28
|
+
const [hasSelection, setHasSelection] = React.useState(false)
|
|
29
|
+
const [last, setLast] = React.useState<string | null>(null)
|
|
30
|
+
|
|
31
|
+
const menus = build({ grid, setGrid, snap, setSnap, hasSelection, setHasSelection, run: setLast })
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="w-full">
|
|
35
|
+
<div className="rounded-lg border border-border bg-card">
|
|
36
|
+
<MenuBar menus={menus} aria-label="Demo menu" className="px-1 py-1" />
|
|
37
|
+
</div>
|
|
38
|
+
<p className="mt-3 text-xs text-muted-foreground">
|
|
39
|
+
Last command: <span className="font-medium text-foreground">{last ?? "—"}</span> · grid {grid ? "on" : "off"} ·
|
|
40
|
+
snap {snap ? "on" : "off"}
|
|
41
|
+
</p>
|
|
42
|
+
<button
|
|
43
|
+
type="button"
|
|
44
|
+
className="mt-2 rounded-md border border-input px-2 py-1 text-xs"
|
|
45
|
+
onClick={() => setHasSelection((v) => !v)}
|
|
46
|
+
>
|
|
47
|
+
{hasSelection ? "Clear selection" : "Simulate a selection"} (drives the disabled items)
|
|
48
|
+
</button>
|
|
49
|
+
</div>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const meta = {
|
|
54
|
+
title: "MenuBar",
|
|
55
|
+
component: MenuBar,
|
|
56
|
+
tags: ["autodocs"],
|
|
57
|
+
parameters: {
|
|
58
|
+
docs: {
|
|
59
|
+
description: {
|
|
60
|
+
component:
|
|
61
|
+
"A desktop-application menu bar (File / Edit / …) for command sets far too large for one toolbar. Built on Radix `Menubar`, so it behaves natively: roving tab focus across the menus, arrow-key traversal, hover-to-switch once a menu is open, character typeahead, Escape/click-outside dismissal and focus restoration. Prefer the declarative `menus` prop — describe commands once (a registry) and render them here, in a toolbar and in a shortcuts sheet without restating any of them.",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
} satisfies Meta<typeof MenuBar>
|
|
66
|
+
|
|
67
|
+
export default meta
|
|
68
|
+
type Story = StoryObj<typeof meta>
|
|
69
|
+
|
|
70
|
+
/** The full vocabulary: actions with shortcut hints, checkable toggles, nested
|
|
71
|
+
* submenus, group labels, separators, disabled and destructive items. */
|
|
72
|
+
export const Default: Story = {
|
|
73
|
+
args: { menus: [] },
|
|
74
|
+
render: () => (
|
|
75
|
+
<Demo
|
|
76
|
+
build={({ grid, setGrid, snap, setSnap, hasSelection, run }) => [
|
|
77
|
+
{
|
|
78
|
+
id: "file",
|
|
79
|
+
label: "File",
|
|
80
|
+
items: [
|
|
81
|
+
{ id: "new", label: "New", icon: <IconFilePlus />, shortcut: "Ctrl+N", onSelect: () => run("new") },
|
|
82
|
+
{ id: "save", label: "Save", shortcut: "Ctrl+S", onSelect: () => run("save") },
|
|
83
|
+
{ kind: "separator", id: "s1" },
|
|
84
|
+
{ id: "print", label: "Print…", icon: <IconPrinter />, shortcut: "Ctrl+P", onSelect: () => run("print") },
|
|
85
|
+
{ kind: "separator", id: "s2" },
|
|
86
|
+
{ id: "delete", label: "Delete document", icon: <IconTrash />, destructive: true, onSelect: () => run("delete") },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: "edit",
|
|
91
|
+
label: "Edit",
|
|
92
|
+
items: [
|
|
93
|
+
{ id: "undo", label: "Undo", shortcut: "Ctrl+Z", onSelect: () => run("undo") },
|
|
94
|
+
{ id: "redo", label: "Redo", shortcut: "Ctrl+Shift+Z", disabled: true, onSelect: () => run("redo") },
|
|
95
|
+
{ kind: "separator", id: "s1" },
|
|
96
|
+
{ id: "cut", label: "Cut", shortcut: "Ctrl+X", disabled: !hasSelection, onSelect: () => run("cut") },
|
|
97
|
+
{ id: "copy", label: "Copy", shortcut: "Ctrl+C", disabled: !hasSelection, onSelect: () => run("copy") },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "insert",
|
|
102
|
+
label: "Insert",
|
|
103
|
+
items: [
|
|
104
|
+
{ id: "text", label: "Text", icon: <IconTypography />, onSelect: () => run("insert text") },
|
|
105
|
+
{ kind: "separator", id: "s1" },
|
|
106
|
+
{
|
|
107
|
+
kind: "submenu",
|
|
108
|
+
id: "block",
|
|
109
|
+
label: "Block",
|
|
110
|
+
items: [
|
|
111
|
+
{ kind: "label", id: "l-sys", label: "System" },
|
|
112
|
+
{ id: "b-header", label: "Company header", onSelect: () => run("insert header block") },
|
|
113
|
+
{ kind: "label", id: "l-mine", label: "Personal" },
|
|
114
|
+
{ id: "b-addr", label: "Return address", onSelect: () => run("insert address block") },
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
kind: "submenu",
|
|
119
|
+
id: "empty",
|
|
120
|
+
label: "Nothing in here",
|
|
121
|
+
items: [],
|
|
122
|
+
emptyLabel: "No blocks in your library",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: "view",
|
|
128
|
+
label: "View",
|
|
129
|
+
items: [
|
|
130
|
+
{ kind: "checkbox", id: "grid", label: "Grid", checked: grid, onCheckedChange: setGrid },
|
|
131
|
+
{ kind: "checkbox", id: "snap", label: "Snap to grid", checked: snap, onCheckedChange: setSnap },
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
{ id: "disabled-menu", label: "Unavailable", disabled: true, items: [] },
|
|
135
|
+
]}
|
|
136
|
+
/>
|
|
137
|
+
),
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Checkable items keep the menu OPEN when toggled, so several view options can
|
|
141
|
+
* be flipped in one visit. */
|
|
142
|
+
export const CheckableToggles: Story = {
|
|
143
|
+
args: { menus: [] },
|
|
144
|
+
render: () => (
|
|
145
|
+
<Demo
|
|
146
|
+
build={({ grid, setGrid, snap, setSnap }) => [
|
|
147
|
+
{
|
|
148
|
+
id: "view",
|
|
149
|
+
label: "View",
|
|
150
|
+
items: [
|
|
151
|
+
{ kind: "checkbox", id: "grid", label: "Grid", checked: grid, onCheckedChange: setGrid },
|
|
152
|
+
{ kind: "checkbox", id: "snap", label: "Snap to grid & guides", checked: snap, onCheckedChange: setSnap },
|
|
153
|
+
{ kind: "separator", id: "s1" },
|
|
154
|
+
{ kind: "checkbox", id: "locked", label: "Disabled toggle", checked: false, disabled: true, onCheckedChange: () => {} },
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
]}
|
|
158
|
+
/>
|
|
159
|
+
),
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** An empty submenu renders a disabled placeholder rather than opening onto
|
|
163
|
+
* nothing — a dead end reads as a bug. */
|
|
164
|
+
export const EmptySubmenu: Story = {
|
|
165
|
+
args: {
|
|
166
|
+
menus: [
|
|
167
|
+
{
|
|
168
|
+
id: "templates",
|
|
169
|
+
label: "Templates",
|
|
170
|
+
items: [
|
|
171
|
+
{
|
|
172
|
+
kind: "submenu",
|
|
173
|
+
id: "open-saved",
|
|
174
|
+
label: "Open saved",
|
|
175
|
+
items: [],
|
|
176
|
+
emptyLabel: "No saved templates yet",
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Many menus, as a real editor has — the bar wraps nothing and keyboard
|
|
185
|
+
* traversal covers all of them. */
|
|
186
|
+
export const ManyMenus: Story = {
|
|
187
|
+
args: {
|
|
188
|
+
menus: ["File", "Edit", "Insert", "Format", "Page", "View", "Data", "Templates", "Help"].map((label) => ({
|
|
189
|
+
id: label.toLowerCase(),
|
|
190
|
+
label,
|
|
191
|
+
items: [
|
|
192
|
+
{ id: `${label}-a`, label: `${label} action`, onSelect: () => {} },
|
|
193
|
+
{ kind: "separator", id: `${label}-s` },
|
|
194
|
+
{ id: `${label}-b`, label: `Another ${label.toLowerCase()} action`, shortcut: "Ctrl+K", onSelect: () => {} },
|
|
195
|
+
],
|
|
196
|
+
})),
|
|
197
|
+
},
|
|
198
|
+
}
|
package/src/menu-bar.tsx
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Menubar as MenubarPrimitive } from "radix-ui"
|
|
5
|
+
import { IconCheck, IconChevronRight } from "@tabler/icons-react"
|
|
6
|
+
|
|
7
|
+
import { cn, useIsDarkMode } from "./utils"
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A desktop-application menu bar (File / Edit / Insert / …), as found in Google
|
|
11
|
+
* Docs, Word and every canvas editor — the home for a command set far too large
|
|
12
|
+
* for a single toolbar row.
|
|
13
|
+
*
|
|
14
|
+
* Two layers, mirroring `dropdown-menu.tsx`:
|
|
15
|
+
*
|
|
16
|
+
* 1. Styled primitive parts (`MenuBarRoot`, `MenuBarItem`, …) over Radix
|
|
17
|
+
* `Menubar`, which supplies the behaviour that makes a menu bar feel native
|
|
18
|
+
* and stays accessible: roving tab focus across the menus, arrow-key
|
|
19
|
+
* traversal, hover-to-switch once a menu is open, character typeahead,
|
|
20
|
+
* Escape/click-outside dismissal and focus restoration.
|
|
21
|
+
* 2. A DECLARATIVE renderer — `<MenuBar menus={…} />` — that draws a plain
|
|
22
|
+
* `MenuBarMenu[]` model. Prefer this: it lets an app describe its commands
|
|
23
|
+
* once (a command registry) and render them here, in a toolbar and in a
|
|
24
|
+
* shortcuts sheet without restating any of them. Every node carries its own
|
|
25
|
+
* `disabled`/`checked` state, so the model is the single source of truth for
|
|
26
|
+
* whether a command is currently available.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// ── the declarative model ───────────────────────────────────────────────────
|
|
30
|
+
|
|
31
|
+
/** A command: runs `onSelect` when chosen. */
|
|
32
|
+
export interface MenuBarActionNode {
|
|
33
|
+
kind?: "item"
|
|
34
|
+
id: string
|
|
35
|
+
label: React.ReactNode
|
|
36
|
+
icon?: React.ReactNode
|
|
37
|
+
/** Display-only shortcut hint, e.g. "Ctrl+S". Binding it is the app's job. */
|
|
38
|
+
shortcut?: string
|
|
39
|
+
disabled?: boolean
|
|
40
|
+
/** Renders in the destructive tone (delete, remove). */
|
|
41
|
+
destructive?: boolean
|
|
42
|
+
onSelect: () => void
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A toggle: shows a tick when `checked`. */
|
|
46
|
+
export interface MenuBarCheckboxNode {
|
|
47
|
+
kind: "checkbox"
|
|
48
|
+
id: string
|
|
49
|
+
label: React.ReactNode
|
|
50
|
+
checked: boolean
|
|
51
|
+
shortcut?: string
|
|
52
|
+
disabled?: boolean
|
|
53
|
+
onCheckedChange: (checked: boolean) => void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A nested menu. An empty `items` renders a disabled placeholder, never a
|
|
57
|
+
* dead end that opens onto nothing. */
|
|
58
|
+
export interface MenuBarSubmenuNode {
|
|
59
|
+
kind: "submenu"
|
|
60
|
+
id: string
|
|
61
|
+
label: React.ReactNode
|
|
62
|
+
icon?: React.ReactNode
|
|
63
|
+
disabled?: boolean
|
|
64
|
+
items: MenuBarNode[]
|
|
65
|
+
/** Shown (disabled) when `items` is empty. */
|
|
66
|
+
emptyLabel?: React.ReactNode
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface MenuBarSeparatorNode {
|
|
70
|
+
kind: "separator"
|
|
71
|
+
id: string
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** A non-interactive heading, for grouping inside a long menu. */
|
|
75
|
+
export interface MenuBarLabelNode {
|
|
76
|
+
kind: "label"
|
|
77
|
+
id: string
|
|
78
|
+
label: React.ReactNode
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type MenuBarNode =
|
|
82
|
+
| MenuBarActionNode
|
|
83
|
+
| MenuBarCheckboxNode
|
|
84
|
+
| MenuBarSubmenuNode
|
|
85
|
+
| MenuBarSeparatorNode
|
|
86
|
+
| MenuBarLabelNode
|
|
87
|
+
|
|
88
|
+
export interface MenuBarMenu {
|
|
89
|
+
id: string
|
|
90
|
+
label: React.ReactNode
|
|
91
|
+
disabled?: boolean
|
|
92
|
+
items: MenuBarNode[]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ── styled primitive parts ──────────────────────────────────────────────────
|
|
96
|
+
|
|
97
|
+
function MenuBarRoot({ className, ...props }: React.ComponentProps<typeof MenubarPrimitive.Root>) {
|
|
98
|
+
return (
|
|
99
|
+
<MenubarPrimitive.Root
|
|
100
|
+
data-slot="menu-bar"
|
|
101
|
+
className={cn("flex items-center gap-0.5", className)}
|
|
102
|
+
{...props}
|
|
103
|
+
/>
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function MenuBarMenuRoot({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Menu>) {
|
|
108
|
+
return <MenubarPrimitive.Menu data-slot="menu-bar-menu" {...props} />
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function MenuBarTrigger({ className, ...props }: React.ComponentProps<typeof MenubarPrimitive.Trigger>) {
|
|
112
|
+
return (
|
|
113
|
+
<MenubarPrimitive.Trigger
|
|
114
|
+
data-slot="menu-bar-trigger"
|
|
115
|
+
className={cn(
|
|
116
|
+
"flex select-none items-center rounded-md px-2 py-1 text-xs font-medium text-foreground outline-hidden hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring/40 data-open:bg-accent data-open:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
|
|
117
|
+
className
|
|
118
|
+
)}
|
|
119
|
+
{...props}
|
|
120
|
+
/>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function MenuBarContent({
|
|
125
|
+
className,
|
|
126
|
+
align = "start",
|
|
127
|
+
sideOffset = 4,
|
|
128
|
+
...props
|
|
129
|
+
}: React.ComponentProps<typeof MenubarPrimitive.Content>) {
|
|
130
|
+
const isDark = useIsDarkMode()
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<MenubarPrimitive.Portal>
|
|
134
|
+
<MenubarPrimitive.Content
|
|
135
|
+
data-slot="menu-bar-content"
|
|
136
|
+
align={align}
|
|
137
|
+
sideOffset={sideOffset}
|
|
138
|
+
className={cn(
|
|
139
|
+
isDark && "dark",
|
|
140
|
+
"z-50 max-h-(--radix-menubar-content-available-height) min-w-52 origin-(--radix-menubar-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg border border-border bg-popover p-1 text-popover-foreground shadow-md duration-100 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
141
|
+
className
|
|
142
|
+
)}
|
|
143
|
+
{...props}
|
|
144
|
+
/>
|
|
145
|
+
</MenubarPrimitive.Portal>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function MenuBarItem({
|
|
150
|
+
className,
|
|
151
|
+
variant = "default",
|
|
152
|
+
...props
|
|
153
|
+
}: React.ComponentProps<typeof MenubarPrimitive.Item> & { variant?: "default" | "destructive" }) {
|
|
154
|
+
return (
|
|
155
|
+
<MenubarPrimitive.Item
|
|
156
|
+
data-slot="menu-bar-item"
|
|
157
|
+
data-variant={variant}
|
|
158
|
+
className={cn(
|
|
159
|
+
"group/menu-bar-item relative flex min-h-7 cursor-default items-center gap-2 rounded-md px-2 py-1 text-xs/relaxed outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5 data-[variant=destructive]:*:[svg]:text-destructive",
|
|
160
|
+
className
|
|
161
|
+
)}
|
|
162
|
+
{...props}
|
|
163
|
+
/>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function MenuBarCheckboxItem({
|
|
168
|
+
className,
|
|
169
|
+
children,
|
|
170
|
+
checked,
|
|
171
|
+
...props
|
|
172
|
+
}: React.ComponentProps<typeof MenubarPrimitive.CheckboxItem>) {
|
|
173
|
+
return (
|
|
174
|
+
<MenubarPrimitive.CheckboxItem
|
|
175
|
+
data-slot="menu-bar-checkbox-item"
|
|
176
|
+
checked={checked}
|
|
177
|
+
className={cn(
|
|
178
|
+
"group/menu-bar-item relative flex min-h-7 cursor-default items-center gap-2 rounded-md py-1 pe-8 ps-2 text-xs/relaxed outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",
|
|
179
|
+
className
|
|
180
|
+
)}
|
|
181
|
+
{...props}
|
|
182
|
+
>
|
|
183
|
+
<span className="pointer-events-none absolute end-2 flex items-center justify-center">
|
|
184
|
+
<MenubarPrimitive.ItemIndicator>
|
|
185
|
+
<IconCheck />
|
|
186
|
+
</MenubarPrimitive.ItemIndicator>
|
|
187
|
+
</span>
|
|
188
|
+
{children}
|
|
189
|
+
</MenubarPrimitive.CheckboxItem>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function MenuBarLabel({ className, ...props }: React.ComponentProps<typeof MenubarPrimitive.Label>) {
|
|
194
|
+
return (
|
|
195
|
+
<MenubarPrimitive.Label
|
|
196
|
+
data-slot="menu-bar-label"
|
|
197
|
+
className={cn("px-2 py-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground", className)}
|
|
198
|
+
{...props}
|
|
199
|
+
/>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function MenuBarSeparator({ className, ...props }: React.ComponentProps<typeof MenubarPrimitive.Separator>) {
|
|
204
|
+
return (
|
|
205
|
+
<MenubarPrimitive.Separator
|
|
206
|
+
data-slot="menu-bar-separator"
|
|
207
|
+
className={cn("-mx-1 my-1 h-px bg-border/50", className)}
|
|
208
|
+
{...props}
|
|
209
|
+
/>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function MenuBarShortcut({ className, ...props }: React.ComponentProps<"span">) {
|
|
214
|
+
return (
|
|
215
|
+
<span
|
|
216
|
+
data-slot="menu-bar-shortcut"
|
|
217
|
+
className={cn(
|
|
218
|
+
"ms-auto ps-4 text-xs tracking-widest text-muted-foreground group-focus/menu-bar-item:text-accent-foreground",
|
|
219
|
+
className
|
|
220
|
+
)}
|
|
221
|
+
{...props}
|
|
222
|
+
/>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function MenuBarSub({ ...props }: React.ComponentProps<typeof MenubarPrimitive.Sub>) {
|
|
227
|
+
return <MenubarPrimitive.Sub data-slot="menu-bar-sub" {...props} />
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function MenuBarSubTrigger({
|
|
231
|
+
className,
|
|
232
|
+
children,
|
|
233
|
+
...props
|
|
234
|
+
}: React.ComponentProps<typeof MenubarPrimitive.SubTrigger>) {
|
|
235
|
+
return (
|
|
236
|
+
<MenubarPrimitive.SubTrigger
|
|
237
|
+
data-slot="menu-bar-sub-trigger"
|
|
238
|
+
className={cn(
|
|
239
|
+
"flex min-h-7 cursor-default items-center gap-2 rounded-md px-2 py-1 text-xs/relaxed outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",
|
|
240
|
+
className
|
|
241
|
+
)}
|
|
242
|
+
{...props}
|
|
243
|
+
>
|
|
244
|
+
{children}
|
|
245
|
+
<IconChevronRight className="ms-auto rtl:rotate-180" />
|
|
246
|
+
</MenubarPrimitive.SubTrigger>
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function MenuBarSubContent({ className, ...props }: React.ComponentProps<typeof MenubarPrimitive.SubContent>) {
|
|
251
|
+
const isDark = useIsDarkMode()
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<MenubarPrimitive.Portal>
|
|
255
|
+
<MenubarPrimitive.SubContent
|
|
256
|
+
data-slot="menu-bar-sub-content"
|
|
257
|
+
className={cn(
|
|
258
|
+
isDark && "dark",
|
|
259
|
+
"z-50 max-h-(--radix-menubar-content-available-height) min-w-44 origin-(--radix-menubar-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg border border-border bg-popover p-1 text-popover-foreground shadow-md duration-100 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
260
|
+
className
|
|
261
|
+
)}
|
|
262
|
+
{...props}
|
|
263
|
+
/>
|
|
264
|
+
</MenubarPrimitive.Portal>
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ── the declarative renderer ────────────────────────────────────────────────
|
|
269
|
+
|
|
270
|
+
/** Render one model node (recursively, for submenus). */
|
|
271
|
+
function MenuBarNodes({ items, emptyLabel }: { items: MenuBarNode[]; emptyLabel?: React.ReactNode }) {
|
|
272
|
+
if (items.length === 0) {
|
|
273
|
+
return <MenuBarItem disabled>{emptyLabel ?? "Nothing here yet"}</MenuBarItem>
|
|
274
|
+
}
|
|
275
|
+
return (
|
|
276
|
+
<>
|
|
277
|
+
{items.map((node) => {
|
|
278
|
+
if ("kind" in node && node.kind === "separator") {
|
|
279
|
+
return <MenuBarSeparator key={node.id} />
|
|
280
|
+
}
|
|
281
|
+
if ("kind" in node && node.kind === "label") {
|
|
282
|
+
return <MenuBarLabel key={node.id}>{node.label}</MenuBarLabel>
|
|
283
|
+
}
|
|
284
|
+
if ("kind" in node && node.kind === "checkbox") {
|
|
285
|
+
return (
|
|
286
|
+
<MenuBarCheckboxItem
|
|
287
|
+
key={node.id}
|
|
288
|
+
data-testid={`menu-item-${node.id}`}
|
|
289
|
+
checked={node.checked}
|
|
290
|
+
disabled={node.disabled}
|
|
291
|
+
// Radix closes the menu on select by default; a toggle is more
|
|
292
|
+
// useful kept open so several can be flipped in one visit.
|
|
293
|
+
onSelect={(e) => e.preventDefault()}
|
|
294
|
+
onCheckedChange={node.onCheckedChange}
|
|
295
|
+
>
|
|
296
|
+
{node.label}
|
|
297
|
+
{node.shortcut && <MenuBarShortcut>{node.shortcut}</MenuBarShortcut>}
|
|
298
|
+
</MenuBarCheckboxItem>
|
|
299
|
+
)
|
|
300
|
+
}
|
|
301
|
+
if ("kind" in node && node.kind === "submenu") {
|
|
302
|
+
return (
|
|
303
|
+
<MenuBarSub key={node.id}>
|
|
304
|
+
<MenuBarSubTrigger data-testid={`menu-item-${node.id}`} disabled={node.disabled}>
|
|
305
|
+
{node.icon}
|
|
306
|
+
{node.label}
|
|
307
|
+
</MenuBarSubTrigger>
|
|
308
|
+
<MenuBarSubContent>
|
|
309
|
+
<MenuBarNodes items={node.items} emptyLabel={node.emptyLabel} />
|
|
310
|
+
</MenuBarSubContent>
|
|
311
|
+
</MenuBarSub>
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
const item = node as MenuBarActionNode
|
|
315
|
+
return (
|
|
316
|
+
<MenuBarItem
|
|
317
|
+
key={item.id}
|
|
318
|
+
data-testid={`menu-item-${item.id}`}
|
|
319
|
+
disabled={item.disabled}
|
|
320
|
+
variant={item.destructive ? "destructive" : "default"}
|
|
321
|
+
onSelect={item.onSelect}
|
|
322
|
+
>
|
|
323
|
+
{item.icon}
|
|
324
|
+
{item.label}
|
|
325
|
+
{item.shortcut && <MenuBarShortcut>{item.shortcut}</MenuBarShortcut>}
|
|
326
|
+
</MenuBarItem>
|
|
327
|
+
)
|
|
328
|
+
})}
|
|
329
|
+
</>
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface MenuBarProps extends Omit<React.ComponentProps<typeof MenubarPrimitive.Root>, "children"> {
|
|
334
|
+
menus: MenuBarMenu[]
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Draw a whole menu bar from a `MenuBarMenu[]` model. Each menu gets a
|
|
339
|
+
* `data-testid` of `menu-<id>` and each item `menu-item-<id>`, so a command can
|
|
340
|
+
* be driven end-to-end in tests by the same id the registry declares it with.
|
|
341
|
+
*/
|
|
342
|
+
function MenuBar({ menus, ...props }: MenuBarProps) {
|
|
343
|
+
return (
|
|
344
|
+
<MenuBarRoot {...props}>
|
|
345
|
+
{menus.map((menu) => (
|
|
346
|
+
<MenuBarMenuRoot key={menu.id}>
|
|
347
|
+
<MenuBarTrigger data-testid={`menu-${menu.id}`} disabled={menu.disabled}>
|
|
348
|
+
{menu.label}
|
|
349
|
+
</MenuBarTrigger>
|
|
350
|
+
<MenuBarContent>
|
|
351
|
+
<MenuBarNodes items={menu.items} />
|
|
352
|
+
</MenuBarContent>
|
|
353
|
+
</MenuBarMenuRoot>
|
|
354
|
+
))}
|
|
355
|
+
</MenuBarRoot>
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export {
|
|
360
|
+
MenuBar,
|
|
361
|
+
MenuBarRoot,
|
|
362
|
+
MenuBarMenuRoot,
|
|
363
|
+
MenuBarTrigger,
|
|
364
|
+
MenuBarContent,
|
|
365
|
+
MenuBarItem,
|
|
366
|
+
MenuBarCheckboxItem,
|
|
367
|
+
MenuBarLabel,
|
|
368
|
+
MenuBarSeparator,
|
|
369
|
+
MenuBarShortcut,
|
|
370
|
+
MenuBarSub,
|
|
371
|
+
MenuBarSubTrigger,
|
|
372
|
+
MenuBarSubContent,
|
|
373
|
+
}
|