@vendure-io/ui 3.0.0-next.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 +2 -2
- package/src/components/atoms/alert.tsx +13 -6
- package/src/components/atoms/avatar.tsx +11 -3
- package/src/components/atoms/breadcrumb.tsx +409 -53
- package/src/components/atoms/combobox.tsx +220 -17
- package/src/components/atoms/command.tsx +51 -130
- package/src/components/atoms/dialog.tsx +23 -1
- package/src/components/atoms/empty.tsx +1 -1
- package/src/components/atoms/input-group.tsx +2 -2
- package/src/components/atoms/label-swap.tsx +32 -1
- package/src/components/atoms/popover.tsx +6 -1
- package/src/components/atoms/sheet.tsx +18 -1
- package/src/components/atoms/sidebar.tsx +73 -1
- package/src/components/atoms/tooltip.tsx +3 -3
- package/src/components/molecules/chip.tsx +43 -4
- package/src/components/molecules/confirm-dialog.tsx +9 -0
- package/src/components/molecules/count-badge.tsx +115 -0
- package/src/components/molecules/data-table/data-table-filters.tsx +61 -21
- package/src/components/molecules/data-table/data-table-helpers.tsx +20 -0
- package/src/components/molecules/data-table/data-table-types.tsx +39 -0
- package/src/components/molecules/data-table/data-table.tsx +36 -5
- package/src/components/molecules/search-trigger.tsx +1 -17
- package/src/components/molecules/secret-value.tsx +6 -3
- package/src/hooks/use-active-label-size.ts +39 -5
- package/src/hooks/use-apple-platform.ts +26 -0
- package/src/lib/utils.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure-io/ui",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.1",
|
|
4
4
|
"description": "React component library for Vendure, built on shadcn/ui and Tailwind v4",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"homepage": "https://github.com/vendurehq/design/tree/main/packages/ui",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"pack:check": "bun pm pack --dry-run"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@vendure-io/design-tokens": "^3.0.0-next.
|
|
50
|
+
"@vendure-io/design-tokens": "^3.0.0-next.1",
|
|
51
51
|
"react": ">=19",
|
|
52
52
|
"react-dom": ">=19",
|
|
53
53
|
"next": ">=14",
|
|
@@ -119,17 +119,24 @@ function AlertDescription({
|
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
// From a 28rem-wide alert up, the action takes the last grid column
|
|
123
|
-
//
|
|
124
|
-
// centres its content, so a button lines up with
|
|
125
|
-
// overflows into the alert padding instead of making the alert taller.
|
|
126
|
-
//
|
|
122
|
+
// From a 28rem-wide alert up, the action takes the last grid column and spans
|
|
123
|
+
// the text rows, so the text wraps before it. The action box is one text line
|
|
124
|
+
// high and centres its content, so a button lines up with a line of text and
|
|
125
|
+
// overflows into the alert padding instead of making the alert taller.
|
|
126
|
+
// Where the box sits follows the height of the text beside it (100% of the
|
|
127
|
+
// spanned rows):
|
|
128
|
+
// - Up to two lines (a title and one sentence), it is centred on the text.
|
|
129
|
+
// - From three lines (an error block, a next step), it stays on the first line.
|
|
130
|
+
// The step happens at 2.5 lines; `(2.5lh - 100%) * 999` turns it into 0 or a
|
|
131
|
+
// large value, so `min()` picks either the centre offset or 0.
|
|
132
|
+
// The span of 9 rows covers every text row; extra implicit rows are 0 high.
|
|
133
|
+
// In a narrower alert the action moves to its own row under the text.
|
|
127
134
|
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
128
135
|
return (
|
|
129
136
|
<div
|
|
130
137
|
data-slot="alert-action"
|
|
131
138
|
className={cn(
|
|
132
|
-
"col-end-[-1] flex flex-wrap content-center items-center gap-2 @max-md/alert:col-start-1 @max-md/alert:mt-2 @max-md/alert:group-has-[>svg]/alert:col-start-2 @md/alert:row-start-1 @md/alert:ms-3 @md/alert:h-lh @md/alert:self-start",
|
|
139
|
+
"col-end-[-1] flex flex-wrap content-center items-center gap-2 @max-md/alert:col-start-1 @max-md/alert:mt-2 @max-md/alert:group-has-[>svg]/alert:col-start-2 @md/alert:relative @md/alert:row-start-1 @md/alert:row-span-9 @md/alert:ms-3 @md/alert:h-lh @md/alert:self-start @md/alert:top-[min((100%_-_1lh)/2,max(0px,(2.5lh_-_100%)*999))]",
|
|
133
140
|
className
|
|
134
141
|
)}
|
|
135
142
|
{...props}
|
|
@@ -8,16 +8,24 @@ import { cn } from "@vendure-io/ui/lib/utils"
|
|
|
8
8
|
function Avatar({
|
|
9
9
|
className,
|
|
10
10
|
size = "default",
|
|
11
|
+
shape = "circle",
|
|
11
12
|
...props
|
|
12
13
|
}: AvatarPrimitive.Root.Props & {
|
|
13
14
|
size?: "default" | "sm" | "lg"
|
|
15
|
+
/**
|
|
16
|
+
* `circle` for a person. `square` for an account, an organisation or a
|
|
17
|
+
* channel: a logo or initials in a rounded square. The shape covers the
|
|
18
|
+
* ring, the image and the fallback, so do not set a radius by hand.
|
|
19
|
+
*/
|
|
20
|
+
shape?: "circle" | "square"
|
|
14
21
|
}) {
|
|
15
22
|
return (
|
|
16
23
|
<AvatarPrimitive.Root
|
|
17
24
|
data-slot="avatar"
|
|
18
25
|
data-size={size}
|
|
26
|
+
data-shape={shape}
|
|
19
27
|
className={cn(
|
|
20
|
-
"after:border-border group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten",
|
|
28
|
+
"after:border-border group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 data-[shape=square]:rounded-lg data-[shape=square]:after:rounded-lg dark:after:mix-blend-lighten",
|
|
21
29
|
className
|
|
22
30
|
)}
|
|
23
31
|
{...props}
|
|
@@ -30,7 +38,7 @@ function AvatarImage({ className, ...props }: AvatarPrimitive.Image.Props) {
|
|
|
30
38
|
<AvatarPrimitive.Image
|
|
31
39
|
data-slot="avatar-image"
|
|
32
40
|
className={cn(
|
|
33
|
-
"aspect-square size-full rounded-full object-cover",
|
|
41
|
+
"aspect-square size-full rounded-full object-cover group-data-[shape=square]/avatar:rounded-lg",
|
|
34
42
|
className
|
|
35
43
|
)}
|
|
36
44
|
{...props}
|
|
@@ -46,7 +54,7 @@ function AvatarFallback({
|
|
|
46
54
|
<AvatarPrimitive.Fallback
|
|
47
55
|
data-slot="avatar-fallback"
|
|
48
56
|
className={cn(
|
|
49
|
-
"bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs",
|
|
57
|
+
"bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs group-data-[shape=square]/avatar:rounded-lg",
|
|
50
58
|
className
|
|
51
59
|
)}
|
|
52
60
|
{...props}
|
|
@@ -7,7 +7,13 @@ import { useRender } from "@base-ui/react/use-render"
|
|
|
7
7
|
import { Menu as MenuPrimitive } from "@base-ui/react/menu"
|
|
8
8
|
|
|
9
9
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
10
|
-
import {
|
|
10
|
+
import { defaultFilter } from "cmdk"
|
|
11
|
+
import {
|
|
12
|
+
ChevronsUpDownIcon,
|
|
13
|
+
Loader2Icon,
|
|
14
|
+
MoreHorizontalIcon,
|
|
15
|
+
RefreshCwIcon,
|
|
16
|
+
} from "lucide-react"
|
|
11
17
|
|
|
12
18
|
import { Button } from "./button.tsx"
|
|
13
19
|
import {
|
|
@@ -17,6 +23,16 @@ import {
|
|
|
17
23
|
DropdownMenuLabel,
|
|
18
24
|
DropdownMenuTrigger,
|
|
19
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"
|
|
20
36
|
// Relative: `label-swap` is closed in the package exports.
|
|
21
37
|
import { LabelSwap } from "./label-swap.tsx"
|
|
22
38
|
import { menuItem, menuRadioItem, MenuCheck } from "../../lib/menu-item.tsx"
|
|
@@ -133,16 +149,209 @@ function BreadcrumbEllipsis({
|
|
|
133
149
|
)
|
|
134
150
|
}
|
|
135
151
|
|
|
136
|
-
/** One item a `BreadcrumbMenu` can switch to. */
|
|
152
|
+
/** One item a `BreadcrumbMenu` or `BreadcrumbSearchMenu` can switch to. */
|
|
137
153
|
type BreadcrumbMenuOption = {
|
|
138
154
|
value: string
|
|
139
155
|
label: string
|
|
140
|
-
/**
|
|
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
|
+
*/
|
|
141
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
|
|
142
166
|
/** Muted text after the label in the menu only, such as a type. */
|
|
143
167
|
detail?: React.ReactNode
|
|
144
168
|
/** The row shows but cannot be picked. The arrow keys still stop on it. */
|
|
145
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
|
|
146
355
|
}
|
|
147
356
|
|
|
148
357
|
/**
|
|
@@ -156,67 +365,68 @@ type BreadcrumbMenuOption = {
|
|
|
156
365
|
* separator and an "Add environment" item. The options and the switch stay
|
|
157
366
|
* with the consumer.
|
|
158
367
|
*
|
|
159
|
-
* `label` names the list: it heads the menu and
|
|
160
|
-
* accessible name ("Environment: Production").
|
|
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`.
|
|
161
375
|
*/
|
|
162
376
|
function BreadcrumbMenu({
|
|
163
377
|
options,
|
|
164
378
|
value,
|
|
165
379
|
onValueChange,
|
|
166
380
|
label,
|
|
381
|
+
placeholder,
|
|
382
|
+
open: openProp,
|
|
383
|
+
onOpenChange,
|
|
384
|
+
defaultOpen = false,
|
|
167
385
|
children,
|
|
168
386
|
className,
|
|
169
387
|
contentClassName,
|
|
170
|
-
}: {
|
|
388
|
+
}: Omit<BreadcrumbMenuBaseProps, "options"> & {
|
|
171
389
|
options: readonly BreadcrumbMenuOption[]
|
|
172
|
-
value: string
|
|
173
|
-
onValueChange?: (value: string) => void
|
|
174
|
-
label: string
|
|
175
390
|
children?: React.ReactNode
|
|
176
|
-
className?: string
|
|
177
|
-
contentClassName?: string
|
|
178
391
|
}) {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
options.findIndex((option) => option.value === value)
|
|
182
|
-
)
|
|
183
|
-
const current = options[active]
|
|
392
|
+
const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
|
|
393
|
+
const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
|
|
184
394
|
return (
|
|
185
|
-
<DropdownMenu>
|
|
186
|
-
<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
/>
|
|
207
|
-
<ChevronsUpDownIcon
|
|
208
|
-
aria-hidden
|
|
209
|
-
className="size-3.5 opacity-40 group-hover/button:opacity-80 group-aria-expanded/button:opacity-80"
|
|
210
|
-
/>
|
|
211
|
-
</DropdownMenuTrigger>
|
|
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>
|
|
212
416
|
<DropdownMenuContent
|
|
213
|
-
|
|
417
|
+
{...popupEventProps}
|
|
418
|
+
className={cn("w-max min-w-72 max-w-90", contentClassName)}
|
|
214
419
|
>
|
|
215
420
|
<DropdownMenuGroup>
|
|
216
421
|
<DropdownMenuLabel>{label}</DropdownMenuLabel>
|
|
217
422
|
<MenuPrimitive.RadioGroup
|
|
218
423
|
value={value}
|
|
219
|
-
onValueChange={(next: string) =>
|
|
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
|
+
}}
|
|
220
430
|
>
|
|
221
431
|
{options.map((option) => (
|
|
222
432
|
<MenuPrimitive.RadioItem
|
|
@@ -225,15 +435,10 @@ function BreadcrumbMenu({
|
|
|
225
435
|
disabled={option.disabled}
|
|
226
436
|
closeOnClick={false}
|
|
227
437
|
data-slot="breadcrumb-menu-item"
|
|
438
|
+
render={option.disabled ? undefined : (option.render ?? (option.href !== undefined ? <a href={option.href} /> : undefined))}
|
|
228
439
|
className={cn(menuItem, menuRadioItem)}
|
|
229
440
|
>
|
|
230
|
-
{option
|
|
231
|
-
<span className="min-w-0 flex-1 truncate">{option.label}</span>
|
|
232
|
-
{option.detail != null && (
|
|
233
|
-
<span className="text-muted-foreground text-xs font-medium">
|
|
234
|
-
{option.detail}
|
|
235
|
-
</span>
|
|
236
|
-
)}
|
|
441
|
+
<OptionRow option={option} />
|
|
237
442
|
<MenuCheck />
|
|
238
443
|
</MenuPrimitive.RadioItem>
|
|
239
444
|
))}
|
|
@@ -245,9 +450,160 @@ function BreadcrumbMenu({
|
|
|
245
450
|
)
|
|
246
451
|
}
|
|
247
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
|
+
|
|
248
603
|
export {
|
|
249
604
|
Breadcrumb,
|
|
250
605
|
BreadcrumbMenu,
|
|
606
|
+
BreadcrumbSearchMenu,
|
|
251
607
|
BreadcrumbList,
|
|
252
608
|
BreadcrumbItem,
|
|
253
609
|
BreadcrumbLink,
|
|
@@ -255,4 +611,4 @@ export {
|
|
|
255
611
|
BreadcrumbSeparator,
|
|
256
612
|
BreadcrumbEllipsis,
|
|
257
613
|
}
|
|
258
|
-
export type { BreadcrumbMenuOption }
|
|
614
|
+
export type { BreadcrumbMenuOption, BreadcrumbSearchMenuOption }
|