@vendure-io/ui 2.1.0 → 3.0.0-next.0
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 +73 -13
- package/src/components/atoms/avatar.tsx +1 -1
- package/src/components/atoms/badge.tsx +7 -2
- package/src/components/atoms/breadcrumb.tsx +137 -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 +147 -21
- package/src/components/atoms/command.tsx +414 -12
- package/src/components/atoms/context-menu.tsx +28 -23
- package/src/components/atoms/dialog.tsx +151 -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 +4 -0
- package/src/components/atoms/field.tsx +41 -15
- package/src/components/atoms/hover-card.tsx +61 -8
- package/src/components/atoms/input-group.tsx +17 -9
- 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 +82 -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 +23 -5
- 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 +59 -23
- package/src/components/atoms/sidebar.tsx +333 -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 +2 -2
- 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 +113 -9
- package/src/components/molecules/copyable-text.tsx +75 -11
- 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 +1 -1
- package/src/components/molecules/data-table/data-table-helpers.tsx +68 -1
- package/src/components/molecules/data-table/data-table-selection-storage.tsx +115 -0
- package/src/components/molecules/data-table/data-table-types.tsx +138 -4
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
- package/src/components/molecules/data-table/data-table.tsx +916 -84
- 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 +127 -0
- package/src/components/molecules/secret-value.tsx +26 -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 +32 -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 +104 -1
|
@@ -4,16 +4,42 @@ import * as React from "react"
|
|
|
4
4
|
import { Select as SelectPrimitive } from "@base-ui/react/select"
|
|
5
5
|
|
|
6
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
|
+
import { MenuCheck, menuCheckItem, menuItemDisabled } from "../../lib/menu-item.tsx"
|
|
8
|
+
import { fieldSurface } from "@vendure-io/ui/lib/field-surface"
|
|
9
|
+
import { popupMotion } from "../../lib/popup-motion.ts"
|
|
7
10
|
import { useFieldControlProps } from "@vendure-io/ui/components/atoms/field"
|
|
8
|
-
import { ChevronDownIcon,
|
|
11
|
+
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
|
12
|
+
import { usePopupDir } from "../../lib/popup-direction.ts"
|
|
13
|
+
import { usePopupAlign } from "../../lib/popup-align.ts"
|
|
14
|
+
import { nameFrom, useRegisteredRef } from "../../lib/control-name.ts"
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The trigger of the nearest Select. Base UI names the trigger but not the
|
|
18
|
+
* list, so SelectContent reads the trigger's name from here and gives it to
|
|
19
|
+
* the list.
|
|
20
|
+
*/
|
|
21
|
+
const SelectTriggerContext = React.createContext<{
|
|
22
|
+
trigger: HTMLElement | null
|
|
23
|
+
setTrigger: (trigger: HTMLElement | null) => void
|
|
24
|
+
} | null>(null)
|
|
25
|
+
|
|
26
|
+
function Select<Value, Multiple extends boolean | undefined = false>(
|
|
27
|
+
props: SelectPrimitive.Root.Props<Value, Multiple>
|
|
28
|
+
) {
|
|
29
|
+
const [trigger, setTrigger] = React.useState<HTMLElement | null>(null)
|
|
30
|
+
const context = React.useMemo(() => ({ trigger, setTrigger }), [trigger])
|
|
31
|
+
return (
|
|
32
|
+
<SelectTriggerContext.Provider value={context}>
|
|
33
|
+
<SelectPrimitive.Root {...props} />
|
|
34
|
+
</SelectTriggerContext.Provider>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
11
37
|
|
|
12
38
|
function SelectGroup({ className, ...props }: SelectPrimitive.Group.Props) {
|
|
13
39
|
return (
|
|
14
40
|
<SelectPrimitive.Group
|
|
15
41
|
data-slot="select-group"
|
|
16
|
-
className={cn("scroll-my-1
|
|
42
|
+
className={cn("scroll-my-1.25", className)}
|
|
17
43
|
{...props}
|
|
18
44
|
/>
|
|
19
45
|
)
|
|
@@ -23,7 +49,7 @@ function SelectValue({ className, ...props }: SelectPrimitive.Value.Props) {
|
|
|
23
49
|
return (
|
|
24
50
|
<SelectPrimitive.Value
|
|
25
51
|
data-slot="select-value"
|
|
26
|
-
className={cn("flex flex-1 text-
|
|
52
|
+
className={cn("flex flex-1 text-start", className)}
|
|
27
53
|
{...props}
|
|
28
54
|
/>
|
|
29
55
|
)
|
|
@@ -33,16 +59,20 @@ function SelectTrigger({
|
|
|
33
59
|
className,
|
|
34
60
|
size = "default",
|
|
35
61
|
children,
|
|
62
|
+
ref,
|
|
36
63
|
...props
|
|
37
64
|
}: SelectPrimitive.Trigger.Props & {
|
|
38
65
|
size?: "sm" | "default"
|
|
39
66
|
}) {
|
|
67
|
+
const triggerRef = useRegisteredRef(ref, React.useContext(SelectTriggerContext)?.setTrigger)
|
|
40
68
|
return (
|
|
41
69
|
<SelectPrimitive.Trigger
|
|
70
|
+
ref={triggerRef}
|
|
42
71
|
data-slot="select-trigger"
|
|
43
72
|
data-size={size}
|
|
44
73
|
className={cn(
|
|
45
|
-
|
|
74
|
+
fieldSurface,
|
|
75
|
+
"data-placeholder:text-faint-foreground flex w-fit items-center justify-between gap-1.5 px-2.5 py-2 text-sm whitespace-nowrap disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-8.5 data-[size=sm]:h-7 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
46
76
|
className
|
|
47
77
|
)}
|
|
48
78
|
{...useFieldControlProps(props)}
|
|
@@ -57,15 +87,193 @@ function SelectTrigger({
|
|
|
57
87
|
)
|
|
58
88
|
}
|
|
59
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Turns a `box-shadow` value into `drop-shadow()` filters. A 1px ring (no
|
|
92
|
+
* offset, no blur, a spread) becomes four 1px drop shadows, one per side.
|
|
93
|
+
* A drop shadow's blur is a standard deviation, half a box-shadow blur, and it
|
|
94
|
+
* has no spread: a soft shadow with a negative spread takes 0.4 of its blur
|
|
95
|
+
* and 60% of its colour instead, which matches `shadow-overlay` in light and
|
|
96
|
+
* dark within a few levels of grey.
|
|
97
|
+
*/
|
|
98
|
+
function shadowToFilter(shadow: string) {
|
|
99
|
+
const outside = /[,\s]+(?![^(]*\))/
|
|
100
|
+
return shadow
|
|
101
|
+
.split(/,(?![^(]*\))/)
|
|
102
|
+
.flatMap((layer) => {
|
|
103
|
+
const parts = layer.trim().split(outside).filter((part) => part && part !== "inset")
|
|
104
|
+
const isLength = (part: string) => /^-?[\d.]+(px)?$/.test(part)
|
|
105
|
+
const [x = 0, y = 0, blur = 0, spread = 0] = parts.filter(isLength).map(parseFloat)
|
|
106
|
+
const color = parts.filter((part) => !isLength(part)).join(" ")
|
|
107
|
+
if (!color) return []
|
|
108
|
+
if (!x && !y && !blur && spread > 0) {
|
|
109
|
+
return [`${spread}px 0`, `-${spread}px 0`, `0 ${spread}px`, `0 -${spread}px`].map(
|
|
110
|
+
(offset) => `drop-shadow(${offset} 0 ${color})`
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
if (spread < 0) {
|
|
114
|
+
const lighter = `color-mix(in oklab, ${color} 60%, transparent)`
|
|
115
|
+
return [`drop-shadow(${x}px ${y}px ${blur * 0.4}px ${lighter})`]
|
|
116
|
+
}
|
|
117
|
+
return [`drop-shadow(${x}px ${y}px ${blur / 2}px ${color})`]
|
|
118
|
+
})
|
|
119
|
+
.join(" ")
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A list that Base UI places over its trigger (`data-side="none"`) covers the
|
|
124
|
+
* trigger and grows out of it.
|
|
125
|
+
*
|
|
126
|
+
* Base UI moves the list so the selected item's text sits on the trigger's
|
|
127
|
+
* text. The item text is further in than the trigger text, so the list starts
|
|
128
|
+
* left of the trigger by the difference; at the trigger's width it then ends
|
|
129
|
+
* inside the trigger, and the trigger's edge and chevron show beside it. The
|
|
130
|
+
* list is made wider by that difference on both sides, so it overhangs the
|
|
131
|
+
* trigger evenly.
|
|
132
|
+
*
|
|
133
|
+
* `--select-trigger-box` is the trigger's box as a `clip-path` inset of the
|
|
134
|
+
* list. The list starts and ends clipped to it, so it opens out of the
|
|
135
|
+
* trigger and closes back into it. A `clip-path` also clips the list's own
|
|
136
|
+
* shadow, so the positioner draws the edge and the shadow as `drop-shadow`
|
|
137
|
+
* filters, which follow the clip.
|
|
138
|
+
*
|
|
139
|
+
* Base UI positions the list on each open, so this runs on every style
|
|
140
|
+
* change of the popup.
|
|
141
|
+
*/
|
|
142
|
+
/**
|
|
143
|
+
* Base UI puts the selected item on the trigger and cuts the list at the edge
|
|
144
|
+
* of the screen, so a short list near an edge shows a few items and scrolls
|
|
145
|
+
* ("10" selected at the bottom of the screen hides 20 to 100 below the edge).
|
|
146
|
+
* When the whole list fits on the screen, this moves it up or down just far
|
|
147
|
+
* enough to show every item, inside Base UI's 10px screen margin, and drops
|
|
148
|
+
* the scroll. It still covers the trigger: Base UI places a list over its
|
|
149
|
+
* trigger only when the trigger is at least 20px from the edges, and the list
|
|
150
|
+
* moves by no more than it ran past the edge. A list taller than the screen
|
|
151
|
+
* keeps Base UI's placement and scrolls.
|
|
152
|
+
*/
|
|
153
|
+
function fitOnScreen(positioner: HTMLElement, list: HTMLElement) {
|
|
154
|
+
const hidden = list.scrollHeight - list.clientHeight
|
|
155
|
+
if (hidden <= 1) return
|
|
156
|
+
const style = getComputedStyle(positioner)
|
|
157
|
+
const marginTop = parseFloat(style.marginTop) || 0
|
|
158
|
+
const marginBottom = parseFloat(style.marginBottom) || 0
|
|
159
|
+
const rect = positioner.getBoundingClientRect()
|
|
160
|
+
const height = rect.height + hidden
|
|
161
|
+
const screen = document.documentElement.clientHeight
|
|
162
|
+
if (height > screen - marginTop - marginBottom) return
|
|
163
|
+
// Where the list's first item would be if the list did not scroll: the
|
|
164
|
+
// selected item stays on the trigger as far as the screen allows.
|
|
165
|
+
const top = Math.min(
|
|
166
|
+
Math.max(rect.top - list.scrollTop, marginTop),
|
|
167
|
+
screen - marginBottom - height
|
|
168
|
+
)
|
|
169
|
+
// `top` positions the margin box: move by the difference from now.
|
|
170
|
+
const currentTop = parseFloat(style.top) || 0
|
|
171
|
+
positioner.style.top = `${currentTop + top - rect.top}px`
|
|
172
|
+
positioner.style.bottom = ""
|
|
173
|
+
positioner.style.height = `${height}px`
|
|
174
|
+
list.scrollTop = 0
|
|
175
|
+
// Base UI shows its scroll arrows from scroll events: a list that no
|
|
176
|
+
// longer scrolls hides them.
|
|
177
|
+
list.dispatchEvent(new Event("scroll"))
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function growFromTrigger(popup: HTMLElement | null) {
|
|
181
|
+
if (!popup) return () => {}
|
|
182
|
+
const positioner = popup.parentElement
|
|
183
|
+
let placed = ""
|
|
184
|
+
const place = () => {
|
|
185
|
+
if (popup.dataset.side !== "none") {
|
|
186
|
+
placed = ""
|
|
187
|
+
popup.style.removeProperty("min-width")
|
|
188
|
+
popup.style.removeProperty("--select-trigger-box")
|
|
189
|
+
positioner?.style.removeProperty("filter")
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
// A closing list keeps the box it opened from: a new box would turn the
|
|
193
|
+
// closing transition towards it.
|
|
194
|
+
if (popup.hasAttribute("data-ending-style") || popup.hasAttribute("data-closed")) return
|
|
195
|
+
const list = popup.querySelector<HTMLElement>("[role=listbox]")
|
|
196
|
+
const trigger = list?.id
|
|
197
|
+
? document.querySelector<HTMLElement>(`[aria-controls="${CSS.escape(list.id)}"]`)
|
|
198
|
+
: null
|
|
199
|
+
const value = trigger?.querySelector<HTMLElement>("[data-slot=select-value]")
|
|
200
|
+
const item =
|
|
201
|
+
popup.querySelector<HTMLElement>("[data-slot=select-item][data-selected]") ??
|
|
202
|
+
popup.querySelector<HTMLElement>("[data-slot=select-item]")
|
|
203
|
+
const text = item?.firstElementChild
|
|
204
|
+
if (!trigger || !value || !text || !popup.offsetWidth) return
|
|
205
|
+
if (positioner && list) fitOnScreen(positioner, list)
|
|
206
|
+
const rtl = getComputedStyle(popup).direction === "rtl"
|
|
207
|
+
const box = trigger.getBoundingClientRect()
|
|
208
|
+
const valueBox = value.getBoundingClientRect()
|
|
209
|
+
const textBox = text.getBoundingClientRect()
|
|
210
|
+
let popupBox = popup.getBoundingClientRect()
|
|
211
|
+
const overhang = Math.max(
|
|
212
|
+
0,
|
|
213
|
+
rtl
|
|
214
|
+
? popupBox.right - textBox.right - (box.right - valueBox.right)
|
|
215
|
+
: textBox.left - popupBox.left - (valueBox.left - box.left)
|
|
216
|
+
)
|
|
217
|
+
const minWidth = `calc(var(--anchor-width) + ${2 * overhang}px)`
|
|
218
|
+
if (popup.style.minWidth !== minWidth) popup.style.minWidth = minWidth
|
|
219
|
+
popupBox = popup.getBoundingClientRect()
|
|
220
|
+
const radius = getComputedStyle(trigger).borderTopLeftRadius
|
|
221
|
+
const inset = [
|
|
222
|
+
box.top - popupBox.top,
|
|
223
|
+
popupBox.right - box.right,
|
|
224
|
+
popupBox.bottom - box.bottom,
|
|
225
|
+
box.left - popupBox.left,
|
|
226
|
+
]
|
|
227
|
+
.map((side) => `${Math.round(side * 100) / 100}px`)
|
|
228
|
+
.join(" ")
|
|
229
|
+
const clip = `inset(${inset} round ${radius})`
|
|
230
|
+
// Writing a style is a style change, which runs this again: skip a write
|
|
231
|
+
// that would only repeat the last one.
|
|
232
|
+
if (clip === placed) return
|
|
233
|
+
placed = clip
|
|
234
|
+
popup.style.setProperty("--select-trigger-box", clip)
|
|
235
|
+
if (positioner) {
|
|
236
|
+
positioner.style.filter = shadowToFilter(
|
|
237
|
+
getComputedStyle(popup).getPropertyValue("--shadow-overlay")
|
|
238
|
+
)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const observer = new MutationObserver(place)
|
|
242
|
+
observer.observe(popup, { attributes: true, attributeFilter: ["style", "data-side", "data-closed"] })
|
|
243
|
+
place()
|
|
244
|
+
return () => observer.disconnect()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The motion of a list over its trigger. It has no side, so it drops the
|
|
249
|
+
* popup's 2px slide and its scale, and keeps its opacity at 1: from the first
|
|
250
|
+
* frame it covers the trigger. Its `clip-path` grows from the trigger's box
|
|
251
|
+
* (`--select-trigger-box`) to its own, with the popup's timings: `normal` on
|
|
252
|
+
* the strong ease-out to open, `quick` on `ease-soft` to close. A transition
|
|
253
|
+
* starts from where the last one stopped, so a list closed while it opens
|
|
254
|
+
* turns back from there. Reduced motion keeps only the popup's fade.
|
|
255
|
+
*/
|
|
256
|
+
const growFromTriggerMotion =
|
|
257
|
+
"data-[side=none]:shadow-none data-[side=none]:transition-[opacity,clip-path] data-[side=none]:[transition-duration:var(--transition-duration-popup-fade),var(--transition-duration-normal)] data-[side=none]:data-ending-style:duration-quick motion-safe:data-[side=none]:[clip-path:inset(0_round_var(--radius-xl))] motion-safe:data-[side=none]:data-starting-style:[clip-path:var(--select-trigger-box)] motion-safe:data-[side=none]:data-ending-style:[clip-path:var(--select-trigger-box)] motion-safe:data-[side=none]:data-starting-style:opacity-100 motion-safe:data-[side=none]:data-ending-style:opacity-100 motion-safe:data-[side=none]:data-starting-style:scale-100 motion-safe:data-[side=none]:data-ending-style:scale-100 motion-safe:data-[side=none]:data-starting-style:translate-y-0 motion-safe:data-[side=none]:data-ending-style:translate-y-0"
|
|
258
|
+
|
|
60
259
|
// min-w-(--anchor-width) rather than w-(--anchor-width) so the popup can expand beyond the trigger to fit content
|
|
260
|
+
/**
|
|
261
|
+
* By default the list opens over its trigger and grows out of it. A list
|
|
262
|
+
* that opens below or above its trigger (`alignItemWithTrigger={false}`, or
|
|
263
|
+
* when Base UI falls back for touch or a lack of room) opens toward the
|
|
264
|
+
* centre of the screen, as a DropdownMenu does: a trigger in the right half
|
|
265
|
+
* lines the list up with its right edge, one in the left half with its left
|
|
266
|
+
* edge. An explicit `align` always wins.
|
|
267
|
+
*/
|
|
61
268
|
function SelectContent({
|
|
62
269
|
className,
|
|
63
270
|
children,
|
|
64
271
|
side = "bottom",
|
|
65
272
|
sideOffset = 4,
|
|
66
|
-
align
|
|
273
|
+
align,
|
|
67
274
|
alignOffset = 0,
|
|
68
275
|
alignItemWithTrigger = true,
|
|
276
|
+
ref,
|
|
69
277
|
...props
|
|
70
278
|
}: SelectPrimitive.Popup.Props &
|
|
71
279
|
Pick<
|
|
@@ -91,24 +299,57 @@ function SelectContent({
|
|
|
91
299
|
[children]
|
|
92
300
|
)
|
|
93
301
|
|
|
302
|
+
const trigger = React.useContext(SelectTriggerContext)?.trigger ?? null
|
|
303
|
+
const getTrigger = React.useCallback(() => trigger, [trigger])
|
|
304
|
+
const { popupRef: alignRef, align: positionAlign } = usePopupAlign(align, side, undefined, getTrigger)
|
|
305
|
+
|
|
306
|
+
const popupRef = React.useCallback(
|
|
307
|
+
(node: HTMLDivElement | null) => {
|
|
308
|
+
alignRef(node)
|
|
309
|
+
const stop = growFromTrigger(node)
|
|
310
|
+
if (typeof ref === "function") ref(node)
|
|
311
|
+
else if (ref) ref.current = node
|
|
312
|
+
return () => {
|
|
313
|
+
stop()
|
|
314
|
+
if (typeof ref === "function") ref(null)
|
|
315
|
+
else if (ref) ref.current = null
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
[ref, alignRef]
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
const dir = usePopupDir()
|
|
94
322
|
return (
|
|
95
323
|
<SelectPrimitive.Portal key={childrenKey}>
|
|
96
324
|
<SelectPrimitive.Positioner
|
|
325
|
+
dir={dir}
|
|
97
326
|
side={side}
|
|
98
327
|
sideOffset={sideOffset}
|
|
99
|
-
align={
|
|
328
|
+
align={positionAlign}
|
|
100
329
|
alignOffset={alignOffset}
|
|
101
330
|
alignItemWithTrigger={alignItemWithTrigger}
|
|
102
|
-
|
|
331
|
+
// Base UI gives up on placing the list over its trigger when less
|
|
332
|
+
// than its min-height (100px by default) fits between the trigger
|
|
333
|
+
// and the edge, and opens it beside the trigger instead. 1px keeps
|
|
334
|
+
// the list over the trigger; `fitOnScreen` then moves it into view.
|
|
335
|
+
className="isolate z-50 min-h-px"
|
|
103
336
|
>
|
|
104
337
|
<SelectPrimitive.Popup
|
|
105
338
|
data-slot="select-content"
|
|
106
339
|
data-align-trigger={alignItemWithTrigger}
|
|
107
|
-
className={cn("bg-popover text-popover-foreground
|
|
340
|
+
className={cn("bg-popover text-popover-foreground shadow-overlay relative isolate z-50 max-h-(--available-height) min-w-(--anchor-width) overflow-x-hidden overflow-y-auto rounded-xl", popupMotion, growFromTriggerMotion, className)}
|
|
341
|
+
ref={popupRef}
|
|
342
|
+
// A closing list is gone for assistive technology: its trigger no
|
|
343
|
+
// longer points at it, and it takes no input while it fades out.
|
|
344
|
+
render={(popupProps, state) => (
|
|
345
|
+
<div {...popupProps} aria-hidden={state.open ? popupProps["aria-hidden"] : true} />
|
|
346
|
+
)}
|
|
108
347
|
{...props}
|
|
109
348
|
>
|
|
110
349
|
<SelectScrollUpButton />
|
|
111
|
-
<SelectPrimitive.List
|
|
350
|
+
<SelectPrimitive.List className="p-1.25" {...nameFrom(trigger, { orSelf: true })}>
|
|
351
|
+
{children}
|
|
352
|
+
</SelectPrimitive.List>
|
|
112
353
|
<SelectScrollDownButton />
|
|
113
354
|
</SelectPrimitive.Popup>
|
|
114
355
|
</SelectPrimitive.Positioner>
|
|
@@ -138,7 +379,9 @@ function SelectItem({
|
|
|
138
379
|
<SelectPrimitive.Item
|
|
139
380
|
data-slot="select-item"
|
|
140
381
|
className={cn(
|
|
141
|
-
|
|
382
|
+
menuItemDisabled,
|
|
383
|
+
menuCheckItem,
|
|
384
|
+
"not-data-disabled:focus:bg-muted not-data-disabled:focus:text-accent-foreground not-data-[variant=destructive]:not-data-disabled:focus:**:text-accent-foreground relative flex min-h-8.5 w-full cursor-default items-center gap-2 rounded-lg py-1.5 pe-8 ps-2 text-sm text-foreground-secondary data-selected:text-foreground outline-hidden select-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='stroke-'])]:stroke-[1.75] [&>:first-child>svg:not([class*='opacity-'])]:opacity-55 [&>:first-child>svg:not([class*='opacity-'])]:transition-opacity [&>:first-child>svg:not([class*='opacity-'])]:duration-moderate not-data-disabled:focus:[&>:first-child>svg:not([class*='opacity-'])]:opacity-85 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
|
142
385
|
className
|
|
143
386
|
)}
|
|
144
387
|
{...props}
|
|
@@ -146,13 +389,9 @@ function SelectItem({
|
|
|
146
389
|
<SelectPrimitive.ItemText className="flex flex-1 shrink-0 gap-2 whitespace-nowrap">
|
|
147
390
|
{children}
|
|
148
391
|
</SelectPrimitive.ItemText>
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
>
|
|
154
|
-
<CheckIcon className="pointer-events-none" />
|
|
155
|
-
</SelectPrimitive.ItemIndicator>
|
|
392
|
+
<span className="pointer-events-none absolute end-2 flex size-4 items-center justify-center">
|
|
393
|
+
<MenuCheck />
|
|
394
|
+
</span>
|
|
156
395
|
</SelectPrimitive.Item>
|
|
157
396
|
)
|
|
158
397
|
}
|
|
@@ -164,7 +403,7 @@ function SelectSeparator({
|
|
|
164
403
|
return (
|
|
165
404
|
<SelectPrimitive.Separator
|
|
166
405
|
data-slot="select-separator"
|
|
167
|
-
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
|
|
406
|
+
className={cn("bg-border pointer-events-none -mx-1.25 my-1.25 h-px", className)}
|
|
168
407
|
{...props}
|
|
169
408
|
/>
|
|
170
409
|
)
|
|
@@ -6,13 +6,16 @@ import { Dialog as SheetPrimitive } from "@base-ui/react/dialog"
|
|
|
6
6
|
import { cn } from "@vendure-io/ui/lib/utils"
|
|
7
7
|
import { Button } from "@vendure-io/ui/components/atoms/button"
|
|
8
8
|
import { XIcon } from "lucide-react"
|
|
9
|
+
import { usePopupDir } from "../../lib/popup-direction.ts"
|
|
10
|
+
import { usePinnedHeight } from "../../hooks/use-pinned-height.ts"
|
|
11
|
+
import { triggerSlot } from "../../lib/trigger-slot.ts"
|
|
9
12
|
|
|
10
13
|
function Sheet({ ...props }: SheetPrimitive.Root.Props) {
|
|
11
14
|
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
function SheetTrigger({ ...props }: SheetPrimitive.Trigger.Props) {
|
|
15
|
-
return <SheetPrimitive.Trigger
|
|
18
|
+
return <SheetPrimitive.Trigger {...triggerSlot("sheet-trigger", props.render)} {...props} />
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
function SheetClose({ ...props }: SheetPrimitive.Close.Props) {
|
|
@@ -28,7 +31,7 @@ function SheetOverlay({ className, ...props }: SheetPrimitive.Backdrop.Props) {
|
|
|
28
31
|
<SheetPrimitive.Backdrop
|
|
29
32
|
data-slot="sheet-overlay"
|
|
30
33
|
className={cn(
|
|
31
|
-
"
|
|
34
|
+
"fixed inset-0 z-50 bg-scrim transition-opacity duration-normal ease-drawer data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-fast supports-backdrop-filter:backdrop-blur-xs",
|
|
32
35
|
className
|
|
33
36
|
)}
|
|
34
37
|
{...props}
|
|
@@ -36,6 +39,29 @@ function SheetOverlay({ className, ...props }: SheetPrimitive.Backdrop.Props) {
|
|
|
36
39
|
)
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
// Tells SheetHeader to host the close button, so the ✕ stays pinned with the
|
|
43
|
+
// header while the body scrolls.
|
|
44
|
+
const SheetCloseButtonContext = React.createContext(false)
|
|
45
|
+
|
|
46
|
+
function SheetCloseButton({ className }: { className?: string }) {
|
|
47
|
+
return (
|
|
48
|
+
<SheetPrimitive.Close
|
|
49
|
+
data-slot="sheet-close"
|
|
50
|
+
render={
|
|
51
|
+
<Button
|
|
52
|
+
variant="ghost"
|
|
53
|
+
className={cn("absolute top-4 end-4", className)}
|
|
54
|
+
size="icon-sm"
|
|
55
|
+
/>
|
|
56
|
+
}
|
|
57
|
+
>
|
|
58
|
+
<XIcon
|
|
59
|
+
/>
|
|
60
|
+
<span className="sr-only">Close</span>
|
|
61
|
+
</SheetPrimitive.Close>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
39
65
|
function SheetContent({
|
|
40
66
|
className,
|
|
41
67
|
children,
|
|
@@ -46,55 +72,65 @@ function SheetContent({
|
|
|
46
72
|
side?: "top" | "right" | "bottom" | "left"
|
|
47
73
|
showCloseButton?: boolean
|
|
48
74
|
}) {
|
|
75
|
+
const dir = usePopupDir()
|
|
49
76
|
return (
|
|
50
77
|
<SheetPortal>
|
|
51
78
|
<SheetOverlay />
|
|
79
|
+
{/* A sheet taller than the viewport scrolls inside; SheetHeader and SheetFooter stick to its edges, and the scroll padding keeps a focused field clear of both. */}
|
|
52
80
|
<SheetPrimitive.Popup
|
|
81
|
+
dir={dir}
|
|
53
82
|
data-slot="sheet-content"
|
|
54
83
|
data-side={side}
|
|
55
84
|
className={cn(
|
|
56
|
-
"bg-overlay
|
|
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 data-[side=left]:sm:max-w-lg data-[side=right]:sm:max-w-lg",
|
|
57
86
|
className
|
|
58
87
|
)}
|
|
59
88
|
{...props}
|
|
60
89
|
>
|
|
61
|
-
{
|
|
90
|
+
<SheetCloseButtonContext.Provider value={showCloseButton}>
|
|
91
|
+
{children}
|
|
92
|
+
</SheetCloseButtonContext.Provider>
|
|
93
|
+
{/* A sheet without a SheetHeader keeps the ✕ here, in the corner. */}
|
|
62
94
|
{showCloseButton && (
|
|
63
|
-
<
|
|
64
|
-
data-slot="sheet-close"
|
|
65
|
-
render={
|
|
66
|
-
<Button
|
|
67
|
-
variant="ghost"
|
|
68
|
-
className="absolute top-4 right-4"
|
|
69
|
-
size="icon-sm"
|
|
70
|
-
/>
|
|
71
|
-
}
|
|
72
|
-
>
|
|
73
|
-
<XIcon
|
|
74
|
-
/>
|
|
75
|
-
<span className="sr-only">Close</span>
|
|
76
|
-
</SheetPrimitive.Close>
|
|
95
|
+
<SheetCloseButton className="group-has-data-[slot=sheet-header]/sheet-content:hidden" />
|
|
77
96
|
)}
|
|
78
97
|
</SheetPrimitive.Popup>
|
|
79
98
|
</SheetPortal>
|
|
80
99
|
)
|
|
81
100
|
}
|
|
82
101
|
|
|
83
|
-
|
|
102
|
+
// The header and the footer stick to the sheet's edges with its surface behind,
|
|
103
|
+
// so a scrolled body passes under them. Their own 16px padding keeps the body
|
|
104
|
+
// clear of their text. Each measures its height for the sheet's scroll padding.
|
|
105
|
+
function SheetHeader({ className, children, ref, ...props }: React.ComponentProps<"div">) {
|
|
106
|
+
const showCloseButton = React.useContext(SheetCloseButtonContext)
|
|
107
|
+
const pinnedRef = usePinnedHeight("--pinned-header-height", "sheet-content", ref)
|
|
84
108
|
return (
|
|
85
109
|
<div
|
|
110
|
+
ref={pinnedRef}
|
|
86
111
|
data-slot="sheet-header"
|
|
87
|
-
className={cn(
|
|
112
|
+
className={cn(
|
|
113
|
+
"bg-overlay sticky top-0 z-10 flex shrink-0 flex-col gap-1.5 p-4",
|
|
114
|
+
className
|
|
115
|
+
)}
|
|
88
116
|
{...props}
|
|
89
|
-
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
{showCloseButton && <SheetCloseButton />}
|
|
120
|
+
</div>
|
|
90
121
|
)
|
|
91
122
|
}
|
|
92
123
|
|
|
93
|
-
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
124
|
+
function SheetFooter({ className, ref, ...props }: React.ComponentProps<"div">) {
|
|
125
|
+
const pinnedRef = usePinnedHeight("--pinned-footer-height", "sheet-content", ref)
|
|
94
126
|
return (
|
|
95
127
|
<div
|
|
128
|
+
ref={pinnedRef}
|
|
96
129
|
data-slot="sheet-footer"
|
|
97
|
-
className={cn(
|
|
130
|
+
className={cn(
|
|
131
|
+
"bg-overlay sticky bottom-0 z-10 mt-auto flex shrink-0 flex-col gap-2 p-4",
|
|
132
|
+
className
|
|
133
|
+
)}
|
|
98
134
|
{...props}
|
|
99
135
|
/>
|
|
100
136
|
)
|