@vendure-io/ui 2.2.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 +59 -12
- 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 +121 -4
- package/src/components/molecules/data-table/data-table-view-options.tsx +2 -2
- package/src/components/molecules/data-table/data-table.tsx +837 -80
- 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
|
@@ -38,4 +38,32 @@ function formatRelative(
|
|
|
38
38
|
return rtf.format(0, 'second');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* How long ago an instant was, as a length of time: `13 days`, `5 hours`,
|
|
43
|
+
* `1 minute`. Use it for a state that continues, with the caller's own words
|
|
44
|
+
* around it (`for 13 days`). It takes the same unit steps and rounding as
|
|
45
|
+
* `formatRelative`, so `for 13 days` and `13 days ago` agree for one instant.
|
|
46
|
+
* The unit words come from `Intl.NumberFormat` in `locale`; `unitStyle` maps
|
|
47
|
+
* to its `unitDisplay` (`13 days`, `13 days`, `13d` in English). An instant
|
|
48
|
+
* ahead of now reads the same as one behind it.
|
|
49
|
+
*
|
|
50
|
+
* Unparseable input yields `0 seconds`, as `formatRelative` yields `now`.
|
|
51
|
+
*/
|
|
52
|
+
function formatRelativeDuration(
|
|
53
|
+
value: string | number | Date,
|
|
54
|
+
{ locale, unitStyle = 'long' }: Omit<FormatRelativeOptions, 'numeric'> = {},
|
|
55
|
+
): string {
|
|
56
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
57
|
+
const diff = date.getTime() - Date.now();
|
|
58
|
+
const signed = Number.isFinite(diff) ? diff : 0;
|
|
59
|
+
const step = UNITS.find(({ ms }) => Math.abs(signed) >= ms) ?? { unit: 'second', ms: 1000 };
|
|
60
|
+
// Round the signed delta, as formatRelative does, so a half step lands on
|
|
61
|
+
// the same number in both.
|
|
62
|
+
return new Intl.NumberFormat(locale, {
|
|
63
|
+
style: 'unit',
|
|
64
|
+
unit: step.unit,
|
|
65
|
+
unitDisplay: unitStyle,
|
|
66
|
+
}).format(Math.abs(Math.round(signed / step.ms)));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { formatRelative, formatRelativeDuration, type FormatRelativeOptions };
|
package/src/lib/highlight.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
transformerNotationHighlight,
|
|
6
6
|
transformerNotationWordHighlight,
|
|
7
7
|
} from '@shikijs/transformers';
|
|
8
|
+
import { githubLightReplacements } from '@vendure-io/ui/lib/syntax-colors';
|
|
8
9
|
import { createHighlighterCore } from 'shiki/core';
|
|
9
10
|
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
|
|
10
11
|
|
|
@@ -85,9 +86,8 @@ async function highlightCode(code: string, language: SupportedLanguage): Promise
|
|
|
85
86
|
light: 'github-light',
|
|
86
87
|
dark: 'github-dark-default',
|
|
87
88
|
},
|
|
88
|
-
// github-light's orange
|
|
89
|
-
|
|
90
|
-
colorReplacements: { 'github-light': { '#e36209': '#a35200' } },
|
|
89
|
+
// github-light's orange is too faint on a card; see syntax-colors.ts.
|
|
90
|
+
colorReplacements: { 'github-light': githubLightReplacements },
|
|
91
91
|
transformers: [
|
|
92
92
|
transformerNotationDiff({ matchAlgorithm: 'v3' }),
|
|
93
93
|
transformerNotationHighlight({ matchAlgorithm: 'v3' }),
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { cn } from './utils.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A disabled item of any menu, Select or Combobox dims all its content to
|
|
5
|
+
* half strength, not itself: an opacity on the item would dim its focus
|
|
6
|
+
* ring too, and the arrow keys still stop on it with the ring at full
|
|
7
|
+
* strength. The item's own text paints at half its colour
|
|
8
|
+
* (`-webkit-text-fill-color`, so its children do not take it). Every child
|
|
9
|
+
* shows at half through `filter: opacity()`, which stacks on the child's own
|
|
10
|
+
* opacity: a status dot, a detail, a shortcut, an icon and a check each dim
|
|
11
|
+
* by the same half from their rest look, whatever colour they bring.
|
|
12
|
+
*/
|
|
13
|
+
export const menuItemDisabled =
|
|
14
|
+
'data-disabled:pointer-events-none data-disabled:[-webkit-text-fill-color:color-mix(in_oklab,currentColor_50%,transparent)] data-disabled:*:[-webkit-text-fill-color:currentColor] data-disabled:*:[filter:opacity(50%)]';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The item of a dropdown menu, and of every menu built on it (Menubar,
|
|
18
|
+
* BreadcrumbMenu). Under the pointer or the arrow keys an item takes the
|
|
19
|
+
* muted fill, its text darkens and its icon strengthens. A disabled item
|
|
20
|
+
* takes none of that and dims its content (`menuItemDisabled`).
|
|
21
|
+
*/
|
|
22
|
+
export const menuItem = cn(
|
|
23
|
+
menuItemDisabled,
|
|
24
|
+
"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.5 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-3.75 [&_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",
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* An item that shows a `MenuCheck`: a checkbox item of a menu, and a Select
|
|
29
|
+
* or Combobox option. The check shows when the item is checked
|
|
30
|
+
* (`data-checked`) or selected (`data-selected`).
|
|
31
|
+
*/
|
|
32
|
+
export const menuCheckItem = 'group/menu-check';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The checked row of a radio group in a menu: semibold text in the
|
|
36
|
+
* foreground colour, and a `MenuCheck`.
|
|
37
|
+
*/
|
|
38
|
+
export const menuRadioItem = `${menuCheckItem} data-checked:text-foreground data-checked:font-semibold`;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The check of a checked row draws in: a path with pathLength 1 and a
|
|
42
|
+
* dash of 1, its offset easing from 1 to 0. The row that loses the check
|
|
43
|
+
* fades it out in `quick`, and its dash resets only after that, while
|
|
44
|
+
* hidden. A transition runs only on a change, so the menu opens with the
|
|
45
|
+
* check in place. With reduced motion the check only fades.
|
|
46
|
+
*/
|
|
47
|
+
const drawCheck =
|
|
48
|
+
'size-3.5 shrink-0 stroke-[1.75] opacity-0 [transition:opacity_var(--transition-duration-quick)_var(--ease-soft)] group-data-checked/menu-check:opacity-90 group-data-[selected]/menu-check:opacity-90 group-data-checked/menu-check:[transition-duration:var(--transition-duration-fast)] group-data-[selected]/menu-check:[transition-duration:var(--transition-duration-fast)] motion-reduce:group-data-checked/menu-check:[transition-duration:var(--transition-duration-normal)] motion-reduce:group-data-[selected]/menu-check:[transition-duration:var(--transition-duration-normal)]';
|
|
49
|
+
const drawCheckPath =
|
|
50
|
+
'[stroke-dasharray:1_2] [stroke-dashoffset:1] [transition:stroke-dashoffset_0s_linear_var(--transition-duration-quick)] group-data-checked/menu-check:[stroke-dashoffset:0] group-data-[selected]/menu-check:[stroke-dashoffset:0] group-data-checked/menu-check:[transition:stroke-dashoffset_var(--transition-duration-normal)_var(--ease-out)] group-data-[selected]/menu-check:[transition:stroke-dashoffset_var(--transition-duration-normal)_var(--ease-out)] motion-reduce:transition-none motion-reduce:group-data-checked/menu-check:transition-none motion-reduce:group-data-[selected]/menu-check:transition-none';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The check of a checked radio or checkbox row, or of a selected Select or
|
|
54
|
+
* Combobox option, inside an item with `menuCheckItem` or `menuRadioItem`.
|
|
55
|
+
*/
|
|
56
|
+
export function MenuCheck({ className }: { className?: string }) {
|
|
57
|
+
return (
|
|
58
|
+
<svg
|
|
59
|
+
viewBox="0 0 24 24"
|
|
60
|
+
fill="none"
|
|
61
|
+
stroke="currentColor"
|
|
62
|
+
strokeLinecap="round"
|
|
63
|
+
strokeLinejoin="round"
|
|
64
|
+
aria-hidden="true"
|
|
65
|
+
focusable="false"
|
|
66
|
+
data-slot="menu-check"
|
|
67
|
+
className={cn(drawCheck, className)}
|
|
68
|
+
>
|
|
69
|
+
<path d="M20 6 9 17l-5-5" pathLength={1} className={drawCheckPath} />
|
|
70
|
+
</svg>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The edge of an outline control: the outline Button, the outline Toggle and
|
|
3
|
+
* the default ButtonGroup. It is the `border` colour, the same hairline as a
|
|
4
|
+
* card, so an outline control on a white card reads as a button without a
|
|
5
|
+
* hard line; `shadow-control` gives it its lift. Hover steps the edge up to
|
|
6
|
+
* the `input` colour. Text fields keep their own `border` hairline
|
|
7
|
+
* (field-surface.ts). The three controls take the edge from here, so they
|
|
8
|
+
* cannot drift apart.
|
|
9
|
+
*/
|
|
10
|
+
export const outlineEdge = 'border-border';
|
|
11
|
+
|
|
12
|
+
/** The same edge as an inset ring, for a ButtonGroup that draws its frame with a ring. */
|
|
13
|
+
export const outlineEdgeRing = 'inset-ring-border';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hover: the edge steps up to `input`. Not inside a ButtonGroup or a joined
|
|
17
|
+
* ToggleGroup (the group owns the edge), not while invalid and not while
|
|
18
|
+
* aria-disabled.
|
|
19
|
+
*/
|
|
20
|
+
export const outlineEdgeHover =
|
|
21
|
+
"[&:not([data-slot=button-group]>*,[data-slot=toggle-group-item][data-spacing='0'],[aria-invalid=true],[aria-disabled=true])]:hover:border-input";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type PopupAlign = 'start' | 'center' | 'end';
|
|
4
|
+
type PopupSide = 'top' | 'right' | 'bottom' | 'left' | 'inline-end' | 'inline-start';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The align that opens a popup toward the centre of the viewport: its edge
|
|
8
|
+
* lines up with the trigger's right edge for a trigger in the right half, and
|
|
9
|
+
* with its left edge in the left half. `start` and `end` are logical, and the
|
|
10
|
+
* positioner reads them in the popup's direction, so in a right-to-left page
|
|
11
|
+
* the two swap.
|
|
12
|
+
*/
|
|
13
|
+
function alignTowardCentre(trigger: Element, popup: Element): PopupAlign {
|
|
14
|
+
const box = trigger.getBoundingClientRect();
|
|
15
|
+
const inRightHalf = box.left + box.width / 2 > window.innerWidth / 2;
|
|
16
|
+
const rtl = getComputedStyle(popup).direction === 'rtl';
|
|
17
|
+
return inRightHalf !== rtl ? 'end' : 'start';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The trigger that opened this popup. Base UI's menu and popover triggers
|
|
22
|
+
* both point at their popup with `aria-controls`, and the open one carries
|
|
23
|
+
* `data-popup-open`.
|
|
24
|
+
*/
|
|
25
|
+
function findTrigger(popup: HTMLElement): Element | null {
|
|
26
|
+
if (!popup.id) return null;
|
|
27
|
+
const controls = `[aria-controls="${CSS.escape(popup.id)}"]`;
|
|
28
|
+
return document.querySelector(`${controls}[data-popup-open]`) ?? document.querySelector(controls);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The `align` for a popup that opens below or above its trigger. An explicit
|
|
33
|
+
* `align` always wins. Without one, the popup opens toward the centre of the
|
|
34
|
+
* viewport: a trigger in the right half lines the popup up with its right
|
|
35
|
+
* edge, so the popup grows to the left and stays on screen, and a trigger in
|
|
36
|
+
* the left half lines it up with its left edge. The side is picked each time
|
|
37
|
+
* the popup opens. A popup that opens to the left or right of its trigger
|
|
38
|
+
* keeps "start".
|
|
39
|
+
*
|
|
40
|
+
* The trigger is found through `aria-controls`, which the menu and popover
|
|
41
|
+
* triggers set. A popup whose trigger does not set it passes `getTrigger`
|
|
42
|
+
* instead, a function that returns the trigger element.
|
|
43
|
+
*
|
|
44
|
+
* Pass `popupRef` as the popup's `ref`. It runs when the popup mounts, before
|
|
45
|
+
* the first paint, so the popup never shows on the wrong side first.
|
|
46
|
+
*/
|
|
47
|
+
export function usePopupAlign<T extends HTMLElement>(
|
|
48
|
+
align: PopupAlign | undefined,
|
|
49
|
+
side: PopupSide,
|
|
50
|
+
ref: React.Ref<T> | undefined,
|
|
51
|
+
getTrigger?: () => Element | null | undefined,
|
|
52
|
+
) {
|
|
53
|
+
// Toward the centre is horizontal: a popup that opens to a side keeps "start".
|
|
54
|
+
const opensBelowOrAbove = side === 'bottom' || side === 'top';
|
|
55
|
+
const [autoAlign, setAutoAlign] = React.useState<PopupAlign>('start');
|
|
56
|
+
const popupRef = React.useCallback(
|
|
57
|
+
(popup: T | null) => {
|
|
58
|
+
if (typeof ref === 'function') ref(popup);
|
|
59
|
+
else if (ref) (ref as React.RefObject<T | null>).current = popup;
|
|
60
|
+
const trigger =
|
|
61
|
+
!align && opensBelowOrAbove && popup && (getTrigger?.() ?? findTrigger(popup));
|
|
62
|
+
if (trigger) setAutoAlign(alignTowardCentre(trigger, popup));
|
|
63
|
+
},
|
|
64
|
+
[ref, align, opensBelowOrAbove, getTrigger],
|
|
65
|
+
);
|
|
66
|
+
return { popupRef, align: align ?? (opensBelowOrAbove ? autoAlign : 'start') };
|
|
67
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type Direction = 'ltr' | 'rtl';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The direction the nearest DirectionProvider sets, or undefined outside one.
|
|
7
|
+
* Base UI's `useDirection` returns "ltr" in both cases, so it cannot tell a
|
|
8
|
+
* provider that says left to right from no provider at all.
|
|
9
|
+
*/
|
|
10
|
+
export const ProvidedDirection = React.createContext<Direction | undefined>(undefined);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The `dir` a popup positioner carries. A popup renders in a portal at the end
|
|
14
|
+
* of the body, so it inherits the document's direction, not the provider's.
|
|
15
|
+
* Floating UI reads the direction from the positioner's computed style to
|
|
16
|
+
* place `start` and `end`, and the items inherit it too. Inside a provider the
|
|
17
|
+
* positioner gets the provider's direction. Outside one it gets no `dir` and
|
|
18
|
+
* keeps the document's, so `dir="rtl"` on `<html>` alone still works.
|
|
19
|
+
*/
|
|
20
|
+
export function usePopupDir(): Direction | undefined {
|
|
21
|
+
return React.useContext(ProvidedDirection);
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a popup opens from its trigger, as the v3-look menu does: opacity in
|
|
3
|
+
* `popup-fade` (160ms), scale and translate in `normal` (200ms) on the strong
|
|
4
|
+
* ease-out, from scale 0.96 and 2px towards the trigger. It closes in `quick`
|
|
5
|
+
* (120ms): the scale and the drop on the strong ease-out, so the popup moves
|
|
6
|
+
* at once, and the fade on `ease-soft`, so it stays readable while it goes.
|
|
7
|
+
* Reduced motion keeps the fade and drops the scale and the drop.
|
|
8
|
+
*
|
|
9
|
+
* DropdownMenu, ContextMenu, Select, Combobox, Popover, HoverCard and the
|
|
10
|
+
* NavigationMenu popup share it, so they open alike. Base UI sets
|
|
11
|
+
* `--transform-origin` and `data-side` on each popup.
|
|
12
|
+
*
|
|
13
|
+
* A Select list placed over its trigger has `data-side="none"`: it has no
|
|
14
|
+
* side, so `SelectContent` drops the slide, the scale and the fade, and grows
|
|
15
|
+
* the list out of the trigger's box with a `clip-path` on the same timings.
|
|
16
|
+
* Reduced motion keeps the fade.
|
|
17
|
+
*/
|
|
18
|
+
export const popupMotion =
|
|
19
|
+
'origin-(--transform-origin) transition-[opacity,scale,translate] [transition-duration:var(--transition-duration-popup-fade),var(--transition-duration-normal),var(--transition-duration-normal)] ease-out data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-quick data-ending-style:ease-[var(--ease-soft),var(--ease-out),var(--ease-out)] motion-safe:data-starting-style:scale-96 motion-safe:data-ending-style:scale-96 motion-safe:data-starting-style:-translate-y-0.5 motion-safe:data-ending-style:-translate-y-0.5 motion-safe:data-[side=top]:data-starting-style:translate-y-0.5 motion-safe:data-[side=top]:data-ending-style:translate-y-0.5';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* The state dictionary — the mechanism that makes the same entity state look
|
|
3
5
|
* the same in every Vendure surface (see CONTEXT.md → "State dictionary").
|
|
@@ -14,26 +16,59 @@
|
|
|
14
16
|
/**
|
|
15
17
|
* The semantic meaning a color expresses about a state. Tone ≠ token name:
|
|
16
18
|
* `critical` renders with the `destructive` slots and `progress` renders with
|
|
17
|
-
* the `
|
|
19
|
+
* the `info` slots plus a spinner — see StatusBadge.
|
|
18
20
|
*/
|
|
19
21
|
export type Tone = 'neutral' | 'info' | 'success' | 'warning' | 'critical' | 'progress';
|
|
20
22
|
|
|
21
23
|
export interface StateEntry {
|
|
22
24
|
tone: Tone;
|
|
23
25
|
defaultLabel: string;
|
|
26
|
+
/**
|
|
27
|
+
* A shape that says more than the tone's own icon, e.g. `<TruckIcon />` for
|
|
28
|
+
* Shipped. Pass it to StatusBadge's `icon` through `iconFor`. Leave it out
|
|
29
|
+
* for the tone's own icon.
|
|
30
|
+
*/
|
|
31
|
+
icon?: ReactNode;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
/**
|
|
27
35
|
* A declared, exhaustiveness-checked state map plus lookups that tolerate open
|
|
28
|
-
* unions. `toneFor` / `labelFor` accept any string (states arrive
|
|
29
|
-
* as bare strings) and fall back to `neutral` / the
|
|
30
|
-
*
|
|
31
|
-
*
|
|
36
|
+
* unions. `toneFor` / `labelFor` / `iconFor` accept any string (states arrive
|
|
37
|
+
* from the wire as bare strings) and fall back to `neutral` / the state name in
|
|
38
|
+
* sentence case words ("ValidatingCustomer" → "Validating customer") / no icon,
|
|
39
|
+
* warning once per unknown state in development so a typo surfaces without
|
|
40
|
+
* spamming a 200-row table.
|
|
32
41
|
*/
|
|
33
42
|
export interface StateMap<S extends string> {
|
|
34
43
|
entries: Record<S, StateEntry>;
|
|
35
44
|
toneFor(state: string): Tone;
|
|
36
45
|
labelFor(state: string): string;
|
|
46
|
+
/** The entry's own icon, or `undefined` for the tone's icon. */
|
|
47
|
+
iconFor(state: string): ReactNode | undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A state name from the wire in sentence case words: "ValidatingCustomer",
|
|
52
|
+
* "VALIDATING_CUSTOMER" and "validating-customer" all read "Validating
|
|
53
|
+
* customer". An acronym inside a mixed-case name stays: "SSLCheckFailed" reads
|
|
54
|
+
* "SSL check failed".
|
|
55
|
+
*/
|
|
56
|
+
export function stateNameToWords(state: string): string {
|
|
57
|
+
const words = state
|
|
58
|
+
.replace(/[_-]+/g, ' ')
|
|
59
|
+
.replace(/([a-z])([A-Z0-9])/g, '$1 $2')
|
|
60
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
61
|
+
.replace(/([0-9])([A-Za-z])/g, '$1 $2')
|
|
62
|
+
.trim()
|
|
63
|
+
.split(/\s+/)
|
|
64
|
+
.filter(Boolean);
|
|
65
|
+
const shouting = state === state.toUpperCase();
|
|
66
|
+
const sentence = words
|
|
67
|
+
.map((word) =>
|
|
68
|
+
!shouting && word.length > 1 && word === word.toUpperCase() ? word : word.toLowerCase(),
|
|
69
|
+
)
|
|
70
|
+
.join(' ');
|
|
71
|
+
return sentence.charAt(0).toUpperCase() + sentence.slice(1);
|
|
37
72
|
}
|
|
38
73
|
|
|
39
74
|
const isDev = process.env.NODE_ENV !== 'production';
|
|
@@ -71,7 +106,8 @@ export function defineStateEntries<S extends string>(entries: Record<S, StateEnt
|
|
|
71
106
|
return {
|
|
72
107
|
entries,
|
|
73
108
|
toneFor: (state) => resolve(state)?.tone ?? 'neutral',
|
|
74
|
-
labelFor: (state) => resolve(state)?.defaultLabel ?? state,
|
|
109
|
+
labelFor: (state) => resolve(state)?.defaultLabel ?? stateNameToWords(state),
|
|
110
|
+
iconFor: (state) => resolve(state)?.icon,
|
|
75
111
|
};
|
|
76
112
|
}
|
|
77
113
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Colours CodeBlock swaps in Shiki's github-light theme. github-light's orange
|
|
3
|
+
* (#e36209, used for GraphQL fields, CSS properties and similar) is 3.5:1 on a
|
|
4
|
+
* white card; #a35200 keeps the hue and holds 4.5:1 on every light surface
|
|
5
|
+
* tier. The contrast test in @vendure-io/design-tokens checks it. This file
|
|
6
|
+
* imports nothing, so the token test can load it.
|
|
7
|
+
*/
|
|
8
|
+
export const githubLightReplacements: Record<string, string> = { '#e36209': '#a35200' };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tint recipes of StatusBadge and Alert, in one place. The components use
|
|
3
|
+
* these class strings, and the contrast test in @vendure-io/design-tokens
|
|
4
|
+
* (`src/contrast.test.ts`) reads the tone slots and mix percentages from them,
|
|
5
|
+
* so a recipe change is tested as it ships. The strings are static so
|
|
6
|
+
* Tailwind's scanner picks them up. This file imports nothing, so the token
|
|
7
|
+
* test can load it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A StatusBadge chip takes its tone from one `--status-tone` colour: a 5% tone
|
|
12
|
+
* wash over the `muted` fill, a 1px inset ring at 34%, and a label tinted 30%
|
|
13
|
+
* from `foreground-secondary` towards the tone.
|
|
14
|
+
*/
|
|
15
|
+
export const statusChipFill = 'bg-[color-mix(in_oklab,var(--status-tone)_5%,var(--muted))]';
|
|
16
|
+
|
|
17
|
+
/** The chip's inset ring. A ComboboxChip uses it with the neutral tone. */
|
|
18
|
+
export const statusChipRing =
|
|
19
|
+
'inset-ring inset-ring-[color-mix(in_oklab,var(--status-tone)_34%,transparent)]';
|
|
20
|
+
|
|
21
|
+
/** The chip label. `--status-label-tone` and `--status-label-mix` override the tone and the 30%. */
|
|
22
|
+
export const statusChipLabel =
|
|
23
|
+
'text-[color-mix(in_oklab,var(--status-label-tone,var(--status-tone))_var(--status-label-mix,30%),var(--foreground-secondary))]';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The tone of each StatusBadge tone. `warning` draws its fill and ring in
|
|
27
|
+
* `warning-indicator` (mixed from `warning-text` they read beige) and mixes
|
|
28
|
+
* its label 70% from `warning-text`.
|
|
29
|
+
*/
|
|
30
|
+
export const statusToneVars = {
|
|
31
|
+
neutral: '[--status-tone:var(--neutral-text)]',
|
|
32
|
+
info: '[--status-tone:var(--info-text)]',
|
|
33
|
+
success: '[--status-tone:var(--success-text)]',
|
|
34
|
+
warning:
|
|
35
|
+
'[--status-label-mix:70%] [--status-label-tone:var(--warning-text)] [--status-tone:var(--warning-indicator)]',
|
|
36
|
+
critical: '[--status-tone:var(--destructive-text)]',
|
|
37
|
+
progress: '[--status-tone:var(--info-text)]',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** The marker colour of each StatusBadge tone: the icon or spinner stroke. */
|
|
41
|
+
export const statusToneText = {
|
|
42
|
+
neutral: 'text-neutral-text',
|
|
43
|
+
info: 'text-info-text',
|
|
44
|
+
success: 'text-success-text',
|
|
45
|
+
warning: 'text-warning-text',
|
|
46
|
+
critical: 'text-destructive-text',
|
|
47
|
+
progress: 'text-info-text',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A toned Alert is a faint tint of its `--alert-tone`. Light: 7% tone in the
|
|
52
|
+
* card, border 14% tone in the border colour. Dark: the tone over
|
|
53
|
+
* transparent (10% fill, 30% border), because mixed into the cool surface it
|
|
54
|
+
* reads grey.
|
|
55
|
+
*/
|
|
56
|
+
export const alertTint =
|
|
57
|
+
'text-foreground [--alert-fill:color-mix(in_oklab,var(--alert-tone)_7%,var(--card))] [--alert-border:color-mix(in_oklab,var(--alert-tone)_14%,var(--border))] dark:[--alert-fill:color-mix(in_oklab,var(--alert-tone)_10%,transparent)] dark:[--alert-border:color-mix(in_oklab,var(--alert-tone)_30%,transparent)] bg-(color:--alert-fill) border-(color:--alert-border)';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The tone and icon colour of each toned Alert. Warning tints with the
|
|
61
|
+
* brighter `warning-indicator` (an amber text colour mixes to brown) and
|
|
62
|
+
* takes its icon from `warning-text`.
|
|
63
|
+
*/
|
|
64
|
+
export const alertToneVars = {
|
|
65
|
+
destructive: '[--alert-tone:var(--destructive-text)] *:[svg]:text-destructive-text',
|
|
66
|
+
warning: '[--alert-tone:var(--warning-indicator)] *:[svg]:text-warning-text',
|
|
67
|
+
info: '[--alert-tone:var(--info-text)] *:[svg]:text-info-text',
|
|
68
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Tone } from '@vendure-io/ui/lib/state-dictionary';
|
|
2
|
+
import {
|
|
3
|
+
CircleCheckIcon,
|
|
4
|
+
CircleDashedIcon,
|
|
5
|
+
CircleDotIcon,
|
|
6
|
+
CircleXIcon,
|
|
7
|
+
LoaderIcon,
|
|
8
|
+
type LucideIcon,
|
|
9
|
+
TriangleAlertIcon,
|
|
10
|
+
} from 'lucide-react';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The icon of each tone. A StatusBadge and a toast read the same map, so a
|
|
14
|
+
* tone has one shape everywhere: the shape says the state again, and a state
|
|
15
|
+
* never depends on colour alone. `progress` is the loader the caller spins.
|
|
16
|
+
*/
|
|
17
|
+
export const toneIcons: Record<Tone, LucideIcon> = {
|
|
18
|
+
neutral: CircleDashedIcon,
|
|
19
|
+
info: CircleDotIcon,
|
|
20
|
+
success: CircleCheckIcon,
|
|
21
|
+
warning: TriangleAlertIcon,
|
|
22
|
+
critical: CircleXIcon,
|
|
23
|
+
progress: LoaderIcon,
|
|
24
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isValidElement } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The slot attributes of a trigger that can take `render`. The trigger always
|
|
5
|
+
* carries `data-<slot>` (for example `data-tooltip-trigger`), so it stays
|
|
6
|
+
* findable. It sets `data-slot` only when it renders a plain element: no
|
|
7
|
+
* `render`, a render function, or an HTML element such as `<span>`. A component
|
|
8
|
+
* passed as `render`, such as a Button or a StatusBadge, keeps its own slot.
|
|
9
|
+
* Without this, the trigger's `data-slot` replaces the slot the component sets
|
|
10
|
+
* inside itself, because Base UI passes the trigger's props into the component.
|
|
11
|
+
* A `data-slot` written on the render element itself always wins.
|
|
12
|
+
*/
|
|
13
|
+
export function triggerSlot(slot: string, render: unknown): Record<string, string> {
|
|
14
|
+
const component = isValidElement(render) && typeof render.type !== 'string';
|
|
15
|
+
return component ? { [`data-${slot}`]: '' } : { 'data-slot': slot, [`data-${slot}`]: '' };
|
|
16
|
+
}
|
package/src/lib/utils.ts
CHANGED
|
@@ -1,5 +1,108 @@
|
|
|
1
1
|
import { type ClassValue, clsx } from 'clsx';
|
|
2
|
-
import {
|
|
2
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
3
|
+
|
|
4
|
+
// tailwind-merge knows only Tailwind's default theme. Without these names it
|
|
5
|
+
// reads `shadow-control` as a shadow colour, so `shadow-primary/20` drops it,
|
|
6
|
+
// reads `text-style-body` as a text colour, so `text-primary` drops it, and
|
|
7
|
+
// keeps two named eases, durations or animations side by side, so the CSS
|
|
8
|
+
// order picks the winner instead of the class order.
|
|
9
|
+
// The names are the @vendure-io/design-tokens theme keys the defaults miss.
|
|
10
|
+
// `utils.test.ts` reads the theme CSS and fails on a key that is missing here.
|
|
11
|
+
const twMerge = extendTailwindMerge<'text-style'>({
|
|
12
|
+
extend: {
|
|
13
|
+
theme: {
|
|
14
|
+
shadow: ['control', 'overlay', 'scrolled'],
|
|
15
|
+
ease: ['default', 'spring', 'drawer', 'drawer-content', 'height', 'press', 'soft', 'flash'],
|
|
16
|
+
animate: [
|
|
17
|
+
'shimmer',
|
|
18
|
+
'spin-slow',
|
|
19
|
+
'progress-sweep',
|
|
20
|
+
'live-pulse',
|
|
21
|
+
'page-enter',
|
|
22
|
+
'page-fade',
|
|
23
|
+
'page-reload',
|
|
24
|
+
'page-reload-fade',
|
|
25
|
+
'page-switch-line',
|
|
26
|
+
'match-flash',
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
classGroups: {
|
|
30
|
+
duration: [
|
|
31
|
+
{
|
|
32
|
+
duration: [
|
|
33
|
+
'instant',
|
|
34
|
+
'fast',
|
|
35
|
+
'quick',
|
|
36
|
+
'moderate',
|
|
37
|
+
'normal',
|
|
38
|
+
'slow',
|
|
39
|
+
'slower',
|
|
40
|
+
'palette-detail-delay',
|
|
41
|
+
'palette-result-delay',
|
|
42
|
+
'palette-detail-exit',
|
|
43
|
+
'palette-exit',
|
|
44
|
+
'palette-tint',
|
|
45
|
+
'palette-result-exit',
|
|
46
|
+
'palette-enter',
|
|
47
|
+
'palette-move',
|
|
48
|
+
'palette-detail-move',
|
|
49
|
+
'palette-result-blur',
|
|
50
|
+
'tooltip-enter',
|
|
51
|
+
'tooltip-delay',
|
|
52
|
+
'tooltip-label-fade',
|
|
53
|
+
'tooltip-label-move',
|
|
54
|
+
'tooltip-resize',
|
|
55
|
+
'progress-fill',
|
|
56
|
+
'row-enter',
|
|
57
|
+
'row-swap-out',
|
|
58
|
+
'row-swap-delay',
|
|
59
|
+
'popup-fade',
|
|
60
|
+
'popup-resize',
|
|
61
|
+
'sidebar-pill',
|
|
62
|
+
'toast-exit-fade',
|
|
63
|
+
'toast-exit-move',
|
|
64
|
+
'toast-fade',
|
|
65
|
+
'toast-move',
|
|
66
|
+
'check-mark-delay',
|
|
67
|
+
'dialog-scrim',
|
|
68
|
+
'dialog-enter',
|
|
69
|
+
'dialog-exit',
|
|
70
|
+
'drawer-slide',
|
|
71
|
+
'drawer-swipe',
|
|
72
|
+
'alert-enter',
|
|
73
|
+
'button-icon-turn',
|
|
74
|
+
'external-arrow',
|
|
75
|
+
'page-fade',
|
|
76
|
+
'page-rise',
|
|
77
|
+
'page-switch',
|
|
78
|
+
'page-reload-fade',
|
|
79
|
+
'page-reload-settle',
|
|
80
|
+
'live-pulse',
|
|
81
|
+
'match-flash',
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
// A text style sets family, size, weight, tracking and leading at once.
|
|
86
|
+
'text-style': [
|
|
87
|
+
{
|
|
88
|
+
'text-style': [
|
|
89
|
+
'page-title',
|
|
90
|
+
'section-title',
|
|
91
|
+
'dialog-title',
|
|
92
|
+
'card-title',
|
|
93
|
+
'body',
|
|
94
|
+
'caption',
|
|
95
|
+
'code',
|
|
96
|
+
'display-xl',
|
|
97
|
+
'display-lg',
|
|
98
|
+
'display-md',
|
|
99
|
+
'display-sm',
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
3
106
|
|
|
4
107
|
export function cn(...inputs: ClassValue[]): string {
|
|
5
108
|
return twMerge(clsx(inputs));
|