@vendure-io/ui 3.0.0-next.3 → 3.0.0-next.5

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.
Files changed (86) hide show
  1. package/package.json +12 -10
  2. package/src/components/atoms/alert-dialog.tsx +1 -4
  3. package/src/components/atoms/alert.tsx +59 -35
  4. package/src/components/atoms/badge.tsx +2 -2
  5. package/src/components/atoms/breadcrumb.tsx +124 -49
  6. package/src/components/atoms/button-group.tsx +1 -1
  7. package/src/components/atoms/button.tsx +4 -3
  8. package/src/components/atoms/calendar.tsx +2 -2
  9. package/src/components/atoms/card.tsx +15 -2
  10. package/src/components/atoms/chart.tsx +3 -3
  11. package/src/components/atoms/checkbox.tsx +1 -1
  12. package/src/components/atoms/combobox.tsx +37 -26
  13. package/src/components/atoms/command.tsx +3 -3
  14. package/src/components/atoms/context-menu.tsx +5 -5
  15. package/src/components/atoms/dialog.tsx +30 -14
  16. package/src/components/atoms/dropdown-menu.tsx +1 -1
  17. package/src/components/atoms/hover-card.tsx +1 -1
  18. package/src/components/atoms/input-group.tsx +30 -12
  19. package/src/components/atoms/input-otp.tsx +2 -2
  20. package/src/components/atoms/input.tsx +13 -3
  21. package/src/components/atoms/menubar.tsx +2 -2
  22. package/src/components/atoms/native-select.tsx +1 -1
  23. package/src/components/atoms/navigation-menu.tsx +3 -3
  24. package/src/components/atoms/pagination.tsx +9 -3
  25. package/src/components/atoms/popover.tsx +1 -1
  26. package/src/components/atoms/select.tsx +3 -3
  27. package/src/components/atoms/sheet.tsx +35 -15
  28. package/src/components/atoms/sidebar.tsx +200 -31
  29. package/src/components/atoms/skeleton.tsx +6 -3
  30. package/src/components/atoms/switch.tsx +1 -1
  31. package/src/components/atoms/tabs.tsx +6 -2
  32. package/src/components/atoms/textarea.tsx +1 -1
  33. package/src/components/atoms/toggle.tsx +1 -1
  34. package/src/components/molecules/action-needed.tsx +483 -0
  35. package/src/components/molecules/anonymized-token.tsx +52 -8
  36. package/src/components/molecules/chip.tsx +37 -18
  37. package/src/components/molecules/choice-card.tsx +114 -9
  38. package/src/components/molecules/code-block/package-manager-storage.ts +50 -0
  39. package/src/components/molecules/code-block/process-code.ts +1 -1
  40. package/src/components/molecules/code-block.tsx +58 -47
  41. package/src/components/molecules/combobox-free-text.tsx +75 -20
  42. package/src/components/molecules/confirm-dialog.tsx +11 -1
  43. package/src/components/molecules/copyable-text.tsx +10 -8
  44. package/src/components/molecules/data-table/data-table-filters.tsx +14 -2
  45. package/src/components/molecules/data-table/data-table-helpers.tsx +109 -3
  46. package/src/components/molecules/data-table/data-table-row-count-storage.tsx +88 -0
  47. package/src/components/molecules/data-table/data-table-selection-storage.tsx +33 -15
  48. package/src/components/molecules/data-table/data-table-types.tsx +123 -13
  49. package/src/components/molecules/data-table/data-table.tsx +112 -55
  50. package/src/components/molecules/data-table/table-pagination.tsx +96 -14
  51. package/src/components/molecules/date-picker.tsx +55 -24
  52. package/src/components/molecules/date-range-picker.tsx +54 -23
  53. package/src/components/molecules/date-time-picker.tsx +60 -24
  54. package/src/components/molecules/date-time.tsx +38 -3
  55. package/src/components/molecules/elapsed-time.tsx +61 -12
  56. package/src/components/molecules/file-dropzone.tsx +139 -39
  57. package/src/components/molecules/format-provider.tsx +14 -4
  58. package/src/components/molecules/id-chip-chrome.tsx +114 -0
  59. package/src/components/molecules/id-chip.tsx +3 -107
  60. package/src/components/molecules/issued-secret.tsx +1 -1
  61. package/src/components/molecules/live-indicator.tsx +1 -1
  62. package/src/components/molecules/money.tsx +46 -4
  63. package/src/components/molecules/multi-select.tsx +58 -15
  64. package/src/components/molecules/page-header.tsx +6 -2
  65. package/src/components/molecules/password-input.tsx +11 -10
  66. package/src/components/molecules/relative-time.tsx +88 -16
  67. package/src/components/molecules/search-trigger.tsx +5 -3
  68. package/src/components/molecules/secret-value.tsx +10 -2
  69. package/src/components/molecules/stat-card.tsx +143 -33
  70. package/src/components/molecules/state-views/empty-state.tsx +16 -12
  71. package/src/components/molecules/state-views/error-state.tsx +19 -15
  72. package/src/components/molecules/state-views/loading-state.tsx +16 -6
  73. package/src/components/molecules/state-views/skeleton-parts.tsx +6 -4
  74. package/src/components/molecules/status-badge.tsx +11 -35
  75. package/src/components/molecules/time-tooltip.tsx +55 -1
  76. package/src/hooks/use-copy.ts +3 -1
  77. package/src/lib/deprecated.ts +71 -0
  78. package/src/lib/env.ts +9 -0
  79. package/src/lib/field-surface.ts +7 -7
  80. package/src/lib/format-messages.ts +192 -0
  81. package/src/lib/highlight.ts +1 -1
  82. package/src/lib/menu-item.tsx +1 -1
  83. package/src/lib/state-dictionary.ts +2 -3
  84. package/src/lib/tint-recipes.ts +10 -5
  85. package/src/lib/utils.ts +19 -1
  86. package/src/lib/dialog-padding.ts +0 -48
@@ -12,6 +12,7 @@ import { formatElapsed } from '../../lib/format-elapsed.ts';
12
12
  import { cn } from '../../lib/utils.ts';
13
13
  // Relative: this module is internal (mapped to null in the package exports).
14
14
  import { Tooltip, TooltipContent, TooltipTrigger } from '../atoms/tooltip.tsx';
15
+ import { SkeletonLine } from './state-views/skeleton-parts.tsx';
15
16
 
16
17
  /**
17
18
  * True inside the second line of a StatusBadge (`detail`). A time there is a
@@ -137,4 +138,57 @@ function useReadersClock(): boolean {
137
138
  );
138
139
  }
139
140
 
140
- export { InStatusDetail, TimeSpan, TimeTooltip, toTime, useReadersClock };
141
+ /**
142
+ * A typical text for the skeleton width. Formatting can throw (an invalid
143
+ * locale, a throwing `format`); the skeleton then uses `fallback`.
144
+ */
145
+ function sampleText(format: () => string, fallback: string): string {
146
+ try {
147
+ return format();
148
+ } catch {
149
+ return fallback;
150
+ }
151
+ }
152
+
153
+ interface TimeSkeletonProps extends Omit<React.ComponentProps<'span'>, 'children'> {
154
+ /** A typical rendered text; the skeleton is as many `ch` wide as it is long. */
155
+ sample: string;
156
+ /** Visually hidden text for screen readers. */
157
+ loadingLabel: string;
158
+ /** The `data-slot` of the component it stands in for. */
159
+ slot: string;
160
+ }
161
+
162
+ /**
163
+ * The loading state of DateTime, RelativeTime and ElapsedTime: one text line
164
+ * of skeleton, as wide as a typical value, so the line does not move when the
165
+ * time arrives. It needs no clock, so the
166
+ * server and the browser render the same markup. The width follows the
167
+ * locale: pin it with FormatProvider in SSR, as the text needs anyway.
168
+ */
169
+ function TimeSkeleton({
170
+ sample,
171
+ loadingLabel,
172
+ slot,
173
+ className,
174
+ style,
175
+ ...props
176
+ }: TimeSkeletonProps) {
177
+ return (
178
+ <span
179
+ data-slot={slot}
180
+ aria-busy="true"
181
+ className={cn('inline-flex max-w-full tabular-nums', className)}
182
+ style={{ width: `${Math.max(sample.length, 4)}ch`, ...style }}
183
+ {...props}
184
+ >
185
+ {/* A zero-width space gives the skeleton a text baseline, so it sits on
186
+ the line like the text and a baseline-aligned row does not grow. */}
187
+ <span aria-hidden="true">{'\u200b'}</span>
188
+ <SkeletonLine />
189
+ <span className="sr-only">{loadingLabel}</span>
190
+ </span>
191
+ );
192
+ }
193
+
194
+ export { InStatusDetail, sampleText, TimeSkeleton, TimeSpan, TimeTooltip, toTime, useReadersClock };
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
- import { type ClipboardSource, writeToClipboard } from '@vendure-io/ui/lib/clipboard';
4
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { type ClipboardSource, writeToClipboard } from '../lib/clipboard.ts';
5
5
 
6
6
  interface UseCopyOptions {
7
7
  /** How long `copied` stays true after a successful copy, in ms. */
@@ -53,3 +53,5 @@ export function useCopy({ timeout = 2000 }: UseCopyOptions = {}): UseCopyReturn
53
53
 
54
54
  return { copied, copy };
55
55
  }
56
+
57
+ export type { ClipboardSource };
@@ -0,0 +1,71 @@
1
+ // Deprecated 2.x and early 3.0 names that still work in 3.x. Remove this
2
+ // module and every caller in 4.0.
3
+ import { isDevelopment } from './env.ts';
4
+
5
+ const warned = new Set<string>();
6
+
7
+ /**
8
+ * Warns once per component and old name, in development only:
9
+ * "<Component>: `<old>` is deprecated, use `<new>`. It will be removed in 4.0."
10
+ */
11
+ export function warnDeprecated(component: string, oldName: string, newName: string): void {
12
+ if (!isDevelopment) return;
13
+ const key = `${component}\u0000${oldName}`;
14
+ if (warned.has(key)) return;
15
+ warned.add(key);
16
+ console.warn(
17
+ `${component}: \`${oldName}\` is deprecated, use \`${newName}\`. It will be removed in 4.0.`,
18
+ );
19
+ }
20
+
21
+ /** Test hook: forget which warnings were shown. */
22
+ export function resetDeprecationWarnings(): void {
23
+ warned.clear();
24
+ }
25
+
26
+ /**
27
+ * Moves a value stored under a pre-3.0 key to its new key. When the new key is
28
+ * absent and the old key holds a value, the value is copied to the new key and
29
+ * the old key is deleted. Call it before reading the new key. Storage errors
30
+ * (private mode, a full quota, no window) are ignored.
31
+ */
32
+ export function migrateStorageKey(
33
+ area: 'localStorage' | 'sessionStorage',
34
+ oldKey: string,
35
+ newKey: string,
36
+ ): void {
37
+ try {
38
+ // Reading the storage itself can throw (a sandboxed frame, blocked cookies).
39
+ const storage: Storage | undefined = globalThis[area];
40
+ if (!storage) return;
41
+ if (storage.getItem(newKey) !== null) return;
42
+ const value = storage.getItem(oldKey);
43
+ if (value === null) return;
44
+ storage.setItem(newKey, value);
45
+ storage.removeItem(oldKey);
46
+ } catch {
47
+ // Storage is unavailable; the reader falls back to its default.
48
+ }
49
+ }
50
+
51
+ /** The 2.x physical sides of Sidebar and SheetContent. */
52
+ export type PhysicalSide = 'left' | 'right';
53
+
54
+ /**
55
+ * Turns a physical 2.x side into the logical side that puts the panel on the
56
+ * same edge, and warns. `left` is the start edge left to right and the end
57
+ * edge right to left. The direction comes from the nearest DirectionProvider
58
+ * or `dir` prop, then from `<html dir>`. Other sides pass through.
59
+ */
60
+ export function logicalSide<S extends string>(
61
+ component: string,
62
+ side: S | PhysicalSide,
63
+ dir: string | undefined,
64
+ ): S | 'start' | 'end' {
65
+ if (side !== 'left' && side !== 'right') return side;
66
+ const logical = side === 'left' ? 'start' : 'end';
67
+ warnDeprecated(component, `side="${side}"`, `side="${logical}"`);
68
+ const documentDir = typeof document === 'undefined' ? undefined : document.documentElement.dir;
69
+ const rtl = (dir === 'ltr' || dir === 'rtl' ? dir : documentDir) === 'rtl';
70
+ return (side === 'left') !== rtl ? 'start' : 'end';
71
+ }
package/src/lib/env.ts ADDED
@@ -0,0 +1,9 @@
1
+ // The build mode, read in one place. The design system ships its source, and a
2
+ // consumer type-checks it without Node types (the Console's app-shell package,
3
+ // for one). So `process` is declared here for this module only. Keep the
4
+ // literal `process.env.NODE_ENV`: bundlers replace it, so a production build
5
+ // drops the development-only checks.
6
+ declare const process: { env: { NODE_ENV?: string } };
7
+
8
+ /** True outside a production build: development warnings and checks run. */
9
+ export const isDevelopment = process.env.NODE_ENV !== 'production';
@@ -1,18 +1,18 @@
1
1
  /**
2
- * The v3 field surface: the `muted` fill with a 1px inset hairline in the
3
- * `border` colour, the lg (6px) radius, and a 2px ring drawn inside the field
2
+ * The v3 field surface: the `field` fill with a 1px inset hairline in the
3
+ * `border` colour (an `inset-ring`), the xl (8px) radius, the same corner as a Button, and a 2px ring drawn inside the field
4
4
  * on keyboard focus, over the hairline. An invalid field turns the hairline
5
- * and the ring destructive. The hairline is a shadow, not a border, so the
6
- * field keeps its size; forced-colors mode, which drops shadows, gets a real
5
+ * and the ring destructive. The hairline is an inset ring, a box-shadow and not a
6
+ * border, so the field keeps its size; forced-colors mode, which drops shadows, gets a real
7
7
  * border.
8
8
  *
9
9
  * Input, Textarea, Select, Combobox, NativeSelect and the date pickers share
10
10
  * it. Each field adds its own height, padding and text size.
11
11
  */
12
12
  const fieldBase =
13
- 'bg-muted shadow-[inset_0_0_0_1px_var(--border)] rounded-lg outline-none transition-shadow duration-quick ease-soft forced-colors:border';
13
+ 'bg-field inset-ring inset-ring-border rounded-xl outline-none transition-shadow duration-quick ease-soft forced-colors:border';
14
14
 
15
- export const fieldSurface = `${fieldBase} focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring aria-invalid:shadow-[inset_0_0_0_1px_var(--destructive)] aria-invalid:focus-visible:outline-destructive`;
15
+ export const fieldSurface = `${fieldBase} focus-visible:outline-solid focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring aria-invalid:inset-ring-destructive aria-invalid:focus-visible:outline-destructive`;
16
16
 
17
17
  /**
18
18
  * The field surface for a field whose focus and invalid state sit on an
@@ -20,7 +20,7 @@ export const fieldSurface = `${fieldBase} focus-visible:outline-solid focus-visi
20
20
  * destructive when a control inside is `aria-invalid`. ComboboxChips and the
21
21
  * InputOTP group use it.
22
22
  */
23
- export const fieldSurfaceWithin = `${fieldBase} focus-within:outline-solid focus-within:outline-2 focus-within:-outline-offset-2 focus-within:outline-ring has-aria-invalid:shadow-[inset_0_0_0_1px_var(--destructive)] has-aria-invalid:focus-within:outline-destructive`;
23
+ export const fieldSurfaceWithin = `${fieldBase} focus-within:outline-solid focus-within:outline-2 focus-within:-outline-offset-2 focus-within:outline-ring has-aria-invalid:inset-ring-destructive has-aria-invalid:focus-within:outline-destructive`;
24
24
 
25
25
  /**
26
26
  * A ghost Button drawn as a field: the trigger of DatePicker, DateRangePicker
@@ -0,0 +1,192 @@
1
+ import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
2
+
3
+ // Every English default text in the library, nested by component. A component
4
+ // that gains a text adds its group here; the `FormatMessages` type follows.
5
+ // List the new texts in the FormatProvider section of `docs/ui-components.md`.
6
+ const defaultMessages = {
7
+ breadcrumb: {
8
+ /** The loading row of a crumb menu, and the pending crumb's status. */
9
+ loading: 'Loading…',
10
+ /** The row of a BreadcrumbSearchMenu that reads the options again. */
11
+ retry: 'Retry',
12
+ },
13
+ codeBlock: {
14
+ copyCode: 'Copy code',
15
+ copied: 'Copied!',
16
+ /** Header of a shell block with no filename and no package-manager tabs. */
17
+ terminal: 'Terminal',
18
+ /** Header of a block with no filename and no language. */
19
+ code: 'Code',
20
+ showLess: 'Show less',
21
+ /** `{count}` is the number of hidden lines, formatted with `FormatProvider`'s `locale`. */
22
+ showMore: 'Show {count} more lines',
23
+ },
24
+ combobox: {
25
+ /** Announced while a page of options loads. */
26
+ loading: 'Loading…',
27
+ },
28
+ comboboxFreeText: {
29
+ /** Announced by the field's spinner while suggestions load. */
30
+ loading: 'Loading…',
31
+ },
32
+ confirmDialog: {
33
+ /** Screen-reader text of the spinner while the confirm action runs. */
34
+ loading: 'Loading',
35
+ },
36
+ copyButton: {
37
+ copy: 'Copy',
38
+ copied: 'Copied',
39
+ },
40
+ loadingState: {
41
+ /** Screen-reader text of the loading region. */
42
+ loading: 'Loading…',
43
+ },
44
+ multiSelect: {
45
+ /** Stands in for the selected values while the options load. */
46
+ loading: 'Loading…',
47
+ },
48
+ passwordInput: {
49
+ showPassword: 'Show password',
50
+ hidePassword: 'Hide password',
51
+ },
52
+ secretValue: {
53
+ /** Screen-reader text of the spinner while the value loads. */
54
+ loading: 'Loading',
55
+ },
56
+ searchTrigger: {
57
+ label: 'Search',
58
+ /** Added to the accessible name in brackets: "Search (command palette)". */
59
+ commandPalette: 'command palette',
60
+ },
61
+ statCard: {
62
+ /** Read before the delta when it rose; the arrow is visual-only. */
63
+ up: 'up',
64
+ /** Read before the delta when it fell. */
65
+ down: 'down',
66
+ /** Screen-reader text while the value loads (`value={undefined}`). */
67
+ loading: 'Loading value',
68
+ },
69
+ money: {
70
+ /** Screen-reader text while the amount loads (`value={undefined}`). */
71
+ loading: 'Loading amount',
72
+ },
73
+ anonymizedToken: {
74
+ /** Screen-reader text while the token loads (`value={undefined}`). */
75
+ loading: 'Loading token',
76
+ },
77
+ dateTime: {
78
+ /** Screen-reader text while the date loads (`value={undefined}`). */
79
+ loading: 'Loading date',
80
+ },
81
+ relativeTime: {
82
+ /** Screen-reader text while the time loads (`value={undefined}`). */
83
+ loading: 'Loading time',
84
+ },
85
+ elapsedTime: {
86
+ /** Screen-reader text while the start loads (`from={undefined}`). */
87
+ loading: 'Loading duration',
88
+ },
89
+ datePicker: {
90
+ /** Accessible name of the button that clears the date. */
91
+ clear: 'Clear date',
92
+ },
93
+ dateTimePicker: {
94
+ /** Accessible name of the button that clears the date and time. */
95
+ clear: 'Clear date and time',
96
+ /** Accessible name of the time field. */
97
+ time: 'Time',
98
+ },
99
+ dateRangePicker: {
100
+ /** Accessible name of the button that clears the range. */
101
+ clear: 'Clear date range',
102
+ },
103
+ fileDropzone: {
104
+ typeNotAccepted: 'This file type is not accepted.',
105
+ /** `{size}` is the largest allowed size, in the `byte`, `kilobyte` or `megabyte` unit. */
106
+ fileTooLarge: 'File size must be {size} or smaller.',
107
+ /** `{max}` is the file limit. Used when it is more than one. */
108
+ tooManyFiles: 'You can select up to {max} files.',
109
+ /** `{max}` is the file limit. Used when it is one. */
110
+ tooManyFilesOne: 'You can select up to {max} file.',
111
+ /** Shown when `validateFile` throws. */
112
+ validationFailed: 'This file could not be validated.',
113
+ /** Replaces the drop prompt while `validateFile` runs. */
114
+ checking: 'Checking files…',
115
+ /** Placed before the `accept` list. */
116
+ accepted: 'Accepted:',
117
+ /** Accessible name of a file's remove button. `{name}` is the file name. */
118
+ remove: 'Remove {name}',
119
+ /** File size units. The number follows `FormatProvider`'s `locale`. */
120
+ byte: 'B',
121
+ kilobyte: 'KB',
122
+ megabyte: 'MB',
123
+ },
124
+ dataTable: {
125
+ /** Placeholder and accessible name of the filter editor's default value input. */
126
+ filterValue: 'Value',
127
+ },
128
+ dialog: {
129
+ /** Accessible name of the ✕, and the text of DialogFooter's Close button. */
130
+ close: 'Close',
131
+ },
132
+ sheet: {
133
+ /** Accessible name of the ✕. */
134
+ close: 'Close',
135
+ },
136
+ sidebar: {
137
+ /** Screen-reader title of the mobile Sidebar's sheet. */
138
+ mobileTitle: 'Sidebar',
139
+ /** Screen-reader description of the mobile Sidebar's sheet. */
140
+ mobileDescription: 'Displays the mobile sidebar.',
141
+ },
142
+ };
143
+
144
+ type DefaultMessages = typeof defaultMessages;
145
+ type MessageGroup = keyof DefaultMessages;
146
+
147
+ /**
148
+ * The texts an app passes to `FormatProvider`'s `messages`. Every group and
149
+ * every text is optional; a missing one falls back to English. An unknown
150
+ * group or text is a type error.
151
+ */
152
+ type FormatMessages = {
153
+ [Group in MessageGroup]?: { [Key in keyof DefaultMessages[Group]]?: string };
154
+ };
155
+
156
+ type ResolvedMessages<Group extends MessageGroup> = {
157
+ [Key in keyof DefaultMessages[Group]]: string;
158
+ };
159
+
160
+ /**
161
+ * The texts of one component, resolved in a fixed order: the component's own
162
+ * label prop (`overrides`) → `FormatProvider`'s `messages` → the English
163
+ * default. Without a provider it returns the English defaults, so it is safe
164
+ * on the server and in tests.
165
+ *
166
+ * ```tsx
167
+ * const t = useMessages('passwordInput', {
168
+ * showPassword: showPasswordLabel,
169
+ * hidePassword: hidePasswordLabel,
170
+ * });
171
+ * ```
172
+ */
173
+ function useMessages<Group extends MessageGroup>(
174
+ group: Group,
175
+ overrides?: Partial<Record<keyof DefaultMessages[Group], string | undefined>>,
176
+ ): ResolvedMessages<Group> {
177
+ const fromProvider = useFormatSettings().messages?.[group];
178
+ const resolved = { ...defaultMessages[group] } as Record<string, string>;
179
+ for (const layer of [fromProvider, overrides] as (
180
+ | Record<string, string | undefined>
181
+ | undefined
182
+ )[]) {
183
+ if (!layer) continue;
184
+ for (const [key, text] of Object.entries(layer)) {
185
+ if (text !== undefined) resolved[key] = text;
186
+ }
187
+ }
188
+ return resolved as ResolvedMessages<Group>;
189
+ }
190
+
191
+ export { defaultMessages, useMessages };
192
+ export type { FormatMessages };
@@ -5,9 +5,9 @@ import {
5
5
  transformerNotationHighlight,
6
6
  transformerNotationWordHighlight,
7
7
  } from '@shikijs/transformers';
8
- import { githubLightReplacements } from '@vendure-io/ui/lib/syntax-colors';
9
8
  import { createHighlighterCore } from 'shiki/core';
10
9
  import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
10
+ import { githubLightReplacements } from './syntax-colors.ts';
11
11
 
12
12
  /**
13
13
  * The design system's Shiki setup: a lazy shared highlighter with the DS themes
@@ -21,7 +21,7 @@ export const menuItemDisabled =
21
21
  */
22
22
  export const menuItem = cn(
23
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",
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-[calc(var(--radius-2xl)-5px)] 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
25
  );
26
26
 
27
27
  /**
@@ -1,4 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
+ import { isDevelopment } from './env.ts';
2
3
 
3
4
  /**
4
5
  * The state dictionary — the mechanism that makes the same entity state look
@@ -72,8 +73,6 @@ export function stateNameToWords(state: string): string {
72
73
  return sentence.charAt(0).toUpperCase() + sentence.slice(1);
73
74
  }
74
75
 
75
- const isDev = process.env.NODE_ENV !== 'production';
76
-
77
76
  /**
78
77
  * Declare a domain's state→tone map. The `Record<S, StateEntry>` argument is
79
78
  * exhaustive over `S`, so typing the call as `defineStateEntries<DeploymentStatus>`
@@ -94,7 +93,7 @@ export function defineStateEntries<S extends string>(entries: Record<S, StateEnt
94
93
  const entry = index.get(key);
95
94
  // Dedup on the lowercased key so casing variants of the same unknown state
96
95
  // ("Foo" / "foo") warn once — matching the lookup semantics.
97
- if (!entry && isDev && !warned.has(key)) {
96
+ if (!entry && isDevelopment && !warned.has(key)) {
98
97
  warned.add(key);
99
98
  console.warn(
100
99
  `[state-dictionary] Unmapped state "${state}" — rendering as neutral. ` +
@@ -57,12 +57,17 @@ export const alertTint =
57
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
58
 
59
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`.
60
+ * The tone and icon colour of each Alert tone, keyed by the state dictionary's
61
+ * tones. The tones match StatusBadge: `critical` tints with `destructive-text`
62
+ * and `progress` with `info-text`. Warning tints with the brighter
63
+ * `warning-indicator` (an amber text colour mixes to brown) and takes its icon
64
+ * from `warning-text`.
63
65
  */
64
66
  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
+ neutral: '[--alert-tone:var(--neutral-text)] *:[svg]:text-neutral-text',
67
68
  info: '[--alert-tone:var(--info-text)] *:[svg]:text-info-text',
69
+ success: '[--alert-tone:var(--success-text)] *:[svg]:text-success-text',
70
+ warning: '[--alert-tone:var(--warning-indicator)] *:[svg]:text-warning-text',
71
+ critical: '[--alert-tone:var(--destructive-text)] *:[svg]:text-destructive-text',
72
+ progress: '[--alert-tone:var(--info-text)] *:[svg]:text-info-text',
68
73
  };
package/src/lib/utils.ts CHANGED
@@ -12,7 +12,17 @@ const twMerge = extendTailwindMerge<'text-style'>({
12
12
  extend: {
13
13
  theme: {
14
14
  shadow: ['control', 'overlay', 'scrolled'],
15
- ease: ['default', 'spring', 'drawer', 'drawer-content', 'height', 'press', 'soft', 'flash'],
15
+ ease: [
16
+ 'default',
17
+ 'spring',
18
+ 'drawer',
19
+ 'drawer-content',
20
+ 'height',
21
+ 'press',
22
+ 'soft',
23
+ 'flash',
24
+ 'fold',
25
+ ],
16
26
  animate: [
17
27
  'shimmer',
18
28
  'spin-slow',
@@ -63,6 +73,14 @@ const twMerge = extendTailwindMerge<'text-style'>({
63
73
  'drawer-slide',
64
74
  'drawer-swipe',
65
75
  'alert-enter',
76
+ 'fold-open',
77
+ 'fold-close',
78
+ 'fold-row-in',
79
+ 'fold-row-out',
80
+ 'fold-badge-in',
81
+ 'fold-hand-off',
82
+ 'fold-stagger',
83
+ 'fold-step',
66
84
  'button-icon-turn',
67
85
  'external-arrow',
68
86
  'page-fade',
@@ -1,48 +0,0 @@
1
- import type * as React from 'react';
2
-
3
- /**
4
- * The value of the last unconditional `p-*` or `px-*` class in `className`,
5
- * as CSS: `p-0` → `0px`, `p-4` → `calc(var(--spacing) * 4)`, `p-px` → `1px`,
6
- * `p-[24px]` → `24px`, `p-(--gap)` → `var(--gap)`. `undefined` when there is
7
- * none. Classes with a variant (`sm:p-0`) are skipped: an inline style
8
- * cannot follow a breakpoint.
9
- */
10
- export function paddingFromClassName(className: unknown): string | undefined {
11
- if (typeof className !== 'string') return undefined;
12
- let value: string | undefined;
13
- for (const token of className.split(/\s+/)) {
14
- const match = /^!?px?-(.+?)!?$/.exec(token);
15
- if (!match || token.includes(':')) continue;
16
- const raw = match[1] as string;
17
- if (raw === 'px') value = '1px';
18
- else if (/^\d+(\.\d+)?$/.test(raw))
19
- value = raw === '0' ? '0px' : `calc(var(--spacing) * ${raw})`;
20
- else if (raw.startsWith('[') && raw.endsWith(']')) value = raw.slice(1, -1).replace(/_/g, ' ');
21
- else if (raw.startsWith('(--') && raw.endsWith(')')) value = `var(${raw.slice(1, -1)})`;
22
- }
23
- return value;
24
- }
25
-
26
- type StyleProp<State> =
27
- | React.CSSProperties
28
- | ((state: State) => React.CSSProperties | undefined)
29
- | undefined;
30
-
31
- /**
32
- * Sets `--dialog-padding` from a `p-*` or `px-*` class on the dialog, so the
33
- * pinned header and footer, which reach over the padding with negative
34
- * margins, stay flush with the dialog's edge. Code written for 2.x sets the
35
- * dialog's padding with a class (`p-0` around a full-bleed picker); without
36
- * this, its header and footer would stick out by the default 20px. A
37
- * `[--dialog-padding:…]` class still works: with no `p-*` class, nothing is set.
38
- */
39
- export function dialogPaddingStyle<State>(
40
- className: unknown,
41
- style: StyleProp<State>,
42
- ): StyleProp<State> {
43
- const padding = paddingFromClassName(className);
44
- if (padding === undefined) return style;
45
- const variable = { '--dialog-padding': padding } as React.CSSProperties;
46
- if (typeof style === 'function') return (state: State) => ({ ...variable, ...style(state) });
47
- return { ...variable, ...style };
48
- }