@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
|
@@ -78,14 +78,34 @@ function DialogCloseButton({ className }: { className?: string }) {
|
|
|
78
78
|
)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// The width per size, as whole class strings so Tailwind finds them in this
|
|
82
|
+
// source. They sit before `className` in `cn`, so a consumer's `sm:max-w-*`
|
|
83
|
+
// still replaces them. Below the breakpoint a dialog is the viewport less 1rem
|
|
84
|
+
// on each side: `xl` waits for `lg`, where 800px fits with that margin.
|
|
85
|
+
const dialogSizes = {
|
|
86
|
+
default: "sm:max-w-110",
|
|
87
|
+
lg: "sm:max-w-140",
|
|
88
|
+
xl: "lg:max-w-200",
|
|
89
|
+
full: "",
|
|
90
|
+
} as const
|
|
91
|
+
|
|
81
92
|
function DialogContent({
|
|
82
93
|
className,
|
|
83
94
|
children,
|
|
95
|
+
size = "default",
|
|
84
96
|
showCloseButton,
|
|
85
97
|
overlayClassName,
|
|
86
98
|
style,
|
|
87
99
|
...props
|
|
88
100
|
}: DialogPrimitive.Popup.Props & {
|
|
101
|
+
/**
|
|
102
|
+
* The width, by the dialog's job. `default` (440px): a confirmation or a
|
|
103
|
+
* form of a few fields. `lg` (560px): a form with longer fields or a short
|
|
104
|
+
* list. `xl` (800px): a wide form, a table or a tree. `full`: the viewport
|
|
105
|
+
* less 1rem on each side, for a picker or a preview. Every size shrinks to
|
|
106
|
+
* the viewport less that margin on a small screen.
|
|
107
|
+
*/
|
|
108
|
+
size?: keyof typeof dialogSizes
|
|
89
109
|
/**
|
|
90
110
|
* Shows a ✕ in the top-right corner. Left out, the dialog shows it only
|
|
91
111
|
* when it holds no `DialogFooter` and no `DialogClose`: a dialog with a
|
|
@@ -115,8 +135,10 @@ function DialogContent({
|
|
|
115
135
|
<DialogPrimitive.Popup
|
|
116
136
|
dir={dir}
|
|
117
137
|
data-slot="dialog-content"
|
|
138
|
+
data-size={size}
|
|
118
139
|
className={cn(
|
|
119
|
-
"group/dialog-content bg-overlay shadow-overlay fixed top-1/2 left-1/2 z-50 grid grid-cols-[minmax(0,1fr)] max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-5 overflow-y-auto overscroll-contain rounded-2xl [--dialog-padding:--spacing(5)] p-(--dialog-padding) [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] text-sm transition-[opacity,scale,translate] duration-[var(--transition-duration-normal),var(--transition-duration-dialog-enter),var(--transition-duration-dialog-enter)] ease-out data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-[var(--transition-duration-quick),var(--transition-duration-dialog-exit),var(--transition-duration-dialog-exit)] data-ending-style:ease-[var(--ease-soft),var(--ease-out),var(--ease-out)] motion-safe:data-starting-style:scale-96 motion-safe:data-starting-style:translate-y-[calc(-50%+4px)] motion-safe:data-ending-style:scale-98 outline-none
|
|
140
|
+
"group/dialog-content bg-overlay shadow-overlay fixed top-1/2 left-1/2 z-50 grid grid-cols-[minmax(0,1fr)] max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-5 overflow-y-auto overscroll-contain rounded-2xl [--dialog-padding:--spacing(5)] p-(--dialog-padding) [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] text-sm transition-[opacity,scale,translate] duration-[var(--transition-duration-normal),var(--transition-duration-dialog-enter),var(--transition-duration-dialog-enter)] ease-out data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-[var(--transition-duration-quick),var(--transition-duration-dialog-exit),var(--transition-duration-dialog-exit)] data-ending-style:ease-[var(--ease-soft),var(--ease-out),var(--ease-out)] motion-safe:data-starting-style:scale-96 motion-safe:data-starting-style:translate-y-[calc(-50%+4px)] motion-safe:data-ending-style:scale-98 outline-none",
|
|
141
|
+
dialogSizes[size],
|
|
120
142
|
className
|
|
121
143
|
)}
|
|
122
144
|
style={dialogPaddingStyle(className, style)}
|
|
@@ -63,7 +63,7 @@ function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
|
63
63
|
return (
|
|
64
64
|
<div
|
|
65
65
|
data-slot="empty-title"
|
|
66
|
-
className={cn("text-style-section-title", className)}
|
|
66
|
+
className={cn("text-style-section-title text-foreground", className)}
|
|
67
67
|
{...props}
|
|
68
68
|
/>
|
|
69
69
|
)
|
|
@@ -78,10 +78,10 @@ const inputGroupButtonVariants = cva(
|
|
|
78
78
|
{
|
|
79
79
|
variants: {
|
|
80
80
|
size: {
|
|
81
|
-
xs: "h-6 gap-1 rounded-
|
|
81
|
+
xs: "h-6 gap-1 rounded-lg px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
|
|
82
82
|
sm: "h-7 gap-1.5 px-2.5",
|
|
83
83
|
"icon-xs":
|
|
84
|
-
"size-6 rounded-
|
|
84
|
+
"size-6 rounded-lg p-0 has-[>svg]:p-0",
|
|
85
85
|
"icon-sm": "size-7 p-0 has-[>svg]:p-0",
|
|
86
86
|
},
|
|
87
87
|
},
|
|
@@ -24,6 +24,18 @@ type LabelSwapProps = Omit<React.ComponentProps<"span">, "children"> & {
|
|
|
24
24
|
timing: keyof typeof TIMINGS
|
|
25
25
|
/** Classes for each label, after the shared ones. */
|
|
26
26
|
labelClassName?: string
|
|
27
|
+
/**
|
|
28
|
+
* The swap may shrink below the active label's width, and the label then
|
|
29
|
+
* ends in an ellipsis. The swap still eases to the label's full width; its
|
|
30
|
+
* container (a flex row with `min-w-0`) decides how much of it shows.
|
|
31
|
+
*/
|
|
32
|
+
truncate?: boolean
|
|
33
|
+
/**
|
|
34
|
+
* Changes when the active label's text changes at the same index, such as
|
|
35
|
+
* a placeholder that becomes the first loaded option. The swap then
|
|
36
|
+
* measures again: a cut label's box does not grow by itself.
|
|
37
|
+
*/
|
|
38
|
+
activeKey?: string
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
/**
|
|
@@ -42,16 +54,34 @@ function LabelSwap({
|
|
|
42
54
|
active,
|
|
43
55
|
timing,
|
|
44
56
|
labelClassName,
|
|
57
|
+
truncate = false,
|
|
58
|
+
activeKey,
|
|
45
59
|
className,
|
|
46
60
|
style,
|
|
47
61
|
...props
|
|
48
62
|
}: LabelSwapProps) {
|
|
49
|
-
const { refs, width, height } = useActiveLabelSize(active)
|
|
63
|
+
const { refs, width, height } = useActiveLabelSize(active, { natural: truncate, key: activeKey })
|
|
64
|
+
// While the width eases, a growing label is clipped, as without
|
|
65
|
+
// `truncate`; the ellipsis shows only at rest, so it does not flash.
|
|
66
|
+
const [resizing, setResizing] = React.useState(false)
|
|
67
|
+
const onResize = (running: boolean) => (event: React.TransitionEvent<HTMLSpanElement>) => {
|
|
68
|
+
if (event.target === event.currentTarget && event.propertyName === "width") setResizing(running)
|
|
69
|
+
}
|
|
70
|
+
const resizeHandlers = truncate
|
|
71
|
+
? {
|
|
72
|
+
onTransitionRun: onResize(true),
|
|
73
|
+
onTransitionEnd: onResize(false),
|
|
74
|
+
onTransitionCancel: onResize(false),
|
|
75
|
+
}
|
|
76
|
+
: undefined
|
|
50
77
|
return (
|
|
51
78
|
<span
|
|
79
|
+
data-resizing={resizing ? "" : undefined}
|
|
80
|
+
{...resizeHandlers}
|
|
52
81
|
className={cn(
|
|
53
82
|
"grid grid-cols-[100%] justify-items-center motion-safe:transition-[width,height] motion-safe:duration-(--label-swap-resize) motion-safe:ease-drawer",
|
|
54
83
|
TIMINGS[timing],
|
|
84
|
+
truncate && "min-w-0 shrink",
|
|
55
85
|
className
|
|
56
86
|
)}
|
|
57
87
|
style={width === undefined ? style : { ...style, width, height }}
|
|
@@ -68,6 +98,7 @@ function LabelSwap({
|
|
|
68
98
|
aria-hidden={index === active ? undefined : true}
|
|
69
99
|
className={cn(
|
|
70
100
|
"col-start-1 row-start-1 [transition:opacity_var(--label-swap-fade)_var(--ease-soft),translate_var(--label-swap-move)_var(--ease-out),filter_var(--label-swap-fade)_var(--ease-soft)] data-[swap=after]:opacity-0 data-[swap=before]:opacity-0 motion-safe:data-[swap=after]:translate-y-(--label-swap-shift) motion-safe:data-[swap=before]:-translate-y-(--label-swap-shift) motion-safe:data-[swap=after]:blur-[2px] motion-safe:data-[swap=before]:blur-[2px]",
|
|
101
|
+
truncate && "max-w-full truncate in-data-resizing:text-clip",
|
|
71
102
|
labelClassName
|
|
72
103
|
)}
|
|
73
104
|
>
|
|
@@ -28,6 +28,9 @@ function PopoverTrigger({ ...props }: PopoverPrimitive.Trigger.Props) {
|
|
|
28
28
|
* it up with its left edge. The side is picked each time it opens. A popover
|
|
29
29
|
* that opens to the left or right of its trigger keeps "start". An explicit
|
|
30
30
|
* `align` always wins. Do not set `align` unless there is a reason.
|
|
31
|
+
*
|
|
32
|
+
* `anchor` positions a popover that has no trigger against another element,
|
|
33
|
+
* e.g. an editor opened from an applied-filter chip.
|
|
31
34
|
*/
|
|
32
35
|
function PopoverContent({
|
|
33
36
|
className,
|
|
@@ -36,11 +39,12 @@ function PopoverContent({
|
|
|
36
39
|
alignOffset = 0,
|
|
37
40
|
side = "bottom",
|
|
38
41
|
sideOffset = 6,
|
|
42
|
+
anchor,
|
|
39
43
|
...props
|
|
40
44
|
}: PopoverPrimitive.Popup.Props &
|
|
41
45
|
Pick<
|
|
42
46
|
PopoverPrimitive.Positioner.Props,
|
|
43
|
-
"align" | "alignOffset" | "side" | "sideOffset"
|
|
47
|
+
"align" | "alignOffset" | "side" | "sideOffset" | "anchor"
|
|
44
48
|
>) {
|
|
45
49
|
const dir = usePopupDir()
|
|
46
50
|
const { popupRef, align: positionAlign } = usePopupAlign(align, side, ref)
|
|
@@ -52,6 +56,7 @@ function PopoverContent({
|
|
|
52
56
|
alignOffset={alignOffset}
|
|
53
57
|
side={side}
|
|
54
58
|
sideOffset={sideOffset}
|
|
59
|
+
anchor={anchor}
|
|
55
60
|
className="isolate z-50"
|
|
56
61
|
>
|
|
57
62
|
<PopoverPrimitive.Popup
|
|
@@ -62,14 +62,29 @@ function SheetCloseButton({ className }: { className?: string }) {
|
|
|
62
62
|
)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// The width of a left or right sheet per size, as whole class strings so
|
|
66
|
+
// Tailwind finds them in this source. A top or bottom sheet spans the viewport
|
|
67
|
+
// and ignores the size. Below `sm` every side sheet is 3/4 of the viewport.
|
|
68
|
+
const sheetSizes = {
|
|
69
|
+
default: "data-[side=left]:sm:max-w-lg data-[side=right]:sm:max-w-lg",
|
|
70
|
+
xl: "data-[side=left]:sm:max-w-200 data-[side=right]:sm:max-w-200",
|
|
71
|
+
} as const
|
|
72
|
+
|
|
65
73
|
function SheetContent({
|
|
66
74
|
className,
|
|
67
75
|
children,
|
|
68
76
|
side = "right",
|
|
77
|
+
size = "default",
|
|
69
78
|
showCloseButton = true,
|
|
70
79
|
...props
|
|
71
80
|
}: SheetPrimitive.Popup.Props & {
|
|
72
81
|
side?: "top" | "right" | "bottom" | "left"
|
|
82
|
+
/**
|
|
83
|
+
* The width of a left or right sheet. `default` (512px): a short form or a
|
|
84
|
+
* settings list. `xl` (800px): a table or a wide form. Both stay at 3/4 of
|
|
85
|
+
* the viewport below 640px. Top and bottom sheets ignore it.
|
|
86
|
+
*/
|
|
87
|
+
size?: keyof typeof sheetSizes
|
|
73
88
|
showCloseButton?: boolean
|
|
74
89
|
}) {
|
|
75
90
|
const dir = usePopupDir()
|
|
@@ -81,8 +96,10 @@ function SheetContent({
|
|
|
81
96
|
dir={dir}
|
|
82
97
|
data-slot="sheet-content"
|
|
83
98
|
data-side={side}
|
|
99
|
+
data-size={size}
|
|
84
100
|
className={cn(
|
|
85
|
-
"group/sheet-content bg-overlay fixed z-50 flex flex-col gap-4 overflow-y-auto overscroll-contain [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] bg-clip-padding text-sm shadow-overlay transition-[opacity,translate] duration-normal ease-drawer data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-fast motion-safe:data-[side=right]:data-starting-style:translate-x-10 motion-safe:data-[side=right]:data-ending-style:translate-x-10 motion-safe:data-[side=left]:data-starting-style:-translate-x-10 motion-safe:data-[side=left]:data-ending-style:-translate-x-10 motion-safe:data-[side=top]:data-starting-style:-translate-y-10 motion-safe:data-[side=top]:data-ending-style:-translate-y-10 motion-safe:data-[side=bottom]:data-starting-style:translate-y-10 motion-safe:data-[side=bottom]:data-ending-style:translate-y-10 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:max-h-dvh data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:max-h-dvh
|
|
101
|
+
"group/sheet-content bg-overlay fixed z-50 flex flex-col gap-4 overflow-y-auto overscroll-contain [scroll-padding-block:calc(var(--pinned-header-height,0px)+--spacing(1))_calc(var(--pinned-footer-height,0px)+--spacing(1))] bg-clip-padding text-sm shadow-overlay transition-[opacity,translate] duration-normal ease-drawer data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-fast motion-safe:data-[side=right]:data-starting-style:translate-x-10 motion-safe:data-[side=right]:data-ending-style:translate-x-10 motion-safe:data-[side=left]:data-starting-style:-translate-x-10 motion-safe:data-[side=left]:data-ending-style:-translate-x-10 motion-safe:data-[side=top]:data-starting-style:-translate-y-10 motion-safe:data-[side=top]:data-ending-style:-translate-y-10 motion-safe:data-[side=bottom]:data-starting-style:translate-y-10 motion-safe:data-[side=bottom]:data-ending-style:translate-y-10 data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:max-h-dvh data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:max-h-dvh",
|
|
102
|
+
sheetSizes[size],
|
|
86
103
|
className
|
|
87
104
|
)}
|
|
88
105
|
{...props}
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
TooltipContent,
|
|
24
24
|
TooltipTrigger,
|
|
25
25
|
} from "@vendure-io/ui/components/atoms/tooltip"
|
|
26
|
-
import { ChevronLeftIcon, PanelLeftIcon } from "lucide-react"
|
|
26
|
+
import { ChevronLeftIcon, ChevronsUpDownIcon, PanelLeftIcon } from "lucide-react"
|
|
27
27
|
|
|
28
28
|
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
|
29
29
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
|
@@ -705,6 +705,76 @@ function SidebarMenuButton({
|
|
|
705
705
|
)
|
|
706
706
|
}
|
|
707
707
|
|
|
708
|
+
// The account or user switch at the top or bottom of the sidebar: media (an
|
|
709
|
+
// Avatar), a SidebarIdentityText (a title over a caption) and an up/down
|
|
710
|
+
// chevron. Render it as the trigger of the menu it opens:
|
|
711
|
+
// <DropdownMenuTrigger render={<SidebarIdentityButton />}>. It takes the fill
|
|
712
|
+
// while that menu is open: a Base UI trigger marks that with data-popup-open,
|
|
713
|
+
// not data-open. The muted avatar fill is translucent and darkens on that fill,
|
|
714
|
+
// so default initials take the sidebar text colour to keep their contrast. A
|
|
715
|
+
// fallback with its own colour (no text-muted-foreground) keeps it. In the
|
|
716
|
+
// icon rail the text and the chevron fade like a label and the media stays;
|
|
717
|
+
// both stay mounted, so the button keeps its accessible name in the rail.
|
|
718
|
+
function SidebarIdentityButton({
|
|
719
|
+
className,
|
|
720
|
+
children,
|
|
721
|
+
...props
|
|
722
|
+
}: Omit<React.ComponentProps<typeof SidebarMenuButton>, "size">) {
|
|
723
|
+
return (
|
|
724
|
+
<SidebarMenuButton
|
|
725
|
+
size="lg"
|
|
726
|
+
className={cn(
|
|
727
|
+
"data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground [&_[data-slot=avatar-fallback].text-muted-foreground]:text-sidebar-foreground",
|
|
728
|
+
className
|
|
729
|
+
)}
|
|
730
|
+
{...props}
|
|
731
|
+
>
|
|
732
|
+
{children}
|
|
733
|
+
<ChevronsUpDownIcon
|
|
734
|
+
data-slot="sidebar-identity-chevron"
|
|
735
|
+
aria-hidden="true"
|
|
736
|
+
className="text-muted-foreground ms-auto transition-opacity duration-moderate group-data-[collapsible=icon]:opacity-0 group-data-[collapsible=icon]:duration-fast"
|
|
737
|
+
/>
|
|
738
|
+
</SidebarMenuButton>
|
|
739
|
+
)
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// The two lines of a SidebarIdentityButton. Also fits the identity row at the
|
|
743
|
+
// top of the menu it opens. The text fades in the icon rail even when the
|
|
744
|
+
// title holds an icon, which the generic label fade of SidebarMenuButton skips.
|
|
745
|
+
function SidebarIdentityText({
|
|
746
|
+
title,
|
|
747
|
+
caption,
|
|
748
|
+
className,
|
|
749
|
+
...props
|
|
750
|
+
}: Omit<React.ComponentProps<"span">, "title" | "children"> & {
|
|
751
|
+
title: React.ReactNode
|
|
752
|
+
caption?: React.ReactNode
|
|
753
|
+
}) {
|
|
754
|
+
return (
|
|
755
|
+
<span
|
|
756
|
+
data-slot="sidebar-identity-text"
|
|
757
|
+
className={cn(
|
|
758
|
+
"grid min-w-0 flex-1 text-start text-sm leading-tight transition-opacity duration-moderate group-data-[collapsible=icon]:opacity-0 group-data-[collapsible=icon]:duration-fast",
|
|
759
|
+
className
|
|
760
|
+
)}
|
|
761
|
+
{...props}
|
|
762
|
+
>
|
|
763
|
+
<span data-slot="sidebar-identity-title" className="truncate font-semibold">
|
|
764
|
+
{title}
|
|
765
|
+
</span>
|
|
766
|
+
{caption ? (
|
|
767
|
+
<span
|
|
768
|
+
data-slot="sidebar-identity-caption"
|
|
769
|
+
className="text-muted-foreground truncate text-xs font-normal"
|
|
770
|
+
>
|
|
771
|
+
{caption}
|
|
772
|
+
</span>
|
|
773
|
+
) : null}
|
|
774
|
+
</span>
|
|
775
|
+
)
|
|
776
|
+
}
|
|
777
|
+
|
|
708
778
|
function SidebarMenuAction({
|
|
709
779
|
className,
|
|
710
780
|
render,
|
|
@@ -1028,6 +1098,8 @@ export {
|
|
|
1028
1098
|
SidebarGroupContent,
|
|
1029
1099
|
SidebarGroupLabel,
|
|
1030
1100
|
SidebarHeader,
|
|
1101
|
+
SidebarIdentityButton,
|
|
1102
|
+
SidebarIdentityText,
|
|
1031
1103
|
SidebarInput,
|
|
1032
1104
|
SidebarInset,
|
|
1033
1105
|
SidebarLevel,
|
|
@@ -18,11 +18,11 @@ const InTooltipProvider = React.createContext(false)
|
|
|
18
18
|
* not import the tokens package at runtime; tooltip.test.ts keeps the two
|
|
19
19
|
* equal.
|
|
20
20
|
*/
|
|
21
|
-
const TOOLTIP_DELAY =
|
|
21
|
+
const TOOLTIP_DELAY = 350
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Wrap the app in one TooltipProvider. The first tooltip then waits
|
|
25
|
-
* `tooltip-delay` (
|
|
25
|
+
* `tooltip-delay` (350ms), so a pointer that only passes over a trigger opens
|
|
26
26
|
* nothing. Once a tooltip is open, the next one opens at once and does not
|
|
27
27
|
* animate, until no tooltip has been open for the provider's `timeout`.
|
|
28
28
|
*/
|
|
@@ -47,7 +47,7 @@ function Tooltip({ ...props }: TooltipPrimitive.Root.Props) {
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Inside a TooltipProvider it leaves `delay` unset, so the provider's delay
|
|
50
|
-
* applies. Without a provider the delay is `tooltip-delay` (
|
|
50
|
+
* applies. Without a provider the delay is `tooltip-delay` (350ms) too, so a
|
|
51
51
|
* pointer that only passes over a trigger opens nothing. An explicit `delay`
|
|
52
52
|
* wins in both cases. A provider is what lets the next tooltips open at once.
|
|
53
53
|
*/
|
|
@@ -21,6 +21,19 @@ interface ChipProps extends React.ComponentProps<'span'> {
|
|
|
21
21
|
* whenever `onRemove` is set — the × has no text otherwise.
|
|
22
22
|
*/
|
|
23
23
|
removeLabel?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Presence of this handler makes the label a button that runs it, e.g. to
|
|
26
|
+
* open an editor for the chip's value. The remove button stays a separate
|
|
27
|
+
* button after it. Absent → the label is plain text.
|
|
28
|
+
*/
|
|
29
|
+
onEdit?: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Accessible label for the edit button. Optional: without it the button is
|
|
32
|
+
* named by the chip's text.
|
|
33
|
+
*/
|
|
34
|
+
editLabel?: string;
|
|
35
|
+
/** `aria-expanded` of the edit button, while the editor it opens is open. */
|
|
36
|
+
editExpanded?: boolean;
|
|
24
37
|
/** Dims the chip and disables removal (e.g. a pending un-assign mutation). */
|
|
25
38
|
disabled?: boolean;
|
|
26
39
|
}
|
|
@@ -42,6 +55,9 @@ function Chip({
|
|
|
42
55
|
icon,
|
|
43
56
|
onRemove,
|
|
44
57
|
removeLabel,
|
|
58
|
+
onEdit,
|
|
59
|
+
editLabel,
|
|
60
|
+
editExpanded,
|
|
45
61
|
disabled,
|
|
46
62
|
children,
|
|
47
63
|
...props
|
|
@@ -61,15 +77,36 @@ function Chip({
|
|
|
61
77
|
// exempts from the contrast minimum.
|
|
62
78
|
aria-disabled={disabled || undefined}
|
|
63
79
|
className={cn(
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
// The StatusBadge shape: 24px high, the 6px corner (`rounded-lg`), the
|
|
81
|
+
// label 10px from the edge (9px of padding and the 1px border).
|
|
82
|
+
'h-6 max-w-full gap-1 rounded-lg px-2.25 [--content-inset:calc(var(--spacing)*2.5)]',
|
|
83
|
+
// The remove button sits 4px from the top, bottom and end edges: the
|
|
84
|
+
// 1px border and 3px of padding.
|
|
85
|
+
onRemove && 'pe-0.75',
|
|
66
86
|
disabled && 'pointer-events-none opacity-60',
|
|
67
87
|
className,
|
|
68
88
|
)}
|
|
69
89
|
{...props}
|
|
70
90
|
>
|
|
71
91
|
{icon}
|
|
72
|
-
|
|
92
|
+
{onEdit ? (
|
|
93
|
+
<button
|
|
94
|
+
type="button"
|
|
95
|
+
data-slot="chip-edit"
|
|
96
|
+
disabled={disabled}
|
|
97
|
+
aria-label={editLabel}
|
|
98
|
+
aria-expanded={editExpanded}
|
|
99
|
+
onClick={onEdit}
|
|
100
|
+
// The label stays text: no padding of its own, so an editable chip
|
|
101
|
+
// has the same size as a static one. The ring is drawn outside the
|
|
102
|
+
// label, 2px from its text.
|
|
103
|
+
className="min-w-0 cursor-pointer truncate rounded-sm hover:underline hover:underline-offset-2 disabled:pointer-events-none outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
|
|
104
|
+
>
|
|
105
|
+
{children}
|
|
106
|
+
</button>
|
|
107
|
+
) : (
|
|
108
|
+
<span className="truncate">{children}</span>
|
|
109
|
+
)}
|
|
73
110
|
{onRemove ? (
|
|
74
111
|
<button
|
|
75
112
|
type="button"
|
|
@@ -77,7 +114,9 @@ function Chip({
|
|
|
77
114
|
disabled={disabled}
|
|
78
115
|
aria-label={removeLabel}
|
|
79
116
|
onClick={onRemove}
|
|
80
|
-
|
|
117
|
+
// Nested in the chip's 6px corner, 4px from each edge: the concentric
|
|
118
|
+
// radius is 6px - 4px = 2px (`rounded-sm`).
|
|
119
|
+
className="ms-0.5 inline-flex size-4 shrink-0 items-center justify-center rounded-sm text-current/70 hover:bg-current/10 hover:text-current disabled:pointer-events-none outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
|
|
81
120
|
>
|
|
82
121
|
<XIcon className="size-3" />
|
|
83
122
|
</button>
|
|
@@ -92,6 +92,13 @@ interface ConfirmDialogProps {
|
|
|
92
92
|
* once, also when a mouse click opened the dialog.
|
|
93
93
|
*/
|
|
94
94
|
initialFocus?: ComponentProps<typeof AlertDialogContent>['initialFocus'];
|
|
95
|
+
/**
|
|
96
|
+
* The element that takes focus when the dialog closes. By default focus goes
|
|
97
|
+
* back to the element that opened it. Set it when that element is gone after
|
|
98
|
+
* a confirm, e.g. the row of a deleted item: return the next row, or the
|
|
99
|
+
* list's main action. Same type as Base UI's `Dialog.Popup` `finalFocus`.
|
|
100
|
+
*/
|
|
101
|
+
finalFocus?: ComponentProps<typeof AlertDialogContent>['finalFocus'];
|
|
95
102
|
/** Uncontrolled mode — the element that opens the dialog. */
|
|
96
103
|
children?: ReactElement;
|
|
97
104
|
/** Controlled mode — supply with `onOpenChange`. */
|
|
@@ -111,6 +118,7 @@ function ConfirmDialog({
|
|
|
111
118
|
confirmDisabled = false,
|
|
112
119
|
confirmDisabledReason,
|
|
113
120
|
initialFocus,
|
|
121
|
+
finalFocus,
|
|
114
122
|
children,
|
|
115
123
|
open,
|
|
116
124
|
onOpenChange,
|
|
@@ -168,6 +176,7 @@ function ConfirmDialog({
|
|
|
168
176
|
<AlertDialogContent
|
|
169
177
|
data-slot="confirm-dialog"
|
|
170
178
|
initialFocus={initialFocus ?? defaultInitialFocus}
|
|
179
|
+
finalFocus={finalFocus}
|
|
171
180
|
>
|
|
172
181
|
<AlertDialogHeader>
|
|
173
182
|
{icon ? (
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Tone } from '@vendure-io/ui/lib/state-dictionary';
|
|
2
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import type * as React from 'react';
|
|
5
|
+
|
|
6
|
+
type CountBadgeTone = Tone | 'brand';
|
|
7
|
+
type CountBadgePlacement = 'inline' | 'corner';
|
|
8
|
+
|
|
9
|
+
// A small solid count: unread notifications or alerts on an icon button, the
|
|
10
|
+
// number of active filters inside a button. The number is the whole content,
|
|
11
|
+
// so the fill is solid, not a tint: a tint at 11px does not read.
|
|
12
|
+
//
|
|
13
|
+
// `tone` takes every shared tone, so a `maxTone()` result passes in as it is,
|
|
14
|
+
// plus `brand`. `critical` takes the `destructive` slots and `progress` the
|
|
15
|
+
// `info` slots, as on StatusBadge. `neutral` is the `primary` ink (near black
|
|
16
|
+
// in light mode, light grey in dark mode): every hand-built count in the apps
|
|
17
|
+
// used it. `brand` follows accent rationing: an opt-in, not the default for
|
|
18
|
+
// unread items. Each pair is held to 4.5:1 by the tokens' contrast test.
|
|
19
|
+
//
|
|
20
|
+
// `corner` sits on the top end corner of an icon button, 16px high. Its start
|
|
21
|
+
// edge is pinned to the middle of the button, so a wider count ("99+") grows
|
|
22
|
+
// away from the icon, not over it, and mirrors in RTL. The button must be the
|
|
23
|
+
// containing block: add `relative` to it. A 2px ring in the
|
|
24
|
+
// page background cuts the count out of the icon under it. `inline` sits in
|
|
25
|
+
// the flow of a button label, 20px high, the button's gap spacing it.
|
|
26
|
+
const countBadgeVariants = cva(
|
|
27
|
+
[
|
|
28
|
+
'inline-flex shrink-0 items-center justify-center rounded-full font-medium tabular-nums whitespace-nowrap',
|
|
29
|
+
// Forced colours drop the fill; an outline keeps the pill visible.
|
|
30
|
+
'outline-1 outline-transparent -outline-offset-1',
|
|
31
|
+
],
|
|
32
|
+
{
|
|
33
|
+
variants: {
|
|
34
|
+
tone: {
|
|
35
|
+
neutral: 'bg-primary text-primary-foreground',
|
|
36
|
+
brand: 'bg-brand text-brand-foreground',
|
|
37
|
+
info: 'bg-info text-info-foreground',
|
|
38
|
+
success: 'bg-success text-success-foreground',
|
|
39
|
+
warning: 'bg-warning text-warning-foreground',
|
|
40
|
+
critical: 'bg-destructive text-destructive-foreground',
|
|
41
|
+
progress: 'bg-info text-info-foreground',
|
|
42
|
+
} satisfies Record<CountBadgeTone, string>,
|
|
43
|
+
placement: {
|
|
44
|
+
inline: 'h-5 min-w-5 px-1.5 text-xs/none',
|
|
45
|
+
corner:
|
|
46
|
+
'pointer-events-none absolute start-1/2 -top-1 h-4 min-w-4 px-1 text-2xs/none ring-2 ring-background',
|
|
47
|
+
} satisfies Record<CountBadgePlacement, string>,
|
|
48
|
+
},
|
|
49
|
+
defaultVariants: {
|
|
50
|
+
tone: 'neutral',
|
|
51
|
+
placement: 'inline',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/** The visible text: the count, or `${max}+` above the cap. */
|
|
57
|
+
function formatCount(count: number, max: number) {
|
|
58
|
+
return count > max ? `${max}+` : String(count);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface CountBadgeProps extends Omit<React.ComponentProps<'span'>, 'children'> {
|
|
62
|
+
/** The number to show. Nothing renders at 0, below 0 or for a non-finite value. */
|
|
63
|
+
count: number;
|
|
64
|
+
/** The highest number shown as is. Above it the badge reads "99+". Default 99. */
|
|
65
|
+
max?: number;
|
|
66
|
+
tone?: CountBadgeTone;
|
|
67
|
+
placement?: CountBadgePlacement;
|
|
68
|
+
/**
|
|
69
|
+
* What the count means to a screen reader, with the real number: "3 unread",
|
|
70
|
+
* "120 unread". The visible number is then hidden from it. The design system
|
|
71
|
+
* does not know the noun, so the caller writes (and translates) it. Leave it
|
|
72
|
+
* out where the text around the count already names it ("Active filters").
|
|
73
|
+
* An `aria-label` on the button replaces its content: put the count in that
|
|
74
|
+
* label instead.
|
|
75
|
+
*/
|
|
76
|
+
label?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function CountBadge({
|
|
80
|
+
count,
|
|
81
|
+
max = 99,
|
|
82
|
+
tone = 'neutral',
|
|
83
|
+
placement = 'inline',
|
|
84
|
+
label,
|
|
85
|
+
className,
|
|
86
|
+
...props
|
|
87
|
+
}: CountBadgeProps) {
|
|
88
|
+
if (!Number.isFinite(count) || count <= 0) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const text = formatCount(Math.floor(count), max);
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<span
|
|
96
|
+
data-slot="count-badge"
|
|
97
|
+
data-tone={tone}
|
|
98
|
+
data-placement={placement}
|
|
99
|
+
className={cn(countBadgeVariants({ tone, placement }), className)}
|
|
100
|
+
{...props}
|
|
101
|
+
>
|
|
102
|
+
{label ? (
|
|
103
|
+
<>
|
|
104
|
+
<span aria-hidden="true">{text}</span>
|
|
105
|
+
<span className="sr-only">{label}</span>
|
|
106
|
+
</>
|
|
107
|
+
) : (
|
|
108
|
+
text
|
|
109
|
+
)}
|
|
110
|
+
</span>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { CountBadge, countBadgeVariants, formatCount };
|
|
115
|
+
export type { CountBadgePlacement, CountBadgeProps, CountBadgeTone };
|
|
@@ -129,6 +129,57 @@ function labelText(label: React.ReactNode, fallback: string): string {
|
|
|
129
129
|
return typeof label === 'string' ? label : fallback;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/** One applied filter. With `renderEditor`, its label opens the consumer's editor. */
|
|
133
|
+
function AppliedFilterChip<TData>({
|
|
134
|
+
table,
|
|
135
|
+
filterId,
|
|
136
|
+
value,
|
|
137
|
+
column,
|
|
138
|
+
removeLabel,
|
|
139
|
+
}: {
|
|
140
|
+
table: Table<TData>;
|
|
141
|
+
filterId: string;
|
|
142
|
+
value: DataTableFilterValue;
|
|
143
|
+
column: DataTableFilterColumn<TData> | undefined;
|
|
144
|
+
removeLabel: (columnLabel: string) => string;
|
|
145
|
+
}) {
|
|
146
|
+
const [editing, setEditing] = React.useState(false);
|
|
147
|
+
const anchor = React.useRef<HTMLSpanElement>(null);
|
|
148
|
+
const text = labelText(column?.label, filterId);
|
|
149
|
+
const content = column?.formatChip ? (
|
|
150
|
+
column.formatChip(value)
|
|
151
|
+
) : (
|
|
152
|
+
<>
|
|
153
|
+
{column?.label ?? filterId}: {JSON.stringify(value)}
|
|
154
|
+
</>
|
|
155
|
+
);
|
|
156
|
+
const editor = column?.renderEditor;
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<>
|
|
160
|
+
<Chip
|
|
161
|
+
ref={anchor}
|
|
162
|
+
onEdit={editor ? () => setEditing((open) => !open) : undefined}
|
|
163
|
+
editExpanded={editor ? editing : undefined}
|
|
164
|
+
onRemove={() => table.getColumn(filterId)?.setFilterValue(undefined)}
|
|
165
|
+
removeLabel={removeLabel(text)}
|
|
166
|
+
>
|
|
167
|
+
{content}
|
|
168
|
+
</Chip>
|
|
169
|
+
{editor && column
|
|
170
|
+
? editor({
|
|
171
|
+
open: editing,
|
|
172
|
+
onOpenChange: setEditing,
|
|
173
|
+
anchor,
|
|
174
|
+
value,
|
|
175
|
+
onChange: (next) => table.getColumn(filterId)?.setFilterValue(next),
|
|
176
|
+
column,
|
|
177
|
+
})
|
|
178
|
+
: null}
|
|
179
|
+
</>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
132
183
|
interface DataTableAppliedFiltersProps<TData> {
|
|
133
184
|
table: Table<TData>;
|
|
134
185
|
columns?: DataTableFilterColumn<TData>[];
|
|
@@ -149,27 +200,16 @@ function DataTableAppliedFilters<TData>({
|
|
|
149
200
|
|
|
150
201
|
const columnMap = new Map((columns ?? []).map((column) => [column.id, column]));
|
|
151
202
|
|
|
152
|
-
const chipFor = (filter: (typeof applied)[number]) =>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
<Chip
|
|
165
|
-
key={filter.id}
|
|
166
|
-
onRemove={() => table.getColumn(filter.id)?.setFilterValue(undefined)}
|
|
167
|
-
removeLabel={removeLabel(text)}
|
|
168
|
-
>
|
|
169
|
-
{content}
|
|
170
|
-
</Chip>
|
|
171
|
-
);
|
|
172
|
-
};
|
|
203
|
+
const chipFor = (filter: (typeof applied)[number]) => (
|
|
204
|
+
<AppliedFilterChip
|
|
205
|
+
key={filter.id}
|
|
206
|
+
table={table}
|
|
207
|
+
filterId={filter.id}
|
|
208
|
+
value={filter.value as DataTableFilterValue}
|
|
209
|
+
column={columnMap.get(filter.id)}
|
|
210
|
+
removeLabel={removeLabel}
|
|
211
|
+
/>
|
|
212
|
+
);
|
|
173
213
|
|
|
174
214
|
const inline = applied.slice(0, inlineChipLimit);
|
|
175
215
|
const overflow = applied.slice(inlineChipLimit);
|