@vendure-io/ui 3.0.0-next.0 → 3.0.0-next.2
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 +467 -53
- package/src/components/atoms/button.tsx +1 -1
- package/src/components/atoms/calendar.tsx +11 -2
- 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/field.tsx +4 -1
- package/src/components/atoms/input-group.tsx +2 -2
- package/src/components/atoms/label-swap.tsx +59 -3
- 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/sonner.tsx +1 -1
- package/src/components/atoms/table.tsx +133 -10
- 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 +26 -1
- package/src/components/molecules/data-table/data-table-types.tsx +66 -2
- package/src/components/molecules/data-table/data-table.tsx +190 -35
- package/src/components/molecules/direction-link.tsx +1 -1
- package/src/components/molecules/format-provider.tsx +12 -2
- package/src/components/molecules/page-header.tsx +1 -1
- package/src/components/molecules/search-trigger.tsx +2 -18
- package/src/components/molecules/secret-value.tsx +6 -3
- package/src/components/molecules/state-views/loading-state.tsx +37 -7
- package/src/components/molecules/state-views/skeleton-parts.tsx +245 -0
- package/src/components/molecules/status-badge.tsx +2 -2
- package/src/components/molecules/timeline.tsx +1 -1
- 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
|
@@ -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,17 @@ 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 { Skeleton } from "./skeleton.tsx"
|
|
36
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.tsx"
|
|
20
37
|
// Relative: `label-swap` is closed in the package exports.
|
|
21
38
|
import { LabelSwap } from "./label-swap.tsx"
|
|
22
39
|
import { menuItem, menuRadioItem, MenuCheck } from "../../lib/menu-item.tsx"
|
|
@@ -133,16 +150,251 @@ function BreadcrumbEllipsis({
|
|
|
133
150
|
)
|
|
134
151
|
}
|
|
135
152
|
|
|
136
|
-
/** One item a `BreadcrumbMenu` can switch to. */
|
|
153
|
+
/** One item a `BreadcrumbMenu` or `BreadcrumbSearchMenu` can switch to. */
|
|
137
154
|
type BreadcrumbMenuOption = {
|
|
138
155
|
value: string
|
|
139
156
|
label: string
|
|
140
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* Before the label, in the crumb and in the menu: a status dot. Keep it
|
|
159
|
+
* decorative (`aria-hidden`) and put its words in `status`.
|
|
160
|
+
*/
|
|
141
161
|
leading?: React.ReactNode
|
|
162
|
+
/**
|
|
163
|
+
* The words for `leading`, such as "Healthy". A screen reader hears them
|
|
164
|
+
* after the label: "Environment: Production, Healthy".
|
|
165
|
+
*/
|
|
166
|
+
status?: string
|
|
142
167
|
/** Muted text after the label in the menu only, such as a type. */
|
|
143
168
|
detail?: React.ReactNode
|
|
144
169
|
/** The row shows but cannot be picked. The arrow keys still stop on it. */
|
|
145
170
|
disabled?: boolean
|
|
171
|
+
/**
|
|
172
|
+
* Renders the row as a link, so it can open in a new tab. It keeps the
|
|
173
|
+
* `menuitemradio` role. An element such as a router `<Link>`; `href` is the
|
|
174
|
+
* short form for a plain `<a>`. The link does the navigation: a plain
|
|
175
|
+
* click follows it and still calls `onValueChange`, so do not navigate
|
|
176
|
+
* there too. A click with a modifier key, or with the middle button, opens
|
|
177
|
+
* the link elsewhere and does not call `onValueChange`. A disabled option
|
|
178
|
+
* renders no link. `BreadcrumbMenu` only: a `BreadcrumbSearchMenu` row is
|
|
179
|
+
* an option of a listbox, which cannot be a link.
|
|
180
|
+
*/
|
|
181
|
+
render?: React.ReactElement
|
|
182
|
+
href?: string
|
|
183
|
+
/** More words the search of a `BreadcrumbSearchMenu` matches, such as a slug. */
|
|
184
|
+
keywords?: readonly string[]
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** One item a `BreadcrumbSearchMenu` can switch to: no link rows. */
|
|
188
|
+
type BreadcrumbSearchMenuOption = Omit<BreadcrumbMenuOption, "render" | "href">
|
|
189
|
+
|
|
190
|
+
/** The props both crumb menus share. */
|
|
191
|
+
type BreadcrumbMenuBaseProps = {
|
|
192
|
+
options: readonly BreadcrumbSearchMenuOption[]
|
|
193
|
+
value: string
|
|
194
|
+
onValueChange?: (value: string) => void
|
|
195
|
+
/** Names the list: it heads the menu and starts the crumb's accessible name. */
|
|
196
|
+
label: string
|
|
197
|
+
/**
|
|
198
|
+
* The crumb's label when no option has `value`, such as "All projects"
|
|
199
|
+
* while none is open, or "Projects unavailable". It swaps like an option.
|
|
200
|
+
* While `pending`, pass the last known name here (from a cache or the
|
|
201
|
+
* previous page) when the options do not have it yet; `undefined` when
|
|
202
|
+
* nothing is known.
|
|
203
|
+
*/
|
|
204
|
+
placeholder?: string
|
|
205
|
+
/**
|
|
206
|
+
* The current item is still loading or being confirmed. Show the name
|
|
207
|
+
* until it is known to be wrong: while pending, the crumb shows the
|
|
208
|
+
* option for `value`, or else `placeholder`, as usual. Only when neither
|
|
209
|
+
* names the item does it show a text skeleton one line tall: it takes no
|
|
210
|
+
* clicks or focus, and a screen reader hears one status, "<label>:
|
|
211
|
+
* Loading…". The first name after the skeleton shows at once, with no
|
|
212
|
+
* swap. When the confirmed name differs from the one shown, the label
|
|
213
|
+
* swaps as usual; when it is the same, nothing moves. Never pass a
|
|
214
|
+
* placeholder word such as "Project" for an unknown name: leave
|
|
215
|
+
* `placeholder` undefined and the skeleton shows.
|
|
216
|
+
*/
|
|
217
|
+
pending?: boolean
|
|
218
|
+
open?: boolean
|
|
219
|
+
onOpenChange?: (open: boolean) => void
|
|
220
|
+
defaultOpen?: boolean
|
|
221
|
+
className?: string
|
|
222
|
+
contentClassName?: string
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The open state, controlled or not, so the crumb knows it too. */
|
|
226
|
+
function useMenuOpen(
|
|
227
|
+
open: boolean | undefined,
|
|
228
|
+
defaultOpen: boolean,
|
|
229
|
+
onOpenChange: ((open: boolean) => void) | undefined
|
|
230
|
+
) {
|
|
231
|
+
const [own, setOwn] = React.useState(defaultOpen)
|
|
232
|
+
const current = open ?? own
|
|
233
|
+
const set = React.useCallback(
|
|
234
|
+
(next: boolean) => {
|
|
235
|
+
setOwn(next)
|
|
236
|
+
onOpenChange?.(next)
|
|
237
|
+
},
|
|
238
|
+
[onOpenChange]
|
|
239
|
+
)
|
|
240
|
+
return [current, set] as const
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The look of a crumb that opens a menu: a 28px ghost button (the `sm`
|
|
245
|
+
* height, the same as `SidebarTrigger` beside it in a top bar) with the
|
|
246
|
+
* current option's `leading` slot, its label and an up-down chevron. It may
|
|
247
|
+
* shrink: the label then ends in an ellipsis and the crumb shows the full
|
|
248
|
+
* label in a tooltip. Give its BreadcrumbItem `min-w-0`, and a `max-w-*` on
|
|
249
|
+
* the crumb where it should stop growing. `--content-inset` is the real
|
|
250
|
+
* start inset of its content (9px padding and the 1px border), so a row
|
|
251
|
+
* under it can line up with the dot.
|
|
252
|
+
*/
|
|
253
|
+
const crumbTriggerClassName =
|
|
254
|
+
"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)]"
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* A crumb menu while its name loads: the crumb's box (28px tall, the same
|
|
258
|
+
* insets and transparent border) with a text skeleton where the name goes.
|
|
259
|
+
* The bar is `0.8lh` of the `text-sm` line, so it follows the line-height
|
|
260
|
+
* token, not a pixel size. It is not a button: nothing opens until the name
|
|
261
|
+
* is known. The skeleton is hidden from screen readers, which hear the
|
|
262
|
+
* status text instead. A `div`, as the skeleton is one.
|
|
263
|
+
*/
|
|
264
|
+
function PendingCrumb({ label, className }: { label: string; className?: string }) {
|
|
265
|
+
return (
|
|
266
|
+
<div
|
|
267
|
+
role="status"
|
|
268
|
+
data-slot="breadcrumb-menu-pending"
|
|
269
|
+
className={cn(
|
|
270
|
+
"inline-flex h-7 min-w-0 shrink items-center rounded-lg border border-transparent ps-2.25 pe-1.75 text-sm",
|
|
271
|
+
className
|
|
272
|
+
)}
|
|
273
|
+
>
|
|
274
|
+
<span className="sr-only">{`${label}: Loading…`}</span>
|
|
275
|
+
<Skeleton aria-hidden className="h-[0.8lh] w-24 min-w-0 shrink" />
|
|
276
|
+
</div>
|
|
277
|
+
)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The inside of the crumb, and its tooltip. The crumb's accessible name is
|
|
282
|
+
* the list label, the option label and then the status, whatever shows
|
|
283
|
+
* first: "Environment: Production, Healthy". With a `status` it is set as
|
|
284
|
+
* `aria-label`, and words inside `leading` are not read. Without one it comes
|
|
285
|
+
* from the content, `leading` first, as before.
|
|
286
|
+
*/
|
|
287
|
+
function useCrumbTrigger({
|
|
288
|
+
options,
|
|
289
|
+
value,
|
|
290
|
+
label,
|
|
291
|
+
placeholder,
|
|
292
|
+
open,
|
|
293
|
+
}: Pick<BreadcrumbMenuBaseProps, "options" | "value" | "label" | "placeholder"> & {
|
|
294
|
+
open: boolean
|
|
295
|
+
}) {
|
|
296
|
+
const found = options.findIndex((option) => option.value === value)
|
|
297
|
+
const fallback = placeholder !== undefined && found === -1
|
|
298
|
+
// The placeholder has its own place before the options, also while it is
|
|
299
|
+
// undefined, so the options arriving after a read swap the label, never
|
|
300
|
+
// rewrite it in place: a last known name passed while pending and then
|
|
301
|
+
// dropped does not shift the options' places.
|
|
302
|
+
const active = fallback ? 0 : Math.max(0, found) + 1
|
|
303
|
+
const current = fallback ? undefined : options[active - 1]
|
|
304
|
+
const labels = [placeholder ?? "", ...options.map((option) => option.label)]
|
|
305
|
+
const currentLabel = labels[active] ?? ""
|
|
306
|
+
// Whether an option or the placeholder names the current item.
|
|
307
|
+
const named = found !== -1 || placeholder !== undefined
|
|
308
|
+
// With a status, the name is set so the status comes after the label.
|
|
309
|
+
// Without one, the name comes from the content, as before.
|
|
310
|
+
const name = current?.status ? `${label}: ${currentLabel}, ${current.status}` : undefined
|
|
311
|
+
// Whether the label is cut now. Read when the pointer or the focus
|
|
312
|
+
// arrives, so a resize or a new label is never stale.
|
|
313
|
+
const [cut, setCut] = React.useState(false)
|
|
314
|
+
const measure = (event: React.SyntheticEvent<HTMLElement>) => {
|
|
315
|
+
const shown = event.currentTarget.querySelector<HTMLElement>(
|
|
316
|
+
'[data-slot="breadcrumb-menu-label"] > [data-swap="in"]'
|
|
317
|
+
)
|
|
318
|
+
setCut(shown !== null && shown.scrollWidth > shown.clientWidth + 0.5)
|
|
319
|
+
}
|
|
320
|
+
const triggerProps = { "aria-label": name, onPointerEnter: measure, onFocus: measure }
|
|
321
|
+
const content = (
|
|
322
|
+
<>
|
|
323
|
+
{current?.leading}
|
|
324
|
+
<span className="sr-only">{label}: </span>
|
|
325
|
+
<LabelSwap
|
|
326
|
+
data-slot="breadcrumb-menu-label"
|
|
327
|
+
timing="button"
|
|
328
|
+
labels={labels}
|
|
329
|
+
active={active}
|
|
330
|
+
truncate
|
|
331
|
+
activeKey={currentLabel}
|
|
332
|
+
className="justify-items-start overflow-x-clip whitespace-nowrap"
|
|
333
|
+
/>
|
|
334
|
+
<ChevronsUpDownIcon
|
|
335
|
+
aria-hidden
|
|
336
|
+
className="size-3.5 opacity-40 group-hover/button:opacity-80 group-aria-expanded/button:opacity-80"
|
|
337
|
+
/>
|
|
338
|
+
</>
|
|
339
|
+
)
|
|
340
|
+
// The tooltip shows only for a cut label, and never over the open menu.
|
|
341
|
+
const tooltip =
|
|
342
|
+
cut && !open ? <TooltipContent side="bottom">{currentLabel}</TooltipContent> : null
|
|
343
|
+
return { triggerProps, content, tooltip, named }
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function stopPropagation(event: React.SyntheticEvent) {
|
|
347
|
+
event.stopPropagation()
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Keeps focus and hover events in the open menu. React passes the events of
|
|
352
|
+
* a portal up through its React parents, so a focus or a hover in the menu
|
|
353
|
+
* would reach a tooltip, or any handler, that wraps the crumb, and open it
|
|
354
|
+
* over the menu.
|
|
355
|
+
*/
|
|
356
|
+
const popupEventProps = {
|
|
357
|
+
onFocus: stopPropagation,
|
|
358
|
+
onBlur: stopPropagation,
|
|
359
|
+
onPointerOver: stopPropagation,
|
|
360
|
+
onPointerOut: stopPropagation,
|
|
361
|
+
onPointerMove: stopPropagation,
|
|
362
|
+
onMouseOver: stopPropagation,
|
|
363
|
+
onMouseOut: stopPropagation,
|
|
364
|
+
onMouseMove: stopPropagation,
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** The leading slot, the label, the status and the detail of a menu row. */
|
|
368
|
+
function OptionRow({ option }: { option: BreadcrumbSearchMenuOption }) {
|
|
369
|
+
return (
|
|
370
|
+
<>
|
|
371
|
+
{option.leading}
|
|
372
|
+
{option.status ? (
|
|
373
|
+
// One text node for the name: a separate sr-only span after the
|
|
374
|
+
// label would read "Production , Healthy".
|
|
375
|
+
<>
|
|
376
|
+
<span aria-hidden className="min-w-0 flex-1 truncate">
|
|
377
|
+
{option.label}
|
|
378
|
+
</span>
|
|
379
|
+
<span className="sr-only">{`${option.label}, ${option.status}`}</span>
|
|
380
|
+
</>
|
|
381
|
+
) : (
|
|
382
|
+
<span className="min-w-0 flex-1 truncate">{option.label}</span>
|
|
383
|
+
)}
|
|
384
|
+
{option.detail != null && (
|
|
385
|
+
// At the end of the row, before the check, in both menus.
|
|
386
|
+
<span className="text-muted-foreground ms-auto shrink-0 ps-3 text-xs font-medium">
|
|
387
|
+
{option.detail}
|
|
388
|
+
</span>
|
|
389
|
+
)}
|
|
390
|
+
</>
|
|
391
|
+
)
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function isNewTabClick(event: Event | undefined) {
|
|
395
|
+
if (!event || !("button" in event)) return false
|
|
396
|
+
const pointer = event as MouseEvent
|
|
397
|
+
return pointer.metaKey || pointer.ctrlKey || pointer.shiftKey || pointer.altKey || pointer.button === 1
|
|
146
398
|
}
|
|
147
399
|
|
|
148
400
|
/**
|
|
@@ -156,67 +408,76 @@ type BreadcrumbMenuOption = {
|
|
|
156
408
|
* separator and an "Add environment" item. The options and the switch stay
|
|
157
409
|
* with the consumer.
|
|
158
410
|
*
|
|
159
|
-
* `label` names the list: it heads the menu and
|
|
160
|
-
* accessible name ("Environment: Production").
|
|
411
|
+
* `label` names the list: it heads the menu and starts the crumb's
|
|
412
|
+
* accessible name ("Environment: Production, Healthy").
|
|
413
|
+
*
|
|
414
|
+
* A long label ends in an ellipsis when the crumb has no room, and a tooltip
|
|
415
|
+
* shows it in full. An option with `href` or `render` is a link; the current
|
|
416
|
+
* row stays a checked `menuitemradio`. `open` and `onOpenChange` control the
|
|
417
|
+
* menu. For a long list with a search field, use `BreadcrumbSearchMenu`.
|
|
418
|
+
*
|
|
419
|
+
* While the current item loads, pass `pending`, and the last known name as an
|
|
420
|
+
* option or `placeholder` if there is one: the crumb shows that name, or a
|
|
421
|
+
* text skeleton when there is none.
|
|
161
422
|
*/
|
|
162
423
|
function BreadcrumbMenu({
|
|
163
424
|
options,
|
|
164
425
|
value,
|
|
165
426
|
onValueChange,
|
|
166
427
|
label,
|
|
428
|
+
placeholder,
|
|
429
|
+
pending = false,
|
|
430
|
+
open: openProp,
|
|
431
|
+
onOpenChange,
|
|
432
|
+
defaultOpen = false,
|
|
167
433
|
children,
|
|
168
434
|
className,
|
|
169
435
|
contentClassName,
|
|
170
|
-
}: {
|
|
436
|
+
}: Omit<BreadcrumbMenuBaseProps, "options"> & {
|
|
171
437
|
options: readonly BreadcrumbMenuOption[]
|
|
172
|
-
value: string
|
|
173
|
-
onValueChange?: (value: string) => void
|
|
174
|
-
label: string
|
|
175
438
|
children?: React.ReactNode
|
|
176
|
-
className?: string
|
|
177
|
-
contentClassName?: string
|
|
178
439
|
}) {
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
440
|
+
const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
|
|
441
|
+
const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
|
|
442
|
+
// Without a name, a skeleton. The trigger mounts with the first name, so
|
|
443
|
+
// it shows without a swap.
|
|
444
|
+
if (pending && !crumb.named) return <PendingCrumb label={label} className={className} />
|
|
184
445
|
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>
|
|
446
|
+
<DropdownMenu open={open} onOpenChange={setOpen}>
|
|
447
|
+
<Tooltip>
|
|
448
|
+
<TooltipTrigger
|
|
449
|
+
render={
|
|
450
|
+
<DropdownMenuTrigger
|
|
451
|
+
data-slot="breadcrumb-menu"
|
|
452
|
+
{...crumb.triggerProps}
|
|
453
|
+
render={
|
|
454
|
+
<Button
|
|
455
|
+
variant="ghost"
|
|
456
|
+
size="sm"
|
|
457
|
+
className={cn(crumbTriggerClassName, className)}
|
|
458
|
+
/>
|
|
459
|
+
}
|
|
460
|
+
/>
|
|
461
|
+
}
|
|
462
|
+
>
|
|
463
|
+
{crumb.content}
|
|
464
|
+
</TooltipTrigger>
|
|
465
|
+
{crumb.tooltip}
|
|
466
|
+
</Tooltip>
|
|
212
467
|
<DropdownMenuContent
|
|
213
|
-
|
|
468
|
+
{...popupEventProps}
|
|
469
|
+
className={cn("w-max min-w-72 max-w-90", contentClassName)}
|
|
214
470
|
>
|
|
215
471
|
<DropdownMenuGroup>
|
|
216
472
|
<DropdownMenuLabel>{label}</DropdownMenuLabel>
|
|
217
473
|
<MenuPrimitive.RadioGroup
|
|
218
474
|
value={value}
|
|
219
|
-
onValueChange={(next: string) =>
|
|
475
|
+
onValueChange={(next: string, details) => {
|
|
476
|
+
// A modifier or middle click opens a link row elsewhere: the
|
|
477
|
+
// current item stays.
|
|
478
|
+
if (isNewTabClick(details.event)) return
|
|
479
|
+
onValueChange?.(next)
|
|
480
|
+
}}
|
|
220
481
|
>
|
|
221
482
|
{options.map((option) => (
|
|
222
483
|
<MenuPrimitive.RadioItem
|
|
@@ -225,15 +486,10 @@ function BreadcrumbMenu({
|
|
|
225
486
|
disabled={option.disabled}
|
|
226
487
|
closeOnClick={false}
|
|
227
488
|
data-slot="breadcrumb-menu-item"
|
|
489
|
+
render={option.disabled ? undefined : (option.render ?? (option.href !== undefined ? <a href={option.href} /> : undefined))}
|
|
228
490
|
className={cn(menuItem, menuRadioItem)}
|
|
229
491
|
>
|
|
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
|
-
)}
|
|
492
|
+
<OptionRow option={option} />
|
|
237
493
|
<MenuCheck />
|
|
238
494
|
</MenuPrimitive.RadioItem>
|
|
239
495
|
))}
|
|
@@ -245,9 +501,167 @@ function BreadcrumbMenu({
|
|
|
245
501
|
)
|
|
246
502
|
}
|
|
247
503
|
|
|
504
|
+
/**
|
|
505
|
+
* The search of a `BreadcrumbSearchMenu`: the option's label and keywords,
|
|
506
|
+
* never its value, which is often an id.
|
|
507
|
+
*/
|
|
508
|
+
function searchFilter(_value: string, search: string, keywords?: string[]) {
|
|
509
|
+
return defaultFilter(keywords?.join(" ") ?? "", search)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* A `BreadcrumbMenu` with a search field, for a list that can grow long, such
|
|
514
|
+
* as the projects of an organization. The crumb is the same, and so is its
|
|
515
|
+
* label swap. The popup is a `Command`: a "Find …" field at the top, the
|
|
516
|
+
* options with a check on the current one, then `children` in a footer that
|
|
517
|
+
* stays in view while the list scrolls, such as "All projects" and "Create
|
|
518
|
+
* project". The search matches the option labels and `keywords`.
|
|
519
|
+
*
|
|
520
|
+
* Picking an option calls `onValueChange` and closes the popup, so the crumb's
|
|
521
|
+
* label is seen swapping. `loading` shows a loading row in place of the
|
|
522
|
+
* options. `error` shows its text as a row that cannot be picked and, with
|
|
523
|
+
* `onRetry`, a Retry row. A search that matches nothing shows `emptyText`.
|
|
524
|
+
* Footer items are `CommandItem`s with `forceMount`, so a search does not
|
|
525
|
+
* hide them, and close the popup themselves through `onOpenChange`. *
|
|
526
|
+
* `loading` is about the list in the open popup. `pending` is about the
|
|
527
|
+
* crumb: while the current item loads, it shows the last known name, or a
|
|
528
|
+
* text skeleton in place of a placeholder word when no name is known.
|
|
529
|
+
*/
|
|
530
|
+
function BreadcrumbSearchMenu({
|
|
531
|
+
options,
|
|
532
|
+
value,
|
|
533
|
+
onValueChange,
|
|
534
|
+
label,
|
|
535
|
+
placeholder,
|
|
536
|
+
pending = false,
|
|
537
|
+
open: openProp,
|
|
538
|
+
onOpenChange,
|
|
539
|
+
defaultOpen = false,
|
|
540
|
+
searchPlaceholder = `Find ${label.toLowerCase()}…`,
|
|
541
|
+
emptyText = "No results.",
|
|
542
|
+
loading = false,
|
|
543
|
+
error,
|
|
544
|
+
onRetry,
|
|
545
|
+
children,
|
|
546
|
+
className,
|
|
547
|
+
contentClassName,
|
|
548
|
+
}: BreadcrumbMenuBaseProps & {
|
|
549
|
+
/** The search field's placeholder. Default: "Find <label>…". */
|
|
550
|
+
searchPlaceholder?: string
|
|
551
|
+
/** Shows when the search matches no option. */
|
|
552
|
+
emptyText?: React.ReactNode
|
|
553
|
+
/** The options are on their way: a loading row shows in their place. */
|
|
554
|
+
loading?: boolean
|
|
555
|
+
/** The options could not be read: this text shows as a row. */
|
|
556
|
+
error?: React.ReactNode
|
|
557
|
+
/** With `error`, a Retry row calls it. */
|
|
558
|
+
onRetry?: () => void
|
|
559
|
+
/** Footer items: `CommandItem`s with `forceMount`. */
|
|
560
|
+
children?: React.ReactNode
|
|
561
|
+
}) {
|
|
562
|
+
const [open, setOpen] = useMenuOpen(openProp, defaultOpen, onOpenChange)
|
|
563
|
+
const crumb = useCrumbTrigger({ options, value, label, placeholder, open })
|
|
564
|
+
const failed = error != null && error !== false
|
|
565
|
+
// Without a name, a skeleton. The trigger mounts with the first name, so
|
|
566
|
+
// it shows without a swap.
|
|
567
|
+
if (pending && !crumb.named) return <PendingCrumb label={label} className={className} />
|
|
568
|
+
return (
|
|
569
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
570
|
+
<Tooltip>
|
|
571
|
+
<TooltipTrigger
|
|
572
|
+
render={
|
|
573
|
+
<PopoverTrigger
|
|
574
|
+
data-slot="breadcrumb-menu"
|
|
575
|
+
{...crumb.triggerProps}
|
|
576
|
+
render={
|
|
577
|
+
<Button
|
|
578
|
+
variant="ghost"
|
|
579
|
+
size="sm"
|
|
580
|
+
className={cn(crumbTriggerClassName, className)}
|
|
581
|
+
/>
|
|
582
|
+
}
|
|
583
|
+
/>
|
|
584
|
+
}
|
|
585
|
+
>
|
|
586
|
+
{crumb.content}
|
|
587
|
+
</TooltipTrigger>
|
|
588
|
+
{crumb.tooltip}
|
|
589
|
+
</Tooltip>
|
|
590
|
+
<PopoverContent
|
|
591
|
+
{...popupEventProps}
|
|
592
|
+
data-slot="breadcrumb-search-menu-content"
|
|
593
|
+
aria-label={label}
|
|
594
|
+
className={cn("w-72 max-w-90 gap-0 overflow-hidden p-0", contentClassName)}
|
|
595
|
+
>
|
|
596
|
+
{/* A new Command once the error clears: cmdk keeps the Retry row
|
|
597
|
+
selected after it unmounts, and the field then points at a row
|
|
598
|
+
that is gone (aria-activedescendant). */}
|
|
599
|
+
<Command key={failed ? "failed" : "read"} label={label} filter={searchFilter}>
|
|
600
|
+
<CommandInput autoFocus placeholder={searchPlaceholder} />
|
|
601
|
+
{/* Outside the list: a listbox takes only options and groups. */}
|
|
602
|
+
{loading && (
|
|
603
|
+
<div
|
|
604
|
+
role="status"
|
|
605
|
+
data-slot="breadcrumb-search-menu-loading"
|
|
606
|
+
className="text-muted-foreground flex min-h-8.5 items-center gap-2.5 px-4 pt-2.5 pb-1 text-sm"
|
|
607
|
+
>
|
|
608
|
+
<Loader2Icon aria-hidden className="size-3.75 animate-spin motion-reduce:animate-none" />
|
|
609
|
+
Loading…
|
|
610
|
+
</div>
|
|
611
|
+
)}
|
|
612
|
+
<CommandList>
|
|
613
|
+
{!loading && !failed && <CommandEmpty>{emptyText}</CommandEmpty>}
|
|
614
|
+
{failed && !loading && (
|
|
615
|
+
<CommandGroup forceMount heading={error}>
|
|
616
|
+
{onRetry && (
|
|
617
|
+
<CommandItem forceMount value="__retry" onSelect={onRetry}>
|
|
618
|
+
<RefreshCwIcon />
|
|
619
|
+
<span className="min-w-0 truncate">Retry</span>
|
|
620
|
+
</CommandItem>
|
|
621
|
+
)}
|
|
622
|
+
</CommandGroup>
|
|
623
|
+
)}
|
|
624
|
+
{!loading && options.length > 0 && (
|
|
625
|
+
<CommandGroup>
|
|
626
|
+
{options.map((option) => (
|
|
627
|
+
<CommandItem
|
|
628
|
+
key={option.value}
|
|
629
|
+
value={option.value}
|
|
630
|
+
keywords={[option.label, ...(option.keywords ?? [])]}
|
|
631
|
+
disabled={option.disabled}
|
|
632
|
+
data-checked={option.value === value ? true : undefined}
|
|
633
|
+
data-slot="breadcrumb-menu-item"
|
|
634
|
+
onSelect={() => {
|
|
635
|
+
setOpen(false)
|
|
636
|
+
if (option.value !== value) onValueChange?.(option.value)
|
|
637
|
+
}}
|
|
638
|
+
>
|
|
639
|
+
<OptionRow option={option} />
|
|
640
|
+
</CommandItem>
|
|
641
|
+
))}
|
|
642
|
+
</CommandGroup>
|
|
643
|
+
)}
|
|
644
|
+
{children != null && (
|
|
645
|
+
// Sticky inside the scrolling list, so a long list keeps it in view.
|
|
646
|
+
<CommandGroup
|
|
647
|
+
forceMount
|
|
648
|
+
data-slot="breadcrumb-search-menu-footer"
|
|
649
|
+
className="bg-popover border-border sticky bottom-0 border-t"
|
|
650
|
+
>
|
|
651
|
+
{children}
|
|
652
|
+
</CommandGroup>
|
|
653
|
+
)}
|
|
654
|
+
</CommandList>
|
|
655
|
+
</Command>
|
|
656
|
+
</PopoverContent>
|
|
657
|
+
</Popover>
|
|
658
|
+
)
|
|
659
|
+
}
|
|
660
|
+
|
|
248
661
|
export {
|
|
249
662
|
Breadcrumb,
|
|
250
663
|
BreadcrumbMenu,
|
|
664
|
+
BreadcrumbSearchMenu,
|
|
251
665
|
BreadcrumbList,
|
|
252
666
|
BreadcrumbItem,
|
|
253
667
|
BreadcrumbLink,
|
|
@@ -255,4 +669,4 @@ export {
|
|
|
255
669
|
BreadcrumbSeparator,
|
|
256
670
|
BreadcrumbEllipsis,
|
|
257
671
|
}
|
|
258
|
-
export type { BreadcrumbMenuOption }
|
|
672
|
+
export type { BreadcrumbMenuOption, BreadcrumbSearchMenuOption }
|
|
@@ -10,7 +10,7 @@ import { contentInsetPull } from "@vendure-io/ui/lib/content-inset"
|
|
|
10
10
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
11
11
|
import { outlineEdge, outlineEdgeHover } from "@vendure-io/ui/lib/outline-edge"
|
|
12
12
|
|
|
13
|
-
// The v3 look: 34px default and 28px sm, the xl radius,
|
|
13
|
+
// The v3 look: 34px default and 28px sm, the xl radius, 14px medium text.
|
|
14
14
|
// Every size keeps its side padding with or without a `data-icon` icon;
|
|
15
15
|
// default and sm have a 7px gap. Press feedback is a 0.97 scale on :active,
|
|
16
16
|
// on ease-press in 150ms. Base UI's Button never emits data-pressed, so the
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
12
12
|
import { Button, buttonVariants } from "@vendure-io/ui/components/atoms/button"
|
|
13
|
+
import { useFormatSettings } from "@vendure-io/ui/components/molecules/format-provider"
|
|
13
14
|
import { ChevronLeftIcon, ChevronRightIcon, ChevronDownIcon } from "lucide-react"
|
|
14
15
|
|
|
15
16
|
function Calendar({
|
|
@@ -26,6 +27,10 @@ function Calendar({
|
|
|
26
27
|
buttonVariant?: React.ComponentProps<typeof Button>["variant"]
|
|
27
28
|
}) {
|
|
28
29
|
const defaultClassNames = getDefaultClassNames()
|
|
30
|
+
// The pickers render this Calendar, so the language set on FormatProvider
|
|
31
|
+
// reaches their popups without each caller passing `locale`.
|
|
32
|
+
const { calendarLocale } = useFormatSettings()
|
|
33
|
+
locale ??= calendarLocale
|
|
29
34
|
|
|
30
35
|
return (
|
|
31
36
|
<DayPicker
|
|
@@ -39,8 +44,12 @@ function Calendar({
|
|
|
39
44
|
captionLayout={captionLayout}
|
|
40
45
|
locale={locale}
|
|
41
46
|
formatters={{
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
// Through DayPicker's date library, so the month names follow `locale`
|
|
48
|
+
// (US English without one) like the caption, not the browser language.
|
|
49
|
+
formatMonthDropdown: (date, dateLib) =>
|
|
50
|
+
dateLib
|
|
51
|
+
? dateLib.format(date, "LLL")
|
|
52
|
+
: date.toLocaleString(locale?.code, { month: "short" }),
|
|
44
53
|
...formatters,
|
|
45
54
|
}}
|
|
46
55
|
classNames={{
|