@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
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { Tooltip, TooltipContent, TooltipTrigger } from '@vendure-io/ui/components/atoms/tooltip';
|
|
4
3
|
import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
|
|
5
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type FormatRelativeOptions,
|
|
6
|
+
formatRelative,
|
|
7
|
+
formatRelativeDuration,
|
|
8
|
+
} from '@vendure-io/ui/lib/format-relative';
|
|
6
9
|
import { cn } from '@vendure-io/ui/lib/utils';
|
|
7
10
|
import { type ComponentProps, type ReactNode, useEffect, useId, useState } from 'react';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (value === null || value === undefined) return null;
|
|
11
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
12
|
-
return Number.isNaN(date.getTime()) ? null : date;
|
|
13
|
-
}
|
|
11
|
+
// Relative: `time-tooltip` is internal.
|
|
12
|
+
import { TimeSpan, TimeTooltip, toTime, useReadersClock } from './time-tooltip.tsx';
|
|
14
13
|
|
|
15
14
|
interface RelativeTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
|
|
16
15
|
value: string | number | Date | null | undefined;
|
|
@@ -23,33 +22,57 @@ interface RelativeTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
|
|
|
23
22
|
* already re-renders (e.g. a polling query drives it).
|
|
24
23
|
*/
|
|
25
24
|
updateInterval?: number | false;
|
|
26
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Rendered for nullish/invalid input, and on the server and the first client
|
|
27
|
+
* render of a server-rendered page (the server has no reader's clock).
|
|
28
|
+
* Default `'—'`.
|
|
29
|
+
*/
|
|
27
30
|
fallback?: ReactNode;
|
|
28
31
|
/**
|
|
29
|
-
*
|
|
30
|
-
* `
|
|
31
|
-
*
|
|
32
|
-
*
|
|
32
|
+
* What the text says.
|
|
33
|
+
* - `relative` (default): how long ago or how far ahead: `2 minutes ago`.
|
|
34
|
+
* - `duration`: how long a state that continues has lasted: `13 days`. The
|
|
35
|
+
* same unit steps as `relative` (seconds, minutes, hours, days, months,
|
|
36
|
+
* years), in the reader's locale. The caller adds the words around it
|
|
37
|
+
* (`for 13 days`), so they are translated with the rest of the page.
|
|
33
38
|
*/
|
|
34
|
-
|
|
39
|
+
display?: 'relative' | 'duration';
|
|
40
|
+
/**
|
|
41
|
+
* When the thing that ended at `value` started. The default tooltip then
|
|
42
|
+
* shows the range from `start` to `value` and how long it took:
|
|
43
|
+
* `11/11/2026, 10:14:47 – 10:15:29 AM` over `42s`.
|
|
44
|
+
*/
|
|
45
|
+
start?: string | number | Date | null;
|
|
46
|
+
/**
|
|
47
|
+
* The tooltip on hover and focus. Default `true`: the absolute time (or the
|
|
48
|
+
* range, with `start`). Pass content to show that instead, or `false` where
|
|
49
|
+
* the time sits inside another tooltip trigger, so the outer tooltip keeps
|
|
50
|
+
* its content. The tooltip content stays the accessible description either
|
|
51
|
+
* way.
|
|
52
|
+
*/
|
|
53
|
+
tooltip?: boolean | ReactNode;
|
|
35
54
|
/**
|
|
36
55
|
* Make the time a tab stop so keyboard users can open the tooltip. Default
|
|
37
|
-
* `false
|
|
38
|
-
*
|
|
56
|
+
* `false`, and `true` under a status label (a StatusBadge `detail`). Opt in
|
|
57
|
+
* where the exact time matters to keyboard users, and never inside
|
|
58
|
+
* interactive content such as a link or a button. Needs `tooltip`.
|
|
39
59
|
*/
|
|
40
60
|
focusable?: boolean;
|
|
41
61
|
}
|
|
42
62
|
|
|
43
63
|
/**
|
|
44
|
-
* SSR
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* props) so the absolute description matches too.
|
|
64
|
+
* SSR: the text depends on the reader's clock, locale and time zone, so the
|
|
65
|
+
* server renders `fallback` and an empty description, and so does the first
|
|
66
|
+
* client render during hydration: the two match. The text shows right after.
|
|
67
|
+
* In an app that renders only in the browser it shows from the first paint.
|
|
49
68
|
*
|
|
50
69
|
* The absolute time is never a native `title`. It is the accessible
|
|
51
70
|
* description (a hidden child linked by `aria-describedby`), and it shows in
|
|
52
71
|
* the DS Tooltip on hover unless `tooltip={false}`.
|
|
72
|
+
*
|
|
73
|
+
* Under a status label (a StatusBadge `detail`) the time is a tab stop, and
|
|
74
|
+
* its tooltip opens beside the whole status block, so the label stays
|
|
75
|
+
* readable.
|
|
53
76
|
*/
|
|
54
77
|
function RelativeTime({
|
|
55
78
|
value,
|
|
@@ -58,8 +81,10 @@ function RelativeTime({
|
|
|
58
81
|
unitStyle,
|
|
59
82
|
updateInterval = 60_000,
|
|
60
83
|
fallback = '—',
|
|
84
|
+
display = 'relative',
|
|
85
|
+
start,
|
|
61
86
|
tooltip = true,
|
|
62
|
-
focusable
|
|
87
|
+
focusable,
|
|
63
88
|
...props
|
|
64
89
|
}: RelativeTimeProps) {
|
|
65
90
|
const descriptionId = useId();
|
|
@@ -67,16 +92,13 @@ function RelativeTime({
|
|
|
67
92
|
// A bare counter to force a re-format on each tick; the value itself is unused.
|
|
68
93
|
const [, tick] = useState(0);
|
|
69
94
|
|
|
70
|
-
const
|
|
95
|
+
const readersClock = useReadersClock();
|
|
96
|
+
const time = toTime(value);
|
|
97
|
+
const date = time === null ? null : new Date(time);
|
|
71
98
|
const hasDate = date !== null;
|
|
72
99
|
|
|
73
100
|
useEffect(() => {
|
|
74
|
-
if (!hasDate) return;
|
|
75
|
-
// SSR'd text can already be stale by the time hydration runs, so re-format
|
|
76
|
-
// once immediately — this also covers `updateInterval={false}`, which
|
|
77
|
-
// otherwise never refreshes on its own.
|
|
78
|
-
tick((n) => n + 1);
|
|
79
|
-
if (updateInterval === false) return;
|
|
101
|
+
if (!hasDate || updateInterval === false) return;
|
|
80
102
|
const id = setInterval(() => tick((n) => n + 1), updateInterval);
|
|
81
103
|
return () => clearInterval(id);
|
|
82
104
|
}, [updateInterval, hasDate]);
|
|
@@ -84,53 +106,60 @@ function RelativeTime({
|
|
|
84
106
|
if (!date) return <>{fallback}</>;
|
|
85
107
|
|
|
86
108
|
const resolvedLocale = locale ?? settings.locale;
|
|
87
|
-
const
|
|
88
|
-
const
|
|
109
|
+
const startTime = toTime(start);
|
|
110
|
+
const absolute =
|
|
111
|
+
startTime === null ? (
|
|
112
|
+
date.toLocaleString(resolvedLocale, { timeZone: settings.timeZone })
|
|
113
|
+
) : (
|
|
114
|
+
<TimeSpan
|
|
115
|
+
start={startTime}
|
|
116
|
+
end={date.getTime()}
|
|
117
|
+
locale={resolvedLocale}
|
|
118
|
+
timeZone={settings.timeZone}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
const custom = typeof tooltip !== 'boolean' && tooltip !== null && tooltip !== undefined;
|
|
122
|
+
const description = custom ? tooltip : absolute;
|
|
123
|
+
const text = !readersClock
|
|
124
|
+
? fallback
|
|
125
|
+
: display === 'duration'
|
|
126
|
+
? formatRelativeDuration(date, { locale: resolvedLocale, unitStyle })
|
|
127
|
+
: formatRelative(date, { locale: resolvedLocale, numeric, unitStyle });
|
|
89
128
|
const describedBy = [props['aria-describedby'], descriptionId].filter(Boolean).join(' ');
|
|
90
129
|
// The description is a `hidden` child, so the component renders one element.
|
|
91
130
|
// `hidden` keeps the text out of view and out of the reading flow;
|
|
92
131
|
// aria-describedby still resolves it.
|
|
93
132
|
const content = (
|
|
94
133
|
<>
|
|
95
|
-
{
|
|
96
|
-
<span id={descriptionId} hidden
|
|
97
|
-
{
|
|
134
|
+
{text}
|
|
135
|
+
<span id={descriptionId} hidden>
|
|
136
|
+
{readersClock ? description : null}
|
|
98
137
|
</span>
|
|
99
138
|
</>
|
|
100
139
|
);
|
|
101
140
|
const timeProps = {
|
|
102
141
|
'data-slot': 'relative-time',
|
|
103
142
|
dateTime: date.toISOString(),
|
|
104
|
-
suppressHydrationWarning: true,
|
|
105
143
|
...props,
|
|
144
|
+
className: cn('tabular-nums', props.className),
|
|
106
145
|
'aria-describedby': describedBy,
|
|
107
146
|
};
|
|
108
147
|
|
|
109
|
-
if (
|
|
148
|
+
if (tooltip === false || tooltip === null) return <time {...timeProps}>{content}</time>;
|
|
110
149
|
|
|
111
150
|
return (
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
<time
|
|
116
|
-
// Opt-in tab stop so keyboard users can open the tooltip (WCAG 2.1.1).
|
|
117
|
-
tabIndex={focusable ? 0 : undefined}
|
|
118
|
-
{...timeProps}
|
|
119
|
-
className={cn(
|
|
120
|
-
focusable &&
|
|
121
|
-
'focus-visible:ring-ring/50 rounded-sm outline-none focus-visible:ring-3',
|
|
122
|
-
props.className,
|
|
123
|
-
)}
|
|
124
|
-
/>
|
|
125
|
-
}
|
|
126
|
-
>
|
|
127
|
-
{content}
|
|
128
|
-
</TooltipTrigger>
|
|
129
|
-
<TooltipContent>{absolute}</TooltipContent>
|
|
130
|
-
</Tooltip>
|
|
151
|
+
<TimeTooltip content={description} focusable={focusable} render={<time {...timeProps} />}>
|
|
152
|
+
{content}
|
|
153
|
+
</TimeTooltip>
|
|
131
154
|
);
|
|
132
155
|
}
|
|
133
156
|
|
|
134
157
|
// Re-exported so the spike's import surface (molecules/relative-time) keeps
|
|
135
158
|
// working; the implementation lives in lib/ per the JSX-or-lib rule.
|
|
136
|
-
export {
|
|
159
|
+
export {
|
|
160
|
+
RelativeTime,
|
|
161
|
+
formatRelative,
|
|
162
|
+
formatRelativeDuration,
|
|
163
|
+
type RelativeTimeProps,
|
|
164
|
+
type FormatRelativeOptions,
|
|
165
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Kbd } from '@vendure-io/ui/components/atoms/kbd';
|
|
4
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
5
|
+
import { SearchIcon } from 'lucide-react';
|
|
6
|
+
import type * as React from 'react';
|
|
7
|
+
import { useSyncExternalStore } from 'react';
|
|
8
|
+
|
|
9
|
+
type SearchTriggerCollapse = 'md' | 'never' | 'always';
|
|
10
|
+
|
|
11
|
+
const subscribe = () => () => {};
|
|
12
|
+
|
|
13
|
+
// Apple platforms show ⌘, the rest show Ctrl. The server and the first
|
|
14
|
+
// hydration render have no platform, so they show Ctrl; React swaps in the
|
|
15
|
+
// client value right after hydration without a mismatch error.
|
|
16
|
+
function isApplePlatform() {
|
|
17
|
+
if (typeof navigator === 'undefined') return false;
|
|
18
|
+
const nav = navigator as Navigator & { userAgentData?: { platform?: string } };
|
|
19
|
+
const platform = nav.userAgentData?.platform || nav.platform || nav.userAgent;
|
|
20
|
+
return /mac|iphone|ipad|ipod/i.test(platform);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function useIsApplePlatform() {
|
|
24
|
+
return useSyncExternalStore(subscribe, isApplePlatform, () => false);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The v3 look: a button that looks like a field. 28px high, 220px wide, on
|
|
28
|
+
// the muted fill with a 1px inset hairline and the lg radius. The 13px text
|
|
29
|
+
// is `foreground-secondary`: muted text on the muted fill is under 4.5:1.
|
|
30
|
+
// The icon is 14px and quieter than the text (55%). Hover steps the fill up
|
|
31
|
+
// to `accent` in 120ms. No press scale: it is a field, not a button, to
|
|
32
|
+
// the eye. Focus is the system's 2px ring, 2px out.
|
|
33
|
+
const fieldClass = [
|
|
34
|
+
'group/search-trigger inline-flex h-7 w-55 shrink-0 cursor-pointer items-center gap-2 rounded-lg bg-muted ps-2.5 pe-1.5 text-sm text-foreground-secondary inset-ring inset-ring-border outline-none select-none',
|
|
35
|
+
'transition-colors duration-quick ease-soft hover:bg-accent',
|
|
36
|
+
'focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
|
|
37
|
+
'[&_svg]:pointer-events-none [&_svg]:shrink-0',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// Collapsed: a 28px ghost icon button, the size of the SidebarTrigger next
|
|
41
|
+
// to it on a narrow top bar. The label and the shortcut leave the box; the
|
|
42
|
+
// accessible name stays. `ps-0 pe-0`, not `px-0`: tailwind-merge does not
|
|
43
|
+
// let `px-0` override the field's `ps-*`/`pe-*`.
|
|
44
|
+
const collapsed = {
|
|
45
|
+
box: 'w-7 justify-center bg-transparent ps-0 pe-0 inset-ring-0 hover:bg-muted',
|
|
46
|
+
hidden: 'hidden',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const collapseClasses: Record<SearchTriggerCollapse, { box: string; hidden: string }> = {
|
|
50
|
+
md: {
|
|
51
|
+
box: 'max-md:w-7 max-md:justify-center max-md:bg-transparent max-md:ps-0 max-md:pe-0 max-md:inset-ring-0 max-md:hover:bg-muted',
|
|
52
|
+
hidden: 'max-md:hidden',
|
|
53
|
+
},
|
|
54
|
+
never: { box: '', hidden: '' },
|
|
55
|
+
always: collapsed,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
interface SearchTriggerProps extends Omit<React.ComponentProps<'button'>, 'children'> {
|
|
59
|
+
/** The placeholder word in the field. @default 'Search' */
|
|
60
|
+
label?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The letter of the shortcut that opens the palette. The trigger shows it
|
|
63
|
+
* after ⌘ on Apple platforms and after Ctrl elsewhere. It only shows the
|
|
64
|
+
* shortcut: the consumer binds the key, as it opens the palette. `null`
|
|
65
|
+
* shows no shortcut. @default 'K'
|
|
66
|
+
*/
|
|
67
|
+
shortcutKey?: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* When the field shrinks to an icon button.
|
|
70
|
+
* - `md` (default): below 768px, where the Sidebar turns into a sheet.
|
|
71
|
+
* - `never`: always the field.
|
|
72
|
+
* - `always`: always the icon button.
|
|
73
|
+
* @default 'md'
|
|
74
|
+
*/
|
|
75
|
+
collapse?: SearchTriggerCollapse;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The search field in a top bar. It is a button: a click opens the command
|
|
80
|
+
* palette (the consumer's `onClick`), and the shortcut that also opens it
|
|
81
|
+
* shows at the end.
|
|
82
|
+
*/
|
|
83
|
+
function SearchTrigger({
|
|
84
|
+
className,
|
|
85
|
+
label = 'Search',
|
|
86
|
+
shortcutKey = 'K',
|
|
87
|
+
collapse = 'md',
|
|
88
|
+
'aria-label': ariaLabel,
|
|
89
|
+
...props
|
|
90
|
+
}: SearchTriggerProps) {
|
|
91
|
+
const apple = useIsApplePlatform();
|
|
92
|
+
const { box, hidden } = collapseClasses[collapse];
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
data-slot="search-trigger"
|
|
98
|
+
aria-haspopup="dialog"
|
|
99
|
+
aria-label={ariaLabel ?? `${label} (command palette)`}
|
|
100
|
+
aria-keyshortcuts={
|
|
101
|
+
shortcutKey ? `${apple ? 'Meta' : 'Control'}+${shortcutKey.toUpperCase()}` : undefined
|
|
102
|
+
}
|
|
103
|
+
className={cn(fieldClass, box, className)}
|
|
104
|
+
{...props}
|
|
105
|
+
>
|
|
106
|
+
<SearchIcon
|
|
107
|
+
aria-hidden
|
|
108
|
+
className="size-3.5 stroke-[1.75] opacity-55 transition-opacity duration-quick ease-soft group-hover/search-trigger:opacity-85"
|
|
109
|
+
/>
|
|
110
|
+
<span className={cn('truncate', hidden)}>{label}</span>
|
|
111
|
+
{shortcutKey ? (
|
|
112
|
+
<Kbd
|
|
113
|
+
aria-hidden
|
|
114
|
+
className={cn(
|
|
115
|
+
'ms-auto h-4.5 bg-transparent text-foreground-secondary inset-ring-input',
|
|
116
|
+
hidden,
|
|
117
|
+
)}
|
|
118
|
+
>
|
|
119
|
+
{apple ? `⌘${shortcutKey.toUpperCase()}` : `Ctrl ${shortcutKey.toUpperCase()}`}
|
|
120
|
+
</Kbd>
|
|
121
|
+
) : null}
|
|
122
|
+
</button>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { SearchTrigger };
|
|
127
|
+
export type { SearchTriggerCollapse, SearchTriggerProps };
|
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
CopyButton,
|
|
7
7
|
type CopyButtonProps,
|
|
8
8
|
} from '@vendure-io/ui/components/molecules/copyable-text';
|
|
9
|
-
import { chipChromeClass } from '@vendure-io/ui/components/molecules/id-chip';
|
|
10
|
-
import {
|
|
9
|
+
import { chipChromeClass, chipIconButtonClass } from '@vendure-io/ui/components/molecules/id-chip';
|
|
10
|
+
import { VisibilityIcon } from '@vendure-io/ui/components/molecules/visibility-icon';
|
|
11
|
+
import { cn } from '@vendure-io/ui/lib/utils';
|
|
11
12
|
import type * as React from 'react';
|
|
12
13
|
import { useReducer, useRef } from 'react';
|
|
13
14
|
|
|
@@ -42,6 +43,16 @@ interface SecretValueProps extends Omit<React.ComponentProps<'span'>, 'children'
|
|
|
42
43
|
|
|
43
44
|
const MASK = '••••••••';
|
|
44
45
|
|
|
46
|
+
// The trailing buttons have the IdChip button look (`chipIconButtonClass`).
|
|
47
|
+
// Each one is its own control (the chip has two), so its icon brightens on
|
|
48
|
+
// its own hover, and its ::after widens the target to 21px.
|
|
49
|
+
const CHIP_BUTTON_CLASS = cn(
|
|
50
|
+
chipIconButtonClass,
|
|
51
|
+
'relative after:absolute after:-inset-1 hover:text-foreground',
|
|
52
|
+
'hover:[&>svg:not([role=status])]:opacity-100',
|
|
53
|
+
'hover:[&_[data-slot=copy-state-icon]:not([data-copied])>svg:first-child]:opacity-100',
|
|
54
|
+
);
|
|
55
|
+
|
|
45
56
|
type RevealState =
|
|
46
57
|
| { status: 'hidden' }
|
|
47
58
|
| { status: 'loading' }
|
|
@@ -118,7 +129,8 @@ function SecretValue({
|
|
|
118
129
|
data-slot="secret-value"
|
|
119
130
|
data-state={state.status}
|
|
120
131
|
role="group"
|
|
121
|
-
|
|
132
|
+
// The reveal button always ends the chip, so it always takes the 6px end.
|
|
133
|
+
className={chipChromeClass(true, className)}
|
|
122
134
|
{...props}
|
|
123
135
|
>
|
|
124
136
|
{/* The mask is fixed: no fake prefix or suffix. The value is visible text
|
|
@@ -127,12 +139,17 @@ function SecretValue({
|
|
|
127
139
|
// `whitespace-normal` lets the value wrap inside a `whitespace-nowrap`
|
|
128
140
|
// parent such as a TableCell, so a long value grows the row in height
|
|
129
141
|
// instead of widening the table.
|
|
130
|
-
|
|
142
|
+
// A secret reads left to right in a right-to-left page too.
|
|
143
|
+
<code
|
|
144
|
+
data-slot="secret-value-value"
|
|
145
|
+
dir="ltr"
|
|
146
|
+
className="min-w-0 break-all whitespace-normal"
|
|
147
|
+
>
|
|
131
148
|
{state.value}
|
|
132
149
|
</code>
|
|
133
150
|
) : (
|
|
134
151
|
<>
|
|
135
|
-
<code data-slot="secret-value-value" aria-hidden="true">
|
|
152
|
+
<code data-slot="secret-value-value" dir="ltr" aria-hidden="true">
|
|
136
153
|
{MASK}
|
|
137
154
|
</code>
|
|
138
155
|
<span className="sr-only">{hiddenLabel}</span>
|
|
@@ -146,14 +163,14 @@ function SecretValue({
|
|
|
146
163
|
aria-label={revealed ? hideLabel : showLabel}
|
|
147
164
|
aria-busy={loading || undefined}
|
|
148
165
|
aria-disabled={loading || undefined}
|
|
149
|
-
className=
|
|
166
|
+
className={CHIP_BUTTON_CLASS}
|
|
150
167
|
onClick={() => {
|
|
151
168
|
if (loading) return;
|
|
152
169
|
if (revealed) hide();
|
|
153
170
|
else void reveal();
|
|
154
171
|
}}
|
|
155
172
|
>
|
|
156
|
-
{loading ? <Spinner /> :
|
|
173
|
+
{loading ? <Spinner /> : <VisibilityIcon visible={!revealed} />}
|
|
157
174
|
</Button>
|
|
158
175
|
{copyable ? (
|
|
159
176
|
<CopyButton
|
|
@@ -163,14 +180,14 @@ function SecretValue({
|
|
|
163
180
|
onCopyError={onCopyError}
|
|
164
181
|
copyLabel={copyLabel}
|
|
165
182
|
copiedLabel={copiedLabel}
|
|
166
|
-
className=
|
|
183
|
+
className={CHIP_BUTTON_CLASS}
|
|
167
184
|
/>
|
|
168
185
|
) : null}
|
|
169
186
|
{state.status === 'error' ? (
|
|
170
187
|
<span
|
|
171
188
|
data-slot="secret-value-error"
|
|
172
189
|
role="alert"
|
|
173
|
-
className="text-destructive-subtle-foreground
|
|
190
|
+
className="text-destructive-subtle-foreground pe-1 font-sans"
|
|
174
191
|
>
|
|
175
192
|
{loadErrorMessage}
|
|
176
193
|
</span>
|
|
@@ -23,7 +23,7 @@ function SkipLink({
|
|
|
23
23
|
data-slot="skip-link"
|
|
24
24
|
href={href}
|
|
25
25
|
className={cn(
|
|
26
|
-
'bg-primary text-primary-foreground fixed top-3
|
|
26
|
+
'bg-primary text-primary-foreground fixed top-3 start-3 z-[100] -translate-y-20 rounded-md px-3 py-2 text-sm font-medium opacity-0 outline-none transition-[transform,opacity] duration-fast ease-out focus-visible:translate-y-0 focus-visible:opacity-100 focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-reduce:transition-opacity',
|
|
27
27
|
className,
|
|
28
28
|
)}
|
|
29
29
|
{...props}
|
|
@@ -7,13 +7,13 @@ import type { ComponentProps, ReactNode } from 'react';
|
|
|
7
7
|
// Delta color follows the outcome, not the direction: `goodWhen` says which
|
|
8
8
|
// way is good for this metric (revenue up vs. refund-rate down), and the token
|
|
9
9
|
// is derived from that, never a hardcoded green/red: good → success,
|
|
10
|
-
// bad → destructive, flat → muted. The
|
|
11
|
-
//
|
|
10
|
+
// bad → destructive, flat → muted. The `*-text` slots are the text-safe tone
|
|
11
|
+
// steps on every surface: the solid tones fall below 4.5:1 in dark mode.
|
|
12
12
|
const statCardDeltaVariants = cva('inline-flex items-center gap-0.5 text-xs font-medium', {
|
|
13
13
|
variants: {
|
|
14
14
|
outcome: {
|
|
15
|
-
good: 'text-success-
|
|
16
|
-
bad: 'text-destructive-
|
|
15
|
+
good: 'text-success-text',
|
|
16
|
+
bad: 'text-destructive-text',
|
|
17
17
|
flat: 'text-muted-foreground',
|
|
18
18
|
},
|
|
19
19
|
},
|
|
@@ -11,7 +11,10 @@ import { cn } from '@vendure-io/ui/lib/utils';
|
|
|
11
11
|
|
|
12
12
|
// `title` is redefined as `ReactNode`, so drop the native string `title` attr.
|
|
13
13
|
export interface EmptyStateProps extends Omit<React.ComponentProps<typeof Empty>, 'title'> {
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Leading icon element, drawn bare: 28px, a light stroke and 40% opacity.
|
|
16
|
+
* Ignored once `illustration` renders (see below).
|
|
17
|
+
*/
|
|
15
18
|
icon?: React.ReactNode;
|
|
16
19
|
/**
|
|
17
20
|
* Illustration rendered above the title, in place of `icon`. Defaults to
|
|
@@ -26,15 +29,17 @@ export interface EmptyStateProps extends Omit<React.ComponentProps<typeof Empty>
|
|
|
26
29
|
/** Actions/CTA — rendered in the content slot below the header. */
|
|
27
30
|
children?: React.ReactNode;
|
|
28
31
|
/**
|
|
29
|
-
* Draw
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
+
* Draw a dashed box around the state. Defaults to `false`: the state sits
|
|
33
|
+
* bare in its region. Set `true` for a drop zone or a slot that needs a
|
|
34
|
+
* visible outline.
|
|
32
35
|
*/
|
|
33
36
|
bordered?: boolean;
|
|
34
37
|
/**
|
|
35
|
-
* `compact` drops the illustration and
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
+
* `compact` drops the illustration and tightens the spacing. Use it with an
|
|
39
|
+
* `icon` inside a card, a secondary panel or a side column: the icon sits
|
|
40
|
+
* above a 14px title. Keep the `default` size with an illustration for a
|
|
41
|
+
* whole page or a whole list. Keep compact to a title, a description and at
|
|
42
|
+
* most one action. Defaults to `default`.
|
|
38
43
|
*/
|
|
39
44
|
size?: 'default' | 'compact';
|
|
40
45
|
}
|
|
@@ -44,9 +49,9 @@ export interface EmptyStateProps extends Omit<React.ComponentProps<typeof Empty>
|
|
|
44
49
|
* `Empty` atom's header/media/title/description/content stack that three
|
|
45
50
|
* codebases (custom-ui, ops-admin, dashboard-common) kept re-assembling inline.
|
|
46
51
|
*
|
|
47
|
-
* The
|
|
48
|
-
*
|
|
49
|
-
*
|
|
52
|
+
* The v3 look has no box: a bare icon, a 16px title and the copy. The `Empty`
|
|
53
|
+
* atom ships `border-dashed` but no `border` width, so the molecule adds
|
|
54
|
+
* `border` only when `bordered` asks for the dashed box.
|
|
50
55
|
*/
|
|
51
56
|
function EmptyState({
|
|
52
57
|
icon,
|
|
@@ -54,7 +59,7 @@ function EmptyState({
|
|
|
54
59
|
title,
|
|
55
60
|
description,
|
|
56
61
|
children,
|
|
57
|
-
bordered =
|
|
62
|
+
bordered = false,
|
|
58
63
|
size = 'default',
|
|
59
64
|
className,
|
|
60
65
|
...props
|
|
@@ -74,17 +79,30 @@ function EmptyState({
|
|
|
74
79
|
<Empty
|
|
75
80
|
data-slot="empty-state"
|
|
76
81
|
data-size={size}
|
|
77
|
-
className={cn(
|
|
82
|
+
className={cn(
|
|
83
|
+
// Unbordered clears the atom's dashed style, so a border the consumer
|
|
84
|
+
// adds through `className` is solid.
|
|
85
|
+
bordered ? 'border' : 'rounded-none border-solid',
|
|
86
|
+
compact && 'gap-3 p-6 py-10',
|
|
87
|
+
className,
|
|
88
|
+
)}
|
|
78
89
|
{...props}
|
|
79
90
|
>
|
|
80
|
-
<EmptyHeader>
|
|
91
|
+
<EmptyHeader className={cn(compact && 'gap-1')}>
|
|
81
92
|
{resolvedIllustration ? (
|
|
82
93
|
<EmptyMedia>{resolvedIllustration}</EmptyMedia>
|
|
83
|
-
) : icon
|
|
84
|
-
|
|
94
|
+
) : icon ? (
|
|
95
|
+
// 20px from the icon to the title in the default size.
|
|
96
|
+
<EmptyMedia variant="bare" className={cn(!compact && 'mb-3')}>
|
|
97
|
+
{icon}
|
|
98
|
+
</EmptyMedia>
|
|
99
|
+
) : null}
|
|
100
|
+
<EmptyTitle className={cn(compact && 'text-style-card-title leading-5.25')}>
|
|
101
|
+
{title}
|
|
102
|
+
</EmptyTitle>
|
|
103
|
+
{description ? (
|
|
104
|
+
<EmptyDescription className={cn(compact && 'text-sm')}>{description}</EmptyDescription>
|
|
85
105
|
) : null}
|
|
86
|
-
<EmptyTitle className={cn(compact && 'text-style-card-title')}>{title}</EmptyTitle>
|
|
87
|
-
{description ? <EmptyDescription>{description}</EmptyDescription> : null}
|
|
88
106
|
</EmptyHeader>
|
|
89
107
|
{children ? <EmptyContent className={cn(compact && 'gap-2')}>{children}</EmptyContent> : null}
|
|
90
108
|
</Empty>
|
|
@@ -14,8 +14,10 @@ import { TriangleAlertIcon } from 'lucide-react';
|
|
|
14
14
|
// `title` is redefined as `ReactNode`, so drop the native string `title` attr.
|
|
15
15
|
export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>, 'title'> {
|
|
16
16
|
/**
|
|
17
|
-
* Leading icon,
|
|
18
|
-
*
|
|
17
|
+
* Leading icon, drawn bare like EmptyState's: 28px and a light stroke, in
|
|
18
|
+
* the `text-destructive-text` tone. Defaults to an alert triangle. In a
|
|
19
|
+
* `compact` state only an explicit icon renders. Ignored once
|
|
20
|
+
* `illustration` renders (see below).
|
|
19
21
|
*/
|
|
20
22
|
icon?: React.ReactNode;
|
|
21
23
|
/**
|
|
@@ -35,20 +37,22 @@ export interface ErrorStateProps extends Omit<React.ComponentProps<typeof Empty>
|
|
|
35
37
|
/** Extra actions (e.g. a not-found "Go back" link) rendered beside retry. */
|
|
36
38
|
children?: React.ReactNode;
|
|
37
39
|
/**
|
|
38
|
-
* Draw the
|
|
39
|
-
*
|
|
40
|
+
* Draw a dashed box around the state. Defaults to `false`: the state sits
|
|
41
|
+
* bare in its region, like EmptyState. Set `true` for a slot that needs a
|
|
42
|
+
* visible outline.
|
|
40
43
|
*/
|
|
41
44
|
bordered?: boolean;
|
|
42
45
|
/**
|
|
43
|
-
* `compact` drops the illustration and
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
+
* `compact` drops the illustration and tightens the spacing, for a small
|
|
47
|
+
* panel or side column where the full state is too tall. An explicit `icon`
|
|
48
|
+
* sits above a 14px title. Keep it to a title, a
|
|
49
|
+
* description and at most one action. Defaults to `default`.
|
|
46
50
|
*/
|
|
47
51
|
size?: 'default' | 'compact';
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
|
-
* The one canonical error presentation: a centered
|
|
55
|
+
* The one canonical error presentation: a centered state that carries semantics
|
|
52
56
|
* no atom has — `role="alert"`, a destructive-tinted icon (or illustration),
|
|
53
57
|
* and an optional retry CTA. Same anatomy as `EmptyState` so failed and empty
|
|
54
58
|
* states line up.
|
|
@@ -61,7 +65,7 @@ function ErrorState({
|
|
|
61
65
|
onRetry,
|
|
62
66
|
retryLabel = 'Try again',
|
|
63
67
|
children,
|
|
64
|
-
bordered =
|
|
68
|
+
bordered = false,
|
|
65
69
|
size = 'default',
|
|
66
70
|
className,
|
|
67
71
|
...props
|
|
@@ -76,26 +80,40 @@ function ErrorState({
|
|
|
76
80
|
) : icon === undefined ? (
|
|
77
81
|
<ErrorIllustration />
|
|
78
82
|
) : null;
|
|
79
|
-
|
|
83
|
+
// A compact state draws only an explicit icon: the default triangle stays
|
|
84
|
+
// off, so a compact error in a small panel keeps to its text and retry.
|
|
85
|
+
const resolvedIcon = compact ? icon : icon === undefined ? <TriangleAlertIcon /> : icon;
|
|
80
86
|
|
|
81
87
|
return (
|
|
82
88
|
<Empty
|
|
83
89
|
role="alert"
|
|
84
90
|
data-slot="error-state"
|
|
85
91
|
data-size={size}
|
|
86
|
-
className={cn(
|
|
92
|
+
className={cn(
|
|
93
|
+
// Unbordered clears the atom's dashed style, so a border the consumer
|
|
94
|
+
// adds through `className` is solid.
|
|
95
|
+
bordered ? 'border' : 'rounded-none border-solid',
|
|
96
|
+
compact && 'gap-3 p-6 py-10',
|
|
97
|
+
className,
|
|
98
|
+
)}
|
|
87
99
|
{...props}
|
|
88
100
|
>
|
|
89
|
-
<EmptyHeader>
|
|
101
|
+
<EmptyHeader className={cn(compact && 'gap-1')}>
|
|
90
102
|
{resolvedIllustration ? (
|
|
91
103
|
<EmptyMedia>{resolvedIllustration}</EmptyMedia>
|
|
92
104
|
) : resolvedIcon ? (
|
|
93
|
-
|
|
105
|
+
// 20px from the icon to the title in the default size.
|
|
106
|
+
<EmptyMedia
|
|
107
|
+
variant="bare"
|
|
108
|
+
className={cn('text-destructive-text opacity-100', !compact && 'mb-3')}
|
|
109
|
+
>
|
|
94
110
|
{resolvedIcon}
|
|
95
111
|
</EmptyMedia>
|
|
96
112
|
) : null}
|
|
97
113
|
<EmptyTitle className={cn(compact && 'text-style-card-title')}>{title}</EmptyTitle>
|
|
98
|
-
{description ?
|
|
114
|
+
{description ? (
|
|
115
|
+
<EmptyDescription className={cn(compact && 'text-sm')}>{description}</EmptyDescription>
|
|
116
|
+
) : null}
|
|
99
117
|
</EmptyHeader>
|
|
100
118
|
{onRetry || children ? (
|
|
101
119
|
<EmptyContent className={cn(compact && 'gap-2')}>
|