@vendure-io/ui 2.2.0 → 3.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -5
- package/src/components/atoms/accordion.tsx +21 -6
- package/src/components/atoms/alert-dialog.tsx +31 -6
- package/src/components/atoms/alert.tsx +72 -18
- package/src/components/atoms/avatar.tsx +12 -4
- package/src/components/atoms/badge.tsx +7 -2
- package/src/components/atoms/breadcrumb.tsx +493 -4
- package/src/components/atoms/button-group.tsx +30 -6
- package/src/components/atoms/button.tsx +128 -18
- package/src/components/atoms/calendar.tsx +6 -6
- package/src/components/atoms/card.tsx +130 -16
- package/src/components/atoms/carousel.tsx +16 -9
- package/src/components/atoms/chart.tsx +87 -1
- package/src/components/atoms/checkbox.tsx +85 -7
- package/src/components/atoms/collapsible.tsx +2 -1
- package/src/components/atoms/combobox.tsx +358 -29
- package/src/components/atoms/command.tsx +336 -13
- package/src/components/atoms/context-menu.tsx +28 -23
- package/src/components/atoms/dialog.tsx +173 -29
- package/src/components/atoms/direction.tsx +23 -2
- package/src/components/atoms/drawer.tsx +15 -10
- package/src/components/atoms/dropdown-menu.tsx +43 -28
- package/src/components/atoms/empty.tsx +5 -1
- package/src/components/atoms/field.tsx +41 -15
- package/src/components/atoms/hover-card.tsx +61 -8
- package/src/components/atoms/input-group.tsx +19 -11
- package/src/components/atoms/input-otp.tsx +6 -6
- package/src/components/atoms/input.tsx +7 -1
- package/src/components/atoms/item.tsx +3 -3
- package/src/components/atoms/kbd.tsx +32 -3
- package/src/components/atoms/label-swap.tsx +113 -0
- package/src/components/atoms/label.tsx +1 -1
- package/src/components/atoms/menubar.tsx +28 -26
- package/src/components/atoms/native-select.tsx +3 -2
- package/src/components/atoms/navigation-menu.tsx +13 -8
- package/src/components/atoms/pagination.tsx +2 -2
- package/src/components/atoms/popover.tsx +29 -6
- package/src/components/atoms/progress.tsx +46 -33
- package/src/components/atoms/radio-group.tsx +9 -4
- package/src/components/atoms/resizable.tsx +1 -1
- package/src/components/atoms/scroll-area.tsx +2 -2
- package/src/components/atoms/select.tsx +258 -19
- package/src/components/atoms/sheet.tsx +76 -23
- package/src/components/atoms/sidebar.tsx +405 -23
- package/src/components/atoms/skeleton.tsx +1 -1
- package/src/components/atoms/slider.tsx +1 -1
- package/src/components/atoms/sonner.tsx +128 -38
- package/src/components/atoms/spinner.tsx +1 -1
- package/src/components/atoms/switch.tsx +10 -5
- package/src/components/atoms/table.tsx +147 -7
- package/src/components/atoms/tabs.tsx +3 -3
- package/src/components/atoms/textarea.tsx +3 -1
- package/src/components/atoms/toggle-group.tsx +4 -2
- package/src/components/atoms/toggle.tsx +28 -6
- package/src/components/atoms/tooltip.tsx +85 -15
- package/src/components/molecules/anonymized-token.tsx +24 -8
- package/src/components/molecules/app-shell.tsx +53 -20
- package/src/components/molecules/arrow-link.tsx +40 -0
- package/src/components/molecules/chip.tsx +43 -4
- package/src/components/molecules/code-block.tsx +54 -31
- package/src/components/molecules/collapsible-section.tsx +129 -0
- package/src/components/molecules/confirm-dialog.tsx +122 -9
- package/src/components/molecules/copyable-text.tsx +75 -11
- package/src/components/molecules/count-badge.tsx +115 -0
- package/src/components/molecules/data-table/data-table-bulk-actions.tsx +32 -4
- package/src/components/molecules/data-table/data-table-column-header.tsx +20 -3
- package/src/components/molecules/data-table/data-table-filters.tsx +62 -22
- package/src/components/molecules/data-table/data-table-helpers.tsx +88 -1
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +115 -0
- package/src/components/molecules/data-table/data-table-types.tsx +160 -4
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
- package/src/components/molecules/data-table/data-table.tsx +869 -81
- package/src/components/molecules/data-table/table-pagination.tsx +2 -2
- package/src/components/molecules/date-picker.tsx +13 -7
- package/src/components/molecules/date-range-picker.tsx +13 -6
- package/src/components/molecules/date-time-picker.tsx +13 -7
- package/src/components/molecules/date-time.tsx +8 -1
- package/src/components/molecules/direction-link.tsx +130 -0
- package/src/components/molecules/elapsed-time.tsx +223 -0
- package/src/components/molecules/file-dropzone.tsx +2 -2
- package/src/components/molecules/id-chip.tsx +169 -32
- package/src/components/molecules/inline-code.tsx +4 -0
- package/src/components/molecules/issued-secret.tsx +318 -0
- package/src/components/molecules/list-row.tsx +349 -0
- package/src/components/molecules/live-indicator.tsx +83 -0
- package/src/components/molecules/page-header.tsx +117 -5
- package/src/components/molecules/password-input.tsx +2 -2
- package/src/components/molecules/relative-time.tsx +85 -56
- package/src/components/molecules/search-trigger.tsx +111 -0
- package/src/components/molecules/secret-value.tsx +29 -9
- package/src/components/molecules/skip-link.tsx +1 -1
- package/src/components/molecules/stat-card.tsx +4 -4
- package/src/components/molecules/state-views/empty-state.tsx +35 -17
- package/src/components/molecules/state-views/error-state.tsx +32 -14
- package/src/components/molecules/status-badge.tsx +415 -49
- package/src/components/molecules/time-tooltip.tsx +140 -0
- package/src/components/molecules/timeline.tsx +246 -0
- package/src/components/molecules/visibility-icon.tsx +89 -0
- package/src/hooks/use-active-label-size.ts +66 -0
- package/src/hooks/use-apple-platform.ts +26 -0
- package/src/hooks/use-pinned-height.ts +55 -0
- package/src/hooks/use-scrolled.ts +27 -0
- package/src/lib/content-inset.ts +17 -0
- package/src/lib/control-name.ts +55 -0
- package/src/lib/dialog-padding.ts +48 -0
- package/src/lib/field-surface.ts +31 -0
- package/src/lib/format-elapsed.ts +67 -0
- package/src/lib/format-relative.ts +29 -1
- package/src/lib/highlight.ts +3 -3
- package/src/lib/menu-item.tsx +72 -0
- package/src/lib/outline-edge.ts +21 -0
- package/src/lib/popup-align.ts +67 -0
- package/src/lib/popup-direction.ts +22 -0
- package/src/lib/popup-motion.ts +19 -0
- package/src/lib/state-dictionary.ts +42 -6
- package/src/lib/syntax-colors.ts +8 -0
- package/src/lib/tint-recipes.ts +68 -0
- package/src/lib/tone-icons.ts +24 -0
- package/src/lib/trigger-slot.ts +16 -0
- package/src/lib/utils.ts +97 -1
|
@@ -4,6 +4,7 @@ import * as React from "react"
|
|
|
4
4
|
import { Command as CommandPrimitive, useCommandState } from "cmdk"
|
|
5
5
|
|
|
6
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
|
+
import { MenuCheck, menuCheckItem } from "../../lib/menu-item.tsx"
|
|
7
8
|
import {
|
|
8
9
|
Dialog,
|
|
9
10
|
DialogContent,
|
|
@@ -15,7 +16,7 @@ import {
|
|
|
15
16
|
InputGroup,
|
|
16
17
|
InputGroupAddon,
|
|
17
18
|
} from "@vendure-io/ui/components/atoms/input-group"
|
|
18
|
-
import { SearchIcon
|
|
19
|
+
import { SearchIcon } from "lucide-react"
|
|
19
20
|
|
|
20
21
|
function Command({
|
|
21
22
|
className,
|
|
@@ -25,7 +26,7 @@ function Command({
|
|
|
25
26
|
<CommandPrimitive
|
|
26
27
|
data-slot="command"
|
|
27
28
|
className={cn(
|
|
28
|
-
"bg-popover text-popover-foreground flex size-full flex-col overflow-hidden rounded-xl!
|
|
29
|
+
"bg-popover text-popover-foreground flex size-full flex-col overflow-hidden rounded-xl! in-data-command-palette:rounded-3xl!",
|
|
29
30
|
className
|
|
30
31
|
)}
|
|
31
32
|
{...props}
|
|
@@ -53,12 +54,23 @@ function CommandDialog({
|
|
|
53
54
|
<DialogTitle>{title}</DialogTitle>
|
|
54
55
|
<DialogDescription>{description}</DialogDescription>
|
|
55
56
|
</DialogHeader>
|
|
57
|
+
{/* The palette: 600px wide, 12% of the viewport from the top so the
|
|
58
|
+
list can grow down without moving the input. It opens often, so its
|
|
59
|
+
motion is smaller than a dialog's: it drops 6px from 98% at the top
|
|
60
|
+
centre instead of scaling from 96%. It takes a little longer to settle
|
|
61
|
+
(opacity 160ms, transform 180ms) and closes in 110ms. Reduced motion
|
|
62
|
+
fades only. data-command-palette scopes the palette styles of the
|
|
63
|
+
Command parts to this dialog. */}
|
|
56
64
|
<DialogContent
|
|
65
|
+
data-command-palette=""
|
|
57
66
|
className={cn(
|
|
58
|
-
"top-
|
|
67
|
+
"shadow-overlay top-[12vh] translate-y-0 gap-0 overflow-hidden rounded-3xl! p-0 ring-0 sm:max-w-150 origin-top transition-[opacity,scale,translate] duration-[var(--transition-duration-palette-enter),var(--transition-duration-palette-move),var(--transition-duration-palette-move)] motion-safe:data-starting-style:-translate-y-1.5 motion-safe:data-starting-style:scale-98 data-ending-style:duration-palette-exit data-ending-style:ease-[var(--ease-soft),var(--ease-out),var(--ease-out)] motion-safe:data-ending-style:scale-98 motion-reduce:transition-opacity motion-reduce:duration-quick motion-reduce:ease-soft",
|
|
59
68
|
className
|
|
60
69
|
)}
|
|
61
70
|
showCloseButton={showCloseButton}
|
|
71
|
+
// The palette is transient and keeps the page in view: a lighter scrim
|
|
72
|
+
// with a 2px blur that fades with the palette.
|
|
73
|
+
overlayClassName="bg-scrim-subtle duration-palette-enter ease-out data-ending-style:duration-palette-exit supports-backdrop-filter:backdrop-blur-[2px]"
|
|
62
74
|
>
|
|
63
75
|
{children}
|
|
64
76
|
</DialogContent>
|
|
@@ -68,15 +80,24 @@ function CommandDialog({
|
|
|
68
80
|
|
|
69
81
|
function CommandInput({
|
|
70
82
|
className,
|
|
83
|
+
end,
|
|
71
84
|
...props
|
|
72
|
-
}: React.ComponentProps<typeof CommandPrimitive.Input>
|
|
85
|
+
}: React.ComponentProps<typeof CommandPrimitive.Input> & {
|
|
86
|
+
/**
|
|
87
|
+
* Content at the end of the field, such as a `Kbd` with the key that closes
|
|
88
|
+
* the palette. It sits in an end addon, so the input never runs under it.
|
|
89
|
+
*/
|
|
90
|
+
end?: React.ReactNode
|
|
91
|
+
}) {
|
|
73
92
|
return (
|
|
74
|
-
|
|
75
|
-
|
|
93
|
+
// Unboxed: the input runs edge to edge above a hairline, with no field
|
|
94
|
+
// border, fill or ring. 54px with 16px text in the palette dialog.
|
|
95
|
+
<div data-slot="command-input-wrapper" className="border-border border-b">
|
|
96
|
+
<InputGroup className="h-10! rounded-none! border-0! bg-transparent! pe-3.5 shadow-none! ring-0! outline-none! in-data-command-palette:h-13.5! *:data-[slot=input-group-addon]:ps-3! in-data-command-palette:*:data-[slot=input-group-addon]:ps-4.5!">
|
|
76
97
|
<CommandPrimitive.Input
|
|
77
98
|
data-slot="command-input"
|
|
78
99
|
className={cn(
|
|
79
|
-
"w-full text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
|
100
|
+
"placeholder:text-muted-foreground w-full ps-2.5! text-sm outline-hidden in-data-command-palette:text-base disabled:cursor-not-allowed disabled:opacity-50",
|
|
80
101
|
className
|
|
81
102
|
)}
|
|
82
103
|
{...props}
|
|
@@ -84,23 +105,238 @@ function CommandInput({
|
|
|
84
105
|
<InputGroupAddon>
|
|
85
106
|
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
|
86
107
|
</InputGroupAddon>
|
|
108
|
+
{end != null && (
|
|
109
|
+
<InputGroupAddon align="inline-end" className="pe-0">
|
|
110
|
+
{end}
|
|
111
|
+
</InputGroupAddon>
|
|
112
|
+
)}
|
|
87
113
|
</InputGroup>
|
|
88
114
|
</div>
|
|
89
115
|
)
|
|
90
116
|
}
|
|
91
117
|
|
|
118
|
+
// cmdk measures the list's content and writes it to --cmdk-list-height, so the
|
|
119
|
+
// list eases to its new height as results change. The first measure is not
|
|
120
|
+
// animated (the height starts as auto). Reduced motion drops the animation.
|
|
121
|
+
// The palette list has no motion: a search is typed fast, and each keystroke
|
|
122
|
+
// must show its results at once. It takes its content's height (capped by
|
|
123
|
+
// max-h) in the same frame, not cmdk's measure, which lands a frame later.
|
|
92
124
|
function CommandList({
|
|
93
125
|
className,
|
|
126
|
+
slidingHighlight = false,
|
|
127
|
+
children,
|
|
94
128
|
...props
|
|
95
|
-
}: React.ComponentProps<typeof CommandPrimitive.List>
|
|
129
|
+
}: React.ComponentProps<typeof CommandPrimitive.List> & {
|
|
130
|
+
/**
|
|
131
|
+
* Draws the selected item's highlight as one fill that follows the
|
|
132
|
+
* selection from item to item, and eases the list's scroll with it. In the
|
|
133
|
+
* palette it jumps to the selected item in the same frame. Off by default:
|
|
134
|
+
* each item then fills itself.
|
|
135
|
+
*/
|
|
136
|
+
slidingHighlight?: boolean
|
|
137
|
+
}) {
|
|
96
138
|
return (
|
|
97
139
|
<CommandPrimitive.List
|
|
98
140
|
data-slot="command-list"
|
|
141
|
+
data-highlight={slidingHighlight ? "slide" : undefined}
|
|
99
142
|
className={cn(
|
|
100
|
-
"no-scrollbar max-h-72 scroll-py-1 overflow-x-hidden overflow-y-auto outline-none",
|
|
143
|
+
"no-scrollbar h-(--cmdk-list-height) max-h-72 scroll-py-1 overflow-x-hidden overflow-y-auto overscroll-contain outline-none transition-[height] duration-normal ease-height in-data-command-palette:h-auto in-data-command-palette:max-h-95 in-data-command-palette:transition-none motion-reduce:transition-none *:[[cmdk-list-sizer]]:relative *:[[cmdk-list-sizer]]:p-1",
|
|
101
144
|
className
|
|
102
145
|
)}
|
|
103
146
|
{...props}
|
|
147
|
+
>
|
|
148
|
+
{slidingHighlight && <CommandHighlight />}
|
|
149
|
+
{children}
|
|
150
|
+
</CommandPrimitive.List>
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The follower's time constant. Each frame closes 1 - e^(-dt/42ms) of the
|
|
155
|
+
// distance: about 95% in 130ms, with no overshoot.
|
|
156
|
+
const FOLLOW_MS = 42
|
|
157
|
+
const NAVIGATION_KEYS = new Set([
|
|
158
|
+
"ArrowDown",
|
|
159
|
+
"ArrowUp",
|
|
160
|
+
"Home",
|
|
161
|
+
"End",
|
|
162
|
+
"PageDown",
|
|
163
|
+
"PageUp",
|
|
164
|
+
])
|
|
165
|
+
|
|
166
|
+
// The sliding highlight of a CommandList. It sits in cmdk's list sizer, so it
|
|
167
|
+
// scrolls with the items, and follows the item cmdk marks
|
|
168
|
+
// data-selected="true": a MutationObserver catches the selection moving and
|
|
169
|
+
// the results changing, a ResizeObserver catches layout changes.
|
|
170
|
+
//
|
|
171
|
+
// One follower moves the highlight and the list's scroll together, so they
|
|
172
|
+
// never disagree. It approaches its target exponentially every frame, so a
|
|
173
|
+
// new target while it moves (a held arrow key) continues from where it is
|
|
174
|
+
// instead of restarting. cmdk scrolls the selected item into view at once;
|
|
175
|
+
// after a key press the follower takes that scroll back and eases to it.
|
|
176
|
+
// Wheel and pointer scrolling stay native. Reduced motion jumps.
|
|
177
|
+
//
|
|
178
|
+
// In the palette the highlight and the scroll jump too, in the same frame as
|
|
179
|
+
// the selection: arrow keys repeat and searches are typed fast, and a
|
|
180
|
+
// highlight that eases there trails behind the row the user reads.
|
|
181
|
+
function CommandHighlight() {
|
|
182
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
183
|
+
|
|
184
|
+
React.useLayoutEffect(() => {
|
|
185
|
+
const highlight = ref.current
|
|
186
|
+
const sizer = highlight?.parentElement
|
|
187
|
+
const list = sizer?.closest<HTMLElement>("[cmdk-list]")
|
|
188
|
+
if (!highlight || !sizer || !list) {
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
const reduced = window.matchMedia("(prefers-reduced-motion: reduce)")
|
|
192
|
+
const inPalette = list.closest("[data-command-palette]") !== null
|
|
193
|
+
const jumps = () => inPalette || reduced.matches
|
|
194
|
+
|
|
195
|
+
// y and h are shown, ty and th are the target. scroll is the list's
|
|
196
|
+
// shown scroll position, scrollTo its target while the follower scrolls.
|
|
197
|
+
const f = {
|
|
198
|
+
y: 0,
|
|
199
|
+
h: 0,
|
|
200
|
+
ty: 0,
|
|
201
|
+
th: 0,
|
|
202
|
+
scroll: list.scrollTop,
|
|
203
|
+
scrollTo: null as number | null,
|
|
204
|
+
placed: false,
|
|
205
|
+
byKey: false,
|
|
206
|
+
raf: 0,
|
|
207
|
+
last: 0,
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const draw = () => {
|
|
211
|
+
highlight.style.transform = `translateY(${f.y}px)`
|
|
212
|
+
highlight.style.height = `${f.h}px`
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const tick = (time: number) => {
|
|
216
|
+
const dt = f.last ? Math.min(time - f.last, 48) : 16
|
|
217
|
+
f.last = time
|
|
218
|
+
const k = jumps() ? 1 : 1 - Math.exp(-dt / FOLLOW_MS)
|
|
219
|
+
f.y = Math.abs(f.ty - f.y) < 0.25 ? f.ty : f.y + (f.ty - f.y) * k
|
|
220
|
+
f.h = Math.abs(f.th - f.h) < 0.25 ? f.th : f.h + (f.th - f.h) * k
|
|
221
|
+
draw()
|
|
222
|
+
let moving = f.y !== f.ty || f.h !== f.th
|
|
223
|
+
if (f.scrollTo !== null) {
|
|
224
|
+
const next = f.scroll + (f.scrollTo - f.scroll) * k
|
|
225
|
+
f.scroll = Math.abs(f.scrollTo - next) < 0.5 ? f.scrollTo : next
|
|
226
|
+
list.scrollTop = f.scroll
|
|
227
|
+
if (f.scroll === f.scrollTo) {
|
|
228
|
+
f.scrollTo = null
|
|
229
|
+
} else {
|
|
230
|
+
moving = true
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (moving) {
|
|
234
|
+
f.raf = requestAnimationFrame(tick)
|
|
235
|
+
} else {
|
|
236
|
+
f.raf = 0
|
|
237
|
+
f.last = 0
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const place = () => {
|
|
242
|
+
const selected = sizer.querySelector<HTMLElement>(
|
|
243
|
+
'[cmdk-item][data-selected="true"]'
|
|
244
|
+
)
|
|
245
|
+
if (!selected) {
|
|
246
|
+
delete highlight.dataset.shown
|
|
247
|
+
f.byKey = false
|
|
248
|
+
return
|
|
249
|
+
}
|
|
250
|
+
// Layout offsets, not client rects: they ignore the dialog's scale-in.
|
|
251
|
+
let top = 0
|
|
252
|
+
let left = 0
|
|
253
|
+
for (
|
|
254
|
+
let node: HTMLElement | null = selected;
|
|
255
|
+
node && node !== sizer;
|
|
256
|
+
node = node.offsetParent as HTMLElement | null
|
|
257
|
+
) {
|
|
258
|
+
top += node.offsetTop
|
|
259
|
+
left += node.offsetLeft
|
|
260
|
+
}
|
|
261
|
+
highlight.style.left = `${left}px`
|
|
262
|
+
highlight.style.width = `${selected.offsetWidth}px`
|
|
263
|
+
f.ty = top
|
|
264
|
+
f.th = selected.offsetHeight
|
|
265
|
+
if (!f.placed || jumps()) {
|
|
266
|
+
f.placed = true
|
|
267
|
+
f.y = f.ty
|
|
268
|
+
f.h = f.th
|
|
269
|
+
draw()
|
|
270
|
+
}
|
|
271
|
+
highlight.dataset.shown = ""
|
|
272
|
+
// cmdk has already scrolled the item into view. Show the old position
|
|
273
|
+
// and let the follower ease to cmdk's.
|
|
274
|
+
if (f.byKey && list.scrollTop !== f.scroll && !jumps()) {
|
|
275
|
+
f.scrollTo = list.scrollTop
|
|
276
|
+
list.scrollTop = f.scroll
|
|
277
|
+
}
|
|
278
|
+
f.byKey = false
|
|
279
|
+
if (!f.raf) {
|
|
280
|
+
f.raf = requestAnimationFrame(tick)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
place()
|
|
285
|
+
const frame = requestAnimationFrame(() => {
|
|
286
|
+
highlight.dataset.ready = ""
|
|
287
|
+
})
|
|
288
|
+
const mutations = new MutationObserver(place)
|
|
289
|
+
mutations.observe(sizer, {
|
|
290
|
+
subtree: true,
|
|
291
|
+
childList: true,
|
|
292
|
+
attributes: true,
|
|
293
|
+
attributeFilter: ["data-selected", "hidden"],
|
|
294
|
+
})
|
|
295
|
+
const resize = new ResizeObserver(place)
|
|
296
|
+
resize.observe(sizer)
|
|
297
|
+
|
|
298
|
+
const root = sizer.closest("[cmdk-root]")
|
|
299
|
+
// Only moves between items scroll through the follower. A new query
|
|
300
|
+
// starts at the top of the list at once.
|
|
301
|
+
const onKeyDown = (event: Event) => {
|
|
302
|
+
const { key, ctrlKey } = event as KeyboardEvent
|
|
303
|
+
f.byKey =
|
|
304
|
+
NAVIGATION_KEYS.has(key) || (ctrlKey && "npjk".includes(key))
|
|
305
|
+
}
|
|
306
|
+
// Scrolling by hand takes over from the follower.
|
|
307
|
+
const onScroll = () => {
|
|
308
|
+
if (f.scrollTo === null) {
|
|
309
|
+
f.scroll = list.scrollTop
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const onManualScroll = () => {
|
|
313
|
+
f.scrollTo = null
|
|
314
|
+
f.scroll = list.scrollTop
|
|
315
|
+
}
|
|
316
|
+
root?.addEventListener("keydown", onKeyDown)
|
|
317
|
+
list.addEventListener("scroll", onScroll, { passive: true })
|
|
318
|
+
list.addEventListener("wheel", onManualScroll, { passive: true })
|
|
319
|
+
list.addEventListener("pointerdown", onManualScroll)
|
|
320
|
+
|
|
321
|
+
return () => {
|
|
322
|
+
cancelAnimationFrame(frame)
|
|
323
|
+
cancelAnimationFrame(f.raf)
|
|
324
|
+
mutations.disconnect()
|
|
325
|
+
resize.disconnect()
|
|
326
|
+
root?.removeEventListener("keydown", onKeyDown)
|
|
327
|
+
list.removeEventListener("scroll", onScroll)
|
|
328
|
+
list.removeEventListener("wheel", onManualScroll)
|
|
329
|
+
list.removeEventListener("pointerdown", onManualScroll)
|
|
330
|
+
}
|
|
331
|
+
}, [])
|
|
332
|
+
|
|
333
|
+
return (
|
|
334
|
+
<div
|
|
335
|
+
ref={ref}
|
|
336
|
+
aria-hidden="true"
|
|
337
|
+
role="none"
|
|
338
|
+
data-slot="command-highlight"
|
|
339
|
+
className="bg-muted pointer-events-none absolute top-0 left-0 rounded-sm opacity-0 will-change-transform forced-colors:outline-2 forced-colors:-outline-offset-2 forced-colors:outline-solid forced-colors:outline-[Highlight] in-data-command-palette:rounded-xl data-shown:opacity-100 data-ready:transition-opacity data-ready:duration-fast data-ready:ease-soft in-data-command-palette:transition-none!"
|
|
104
340
|
/>
|
|
105
341
|
)
|
|
106
342
|
}
|
|
@@ -157,7 +393,23 @@ function CommandSeparator({
|
|
|
157
393
|
}
|
|
158
394
|
|
|
159
395
|
// cmdk writes data-selected="true" or "false" on every item, so the highlight
|
|
160
|
-
//
|
|
396
|
+
// keys on the "true" value. A checked item (`data-checked="true"`) draws the
|
|
397
|
+
// MenuCheck of every menu and list; the check sits in its own span, because
|
|
398
|
+
// MenuCheck also shows for a selected option and every cmdk item carries
|
|
399
|
+
// data-selected. The check hides when the item has a shortcut or a detail.
|
|
400
|
+
// In a CommandList with slidingHighlight, the list's highlight replaces the
|
|
401
|
+
// item's own fill. The highlight is the muted fill, as in every combobox,
|
|
402
|
+
// select and menu. In forced colors, where fills drop, the
|
|
403
|
+
// highlight is a Highlight outline. Palette items are 40px tall and quiet at
|
|
404
|
+
// rest: foreground-secondary text, with the label (CommandItemLabel) in medium
|
|
405
|
+
// weight. The highlighted row has the muted fill, turns its text to
|
|
406
|
+
// foreground and its leading icon to the brand indicator, all at once: the
|
|
407
|
+
// selection moves on every arrow key and keystroke, so a tint that eases
|
|
408
|
+
// would trail behind it.
|
|
409
|
+
function isChecked(value: unknown) {
|
|
410
|
+
return value === true || value === "true"
|
|
411
|
+
}
|
|
412
|
+
|
|
161
413
|
function CommandItem({
|
|
162
414
|
className,
|
|
163
415
|
children,
|
|
@@ -167,17 +419,41 @@ function CommandItem({
|
|
|
167
419
|
<CommandPrimitive.Item
|
|
168
420
|
data-slot="command-item"
|
|
169
421
|
className={cn(
|
|
170
|
-
"data-[selected=true]:bg-
|
|
422
|
+
"group/command-item relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[selected=true]:bg-muted not-in-data-command-palette:data-[selected=true]:text-accent-foreground not-in-data-command-palette:data-[selected=true]:**:[svg]:text-accent-foreground in-data-[highlight=slide]:data-[selected=true]:bg-transparent! not-in-data-[highlight=slide]:data-[selected=true]:forced-colors:outline-2 not-in-data-[highlight=slide]:data-[selected=true]:forced-colors:-outline-offset-2 not-in-data-[highlight=slide]:data-[selected=true]:forced-colors:outline-solid not-in-data-[highlight=slide]:data-[selected=true]:forced-colors:outline-[Highlight] in-data-command-palette:h-10 in-data-command-palette:gap-3 in-data-command-palette:rounded-xl in-data-command-palette:px-2.5 in-data-command-palette:text-foreground-secondary in-data-command-palette:data-[selected=true]:text-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75] [&>svg:not([class*='opacity-'])]:opacity-55 [&>svg:not([class*='opacity-'])]:transition-[opacity,color] [&>svg:not([class*='opacity-'])]:duration-moderate not-in-data-command-palette:data-[selected=true]:[&>svg:not([class*='opacity-'])]:opacity-85 in-data-command-palette:[&>svg:not([class*='opacity-'])]:transition-none! in-data-command-palette:data-[selected=true]:[&>svg:not([class*='opacity-'])]:opacity-100 in-data-command-palette:data-[selected=true]:[&>svg:not([class*='opacity-'])]:text-brand-indicator",
|
|
171
423
|
className
|
|
172
424
|
)}
|
|
173
425
|
{...props}
|
|
174
426
|
>
|
|
175
427
|
{children}
|
|
176
|
-
<
|
|
428
|
+
<span
|
|
429
|
+
data-slot="command-item-check"
|
|
430
|
+
data-checked={isChecked(props["data-checked" as keyof typeof props]) ? "" : undefined}
|
|
431
|
+
className={cn(
|
|
432
|
+
menuCheckItem,
|
|
433
|
+
"ms-auto flex shrink-0 group-has-data-[slot=command-shortcut]/command-item:hidden group-has-data-[slot=command-item-detail]/command-item:hidden"
|
|
434
|
+
)}
|
|
435
|
+
>
|
|
436
|
+
<MenuCheck />
|
|
437
|
+
</span>
|
|
177
438
|
</CommandPrimitive.Item>
|
|
178
439
|
)
|
|
179
440
|
}
|
|
180
441
|
|
|
442
|
+
// An item's label. In the palette it is medium weight; text after it, such as
|
|
443
|
+
// a hint or CommandItemDetail, keeps the regular weight.
|
|
444
|
+
function CommandItemLabel({
|
|
445
|
+
className,
|
|
446
|
+
...props
|
|
447
|
+
}: React.ComponentProps<"span">) {
|
|
448
|
+
return (
|
|
449
|
+
<span
|
|
450
|
+
data-slot="command-item-label"
|
|
451
|
+
className={cn("min-w-0 truncate in-data-command-palette:font-medium", className)}
|
|
452
|
+
{...props}
|
|
453
|
+
/>
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
|
|
181
457
|
function CommandShortcut({
|
|
182
458
|
className,
|
|
183
459
|
...props
|
|
@@ -186,7 +462,27 @@ function CommandShortcut({
|
|
|
186
462
|
<span
|
|
187
463
|
data-slot="command-shortcut"
|
|
188
464
|
className={cn(
|
|
189
|
-
"text-muted-foreground group-data-[selected=true]/command-item:text-foreground
|
|
465
|
+
"text-muted-foreground group-data-[selected=true]/command-item:text-foreground ms-auto text-xs tracking-widest",
|
|
466
|
+
className
|
|
467
|
+
)}
|
|
468
|
+
{...props}
|
|
469
|
+
/>
|
|
470
|
+
)
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// Where an item lives, such as "Production · Acme", at the end of the row. It
|
|
474
|
+
// shows on every row, so the results can be scanned without moving the
|
|
475
|
+
// selection through them. It stays muted and small so the label is read
|
|
476
|
+
// first, and it truncates before the label does (at most 45% of the row).
|
|
477
|
+
function CommandItemDetail({
|
|
478
|
+
className,
|
|
479
|
+
...props
|
|
480
|
+
}: React.ComponentProps<"span">) {
|
|
481
|
+
return (
|
|
482
|
+
<span
|
|
483
|
+
data-slot="command-item-detail"
|
|
484
|
+
className={cn(
|
|
485
|
+
"text-muted-foreground ms-auto max-w-[45%] min-w-0 truncate ps-3 text-xs",
|
|
190
486
|
className
|
|
191
487
|
)}
|
|
192
488
|
{...props}
|
|
@@ -194,6 +490,30 @@ function CommandShortcut({
|
|
|
194
490
|
)
|
|
195
491
|
}
|
|
196
492
|
|
|
493
|
+
// Key hints under the list. Each direct child is one hint: Kbd keys and a
|
|
494
|
+
// label. The keys render at 18px here. `end` is a hint set apart at the right
|
|
495
|
+
// end of the footer, such as the key that toggles the palette.
|
|
496
|
+
function CommandFooter({
|
|
497
|
+
className,
|
|
498
|
+
children,
|
|
499
|
+
end,
|
|
500
|
+
...props
|
|
501
|
+
}: React.ComponentProps<"div"> & { end?: React.ReactNode }) {
|
|
502
|
+
return (
|
|
503
|
+
<div
|
|
504
|
+
data-slot="command-footer"
|
|
505
|
+
className={cn(
|
|
506
|
+
"border-border bg-muted/50 text-muted-foreground flex h-10 shrink-0 items-center gap-4 border-t px-3.5 text-xs *:flex *:items-center *:gap-1 **:data-[slot=kbd]:h-4.5 **:data-[slot=kbd]:min-w-4.5",
|
|
507
|
+
className
|
|
508
|
+
)}
|
|
509
|
+
{...props}
|
|
510
|
+
>
|
|
511
|
+
{children}
|
|
512
|
+
{end != null && <span data-slot="command-footer-end" className="ms-auto">{end}</span>}
|
|
513
|
+
</div>
|
|
514
|
+
)
|
|
515
|
+
}
|
|
516
|
+
|
|
197
517
|
export {
|
|
198
518
|
Command,
|
|
199
519
|
CommandDialog,
|
|
@@ -202,6 +522,9 @@ export {
|
|
|
202
522
|
CommandEmpty,
|
|
203
523
|
CommandGroup,
|
|
204
524
|
CommandItem,
|
|
525
|
+
CommandItemLabel,
|
|
205
526
|
CommandShortcut,
|
|
527
|
+
CommandItemDetail,
|
|
206
528
|
CommandSeparator,
|
|
529
|
+
CommandFooter,
|
|
207
530
|
}
|
|
@@ -4,7 +4,11 @@ import * as React from "react"
|
|
|
4
4
|
import { ContextMenu as ContextMenuPrimitive } from "@base-ui/react/context-menu"
|
|
5
5
|
|
|
6
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
|
-
import {
|
|
7
|
+
import { popupMotion } from "../../lib/popup-motion.ts"
|
|
8
|
+
import { ChevronRightIcon } from "lucide-react"
|
|
9
|
+
import { usePopupDir } from "../../lib/popup-direction.ts"
|
|
10
|
+
import { triggerSlot } from "../../lib/trigger-slot.ts"
|
|
11
|
+
import { menuCheckItem, menuItemDisabled, menuRadioItem, MenuCheck } from "../../lib/menu-item.tsx"
|
|
8
12
|
|
|
9
13
|
function ContextMenu({ ...props }: ContextMenuPrimitive.Root.Props) {
|
|
10
14
|
return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />
|
|
@@ -22,7 +26,7 @@ function ContextMenuTrigger({
|
|
|
22
26
|
}: ContextMenuPrimitive.Trigger.Props) {
|
|
23
27
|
return (
|
|
24
28
|
<ContextMenuPrimitive.Trigger
|
|
25
|
-
|
|
29
|
+
{...triggerSlot("context-menu-trigger", props.render)}
|
|
26
30
|
className={cn("select-none", className)}
|
|
27
31
|
{...props}
|
|
28
32
|
/>
|
|
@@ -41,9 +45,11 @@ function ContextMenuContent({
|
|
|
41
45
|
ContextMenuPrimitive.Positioner.Props,
|
|
42
46
|
"align" | "alignOffset" | "side" | "sideOffset"
|
|
43
47
|
>) {
|
|
48
|
+
const dir = usePopupDir()
|
|
44
49
|
return (
|
|
45
50
|
<ContextMenuPrimitive.Portal>
|
|
46
51
|
<ContextMenuPrimitive.Positioner
|
|
52
|
+
dir={dir}
|
|
47
53
|
className="isolate z-50 outline-none"
|
|
48
54
|
align={align}
|
|
49
55
|
alignOffset={alignOffset}
|
|
@@ -52,7 +58,7 @@ function ContextMenuContent({
|
|
|
52
58
|
>
|
|
53
59
|
<ContextMenuPrimitive.Popup
|
|
54
60
|
data-slot="context-menu-content"
|
|
55
|
-
className={cn("
|
|
61
|
+
className={cn("bg-popover text-popover-foreground shadow-overlay rounded-xl p-1.25 z-50 max-h-(--available-height) min-w-36 overflow-x-hidden overflow-y-auto outline-none", popupMotion, className )}
|
|
56
62
|
{...props}
|
|
57
63
|
/>
|
|
58
64
|
</ContextMenuPrimitive.Positioner>
|
|
@@ -78,7 +84,7 @@ function ContextMenuLabel({
|
|
|
78
84
|
data-slot="context-menu-label"
|
|
79
85
|
data-inset={inset}
|
|
80
86
|
className={cn(
|
|
81
|
-
"text-muted-foreground px-2 py-1.5 text-xs font-medium data-inset:
|
|
87
|
+
"text-muted-foreground px-2 py-1.5 text-xs font-medium data-inset:ps-8",
|
|
82
88
|
className
|
|
83
89
|
)}
|
|
84
90
|
{...props}
|
|
@@ -101,7 +107,8 @@ function ContextMenuItem({
|
|
|
101
107
|
data-inset={inset}
|
|
102
108
|
data-variant={variant}
|
|
103
109
|
className={cn(
|
|
104
|
-
|
|
110
|
+
menuItemDisabled,
|
|
111
|
+
"not-data-disabled:focus:bg-muted not-data-disabled:focus:text-accent-foreground data-[variant=destructive]:text-destructive-text data-[variant=destructive]:not-data-disabled:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive-text data-[variant=destructive]:*:[svg]:text-destructive-text data-[variant=destructive]:[&>svg:not([class*='opacity-'])]:opacity-100 not-data-[variant=destructive]:not-data-disabled:focus:*:[svg]:text-accent-foreground group/context-menu-item relative flex min-h-8.5 cursor-default items-center gap-2 rounded-lg px-2 py-1.5 text-sm text-foreground-secondary outline-hidden select-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring data-inset:ps-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75] [&>svg:not([class*='opacity-'])]:opacity-55 [&>svg:not([class*='opacity-'])]:transition-opacity [&>svg:not([class*='opacity-'])]:duration-moderate not-data-disabled:focus:[&>svg:not([class*='opacity-'])]:opacity-85",
|
|
105
112
|
className
|
|
106
113
|
)}
|
|
107
114
|
{...props}
|
|
@@ -128,13 +135,14 @@ function ContextMenuSubTrigger({
|
|
|
128
135
|
data-slot="context-menu-sub-trigger"
|
|
129
136
|
data-inset={inset}
|
|
130
137
|
className={cn(
|
|
131
|
-
|
|
138
|
+
menuItemDisabled,
|
|
139
|
+
"not-data-disabled:focus:bg-muted not-data-disabled:focus:text-accent-foreground data-popup-open:bg-muted data-popup-open:text-accent-foreground relative flex min-h-8.5 cursor-default items-center gap-2 rounded-lg px-2 py-1.5 text-sm text-foreground-secondary outline-hidden select-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring data-inset:ps-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75] [&>svg:not([class*='opacity-'])]:opacity-55 [&>svg:not([class*='opacity-'])]:transition-opacity [&>svg:not([class*='opacity-'])]:duration-moderate not-data-disabled:focus:[&>svg:not([class*='opacity-'])]:opacity-85",
|
|
132
140
|
className
|
|
133
141
|
)}
|
|
134
142
|
{...props}
|
|
135
143
|
>
|
|
136
144
|
{children}
|
|
137
|
-
<ChevronRightIcon className="
|
|
145
|
+
<ChevronRightIcon className="ms-auto rtl:rotate-180" />
|
|
138
146
|
</ContextMenuPrimitive.SubmenuTrigger>
|
|
139
147
|
)
|
|
140
148
|
}
|
|
@@ -145,8 +153,7 @@ function ContextMenuSubContent({
|
|
|
145
153
|
return (
|
|
146
154
|
<ContextMenuContent
|
|
147
155
|
data-slot="context-menu-sub-content"
|
|
148
|
-
|
|
149
|
-
side="right"
|
|
156
|
+
side="inline-end"
|
|
150
157
|
{...props}
|
|
151
158
|
/>
|
|
152
159
|
)
|
|
@@ -166,17 +173,16 @@ function ContextMenuCheckboxItem({
|
|
|
166
173
|
data-slot="context-menu-checkbox-item"
|
|
167
174
|
data-inset={inset}
|
|
168
175
|
className={cn(
|
|
169
|
-
|
|
176
|
+
menuItemDisabled,
|
|
177
|
+
menuCheckItem,
|
|
178
|
+
"not-data-disabled:focus:bg-muted not-data-disabled:focus:text-accent-foreground relative flex min-h-8.5 cursor-default items-center gap-2 rounded-lg px-2 py-1.5 text-sm text-foreground-secondary outline-hidden select-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring data-inset:ps-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75] [&>svg:not([class*='opacity-'])]:opacity-55 [&>svg:not([class*='opacity-'])]:transition-opacity [&>svg:not([class*='opacity-'])]:duration-moderate not-data-disabled:focus:[&>svg:not([class*='opacity-'])]:opacity-85 pe-8",
|
|
170
179
|
className
|
|
171
180
|
)}
|
|
172
181
|
checked={checked}
|
|
173
182
|
{...props}
|
|
174
183
|
>
|
|
175
|
-
<span className="pointer-events-none absolute
|
|
176
|
-
<
|
|
177
|
-
<CheckIcon
|
|
178
|
-
/>
|
|
179
|
-
</ContextMenuPrimitive.CheckboxItemIndicator>
|
|
184
|
+
<span className="pointer-events-none absolute end-2 flex items-center justify-center">
|
|
185
|
+
<MenuCheck />
|
|
180
186
|
</span>
|
|
181
187
|
{children}
|
|
182
188
|
</ContextMenuPrimitive.CheckboxItem>
|
|
@@ -207,16 +213,15 @@ function ContextMenuRadioItem({
|
|
|
207
213
|
data-slot="context-menu-radio-item"
|
|
208
214
|
data-inset={inset}
|
|
209
215
|
className={cn(
|
|
210
|
-
|
|
216
|
+
menuItemDisabled,
|
|
217
|
+
menuRadioItem,
|
|
218
|
+
"not-data-disabled:focus:bg-muted not-data-disabled:focus:text-accent-foreground relative flex min-h-8.5 cursor-default items-center gap-2 rounded-lg px-2 py-1.5 text-sm text-foreground-secondary outline-hidden select-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring data-inset:ps-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75] [&>svg:not([class*='opacity-'])]:opacity-55 [&>svg:not([class*='opacity-'])]:transition-opacity [&>svg:not([class*='opacity-'])]:duration-moderate not-data-disabled:focus:[&>svg:not([class*='opacity-'])]:opacity-85 pe-8",
|
|
211
219
|
className
|
|
212
220
|
)}
|
|
213
221
|
{...props}
|
|
214
222
|
>
|
|
215
|
-
<span className="pointer-events-none absolute
|
|
216
|
-
<
|
|
217
|
-
<CheckIcon
|
|
218
|
-
/>
|
|
219
|
-
</ContextMenuPrimitive.RadioItemIndicator>
|
|
223
|
+
<span className="pointer-events-none absolute end-2 flex items-center justify-center">
|
|
224
|
+
<MenuCheck />
|
|
220
225
|
</span>
|
|
221
226
|
{children}
|
|
222
227
|
</ContextMenuPrimitive.RadioItem>
|
|
@@ -230,7 +235,7 @@ function ContextMenuSeparator({
|
|
|
230
235
|
return (
|
|
231
236
|
<ContextMenuPrimitive.Separator
|
|
232
237
|
data-slot="context-menu-separator"
|
|
233
|
-
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
|
238
|
+
className={cn("bg-border -mx-1.25 my-1.25 h-px", className)}
|
|
234
239
|
{...props}
|
|
235
240
|
/>
|
|
236
241
|
)
|
|
@@ -244,7 +249,7 @@ function ContextMenuShortcut({
|
|
|
244
249
|
<span
|
|
245
250
|
data-slot="context-menu-shortcut"
|
|
246
251
|
className={cn(
|
|
247
|
-
"text-muted-foreground group-focus/context-menu-item:text-accent-foreground
|
|
252
|
+
"text-muted-foreground group-focus/context-menu-item:text-accent-foreground ms-auto text-xs tracking-widest",
|
|
248
253
|
className
|
|
249
254
|
)}
|
|
250
255
|
{...props}
|