@vendure-io/ui 2.0.1 → 2.2.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.
@@ -15,7 +15,7 @@ import { SlidersHorizontalIcon } from 'lucide-react';
15
15
  // Relative: `data-table-helpers` is closed in the package exports.
16
16
  import { getHideableLeafColumns } from './data-table-helpers.tsx';
17
17
 
18
- // The column-visibility gear. Lists only hideable columns (`getCanHide()`), so
18
+ // The column picker ("Columns" trigger). Lists only hideable columns (`getCanHide()`), so
19
19
  // the always-on `select`/`actions` display columns never appear here. Labels
20
20
  // come from a string `ColumnDef.header`, falling back to the column id — `meta`
21
21
  // is deliberately never read (it belongs to the consumer, make-or-break #7).
@@ -40,10 +40,13 @@ function DataTableViewOptions<TData>({
40
40
 
41
41
  return (
42
42
  <DropdownMenu>
43
+ {/* `ml-auto` pins the trigger to the end of the controls row, so it reads
44
+ as a table setting even when no search input fills the row. */}
43
45
  <DropdownMenuTrigger
44
46
  data-slot="data-table-view-options"
47
+ className="ml-auto"
45
48
  render={
46
- <Button variant="outline" size="sm">
49
+ <Button variant="outline">
47
50
  <SlidersHorizontalIcon />
48
51
  {triggerLabel}
49
52
  </Button>
@@ -61,6 +61,29 @@ import * as React from 'react';
61
61
  // Relative: `data-table-helpers` is closed in the package exports.
62
62
  import { buildDisplayColumns, getSelectedRowIds, resolveSlot } from './data-table-helpers.tsx';
63
63
 
64
+ // Id of the generated row-actions column. Public: it is the `skeletonCells` key
65
+ // for the actions cell.
66
+ const ACTIONS_COLUMN_ID = 'actions';
67
+
68
+ /**
69
+ * One text line of loading placeholder: a box exactly one line box tall (`1lh`
70
+ * of the inherited font) with a bar centred in it, so a skeleton line is as tall
71
+ * as the text line it stands in for. Size the line with a text utility
72
+ * (`text-xs` for a muted sub-line) and its width with `w-*`. DataTable uses it as
73
+ * the default loading cell; stack several for multi-line `skeletonCells`.
74
+ */
75
+ function DataTableSkeletonLine({ className, ...props }: React.ComponentProps<'div'>) {
76
+ return (
77
+ <div
78
+ data-slot="data-table-skeleton-line"
79
+ className={cn('flex h-[1lh] w-full items-center', className)}
80
+ {...props}
81
+ >
82
+ <Skeleton className="h-[0.8lh] w-full" />
83
+ </div>
84
+ );
85
+ }
86
+
64
87
  // The composition root. Owns the single `useReactTable` instance and the
65
88
  // controlled/uncontrolled bridge, then lays out the card-framed table anatomy:
66
89
  // a CardHeader band (header → controls → chips → bulk overlay), a CardTable
@@ -126,6 +149,7 @@ function DataTable<TData>({
126
149
  getRowId,
127
150
  isLoading,
128
151
  skeletonRowCount = 10,
152
+ skeletonCells,
129
153
  pagination,
130
154
  sorting,
131
155
  filters,
@@ -235,7 +259,7 @@ function DataTable<TData>({
235
259
  // biome-ignore lint/suspicious/noExplicitAny: matches TanStack's ColumnDef value-type convention
236
260
  const actionsColumn: ColumnDef<TData, any> | undefined = rowActions
237
261
  ? {
238
- id: 'actions',
262
+ id: ACTIONS_COLUMN_ID,
239
263
  enableSorting: false,
240
264
  enableHiding: false,
241
265
  header: () => <span className="sr-only">{l.rowActions}</span>,
@@ -332,20 +356,65 @@ function DataTable<TData>({
332
356
  rowSelection != null
333
357
  ? table.getVisibleLeafColumns().find((column) => column.id !== selectColumnId)?.id
334
358
  : undefined;
359
+ // Which generated display column an id belongs to, if any. Consumer columns
360
+ // can't collide: buildDisplayColumns only injects these when configured.
361
+ const generatedColumn = (id: string): 'select' | 'actions' | undefined => {
362
+ if (rowSelection != null && id === selectColumnId) return 'select';
363
+ if (rowActions != null && id === ACTIONS_COLUMN_ID) return 'actions';
364
+ return undefined;
365
+ };
335
366
  const columnClass = (id: string): string | undefined => {
367
+ const generated = generatedColumn(id);
336
368
  // `pl-0!`: the select cell is the first child, so CardTable's edge-cell
337
369
  // padding would otherwise widen the zero-width cell and push the whole
338
370
  // gutter arrangement out; important because CardTable's descendant rule
339
371
  // out-specifies a plain utility on the cell.
340
- if (id === selectColumnId) return 'relative w-0 p-0 pl-0!';
372
+ if (generated === 'select') return 'relative w-0 p-0 pl-0!';
341
373
  if (id === leadingColumnId) return 'pl-8';
342
374
  // Actions cells drop vertical padding so a row-action button (taller than a
343
375
  // text line) sits inside the natural row height rather than inflating every
344
376
  // row; `align-middle` on the cell keeps it centred.
345
- if (id === 'actions') return 'py-0';
377
+ if (generated === 'actions') return 'py-0';
346
378
  return undefined;
347
379
  };
348
380
 
381
+ // Loading cells follow the real column layout (same ids, same cell classes),
382
+ // so a consumer's `skeletonCells` entry can match its loaded cell's height.
383
+ const skeletonCell = (id: string): React.ReactNode => {
384
+ const generated = generatedColumn(id);
385
+ // The checkbox is hidden at rest and the cell is zero-width, so there is
386
+ // nothing to stand in for — and no room for an override.
387
+ if (generated === 'select') return null;
388
+ // `null` is a deliberate empty cell; only a missing/undefined entry falls back.
389
+ const custom = skeletonCells?.[id];
390
+ if (custom !== undefined) return custom;
391
+ if (generated === 'actions') return <Skeleton className="size-8" />;
392
+ return <DataTableSkeletonLine />;
393
+ };
394
+
395
+ const warnedUnknownSkeletonCells = React.useRef(false);
396
+ if (
397
+ process.env.NODE_ENV !== 'production' &&
398
+ skeletonCells != null &&
399
+ !warnedUnknownSkeletonCells.current
400
+ ) {
401
+ const knownIds = new Set(
402
+ table
403
+ .getAllLeafColumns()
404
+ .map((column) => column.id)
405
+ .filter((id) => generatedColumn(id) !== 'select'),
406
+ );
407
+ const unknownKeys = Object.keys(skeletonCells).filter((key) => !knownIds.has(key));
408
+ if (unknownKeys.length > 0) {
409
+ warnedUnknownSkeletonCells.current = true;
410
+ console.warn(
411
+ `[DataTable] skeletonCells keys match no column: ${unknownKeys.join(', ')}. ` +
412
+ "Keys are column ids: `id`, else `accessorKey` with '.' replaced by '_' " +
413
+ "(`customer.name` → `customer_name`). The select column can't be overridden.",
414
+ );
415
+ }
416
+ }
417
+
349
418
  const toolbarNode = toolbar != null ? resolveSlot(toolbar, table) : undefined;
350
419
  const showViewOptions = columnVisibility != null && columnVisibility.showViewOptions !== false;
351
420
  const hasFilterMenu = Boolean(
@@ -461,11 +530,17 @@ function DataTable<TData>({
461
530
  {isLoading && rows.length === 0 ? (
462
531
  Array.from({ length: skeletonRowCount }).map((_, rowIndex) => (
463
532
  <TableRow key={`skeleton-${rowIndex}`}>
464
- {Array.from({ length: Math.max(columnCount, 1) }).map((__, cellIndex) => (
465
- <TableCell key={`skeleton-cell-${cellIndex}`}>
466
- <Skeleton className="h-4 w-full" />
533
+ {columnCount === 0 ? (
534
+ <TableCell>
535
+ <DataTableSkeletonLine />
467
536
  </TableCell>
468
- ))}
537
+ ) : (
538
+ table.getVisibleLeafColumns().map((column) => (
539
+ <TableCell key={column.id} className={columnClass(column.id)}>
540
+ {skeletonCell(column.id)}
541
+ </TableCell>
542
+ ))
543
+ )}
469
544
  </TableRow>
470
545
  ))
471
546
  ) : bodyRows.length === 0 ? (
@@ -569,7 +644,7 @@ function DataTable<TData>({
569
644
  );
570
645
  }
571
646
 
572
- export { DataTable };
647
+ export { DataTable, DataTableSkeletonLine };
573
648
 
574
649
  // Re-export the consumer-facing TanStack types so columns can be authored from
575
650
  // the same import as `DataTable` — no direct `@tanstack/react-table` dependency
@@ -1,15 +1,17 @@
1
1
  'use client';
2
2
 
3
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@vendure-io/ui/components/atoms/tooltip';
3
4
  import { CopyButton } from '@vendure-io/ui/components/molecules/copyable-text';
4
5
  import { cn } from '@vendure-io/ui/lib/utils';
5
6
 
6
7
  type TruncateMode = 'middle' | 'start' | 'none';
7
8
 
8
9
  /**
9
- * Shared chrome for the identifier-chip family (`IdChip`, `AnonymizedToken`): a
10
- * bordered, `bg-muted`, monospace `text-xs` pill sized to its content. Kept in
11
- * one place so the two chips can't drift apart — only their *contents* differ
12
- * (a plain value vs a blurred, reveal-on-hover secret).
10
+ * Shared chrome for the identifier-chip family (`IdChip`, `AnonymizedToken`,
11
+ * `SecretValue`): a bordered, `bg-muted`, monospace `text-xs` pill sized to its
12
+ * content. Kept in one place so the chips can't drift apart — only their
13
+ * *contents* differ (a plain value, a blurred reveal-on-hover secret, or a
14
+ * masked secret loaded on click).
13
15
  */
14
16
  function chipChromeClass(copyable: boolean, className?: string): string {
15
17
  return cn(
@@ -31,7 +33,7 @@ function truncateId(value: string, mode: TruncateMode): string {
31
33
  }
32
34
 
33
35
  interface IdChipProps {
34
- /** The full value — always copied in full and revealed on hover via `title`. */
36
+ /** The full value: always copied in full, and shown in a tooltip when the chip shortens it. */
35
37
  value: string;
36
38
  /** Override the rendered text (e.g. a longer prefix). Bypasses `truncate`. */
37
39
  display?: string;
@@ -42,12 +44,21 @@ interface IdChipProps {
42
44
  className?: string;
43
45
  /** Called after a successful copy. Wire your toast here — the DS never toasts. Falls back to `CopyFeedbackProvider`. */
44
46
  onCopied?: () => void;
47
+ /** Called when the clipboard write fails. Falls back to `CopyFeedbackProvider`. */
48
+ onCopyError?: (error: Error) => void;
49
+ /** Accessible label of the copy button before copying, e.g. "Copy commit SHA". @default "Copy" */
50
+ copyLabel?: string;
51
+ /** Accessible label of the copy button while the copied state is active. @default "Copied" */
52
+ copiedLabel?: string;
53
+ /** How long the check-mark feedback stays visible, in ms. @default 2000 */
54
+ timeout?: number;
45
55
  }
46
56
 
47
57
  /**
48
58
  * A bordered, monospace chip for IDs/tokens with a built-in copy affordance.
49
59
  * The rendered text is truncated for density while the full value is copied and
50
- * available on hover (`title`).
60
+ * shown in a DS Tooltip on hover, or when the copy button has focus. The chip
61
+ * adds no tab stop of its own; the copy button is its only interactive part.
51
62
  */
52
63
  function IdChip({
53
64
  value,
@@ -56,23 +67,42 @@ function IdChip({
56
67
  copyable = true,
57
68
  className,
58
69
  onCopied,
70
+ onCopyError,
71
+ copyLabel,
72
+ copiedLabel,
73
+ timeout,
59
74
  }: IdChipProps) {
60
75
  const text = display ?? truncateId(value, truncate);
61
-
62
- return (
63
- <span data-slot="id-chip" title={value} className={chipChromeClass(copyable, className)}>
76
+ const chip = (
77
+ <span data-slot="id-chip" className={chipChromeClass(copyable, className)}>
64
78
  <span className="truncate">{text}</span>
65
79
  {/* 16px visual button to match the chip's density, but the ::after inset
66
80
  extends the hit target to 24px for the WCAG 2.2 AA minimum. */}
67
81
  {copyable ? (
68
82
  <CopyButton
69
83
  value={value}
84
+ timeout={timeout}
70
85
  onCopied={onCopied}
86
+ onCopyError={onCopyError}
87
+ copyLabel={copyLabel}
88
+ copiedLabel={copiedLabel}
71
89
  className="relative size-4 after:absolute after:-inset-1"
72
90
  />
73
91
  ) : null}
74
92
  </span>
75
93
  );
94
+
95
+ // Nothing is hidden when the chip shows the whole value.
96
+ if (text === value) return chip;
97
+
98
+ // The chip itself is the trigger, so hover anywhere on it opens the tooltip;
99
+ // focus on the copy button bubbles to it for keyboard users.
100
+ return (
101
+ <Tooltip>
102
+ <TooltipTrigger render={chip} />
103
+ <TooltipContent className="font-mono">{value}</TooltipContent>
104
+ </Tooltip>
105
+ );
76
106
  }
77
107
 
78
108
  export { chipChromeClass, IdChip };
@@ -1,8 +1,10 @@
1
1
  'use client';
2
2
 
3
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@vendure-io/ui/components/atoms/tooltip';
3
4
  import { useFormatSettings } from '@vendure-io/ui/components/molecules/format-provider';
4
5
  import { type FormatRelativeOptions, formatRelative } from '@vendure-io/ui/lib/format-relative';
5
- import { type ComponentProps, type ReactNode, useEffect, useState } from 'react';
6
+ import { cn } from '@vendure-io/ui/lib/utils';
7
+ import { type ComponentProps, type ReactNode, useEffect, useId, useState } from 'react';
6
8
 
7
9
  function toDate(value: string | number | Date | null | undefined): Date | null {
8
10
  if (value === null || value === undefined) return null;
@@ -23,6 +25,19 @@ interface RelativeTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
23
25
  updateInterval?: number | false;
24
26
  /** Rendered for nullish/invalid input. Default `'—'`. */
25
27
  fallback?: ReactNode;
28
+ /**
29
+ * Show the absolute time in a DS Tooltip on hover. Default `true`. Pass
30
+ * `false` where the time sits inside another tooltip trigger, so the outer
31
+ * tooltip keeps its content. The absolute time stays the accessible
32
+ * description either way.
33
+ */
34
+ tooltip?: boolean;
35
+ /**
36
+ * Make the time a tab stop so keyboard users can open the tooltip. Default
37
+ * `false`. Opt in where the exact time matters to keyboard users, and never
38
+ * inside interactive content such as a link or a button. Needs `tooltip`.
39
+ */
40
+ focusable?: boolean;
26
41
  }
27
42
 
28
43
  /**
@@ -30,7 +45,11 @@ interface RelativeTimeProps extends Omit<ComponentProps<'time'>, 'dateTime'> {
30
45
  * first client render can disagree. The `<time>` carries
31
46
  * `suppressHydrationWarning` and re-formats once right after mount; SSR
32
47
  * consumers should still pin `locale`/`timeZone` via `FormatProvider` (or
33
- * props) so the absolute `title` matches too.
48
+ * props) so the absolute description matches too.
49
+ *
50
+ * The absolute time is never a native `title`. It is the accessible
51
+ * description (a hidden child linked by `aria-describedby`), and it shows in
52
+ * the DS Tooltip on hover unless `tooltip={false}`.
34
53
  */
35
54
  function RelativeTime({
36
55
  value,
@@ -39,8 +58,11 @@ function RelativeTime({
39
58
  unitStyle,
40
59
  updateInterval = 60_000,
41
60
  fallback = '—',
61
+ tooltip = true,
62
+ focusable = false,
42
63
  ...props
43
64
  }: RelativeTimeProps) {
65
+ const descriptionId = useId();
44
66
  const settings = useFormatSettings();
45
67
  // A bare counter to force a re-format on each tick; the value itself is unused.
46
68
  const [, tick] = useState(0);
@@ -62,17 +84,50 @@ function RelativeTime({
62
84
  if (!date) return <>{fallback}</>;
63
85
 
64
86
  const resolvedLocale = locale ?? settings.locale;
87
+ const absolute = date.toLocaleString(resolvedLocale, { timeZone: settings.timeZone });
88
+ const relative = formatRelative(date, { locale: resolvedLocale, numeric, unitStyle });
89
+ const describedBy = [props['aria-describedby'], descriptionId].filter(Boolean).join(' ');
90
+ // The description is a `hidden` child, so the component renders one element.
91
+ // `hidden` keeps the text out of view and out of the reading flow;
92
+ // aria-describedby still resolves it.
93
+ const content = (
94
+ <>
95
+ {relative}
96
+ <span id={descriptionId} hidden suppressHydrationWarning>
97
+ {absolute}
98
+ </span>
99
+ </>
100
+ );
101
+ const timeProps = {
102
+ 'data-slot': 'relative-time',
103
+ dateTime: date.toISOString(),
104
+ suppressHydrationWarning: true,
105
+ ...props,
106
+ 'aria-describedby': describedBy,
107
+ };
108
+
109
+ if (!tooltip) return <time {...timeProps}>{content}</time>;
65
110
 
66
111
  return (
67
- <time
68
- data-slot="relative-time"
69
- dateTime={date.toISOString()}
70
- title={date.toLocaleString(resolvedLocale, { timeZone: settings.timeZone })}
71
- suppressHydrationWarning
72
- {...props}
73
- >
74
- {formatRelative(date, { locale: resolvedLocale, numeric, unitStyle })}
75
- </time>
112
+ <Tooltip>
113
+ <TooltipTrigger
114
+ render={
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>
76
131
  );
77
132
  }
78
133
 
@@ -0,0 +1,183 @@
1
+ 'use client';
2
+
3
+ import { Button } from '@vendure-io/ui/components/atoms/button';
4
+ import { Spinner } from '@vendure-io/ui/components/atoms/spinner';
5
+ import {
6
+ CopyButton,
7
+ type CopyButtonProps,
8
+ } from '@vendure-io/ui/components/molecules/copyable-text';
9
+ import { chipChromeClass } from '@vendure-io/ui/components/molecules/id-chip';
10
+ import { EyeIcon, EyeOffIcon } from 'lucide-react';
11
+ import type * as React from 'react';
12
+ import { useReducer, useRef } from 'react';
13
+
14
+ interface SecretValueProps extends Omit<React.ComponentProps<'span'>, 'children'> {
15
+ /**
16
+ * Loads the full value on request, for secrets the server returns only when
17
+ * asked. Reveal and copy call it; each call may be audited, so it never runs
18
+ * on hover or focus.
19
+ */
20
+ loadValue: () => Promise<string>;
21
+ /** Render the copy affordance. Copy while hidden loads without revealing. @default true */
22
+ copyable?: boolean;
23
+ /** How long the check-mark feedback stays visible, in ms. */
24
+ timeout?: CopyButtonProps['timeout'];
25
+ /** Called after a successful copy. Wire your toast here. Falls back to `CopyFeedbackProvider`. */
26
+ onCopied?: CopyButtonProps['onCopied'];
27
+ /** Called when the load or the clipboard write fails. Falls back to `CopyFeedbackProvider`. */
28
+ onCopyError?: CopyButtonProps['onCopyError'];
29
+ /** Accessible name while the value is masked. @default "Hidden value" */
30
+ hiddenLabel?: string;
31
+ /** Accessible label of the reveal button. @default "Show value" */
32
+ showLabel?: string;
33
+ /** Accessible label of the button that masks the value again. @default "Hide value" */
34
+ hideLabel?: string;
35
+ /** Accessible label before copying. @default "Copy value" */
36
+ copyLabel?: CopyButtonProps['copyLabel'];
37
+ /** Accessible label while the copied state is active. @default "Value copied" */
38
+ copiedLabel?: CopyButtonProps['copiedLabel'];
39
+ /** Shown inline when `loadValue` rejects. @default "Couldn't load the value." */
40
+ loadErrorMessage?: string;
41
+ }
42
+
43
+ const MASK = '••••••••';
44
+
45
+ type RevealState =
46
+ | { status: 'hidden' }
47
+ | { status: 'loading' }
48
+ | { status: 'revealed'; value: string }
49
+ | { status: 'error' };
50
+
51
+ type RevealAction =
52
+ | { type: 'load' }
53
+ | { type: 'loaded'; value: string }
54
+ | { type: 'failed' }
55
+ | { type: 'hide' };
56
+
57
+ /** State of a SecretValue: hidden, loading, revealed or error. */
58
+ function revealReducer(state: RevealState, action: RevealAction): RevealState {
59
+ switch (action.type) {
60
+ case 'load':
61
+ return state.status === 'revealed' ? state : { status: 'loading' };
62
+ case 'loaded':
63
+ return state.status === 'loading' ? { status: 'revealed', value: action.value } : state;
64
+ case 'failed':
65
+ return state.status === 'loading' ? { status: 'error' } : state;
66
+ case 'hide':
67
+ return { status: 'hidden' };
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Shows a secret that the server returns only on request. At rest it is a fixed
73
+ * mask; a click on the reveal button loads and shows the value, and copy loads
74
+ * it without showing it. Hiding drops the value from state.
75
+ *
76
+ * Use `AnonymizedToken` instead when the full value is already on the client.
77
+ */
78
+ function SecretValue({
79
+ loadValue,
80
+ copyable = true,
81
+ timeout,
82
+ onCopied,
83
+ onCopyError,
84
+ hiddenLabel = 'Hidden value',
85
+ showLabel = 'Show value',
86
+ hideLabel = 'Hide value',
87
+ copyLabel = 'Copy value',
88
+ copiedLabel = 'Value copied',
89
+ loadErrorMessage = "Couldn't load the value.",
90
+ className,
91
+ ...props
92
+ }: SecretValueProps) {
93
+ const [state, dispatch] = useReducer(revealReducer, { status: 'hidden' });
94
+ // Drops a load that settles after the user hid the value or asked again.
95
+ const request = useRef(0);
96
+
97
+ async function reveal() {
98
+ const id = ++request.current;
99
+ dispatch({ type: 'load' });
100
+ try {
101
+ const value = await loadValue();
102
+ if (id === request.current) dispatch({ type: 'loaded', value });
103
+ } catch {
104
+ if (id === request.current) dispatch({ type: 'failed' });
105
+ }
106
+ }
107
+
108
+ function hide() {
109
+ request.current++;
110
+ dispatch({ type: 'hide' });
111
+ }
112
+
113
+ const revealed = state.status === 'revealed';
114
+ const loading = state.status === 'loading';
115
+
116
+ return (
117
+ <span
118
+ data-slot="secret-value"
119
+ data-state={state.status}
120
+ role="group"
121
+ className={chipChromeClass(copyable, className)}
122
+ {...props}
123
+ >
124
+ {/* The mask is fixed: no fake prefix or suffix. The value is visible text
125
+ only after a deliberate reveal, and never in a title or label. */}
126
+ {revealed ? (
127
+ // `whitespace-normal` lets the value wrap inside a `whitespace-nowrap`
128
+ // parent such as a TableCell, so a long value grows the row in height
129
+ // instead of widening the table.
130
+ <code data-slot="secret-value-value" className="min-w-0 break-all whitespace-normal">
131
+ {state.value}
132
+ </code>
133
+ ) : (
134
+ <>
135
+ <code data-slot="secret-value-value" aria-hidden="true">
136
+ {MASK}
137
+ </code>
138
+ <span className="sr-only">{hiddenLabel}</span>
139
+ </>
140
+ )}
141
+ <Button
142
+ type="button"
143
+ data-slot="secret-value-reveal"
144
+ variant="ghost"
145
+ size="icon-xs"
146
+ aria-label={revealed ? hideLabel : showLabel}
147
+ aria-busy={loading || undefined}
148
+ aria-disabled={loading || undefined}
149
+ className="text-muted-foreground hover:text-foreground relative size-4 shrink-0 after:absolute after:-inset-1"
150
+ onClick={() => {
151
+ if (loading) return;
152
+ if (revealed) hide();
153
+ else void reveal();
154
+ }}
155
+ >
156
+ {loading ? <Spinner /> : revealed ? <EyeOffIcon /> : <EyeIcon />}
157
+ </Button>
158
+ {copyable ? (
159
+ <CopyButton
160
+ value={revealed ? state.value : loadValue}
161
+ timeout={timeout}
162
+ onCopied={onCopied}
163
+ onCopyError={onCopyError}
164
+ copyLabel={copyLabel}
165
+ copiedLabel={copiedLabel}
166
+ className="relative size-4 shrink-0 after:absolute after:-inset-1"
167
+ />
168
+ ) : null}
169
+ {state.status === 'error' ? (
170
+ <span
171
+ data-slot="secret-value-error"
172
+ role="alert"
173
+ className="text-destructive-subtle-foreground pr-1 font-sans"
174
+ >
175
+ {loadErrorMessage}
176
+ </span>
177
+ ) : null}
178
+ </span>
179
+ );
180
+ }
181
+
182
+ export { SecretValue };
183
+ export type { SecretValueProps };
@@ -31,6 +31,12 @@ export interface EmptyStateProps extends Omit<React.ComponentProps<typeof Empty>
31
31
  * owns its perimeter.
32
32
  */
33
33
  bordered?: boolean;
34
+ /**
35
+ * `compact` drops the illustration and icon and tightens the spacing, for a
36
+ * small panel or side column where the full state is too tall. Keep it to a
37
+ * title, a description and at most one action. Defaults to `default`.
38
+ */
39
+ size?: 'default' | 'compact';
34
40
  }
35
41
 
36
42
  /**
@@ -49,36 +55,38 @@ function EmptyState({
49
55
  description,
50
56
  children,
51
57
  bordered = true,
58
+ size = 'default',
52
59
  className,
53
60
  ...props
54
61
  }: EmptyStateProps) {
62
+ const compact = size === 'compact';
55
63
  // Precedence: an explicit `illustration` (including `null`, to opt out)
56
64
  // always wins; otherwise an explicit `icon` keeps rendering exactly as
57
65
  // before. Only when neither is touched does the default illustration fill
58
66
  // the media slot, so existing icon-only consumers see no change.
59
- const resolvedIllustration =
60
- illustration !== undefined ? (
61
- illustration
62
- ) : icon === undefined ? (
63
- <EmptyCollectionIllustration />
64
- ) : null;
67
+ const resolvedIllustration = compact ? null : illustration !== undefined ? (
68
+ illustration
69
+ ) : icon === undefined ? (
70
+ <EmptyCollectionIllustration />
71
+ ) : null;
65
72
 
66
73
  return (
67
74
  <Empty
68
75
  data-slot="empty-state"
69
- className={cn(bordered ? 'border' : 'rounded-none', className)}
76
+ data-size={size}
77
+ className={cn(bordered ? 'border' : 'rounded-none', compact && 'gap-2 p-4', className)}
70
78
  {...props}
71
79
  >
72
80
  <EmptyHeader>
73
81
  {resolvedIllustration ? (
74
82
  <EmptyMedia>{resolvedIllustration}</EmptyMedia>
75
- ) : icon ? (
83
+ ) : icon && !compact ? (
76
84
  <EmptyMedia variant="icon">{icon}</EmptyMedia>
77
85
  ) : null}
78
- <EmptyTitle>{title}</EmptyTitle>
86
+ <EmptyTitle className={cn(compact && 'text-style-card-title')}>{title}</EmptyTitle>
79
87
  {description ? <EmptyDescription>{description}</EmptyDescription> : null}
80
88
  </EmptyHeader>
81
- {children ? <EmptyContent>{children}</EmptyContent> : null}
89
+ {children ? <EmptyContent className={cn(compact && 'gap-2')}>{children}</EmptyContent> : null}
82
90
  </Empty>
83
91
  );
84
92
  }