@vendure-io/ui 2.2.0 → 3.0.0-next.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/package.json +19 -5
- package/src/components/atoms/accordion.tsx +21 -6
- package/src/components/atoms/alert-dialog.tsx +31 -6
- package/src/components/atoms/alert.tsx +72 -18
- package/src/components/atoms/avatar.tsx +12 -4
- package/src/components/atoms/badge.tsx +7 -2
- package/src/components/atoms/breadcrumb.tsx +493 -4
- package/src/components/atoms/button-group.tsx +30 -6
- package/src/components/atoms/button.tsx +128 -18
- package/src/components/atoms/calendar.tsx +6 -6
- package/src/components/atoms/card.tsx +130 -16
- package/src/components/atoms/carousel.tsx +16 -9
- package/src/components/atoms/chart.tsx +87 -1
- package/src/components/atoms/checkbox.tsx +85 -7
- package/src/components/atoms/collapsible.tsx +2 -1
- package/src/components/atoms/combobox.tsx +358 -29
- package/src/components/atoms/command.tsx +336 -13
- package/src/components/atoms/context-menu.tsx +28 -23
- package/src/components/atoms/dialog.tsx +173 -29
- package/src/components/atoms/direction.tsx +23 -2
- package/src/components/atoms/drawer.tsx +15 -10
- package/src/components/atoms/dropdown-menu.tsx +43 -28
- package/src/components/atoms/empty.tsx +5 -1
- package/src/components/atoms/field.tsx +41 -15
- package/src/components/atoms/hover-card.tsx +61 -8
- package/src/components/atoms/input-group.tsx +19 -11
- package/src/components/atoms/input-otp.tsx +6 -6
- package/src/components/atoms/input.tsx +7 -1
- package/src/components/atoms/item.tsx +3 -3
- package/src/components/atoms/kbd.tsx +32 -3
- package/src/components/atoms/label-swap.tsx +113 -0
- package/src/components/atoms/label.tsx +1 -1
- package/src/components/atoms/menubar.tsx +28 -26
- package/src/components/atoms/native-select.tsx +3 -2
- package/src/components/atoms/navigation-menu.tsx +13 -8
- package/src/components/atoms/pagination.tsx +2 -2
- package/src/components/atoms/popover.tsx +29 -6
- package/src/components/atoms/progress.tsx +46 -33
- package/src/components/atoms/radio-group.tsx +9 -4
- package/src/components/atoms/resizable.tsx +1 -1
- package/src/components/atoms/scroll-area.tsx +2 -2
- package/src/components/atoms/select.tsx +258 -19
- package/src/components/atoms/sheet.tsx +76 -23
- package/src/components/atoms/sidebar.tsx +405 -23
- package/src/components/atoms/skeleton.tsx +1 -1
- package/src/components/atoms/slider.tsx +1 -1
- package/src/components/atoms/sonner.tsx +128 -38
- package/src/components/atoms/spinner.tsx +1 -1
- package/src/components/atoms/switch.tsx +10 -5
- package/src/components/atoms/table.tsx +147 -7
- package/src/components/atoms/tabs.tsx +3 -3
- package/src/components/atoms/textarea.tsx +3 -1
- package/src/components/atoms/toggle-group.tsx +4 -2
- package/src/components/atoms/toggle.tsx +28 -6
- package/src/components/atoms/tooltip.tsx +85 -15
- package/src/components/molecules/anonymized-token.tsx +24 -8
- package/src/components/molecules/app-shell.tsx +53 -20
- package/src/components/molecules/arrow-link.tsx +40 -0
- package/src/components/molecules/chip.tsx +43 -4
- package/src/components/molecules/code-block.tsx +54 -31
- package/src/components/molecules/collapsible-section.tsx +129 -0
- package/src/components/molecules/confirm-dialog.tsx +122 -9
- package/src/components/molecules/copyable-text.tsx +75 -11
- package/src/components/molecules/count-badge.tsx +115 -0
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +32 -4
- package/src/components/molecules/data-table/data-table-column-header.tsx +20 -3
- package/src/components/molecules/data-table/data-table-filters.tsx +62 -22
- package/src/components/molecules/data-table/data-table-helpers.tsx +88 -1
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +115 -0
- package/src/components/molecules/data-table/data-table-types.tsx +160 -4
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
- package/src/components/molecules/data-table/data-table.tsx +869 -81
- package/src/components/molecules/data-table/table-pagination.tsx +2 -2
- package/src/components/molecules/date-picker.tsx +13 -7
- package/src/components/molecules/date-range-picker.tsx +13 -6
- package/src/components/molecules/date-time-picker.tsx +13 -7
- package/src/components/molecules/date-time.tsx +8 -1
- package/src/components/molecules/direction-link.tsx +130 -0
- package/src/components/molecules/elapsed-time.tsx +223 -0
- package/src/components/molecules/file-dropzone.tsx +2 -2
- package/src/components/molecules/id-chip.tsx +169 -32
- package/src/components/molecules/inline-code.tsx +4 -0
- package/src/components/molecules/issued-secret.tsx +318 -0
- package/src/components/molecules/list-row.tsx +349 -0
- package/src/components/molecules/live-indicator.tsx +83 -0
- package/src/components/molecules/page-header.tsx +117 -5
- package/src/components/molecules/password-input.tsx +2 -2
- package/src/components/molecules/relative-time.tsx +85 -56
- package/src/components/molecules/search-trigger.tsx +111 -0
- package/src/components/molecules/secret-value.tsx +29 -9
- package/src/components/molecules/skip-link.tsx +1 -1
- package/src/components/molecules/stat-card.tsx +4 -4
- package/src/components/molecules/state-views/empty-state.tsx +35 -17
- package/src/components/molecules/state-views/error-state.tsx +32 -14
- package/src/components/molecules/status-badge.tsx +415 -49
- package/src/components/molecules/time-tooltip.tsx +140 -0
- package/src/components/molecules/timeline.tsx +246 -0
- package/src/components/molecules/visibility-icon.tsx +89 -0
- package/src/hooks/use-active-label-size.ts +66 -0
- package/src/hooks/use-apple-platform.ts +26 -0
- package/src/hooks/use-pinned-height.ts +55 -0
- package/src/hooks/use-scrolled.ts +27 -0
- package/src/lib/content-inset.ts +17 -0
- package/src/lib/control-name.ts +55 -0
- package/src/lib/dialog-padding.ts +48 -0
- package/src/lib/field-surface.ts +31 -0
- package/src/lib/format-elapsed.ts +67 -0
- package/src/lib/format-relative.ts +29 -1
- package/src/lib/highlight.ts +3 -3
- package/src/lib/menu-item.tsx +72 -0
- package/src/lib/outline-edge.ts +21 -0
- package/src/lib/popup-align.ts +67 -0
- package/src/lib/popup-direction.ts +22 -0
- package/src/lib/popup-motion.ts +19 -0
- package/src/lib/state-dictionary.ts +42 -6
- package/src/lib/syntax-colors.ts +8 -0
- package/src/lib/tint-recipes.ts +68 -0
- package/src/lib/tone-icons.ts +24 -0
- package/src/lib/trigger-slot.ts +16 -0
- package/src/lib/utils.ts +97 -1
|
@@ -1,9 +1,41 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
1
3
|
import * as React from "react"
|
|
2
4
|
import { mergeProps } from "@base-ui/react/merge-props"
|
|
3
5
|
import { useRender } from "@base-ui/react/use-render"
|
|
4
6
|
|
|
7
|
+
import { Menu as MenuPrimitive } from "@base-ui/react/menu"
|
|
8
|
+
|
|
5
9
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
|
-
import {
|
|
10
|
+
import { defaultFilter } from "cmdk"
|
|
11
|
+
import {
|
|
12
|
+
ChevronsUpDownIcon,
|
|
13
|
+
Loader2Icon,
|
|
14
|
+
MoreHorizontalIcon,
|
|
15
|
+
RefreshCwIcon,
|
|
16
|
+
} from "lucide-react"
|
|
17
|
+
|
|
18
|
+
import { Button } from "./button.tsx"
|
|
19
|
+
import {
|
|
20
|
+
DropdownMenu,
|
|
21
|
+
DropdownMenuContent,
|
|
22
|
+
DropdownMenuGroup,
|
|
23
|
+
DropdownMenuLabel,
|
|
24
|
+
DropdownMenuTrigger,
|
|
25
|
+
} from "./dropdown-menu.tsx"
|
|
26
|
+
import {
|
|
27
|
+
Command,
|
|
28
|
+
CommandEmpty,
|
|
29
|
+
CommandGroup,
|
|
30
|
+
CommandInput,
|
|
31
|
+
CommandItem,
|
|
32
|
+
CommandList,
|
|
33
|
+
} from "./command.tsx"
|
|
34
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover.tsx"
|
|
35
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.tsx"
|
|
36
|
+
// Relative: `label-swap` is closed in the package exports.
|
|
37
|
+
import { LabelSwap } from "./label-swap.tsx"
|
|
38
|
+
import { menuItem, menuRadioItem, MenuCheck } from "../../lib/menu-item.tsx"
|
|
7
39
|
|
|
8
40
|
function Breadcrumb({ className, ...props }: React.ComponentProps<"nav">) {
|
|
9
41
|
return (
|
|
@@ -66,7 +98,7 @@ function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
|
|
|
66
98
|
role="link"
|
|
67
99
|
aria-disabled="true"
|
|
68
100
|
aria-current="page"
|
|
69
|
-
className={cn("text-foreground font-
|
|
101
|
+
className={cn("text-foreground-secondary font-medium", className)}
|
|
70
102
|
{...props}
|
|
71
103
|
/>
|
|
72
104
|
)
|
|
@@ -82,11 +114,14 @@ function BreadcrumbSeparator({
|
|
|
82
114
|
data-slot="breadcrumb-separator"
|
|
83
115
|
role="presentation"
|
|
84
116
|
aria-hidden="true"
|
|
85
|
-
className={cn("[&>svg]:size-3.5", className)}
|
|
117
|
+
className={cn("mx-0.5 [&>svg]:size-3.5", className)}
|
|
86
118
|
{...props}
|
|
87
119
|
>
|
|
88
120
|
{children ?? (
|
|
89
|
-
|
|
121
|
+
// A thin slanted slash, quieter than the crumbs on both sides.
|
|
122
|
+
<span className="inline-block -skew-x-12 text-base leading-none font-light text-muted-foreground/40 select-none">
|
|
123
|
+
/
|
|
124
|
+
</span>
|
|
90
125
|
)}
|
|
91
126
|
</li>
|
|
92
127
|
)
|
|
@@ -114,8 +149,461 @@ function BreadcrumbEllipsis({
|
|
|
114
149
|
)
|
|
115
150
|
}
|
|
116
151
|
|
|
152
|
+
/** One item a `BreadcrumbMenu` or `BreadcrumbSearchMenu` can switch to. */
|
|
153
|
+
type BreadcrumbMenuOption = {
|
|
154
|
+
value: string
|
|
155
|
+
label: string
|
|
156
|
+
/**
|
|
157
|
+
* Before the label, in the crumb and in the menu: a status dot. Keep it
|
|
158
|
+
* decorative (`aria-hidden`) and put its words in `status`.
|
|
159
|
+
*/
|
|
160
|
+
leading?: React.ReactNode
|
|
161
|
+
/**
|
|
162
|
+
* The words for `leading`, such as "Healthy". A screen reader hears them
|
|
163
|
+
* after the label: "Environment: Production, Healthy".
|
|
164
|
+
*/
|
|
165
|
+
status?: string
|
|
166
|
+
/** Muted text after the label in the menu only, such as a type. */
|
|
167
|
+
detail?: React.ReactNode
|
|
168
|
+
/** The row shows but cannot be picked. The arrow keys still stop on it. */
|
|
169
|
+
disabled?: boolean
|
|
170
|
+
/**
|
|
171
|
+
* Renders the row as a link, so it can open in a new tab. It keeps the
|
|
172
|
+
* `menuitemradio` role. An element such as a router `<Link>`; `href` is the
|
|
173
|
+
* short form for a plain `<a>`. The link does the navigation: a plain
|
|
174
|
+
* click follows it and still calls `onValueChange`, so do not navigate
|
|
175
|
+
* there too. A click with a modifier key, or with the middle button, opens
|
|
176
|
+
* the link elsewhere and does not call `onValueChange`. A disabled option
|
|
177
|
+
* renders no link. `BreadcrumbMenu` only: a `BreadcrumbSearchMenu` row is
|
|
178
|
+
* an option of a listbox, which cannot be a link.
|
|
179
|
+
*/
|
|
180
|
+
render?: React.ReactElement
|
|
181
|
+
href?: string
|
|
182
|
+
/** More words the search of a `BreadcrumbSearchMenu` matches, such as a slug. */
|
|
183
|
+
keywords?: readonly string[]
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** One item a `BreadcrumbSearchMenu` can switch to: no link rows. */
|
|
187
|
+
type BreadcrumbSearchMenuOption = Omit<BreadcrumbMenuOption, "render" | "href">
|
|
188
|
+
|
|
189
|
+
/** The props both crumb menus share. */
|
|
190
|
+
type BreadcrumbMenuBaseProps = {
|
|
191
|
+
options: readonly BreadcrumbSearchMenuOption[]
|
|
192
|
+
value: string
|
|
193
|
+
onValueChange?: (value: string) => void
|
|
194
|
+
/** Names the list: it heads the menu and starts the crumb's accessible name. */
|
|
195
|
+
label: string
|
|
196
|
+
/**
|
|
197
|
+
* The crumb's label when no option has `value`, such as "All projects"
|
|
198
|
+
* while none is open, or "Projects unavailable". It swaps like an option.
|
|
199
|
+
*/
|
|
200
|
+
placeholder?: string
|
|
201
|
+
open?: boolean
|
|
202
|
+
onOpenChange?: (open: boolean) => void
|
|
203
|
+
defaultOpen?: boolean
|
|
204
|
+
className?: string
|
|
205
|
+
contentClassName?: string
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** The open state, controlled or not, so the crumb knows it too. */
|
|
209
|
+
function useMenuOpen(
|
|
210
|
+
open: boolean | undefined,
|
|
211
|
+
defaultOpen: boolean,
|
|
212
|
+
onOpenChange: ((open: boolean) => void) | undefined
|
|
213
|
+
) {
|
|
214
|
+
const [own, setOwn] = React.useState(defaultOpen)
|
|
215
|
+
const current = open ?? own
|
|
216
|
+
const set = React.useCallback(
|
|
217
|
+
(next: boolean) => {
|
|
218
|
+
setOwn(next)
|
|
219
|
+
onOpenChange?.(next)
|
|
220
|
+
},
|
|
221
|
+
[onOpenChange]
|
|
222
|
+
)
|
|
223
|
+
return [current, set] as const
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* The look of a crumb that opens a menu: a 28px ghost button (the `sm`
|
|
228
|
+
* height, the same as `SidebarTrigger` beside it in a top bar) with the
|
|
229
|
+
* current option's `leading` slot, its label and an up-down chevron. It may
|
|
230
|
+
* shrink: the label then ends in an ellipsis and the crumb shows the full
|
|
231
|
+
* label in a tooltip. Give its BreadcrumbItem `min-w-0`, and a `max-w-*` on
|
|
232
|
+
* the crumb where it should stop growing. `--content-inset` is the real
|
|
233
|
+
* start inset of its content (9px padding and the 1px border), so a row
|
|
234
|
+
* under it can line up with the dot.
|
|
235
|
+
*/
|
|
236
|
+
const crumbTriggerClassName =
|
|
237
|
+
"text-foreground hover:text-foreground aria-expanded:text-foreground min-w-0 shrink gap-2.25 rounded-lg ps-2.25 pe-1.75 text-sm font-semibold [--content-inset:calc(var(--spacing)*2.25+1px)]"
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The inside of the crumb, and its tooltip. The crumb's accessible name is
|
|
241
|
+
* the list label, the option label and then the status, whatever shows
|
|
242
|
+
* first: "Environment: Production, Healthy". With a `status` it is set as
|
|
243
|
+
* `aria-label`, and words inside `leading` are not read. Without one it comes
|
|
244
|
+
* from the content, `leading` first, as before.
|
|
245
|
+
*/
|
|
246
|
+
function useCrumbTrigger({
|
|
247
|
+
options,
|
|
248
|
+
value,
|
|
249
|
+
label,
|
|
250
|
+
placeholder,
|
|
251
|
+
open,
|
|
252
|
+
}: Pick<BreadcrumbMenuBaseProps, "options" | "value" | "label" | "placeholder"> & {
|
|
253
|
+
open: boolean
|
|
254
|
+
}) {
|
|
255
|
+
const found = options.findIndex((option) => option.value === value)
|
|
256
|
+
const fallback = placeholder !== undefined && found === -1
|
|
257
|
+
// The placeholder has its own place before the options, so the options
|
|
258
|
+
// arriving after a read swap the label, never rewrite it in place.
|
|
259
|
+
const offset = placeholder === undefined ? 0 : 1
|
|
260
|
+
const active = fallback ? 0 : Math.max(0, found) + offset
|
|
261
|
+
const current = fallback ? undefined : options[active - offset]
|
|
262
|
+
const labels = options.map((option) => option.label)
|
|
263
|
+
if (placeholder !== undefined) labels.unshift(placeholder)
|
|
264
|
+
const currentLabel = labels[active] ?? ""
|
|
265
|
+
// With a status, the name is set so the status comes after the label.
|
|
266
|
+
// Without one, the name comes from the content, as before.
|
|
267
|
+
const name = current?.status ? `${label}: ${currentLabel}, ${current.status}` : undefined
|
|
268
|
+
// Whether the label is cut now. Read when the pointer or the focus
|
|
269
|
+
// arrives, so a resize or a new label is never stale.
|
|
270
|
+
const [cut, setCut] = React.useState(false)
|
|
271
|
+
const measure = (event: React.SyntheticEvent<HTMLElement>) => {
|
|
272
|
+
const shown = event.currentTarget.querySelector<HTMLElement>(
|
|
273
|
+
'[data-slot="breadcrumb-menu-label"] > [data-swap="in"]'
|
|
274
|
+
)
|
|
275
|
+
setCut(shown !== null && shown.scrollWidth > shown.clientWidth + 0.5)
|
|
276
|
+
}
|
|
277
|
+
const triggerProps = { "aria-label": name, onPointerEnter: measure, onFocus: measure }
|
|
278
|
+
const content = (
|
|
279
|
+
<>
|
|
280
|
+
{current?.leading}
|
|
281
|
+
<span className="sr-only">{label}: </span>
|
|
282
|
+
<LabelSwap
|
|
283
|
+
data-slot="breadcrumb-menu-label"
|
|
284
|
+
timing="button"
|
|
285
|
+
labels={labels}
|
|
286
|
+
active={active}
|
|
287
|
+
truncate
|
|
288
|
+
activeKey={currentLabel}
|
|
289
|
+
className="justify-items-start overflow-x-clip whitespace-nowrap"
|
|
290
|
+
/>
|
|
291
|
+
<ChevronsUpDownIcon
|
|
292
|
+
aria-hidden
|
|
293
|
+
className="size-3.5 opacity-40 group-hover/button:opacity-80 group-aria-expanded/button:opacity-80"
|
|
294
|
+
/>
|
|
295
|
+
</>
|
|
296
|
+
)
|
|
297
|
+
// The tooltip shows only for a cut label, and never over the open menu.
|
|
298
|
+
const tooltip =
|
|
299
|
+
cut && !open ? <TooltipContent side="bottom">{currentLabel}</TooltipContent> : null
|
|
300
|
+
return { triggerProps, content, tooltip }
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function stopPropagation(event: React.SyntheticEvent) {
|
|
304
|
+
event.stopPropagation()
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Keeps focus and hover events in the open menu. React passes the events of
|
|
309
|
+
* a portal up through its React parents, so a focus or a hover in the menu
|
|
310
|
+
* would reach a tooltip, or any handler, that wraps the crumb, and open it
|
|
311
|
+
* over the menu.
|
|
312
|
+
*/
|
|
313
|
+
const popupEventProps = {
|
|
314
|
+
onFocus: stopPropagation,
|
|
315
|
+
onBlur: stopPropagation,
|
|
316
|
+
onPointerOver: stopPropagation,
|
|
317
|
+
onPointerOut: stopPropagation,
|
|
318
|
+
onPointerMove: stopPropagation,
|
|
319
|
+
onMouseOver: stopPropagation,
|
|
320
|
+
onMouseOut: stopPropagation,
|
|
321
|
+
onMouseMove: stopPropagation,
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** The leading slot, the label, the status and the detail of a menu row. */
|
|
325
|
+
function OptionRow({ option }: { option: BreadcrumbSearchMenuOption }) {
|
|
326
|
+
return (
|
|
327
|
+
<>
|
|
328
|
+
{option.leading}
|
|
329
|
+
{option.status ? (
|
|
330
|
+
// One text node for the name: a separate sr-only span after the
|
|
331
|
+
// label would read "Production , Healthy".
|
|
332
|
+
<>
|
|
333
|
+
<span aria-hidden className="min-w-0 flex-1 truncate">
|
|
334
|
+
{option.label}
|
|
335
|
+
</span>
|
|
336
|
+
<span className="sr-only">{`${option.label}, ${option.status}`}</span>
|
|
337
|
+
</>
|
|
338
|
+
) : (
|
|
339
|
+
<span className="min-w-0 flex-1 truncate">{option.label}</span>
|
|
340
|
+
)}
|
|
341
|
+
{option.detail != null && (
|
|
342
|
+
// At the end of the row, before the check, in both menus.
|
|
343
|
+
<span className="text-muted-foreground ms-auto shrink-0 ps-3 text-xs font-medium">
|
|
344
|
+
{option.detail}
|
|
345
|
+
</span>
|
|
346
|
+
)}
|
|
347
|
+
</>
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function isNewTabClick(event: Event | undefined) {
|
|
352
|
+
if (!event || !("button" in event)) return false
|
|
353
|
+
const pointer = event as MouseEvent
|
|
354
|
+
return pointer.metaKey || pointer.ctrlKey || pointer.shiftKey || pointer.altKey || pointer.button === 1
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* A crumb that opens a menu to switch the current item, such as the
|
|
359
|
+
* environment at the start of a breadcrumb. It shows the current option's
|
|
360
|
+
* `leading` slot (a status dot) and label, and an up-down chevron. The menu
|
|
361
|
+
* lists the options with a check on the current one and opens toward the
|
|
362
|
+
* centre of the screen. Picking an option calls `onValueChange` and keeps the
|
|
363
|
+
* menu open, so the check is seen moving; the crumb's label crossfades to the
|
|
364
|
+
* new one and its width follows. `children` go after the options, such as a
|
|
365
|
+
* separator and an "Add environment" item. The options and the switch stay
|
|
366
|
+
* with the consumer.
|
|
367
|
+
*
|
|
368
|
+
* `label` names the list: it heads the menu and starts the crumb's
|
|
369
|
+
* accessible name ("Environment: Production, Healthy").
|
|
370
|
+
*
|
|
371
|
+
* A long label ends in an ellipsis when the crumb has no room, and a tooltip
|
|
372
|
+
* shows it in full. An option with `href` or `render` is a link; the current
|
|
373
|
+
* row stays a checked `menuitemradio`. `open` and `onOpenChange` control the
|
|
374
|
+
* menu. For a long list with a search field, use `BreadcrumbSearchMenu`.
|
|
375
|
+
*/
|
|
376
|
+
function BreadcrumbMenu({
|
|
377
|
+
options,
|
|
378
|
+
value,
|
|
379
|
+
onValueChange,
|
|
380
|
+
label,
|
|
381
|
+
placeholder,
|
|
382
|
+
open: openProp,
|
|
383
|
+
onOpenChange,
|
|
384
|
+
defaultOpen = false,
|
|
385
|
+
children,
|
|
386
|
+
className,
|
|
387
|
+
contentClassName,
|
|
388
|
+
}: Omit<BreadcrumbMenuBaseProps, "options"> & {
|
|
389
|
+
options: readonly BreadcrumbMenuOption[]
|
|
390
|
+
children?: React.ReactNode
|
|
391
|
+
}) {
|
|
392
|
+
const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
|
|
393
|
+
const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
|
|
394
|
+
return (
|
|
395
|
+
<DropdownMenu open={open} onOpenChange={setOpen}>
|
|
396
|
+
<Tooltip>
|
|
397
|
+
<TooltipTrigger
|
|
398
|
+
render={
|
|
399
|
+
<DropdownMenuTrigger
|
|
400
|
+
data-slot="breadcrumb-menu"
|
|
401
|
+
{...crumb.triggerProps}
|
|
402
|
+
render={
|
|
403
|
+
<Button
|
|
404
|
+
variant="ghost"
|
|
405
|
+
size="sm"
|
|
406
|
+
className={cn(crumbTriggerClassName, className)}
|
|
407
|
+
/>
|
|
408
|
+
}
|
|
409
|
+
/>
|
|
410
|
+
}
|
|
411
|
+
>
|
|
412
|
+
{crumb.content}
|
|
413
|
+
</TooltipTrigger>
|
|
414
|
+
{crumb.tooltip}
|
|
415
|
+
</Tooltip>
|
|
416
|
+
<DropdownMenuContent
|
|
417
|
+
{...popupEventProps}
|
|
418
|
+
className={cn("w-max min-w-72 max-w-90", contentClassName)}
|
|
419
|
+
>
|
|
420
|
+
<DropdownMenuGroup>
|
|
421
|
+
<DropdownMenuLabel>{label}</DropdownMenuLabel>
|
|
422
|
+
<MenuPrimitive.RadioGroup
|
|
423
|
+
value={value}
|
|
424
|
+
onValueChange={(next: string, details) => {
|
|
425
|
+
// A modifier or middle click opens a link row elsewhere: the
|
|
426
|
+
// current item stays.
|
|
427
|
+
if (isNewTabClick(details.event)) return
|
|
428
|
+
onValueChange?.(next)
|
|
429
|
+
}}
|
|
430
|
+
>
|
|
431
|
+
{options.map((option) => (
|
|
432
|
+
<MenuPrimitive.RadioItem
|
|
433
|
+
key={option.value}
|
|
434
|
+
value={option.value}
|
|
435
|
+
disabled={option.disabled}
|
|
436
|
+
closeOnClick={false}
|
|
437
|
+
data-slot="breadcrumb-menu-item"
|
|
438
|
+
render={option.disabled ? undefined : (option.render ?? (option.href !== undefined ? <a href={option.href} /> : undefined))}
|
|
439
|
+
className={cn(menuItem, menuRadioItem)}
|
|
440
|
+
>
|
|
441
|
+
<OptionRow option={option} />
|
|
442
|
+
<MenuCheck />
|
|
443
|
+
</MenuPrimitive.RadioItem>
|
|
444
|
+
))}
|
|
445
|
+
</MenuPrimitive.RadioGroup>
|
|
446
|
+
</DropdownMenuGroup>
|
|
447
|
+
{children}
|
|
448
|
+
</DropdownMenuContent>
|
|
449
|
+
</DropdownMenu>
|
|
450
|
+
)
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* The search of a `BreadcrumbSearchMenu`: the option's label and keywords,
|
|
455
|
+
* never its value, which is often an id.
|
|
456
|
+
*/
|
|
457
|
+
function searchFilter(_value: string, search: string, keywords?: string[]) {
|
|
458
|
+
return defaultFilter(keywords?.join(" ") ?? "", search)
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* A `BreadcrumbMenu` with a search field, for a list that can grow long, such
|
|
463
|
+
* as the projects of an organization. The crumb is the same, and so is its
|
|
464
|
+
* label swap. The popup is a `Command`: a "Find …" field at the top, the
|
|
465
|
+
* options with a check on the current one, then `children` in a footer that
|
|
466
|
+
* stays in view while the list scrolls, such as "All projects" and "Create
|
|
467
|
+
* project". The search matches the option labels and `keywords`.
|
|
468
|
+
*
|
|
469
|
+
* Picking an option calls `onValueChange` and closes the popup, so the crumb's
|
|
470
|
+
* label is seen swapping. `loading` shows a loading row in place of the
|
|
471
|
+
* options. `error` shows its text as a row that cannot be picked and, with
|
|
472
|
+
* `onRetry`, a Retry row. A search that matches nothing shows `emptyText`.
|
|
473
|
+
* Footer items are `CommandItem`s with `forceMount`, so a search does not
|
|
474
|
+
* hide them, and close the popup themselves through `onOpenChange`.
|
|
475
|
+
*/
|
|
476
|
+
function BreadcrumbSearchMenu({
|
|
477
|
+
options,
|
|
478
|
+
value,
|
|
479
|
+
onValueChange,
|
|
480
|
+
label,
|
|
481
|
+
placeholder,
|
|
482
|
+
open: openProp,
|
|
483
|
+
onOpenChange,
|
|
484
|
+
defaultOpen = false,
|
|
485
|
+
searchPlaceholder = `Find ${label.toLowerCase()}…`,
|
|
486
|
+
emptyText = "No results.",
|
|
487
|
+
loading = false,
|
|
488
|
+
error,
|
|
489
|
+
onRetry,
|
|
490
|
+
children,
|
|
491
|
+
className,
|
|
492
|
+
contentClassName,
|
|
493
|
+
}: BreadcrumbMenuBaseProps & {
|
|
494
|
+
/** The search field's placeholder. Default: "Find <label>…". */
|
|
495
|
+
searchPlaceholder?: string
|
|
496
|
+
/** Shows when the search matches no option. */
|
|
497
|
+
emptyText?: React.ReactNode
|
|
498
|
+
/** The options are on their way: a loading row shows in their place. */
|
|
499
|
+
loading?: boolean
|
|
500
|
+
/** The options could not be read: this text shows as a row. */
|
|
501
|
+
error?: React.ReactNode
|
|
502
|
+
/** With `error`, a Retry row calls it. */
|
|
503
|
+
onRetry?: () => void
|
|
504
|
+
/** Footer items: `CommandItem`s with `forceMount`. */
|
|
505
|
+
children?: React.ReactNode
|
|
506
|
+
}) {
|
|
507
|
+
const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
|
|
508
|
+
const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
|
|
509
|
+
const failed = error != null && error !== false
|
|
510
|
+
return (
|
|
511
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
512
|
+
<Tooltip>
|
|
513
|
+
<TooltipTrigger
|
|
514
|
+
render={
|
|
515
|
+
<PopoverTrigger
|
|
516
|
+
data-slot="breadcrumb-menu"
|
|
517
|
+
{...crumb.triggerProps}
|
|
518
|
+
render={
|
|
519
|
+
<Button
|
|
520
|
+
variant="ghost"
|
|
521
|
+
size="sm"
|
|
522
|
+
className={cn(crumbTriggerClassName, className)}
|
|
523
|
+
/>
|
|
524
|
+
}
|
|
525
|
+
/>
|
|
526
|
+
}
|
|
527
|
+
>
|
|
528
|
+
{crumb.content}
|
|
529
|
+
</TooltipTrigger>
|
|
530
|
+
{crumb.tooltip}
|
|
531
|
+
</Tooltip>
|
|
532
|
+
<PopoverContent
|
|
533
|
+
{...popupEventProps}
|
|
534
|
+
data-slot="breadcrumb-search-menu-content"
|
|
535
|
+
aria-label={label}
|
|
536
|
+
className={cn("w-72 max-w-90 gap-0 overflow-hidden p-0", contentClassName)}
|
|
537
|
+
>
|
|
538
|
+
{/* A new Command once the error clears: cmdk keeps the Retry row
|
|
539
|
+
selected after it unmounts, and the field then points at a row
|
|
540
|
+
that is gone (aria-activedescendant). */}
|
|
541
|
+
<Command key={failed ? "failed" : "read"} label={label} filter={searchFilter}>
|
|
542
|
+
<CommandInput autoFocus placeholder={searchPlaceholder} />
|
|
543
|
+
{/* Outside the list: a listbox takes only options and groups. */}
|
|
544
|
+
{loading && (
|
|
545
|
+
<div
|
|
546
|
+
role="status"
|
|
547
|
+
data-slot="breadcrumb-search-menu-loading"
|
|
548
|
+
className="text-muted-foreground flex min-h-8.5 items-center gap-2.5 px-4 pt-2.5 pb-1 text-sm"
|
|
549
|
+
>
|
|
550
|
+
<Loader2Icon aria-hidden className="size-3.75 animate-spin motion-reduce:animate-none" />
|
|
551
|
+
Loading…
|
|
552
|
+
</div>
|
|
553
|
+
)}
|
|
554
|
+
<CommandList>
|
|
555
|
+
{!loading && !failed && <CommandEmpty>{emptyText}</CommandEmpty>}
|
|
556
|
+
{failed && !loading && (
|
|
557
|
+
<CommandGroup forceMount heading={error}>
|
|
558
|
+
{onRetry && (
|
|
559
|
+
<CommandItem forceMount value="__retry" onSelect={onRetry}>
|
|
560
|
+
<RefreshCwIcon />
|
|
561
|
+
<span className="min-w-0 truncate">Retry</span>
|
|
562
|
+
</CommandItem>
|
|
563
|
+
)}
|
|
564
|
+
</CommandGroup>
|
|
565
|
+
)}
|
|
566
|
+
{!loading && options.length > 0 && (
|
|
567
|
+
<CommandGroup>
|
|
568
|
+
{options.map((option) => (
|
|
569
|
+
<CommandItem
|
|
570
|
+
key={option.value}
|
|
571
|
+
value={option.value}
|
|
572
|
+
keywords={[option.label, ...(option.keywords ?? [])]}
|
|
573
|
+
disabled={option.disabled}
|
|
574
|
+
data-checked={option.value === value ? true : undefined}
|
|
575
|
+
data-slot="breadcrumb-menu-item"
|
|
576
|
+
onSelect={() => {
|
|
577
|
+
setOpen(false)
|
|
578
|
+
if (option.value !== value) onValueChange?.(option.value)
|
|
579
|
+
}}
|
|
580
|
+
>
|
|
581
|
+
<OptionRow option={option} />
|
|
582
|
+
</CommandItem>
|
|
583
|
+
))}
|
|
584
|
+
</CommandGroup>
|
|
585
|
+
)}
|
|
586
|
+
{children != null && (
|
|
587
|
+
// Sticky inside the scrolling list, so a long list keeps it in view.
|
|
588
|
+
<CommandGroup
|
|
589
|
+
forceMount
|
|
590
|
+
data-slot="breadcrumb-search-menu-footer"
|
|
591
|
+
className="bg-popover border-border sticky bottom-0 border-t"
|
|
592
|
+
>
|
|
593
|
+
{children}
|
|
594
|
+
</CommandGroup>
|
|
595
|
+
)}
|
|
596
|
+
</CommandList>
|
|
597
|
+
</Command>
|
|
598
|
+
</PopoverContent>
|
|
599
|
+
</Popover>
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
|
|
117
603
|
export {
|
|
118
604
|
Breadcrumb,
|
|
605
|
+
BreadcrumbMenu,
|
|
606
|
+
BreadcrumbSearchMenu,
|
|
119
607
|
BreadcrumbList,
|
|
120
608
|
BreadcrumbItem,
|
|
121
609
|
BreadcrumbLink,
|
|
@@ -123,3 +611,4 @@ export {
|
|
|
123
611
|
BreadcrumbSeparator,
|
|
124
612
|
BreadcrumbEllipsis,
|
|
125
613
|
}
|
|
614
|
+
export type { BreadcrumbMenuOption, BreadcrumbSearchMenuOption }
|
|
@@ -3,21 +3,43 @@ import { useRender } from "@base-ui/react/use-render"
|
|
|
3
3
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
4
|
|
|
5
5
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
6
|
+
import { outlineEdgeRing } from "@vendure-io/ui/lib/outline-edge"
|
|
6
7
|
import { Separator } from "@vendure-io/ui/components/atoms/separator"
|
|
7
8
|
|
|
9
|
+
// The v3 look: the group draws one outer edge and its children draw none.
|
|
10
|
+
// Children keep a transparent 1px border, so a child's padding-clipped fill
|
|
11
|
+
// never covers the group's inset ring, and a later child's leading border is
|
|
12
|
+
// the 1px divider (a ButtonGroupSeparator replaces it). Only the outer ends
|
|
13
|
+
// are rounded. A group that holds other groups is a layout row only: no edge,
|
|
14
|
+
// no fill, and its child groups keep their own radius. The group sits on
|
|
15
|
+
// shadow-control; its children drop their own.
|
|
8
16
|
const buttonGroupVariants = cva(
|
|
9
|
-
"has-[>[data-slot=button-group]]:gap-2 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-
|
|
17
|
+
"has-[>[data-slot=button-group]]:gap-2 has-[>[data-slot=button-group]]:bg-transparent has-[>[data-slot=button-group]]:inset-ring-0 has-[>[data-slot=button-group]]:shadow-none has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-e-xl flex w-fit items-stretch rounded-xl *:data-slot:border-transparent [&>[data-slot]:not([data-slot=button-group])]:shadow-none *:focus-visible:z-10 *:focus-visible:relative [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1 [&>[data-slot=button-group-separator]+[data-slot]]:border-s-transparent! [&>[data-slot=button-group-separator]+[data-slot]]:border-t-transparent!",
|
|
10
18
|
{
|
|
11
19
|
variants: {
|
|
12
20
|
orientation: {
|
|
13
21
|
horizontal:
|
|
14
|
-
"[&>[data-slot]:not(
|
|
22
|
+
"[&>[data-slot]:not([data-slot=button-group])]:rounded-none [&>[data-slot]:not([data-slot]~*)]:rounded-s-xl! [&>[data-slot]:not(:has(~[data-slot]))]:rounded-e-xl!",
|
|
15
23
|
vertical:
|
|
16
|
-
"[&>[data-slot]:not(
|
|
24
|
+
"[&>[data-slot]:not([data-slot=button-group])]:rounded-none [&>[data-slot]:not([data-slot]~*)]:rounded-t-xl! [&>[data-slot]:not(:has(~[data-slot]))]:rounded-b-xl! flex-col",
|
|
25
|
+
},
|
|
26
|
+
variant: {
|
|
27
|
+
default: ["bg-card inset-ring shadow-control", outlineEdgeRing],
|
|
28
|
+
// A primary split button: a main action and a menu trigger on one
|
|
29
|
+
// primary fill. Use default Buttons inside. Children clip their fill
|
|
30
|
+
// to the border box so a hovered segment fills edge to edge.
|
|
31
|
+
primary: "bg-primary shadow-control *:data-slot:bg-clip-border",
|
|
17
32
|
},
|
|
18
33
|
},
|
|
34
|
+
compoundVariants: [
|
|
35
|
+
{ orientation: "horizontal", variant: "default", className: "[&>[data-slot]~[data-slot]]:border-s-border" },
|
|
36
|
+
{ orientation: "vertical", variant: "default", className: "[&>[data-slot]~[data-slot]]:border-t-border" },
|
|
37
|
+
{ orientation: "horizontal", variant: "primary", className: "[&>[data-slot]~[data-slot]]:border-s-primary-foreground/20" },
|
|
38
|
+
{ orientation: "vertical", variant: "primary", className: "[&>[data-slot]~[data-slot]]:border-t-primary-foreground/20" },
|
|
39
|
+
],
|
|
19
40
|
defaultVariants: {
|
|
20
41
|
orientation: "horizontal",
|
|
42
|
+
variant: "default",
|
|
21
43
|
},
|
|
22
44
|
}
|
|
23
45
|
)
|
|
@@ -25,6 +47,7 @@ const buttonGroupVariants = cva(
|
|
|
25
47
|
function ButtonGroup({
|
|
26
48
|
className,
|
|
27
49
|
orientation,
|
|
50
|
+
variant,
|
|
28
51
|
...props
|
|
29
52
|
}: React.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>) {
|
|
30
53
|
return (
|
|
@@ -32,7 +55,8 @@ function ButtonGroup({
|
|
|
32
55
|
role="group"
|
|
33
56
|
data-slot="button-group"
|
|
34
57
|
data-orientation={orientation}
|
|
35
|
-
|
|
58
|
+
data-variant={variant}
|
|
59
|
+
className={cn(buttonGroupVariants({ orientation, variant }), className)}
|
|
36
60
|
{...props}
|
|
37
61
|
/>
|
|
38
62
|
)
|
|
@@ -48,7 +72,7 @@ function ButtonGroupText({
|
|
|
48
72
|
props: mergeProps<"div">(
|
|
49
73
|
{
|
|
50
74
|
className: cn(
|
|
51
|
-
"bg-muted gap-2 rounded-
|
|
75
|
+
"bg-muted gap-2 rounded-xl border px-2.5 text-sm font-medium [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none",
|
|
52
76
|
className
|
|
53
77
|
),
|
|
54
78
|
},
|
|
@@ -71,7 +95,7 @@ function ButtonGroupSeparator({
|
|
|
71
95
|
data-slot="button-group-separator"
|
|
72
96
|
orientation={orientation}
|
|
73
97
|
className={cn(
|
|
74
|
-
"bg-
|
|
98
|
+
"bg-border relative self-stretch data-horizontal:mx-px data-horizontal:w-auto data-vertical:my-px data-vertical:h-auto",
|
|
75
99
|
className
|
|
76
100
|
)}
|
|
77
101
|
{...props}
|