@workflow/web-shared 5.1.1 → 5.3.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.
Files changed (175) hide show
  1. package/dist/components/event-list/event-details-panel.d.ts.map +1 -1
  2. package/dist/components/event-list/event-details-panel.js +7 -6
  3. package/dist/components/event-list/event-list-toolbar.d.ts +2 -1
  4. package/dist/components/event-list/event-list-toolbar.d.ts.map +1 -1
  5. package/dist/components/event-list/event-list-toolbar.js +20 -11
  6. package/dist/components/event-list/event-row.d.ts +3 -3
  7. package/dist/components/event-list/event-row.d.ts.map +1 -1
  8. package/dist/components/event-list/event-row.js +15 -13
  9. package/dist/components/event-list/use-event-search.d.ts +3 -1
  10. package/dist/components/event-list/use-event-search.d.ts.map +1 -1
  11. package/dist/components/event-list/use-event-search.js +19 -20
  12. package/dist/components/event-list-view.d.ts.map +1 -1
  13. package/dist/components/event-list-view.js +53 -24
  14. package/dist/components/hook-actions.d.ts +0 -1
  15. package/dist/components/hook-actions.d.ts.map +1 -1
  16. package/dist/components/hook-actions.js +1 -3
  17. package/dist/components/index.d.ts +5 -9
  18. package/dist/components/index.d.ts.map +1 -1
  19. package/dist/components/index.js +4 -9
  20. package/dist/components/sidebar/attribute-panel.d.ts +0 -13
  21. package/dist/components/sidebar/attribute-panel.d.ts.map +1 -1
  22. package/dist/components/sidebar/attribute-panel.js +5 -5
  23. package/dist/components/sidebar/attributes-block.d.ts +0 -7
  24. package/dist/components/sidebar/attributes-block.d.ts.map +1 -1
  25. package/dist/components/sidebar/attributes-block.js +5 -5
  26. package/dist/components/sidebar/conversation-view.d.ts.map +1 -1
  27. package/dist/components/sidebar/conversation-view.js +4 -3
  28. package/dist/components/sidebar/copyable-data-block.d.ts.map +1 -1
  29. package/dist/components/sidebar/copyable-data-block.js +8 -6
  30. package/dist/components/sidebar/entity-detail-panel.d.ts.map +1 -1
  31. package/dist/components/sidebar/entity-detail-panel.js +2 -3
  32. package/dist/components/stream-image-preview.js +2 -2
  33. package/dist/components/stream-viewer.js +3 -3
  34. package/dist/components/trace-viewer/components/detail-panel-shell.d.ts +2 -1
  35. package/dist/components/trace-viewer/components/detail-panel-shell.d.ts.map +1 -1
  36. package/dist/components/trace-viewer/components/detail-panel-shell.js +3 -3
  37. package/dist/components/trace-viewer/components/event-list.d.ts.map +1 -1
  38. package/dist/components/trace-viewer/components/event-list.js +2 -2
  39. package/dist/components/trace-viewer/components/middle-truncate/truncate.d.ts +1 -4
  40. package/dist/components/trace-viewer/components/middle-truncate/truncate.d.ts.map +1 -1
  41. package/dist/components/trace-viewer/components/middle-truncate/truncate.js +2 -2
  42. package/dist/components/trace-viewer/components/minimap.d.ts.map +1 -1
  43. package/dist/components/trace-viewer/components/minimap.js +6 -4
  44. package/dist/components/trace-viewer/components/timeline.d.ts +0 -11
  45. package/dist/components/trace-viewer/components/timeline.d.ts.map +1 -1
  46. package/dist/components/trace-viewer/components/timeline.js +1 -2
  47. package/dist/components/trace-viewer/trace-viewer.js +9 -10
  48. package/dist/components/ui/button.d.ts +28 -17
  49. package/dist/components/ui/button.d.ts.map +1 -1
  50. package/dist/components/ui/button.js +47 -43
  51. package/dist/components/ui/context-card.js +3 -3
  52. package/dist/components/ui/copy-button.d.ts +15 -0
  53. package/dist/components/ui/copy-button.d.ts.map +1 -0
  54. package/dist/components/ui/copy-button.js +41 -0
  55. package/dist/components/ui/data-inspector.d.ts.map +1 -1
  56. package/dist/components/ui/data-inspector.js +8 -38
  57. package/dist/components/ui/decrypt-button.d.ts +3 -2
  58. package/dist/components/ui/decrypt-button.d.ts.map +1 -1
  59. package/dist/components/ui/decrypt-button.js +13 -7
  60. package/dist/components/ui/duplicate-event-tooltip.d.ts +1 -9
  61. package/dist/components/ui/duplicate-event-tooltip.d.ts.map +1 -1
  62. package/dist/components/ui/duplicate-event-tooltip.js +2 -10
  63. package/dist/components/ui/error-stack-block.js +3 -3
  64. package/dist/components/ui/icon-button.d.ts +2 -2
  65. package/dist/components/ui/icon-button.d.ts.map +1 -1
  66. package/dist/components/ui/icon-button.js +2 -3
  67. package/dist/components/ui/kbd.d.ts +1 -1
  68. package/dist/components/ui/kbd.d.ts.map +1 -1
  69. package/dist/components/ui/kbd.js +1 -2
  70. package/dist/components/ui/search-input.d.ts +19 -0
  71. package/dist/components/ui/search-input.d.ts.map +1 -0
  72. package/dist/components/ui/search-input.js +61 -0
  73. package/dist/components/ui/spinner.d.ts +54 -6
  74. package/dist/components/ui/spinner.d.ts.map +1 -1
  75. package/dist/components/ui/spinner.js +84 -46
  76. package/dist/components/workflow-traces/trace-span-construction.d.ts +1 -22
  77. package/dist/components/workflow-traces/trace-span-construction.d.ts.map +1 -1
  78. package/dist/components/workflow-traces/trace-span-construction.js +3 -3
  79. package/dist/index.d.ts +9 -14
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +8 -11
  82. package/dist/lib/event-analysis.d.ts +1 -25
  83. package/dist/lib/event-analysis.d.ts.map +1 -1
  84. package/dist/lib/event-analysis.js +2 -75
  85. package/dist/lib/event-list-model.d.ts +4 -2
  86. package/dist/lib/event-list-model.d.ts.map +1 -1
  87. package/dist/lib/event-list-model.js +13 -11
  88. package/dist/lib/exact-event-search-id.d.ts +0 -2
  89. package/dist/lib/exact-event-search-id.d.ts.map +1 -1
  90. package/dist/lib/exact-event-search-id.js +1 -12
  91. package/dist/lib/hydration.d.ts +1 -12
  92. package/dist/lib/hydration.d.ts.map +1 -1
  93. package/dist/lib/hydration.js +8 -20
  94. package/dist/lib/stream-display.d.ts +0 -1
  95. package/dist/lib/stream-display.d.ts.map +1 -1
  96. package/dist/lib/stream-display.js +2 -2
  97. package/dist/lib/trace-builder.d.ts +0 -8
  98. package/dist/lib/trace-builder.d.ts.map +1 -1
  99. package/dist/lib/trace-builder.js +2 -2
  100. package/dist/lib/utils.d.ts +0 -22
  101. package/dist/lib/utils.d.ts.map +1 -1
  102. package/dist/lib/utils.js +1 -31
  103. package/dist/styles.css +286 -117
  104. package/package.json +5 -17
  105. package/src/components/event-list/event-details-panel.tsx +22 -26
  106. package/src/components/event-list/event-list-toolbar.tsx +35 -28
  107. package/src/components/event-list/event-row.tsx +33 -29
  108. package/src/components/event-list/use-event-search.ts +29 -22
  109. package/src/components/event-list-view.tsx +180 -52
  110. package/src/components/hook-actions.tsx +0 -1
  111. package/src/components/index.ts +4 -20
  112. package/src/components/sidebar/attribute-panel.tsx +4 -7
  113. package/src/components/sidebar/attributes-block.tsx +7 -6
  114. package/src/components/sidebar/conversation-view.tsx +3 -2
  115. package/src/components/sidebar/copyable-data-block.tsx +17 -14
  116. package/src/components/sidebar/entity-detail-panel.tsx +2 -7
  117. package/src/components/stream-image-preview.tsx +1 -1
  118. package/src/components/stream-viewer.tsx +4 -4
  119. package/src/components/trace-viewer/components/detail-panel-shell.tsx +3 -0
  120. package/src/components/trace-viewer/components/event-list.tsx +16 -18
  121. package/src/components/trace-viewer/components/middle-truncate/truncate.ts +1 -2
  122. package/src/components/trace-viewer/components/minimap.tsx +4 -3
  123. package/src/components/trace-viewer/components/timeline.tsx +0 -2
  124. package/src/components/trace-viewer/trace-viewer.tsx +19 -38
  125. package/src/components/ui/button.tsx +144 -46
  126. package/src/components/ui/context-card.tsx +2 -2
  127. package/src/components/ui/copy-button.tsx +86 -0
  128. package/src/components/ui/data-inspector.tsx +23 -67
  129. package/src/components/ui/decrypt-button.tsx +23 -48
  130. package/src/components/ui/duplicate-event-tooltip.tsx +1 -22
  131. package/src/components/ui/error-stack-block.tsx +4 -4
  132. package/src/components/ui/icon-button.tsx +1 -3
  133. package/src/components/ui/kbd.tsx +0 -2
  134. package/src/components/ui/search-input.tsx +143 -0
  135. package/src/components/ui/spinner.tsx +105 -55
  136. package/src/components/workflow-traces/trace-span-construction.ts +2 -2
  137. package/src/index.ts +7 -55
  138. package/src/lib/event-analysis.ts +1 -104
  139. package/src/lib/event-list-model.ts +15 -12
  140. package/src/lib/exact-event-search-id.ts +0 -13
  141. package/src/lib/hydration.ts +6 -31
  142. package/src/lib/stream-display.ts +1 -1
  143. package/src/lib/trace-builder.ts +1 -1
  144. package/src/lib/utils.ts +0 -48
  145. package/src/styles.css +286 -117
  146. package/dist/components/trace-viewer/components/copy-button.d.ts +0 -9
  147. package/dist/components/trace-viewer/components/copy-button.d.ts.map +0 -1
  148. package/dist/components/trace-viewer/components/copy-button.js +0 -27
  149. package/dist/components/ui/alert.d.ts +0 -9
  150. package/dist/components/ui/alert.d.ts.map +0 -1
  151. package/dist/components/ui/alert.js +0 -23
  152. package/dist/components/ui/card.d.ts +0 -9
  153. package/dist/components/ui/card.d.ts.map +0 -1
  154. package/dist/components/ui/card.js +0 -18
  155. package/dist/components/ui/load-more-button.d.ts +0 -13
  156. package/dist/components/ui/load-more-button.d.ts.map +0 -1
  157. package/dist/components/ui/load-more-button.js +0 -12
  158. package/dist/components/ui/menu-dropdown.d.ts +0 -16
  159. package/dist/components/ui/menu-dropdown.d.ts.map +0 -1
  160. package/dist/components/ui/menu-dropdown.js +0 -30
  161. package/dist/hooks/use-dark-mode.d.ts +0 -9
  162. package/dist/hooks/use-dark-mode.d.ts.map +0 -1
  163. package/dist/hooks/use-dark-mode.js +0 -30
  164. package/dist/lib/event-materialization.d.ts +0 -91
  165. package/dist/lib/event-materialization.d.ts.map +0 -1
  166. package/dist/lib/event-materialization.js +0 -219
  167. package/src/components/index.d.ts +0 -1
  168. package/src/components/trace-viewer/components/copy-button.tsx +0 -68
  169. package/src/components/ui/alert.tsx +0 -59
  170. package/src/components/ui/card.tsx +0 -79
  171. package/src/components/ui/load-more-button.tsx +0 -38
  172. package/src/components/ui/menu-dropdown.tsx +0 -97
  173. package/src/hooks/use-dark-mode.ts +0 -34
  174. package/src/index.d.ts +0 -1
  175. package/src/lib/event-materialization.ts +0 -304
@@ -102,7 +102,7 @@ const EventRow = ({
102
102
  return (
103
103
  <li
104
104
  className={cn(
105
- 'relative overflow-clip group transition-opacity',
105
+ 'relative overflow-clip transition-opacity hover:bg-gray-100 aria-selected:bg-gray-100 aria-selected:hover:bg-gray-200',
106
106
  ROW_HEIGHT_CLASS,
107
107
  isDimmed && 'opacity-35'
108
108
  )}
@@ -112,23 +112,21 @@ const EventRow = ({
112
112
  aria-level={1}
113
113
  onClick={() => onSelectSpan(span.spanId)}
114
114
  >
115
- <div className="h-full hover:bg-gray-100 group-aria-selected:bg-gray-100 group-aria-selected:hover:bg-gray-200">
116
- <div className="flex h-full min-w-0 items-center pl-4 pr-2">
117
- <div className="flex min-w-0 flex-1 items-center gap-2">
118
- <ResourceIcon
119
- resource={span.resource}
120
- isErrored={isErrored}
121
- isCancelled={isCancelled}
122
- />
123
- <span className="min-w-0 text-label-14">
124
- <MiddleTruncate value={span.name} />
125
- </span>
126
- </div>
127
- <div className="ml-2 shrink-0">
128
- <span className="text-label-14 text-gray-900 tabular-nums">
129
- {formatDurationPrecise(durationMs)}
130
- </span>
131
- </div>
115
+ <div className="flex h-full min-w-0 items-center pl-4 pr-2">
116
+ <div className="flex min-w-0 flex-1 items-center gap-2">
117
+ <ResourceIcon
118
+ resource={span.resource}
119
+ isErrored={isErrored}
120
+ isCancelled={isCancelled}
121
+ />
122
+ <span className="min-w-0 text-label-14">
123
+ <MiddleTruncate value={span.name} />
124
+ </span>
125
+ </div>
126
+ <div className="ml-2 shrink-0">
127
+ <span className="text-label-14 text-gray-900 tabular-nums">
128
+ {formatDurationPrecise(durationMs)}
129
+ </span>
132
130
  </div>
133
131
  </div>
134
132
  </li>
@@ -128,5 +128,4 @@ function middleTruncate(
128
128
  return buildCandidate(graphemes, best);
129
129
  }
130
130
 
131
- export { middleTruncate, toGraphemes, ELLIPSIS, MIN_START, MIN_END };
132
- export type { MeasureFn, TruncateResult };
131
+ export { middleTruncate, toGraphemes, ELLIPSIS };
@@ -236,8 +236,9 @@ export const Minimap = memo(function Minimap({
236
236
  const drawToken = (token: string): void => {
237
237
  const rects = rectsByToken.get(token);
238
238
  if (!rects) return;
239
- ctx.fillStyle =
240
- style.getPropertyValue(token).trim() || 'rgb(160,160,160)';
239
+ const color = style.getPropertyValue(token).trim();
240
+ if (!color) return;
241
+ ctx.fillStyle = color;
241
242
  ctx.beginPath();
242
243
  for (const [x, y, w] of rects) {
243
244
  ctx.roundRect(x, y, w, lineHeight, lineHeight / 2);
@@ -499,7 +500,7 @@ export const Minimap = memo(function Minimap({
499
500
  <canvas
500
501
  ref={canvasRef}
501
502
  aria-hidden
502
- className="pointer-events-none absolute inset-0 h-full w-full mix-blend-multiply [.dark-theme_&]:mix-blend-screen [.dark_&]:mix-blend-screen [[data-theme=dark]_&]:mix-blend-screen"
503
+ className="pointer-events-none absolute inset-0 h-full w-full mix-blend-multiply dark:mix-blend-screen"
503
504
  />
504
505
  {selection ? (
505
506
  <div
@@ -539,8 +539,6 @@ const TimelineBar = memo(function TimelineBar({
539
539
  );
540
540
  });
541
541
 
542
- export { TimelineBar };
543
-
544
542
  // ---------------------------------------------------------------------------
545
543
  // DeltaMeasureLine (Alt-key measurement overlays: the selected ↔ hovered
546
544
  // measurement, and the ambient consecutive-gap indicators shown without a
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import { RotateCcw, Search, ZoomIn, ZoomOut } from 'lucide-react';
3
+ import { RotateCcw, ZoomIn, ZoomOut } from 'lucide-react';
4
4
  import {
5
5
  type ReactNode,
6
6
  useCallback,
@@ -13,7 +13,7 @@ import {
13
13
  import { useLoadMoreOnScroll } from '../../hooks/use-load-more-on-scroll';
14
14
  import { useReducedMotion } from '../../hooks/use-reduced-motion';
15
15
  import { IconButton } from '../ui/icon-button';
16
- import { Kbd } from '../ui/kbd';
16
+ import { SearchInput } from '../ui/search-input';
17
17
  import { Spinner } from '../ui/spinner';
18
18
  import { TooltipProvider } from '../ui/tooltip';
19
19
  import { TraceDetailPanel } from './components/detail-panel';
@@ -163,6 +163,12 @@ function TraceViewerContent({
163
163
 
164
164
  const reducedMotion = useReducedMotion();
165
165
 
166
+ const [isLanding, setIsLanding] = useState(activeSpanId !== null);
167
+ useEffect(() => {
168
+ const timer = setTimeout(() => setIsLanding(false), 1000);
169
+ return () => clearTimeout(timer);
170
+ }, []);
171
+
166
172
  const [searchQuery, setSearchQuery] = useState('');
167
173
  const deferredSearchQuery = useDeferredValue(searchQuery);
168
174
 
@@ -477,6 +483,7 @@ function TraceViewerContent({
477
483
  >
478
484
  <div
479
485
  id="trace-parent"
486
+ data-span-landing={isLanding || undefined}
480
487
  className="@container flex-1 min-w-0 grid grid-rows-[auto_1fr] h-full min-h-0 overflow-hidden relative bg-background-100"
481
488
  >
482
489
  <Minimap
@@ -490,38 +497,15 @@ function TraceViewerContent({
490
497
  <SplitPane
491
498
  scrollContainerRef={scrollContainerRef}
492
499
  startHeader={
493
- <div className="bg-background-100 border-b border-gray-alpha-400 h-10 min-h-10 flex items-center pl-4 pr-2 gap-1.5">
494
- <Search className="w-3.5 h-3.5 shrink-0 text-gray-800" />
495
- <input
496
- id="trace-viewer-search"
497
- name="trace-viewer-search"
498
- type="text"
499
- value={searchQuery}
500
- onChange={(e) => setSearchQuery(e.target.value)}
501
- onKeyDown={(e) => {
502
- if (e.key === 'Escape' && searchQuery) {
503
- e.preventDefault();
504
- e.stopPropagation();
505
- setSearchQuery('');
506
- }
507
- }}
508
- placeholder="Search spans..."
509
- aria-label="Search spans"
510
- className="flex-1 min-w-0 bg-transparent text-label-14 text-gray-1000 placeholder:text-gray-800 outline-none"
511
- />
512
- {searchQuery && (
513
- <button
514
- type="button"
515
- aria-label="Clear search"
516
- onClick={() => setSearchQuery('')}
517
- className="-mr-2 hidden h-full max-w-full shrink-0 cursor-pointer items-center rounded-r-md border-0 bg-transparent px-2.5 font-inherit text-label-16 text-gray-900 no-underline transition-colors duration-150 ease-in hover:text-gray-1000 focus-visible:-outline-offset-1 focus-visible:outline focus-visible:outline-2 focus-visible:outline-[var(--ds-focus-color)] min-[961px]:flex"
518
- >
519
- <Kbd variant="outline" size="search">
520
- Esc
521
- </Kbd>
522
- </button>
523
- )}
524
- </div>
500
+ <SearchInput
501
+ id="trace-viewer-search"
502
+ name="trace-viewer-search"
503
+ label="Search spans"
504
+ placeholder="Search spans…"
505
+ value={searchQuery}
506
+ onValueChange={setSearchQuery}
507
+ className="pl-4"
508
+ />
525
509
  }
526
510
  endHeader={
527
511
  <TimelineHeader markers={timeMarkers} hoverInfo={hoverInfo} />
@@ -537,7 +521,7 @@ function TraceViewerContent({
537
521
  <div ref={loadMoreSentinelRef} className="flex justify-center">
538
522
  {isLoadingMore ? (
539
523
  <div className="flex items-center justify-center gap-2 py-3 text-label-14 text-gray-800">
540
- <Spinner size={14} />
524
+ <Spinner size="md" />
541
525
  <span>Loading spans…</span>
542
526
  </div>
543
527
  ) : null}
@@ -572,7 +556,6 @@ function TraceViewerContent({
572
556
  />
573
557
  <div className="pointer-events-auto flex items-center border border-gray-alpha-400 rounded-md bg-background-100 shadow-sm overflow-hidden divide-x divide-gray-alpha-400">
574
558
  <IconButton
575
- variant="muted"
576
559
  size="small"
577
560
  onClick={zoomOut}
578
561
  disabled={isAtMinZoom}
@@ -581,7 +564,6 @@ function TraceViewerContent({
581
564
  <ZoomOut className="w-4 h-4" />
582
565
  </IconButton>
583
566
  <IconButton
584
- variant="muted"
585
567
  size="small"
586
568
  onClick={resetZoom}
587
569
  aria-label="Reset zoom"
@@ -589,7 +571,6 @@ function TraceViewerContent({
589
571
  <RotateCcw className="w-3.5 h-3.5" />
590
572
  </IconButton>
591
573
  <IconButton
592
- variant="muted"
593
574
  size="small"
594
575
  onClick={zoomIn}
595
576
  disabled={isAtMaxZoom}
@@ -2,6 +2,7 @@ import { Slot } from '@radix-ui/react-slot';
2
2
  import { cva, type VariantProps } from 'class-variance-authority';
3
3
  import * as React from 'react';
4
4
  import { cn } from '../../lib/cn';
5
+ import { Spinner, type SpinnerSize } from './spinner';
5
6
 
6
7
  /**
7
8
  * The button for the observability UI.
@@ -9,22 +10,13 @@ import { cn } from '../../lib/cn';
9
10
  * Fill, text and border are painted from four custom properties —
10
11
  * `--themed-bg`, `--themed-fg`, `--themed-border` and `--themed-hover-bg` — so
11
12
  * a variant only redeclares the tokens it changes and the base rules stay the
12
- * same. Geometry follows the `--ds-*` control scale: 24/32/36/40px tall for
13
- * tiny/small/medium/large, a 6px radius (4px at tiny, 8px at large), and 16px
14
- * of horizontal padding at medium.
15
- *
16
- * The styles have to resolve in whichever app consumes
17
- * `@workflow/web-shared`, so:
18
- * - dark mode is matched with ancestor selectors rather than a `dark-theme:`
19
- * variant, which only exists once our `styles.css` is imported;
20
- * - the focus ring is written as arbitrary properties, because bare
21
- * `outline` and arbitrary-colour utilities differ between Tailwind v3
22
- * and v4.
13
+ * same. The label's span holds 6px of the horizontal padding so the label
14
+ * can truncate, which is why each size's own padding is 6px short.
23
15
  */
24
16
  const buttonVariants = cva(
25
17
  [
26
- 'group/trigger relative m-0 inline-flex max-w-full shrink-0 items-center justify-center gap-2',
27
- 'cursor-pointer select-none whitespace-nowrap border-0 align-baseline font-medium no-underline outline-none',
18
+ 'group/trigger relative m-0 inline-flex max-w-full shrink-0 items-center justify-center',
19
+ 'cursor-pointer select-none whitespace-nowrap border-0 align-baseline font-sans font-medium no-underline outline-none',
28
20
  'transform translate-z-0',
29
21
  // Fill, text and border all come from --themed-*; the fallbacks below are
30
22
  // the inverted `default` variant, so it declares no colour tokens at all.
@@ -35,9 +27,12 @@ const buttonVariants = cva(
35
27
  // `hover:bg-*` utility on the element and a call site that needs its own
36
28
  // hover fill replaces it in both themes at once.
37
29
  'hover:bg-[var(--themed-hover-bg)]',
38
- 'transition-[border-color,background,color,transform,box-shadow] duration-150 ease-in-out',
39
- 'focus-visible:[outline:2px_solid_var(--ds-focus-color)] focus-visible:[outline-offset:2px]',
30
+ 'transition-all duration-150 ease-in-out',
31
+ 'focus-visible:shadow-[var(--ds-focus-ring)] focus-visible:transition-none',
40
32
  '[&_svg]:shrink-0',
33
+ // Icons in the prefix and suffix slots use the decoration size. The
34
+ // attribute keeps this rule more specific than each size's `[&_svg]` rule.
35
+ '[&_[data-button-slot]_svg]:size-[var(--ds-control-decoration-size)]',
41
36
  // Disabled buttons flatten to the gray-100 fill with a gray-400 border.
42
37
  'disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-gray-700 disabled:[--themed-border:_var(--ds-gray-400)] disabled:hover:bg-gray-100',
43
38
  'aria-disabled:cursor-not-allowed aria-disabled:bg-gray-100 aria-disabled:text-gray-700 aria-disabled:[--themed-border:_var(--ds-gray-400)] aria-disabled:hover:bg-gray-100',
@@ -45,44 +40,38 @@ const buttonVariants = cva(
45
40
  {
46
41
  variants: {
47
42
  variant: {
48
- // No `--ds-*` token sits one step lighter/darker than the inverted
49
- // fill, so its hover colours are literal — and they have to flip with
50
- // the theme, because the fill itself does.
43
+ // Literal hover fills for the inverted default type: no `--ds-*`
44
+ // token sits one step off gray-1000.
51
45
  default: [
52
46
  '[--themed-hover-bg:_hsl(0,_0%,_22%)]',
53
- '[.dark_&]:[--themed-hover-bg:_hsl(0,_0%,_80%)]',
54
- '[.dark-theme_&]:[--themed-hover-bg:_hsl(0,_0%,_80%)]',
55
- '[[data-theme=dark]_&]:[--themed-hover-bg:_hsl(0,_0%,_80%)]',
47
+ 'dark:[--themed-hover-bg:_hsl(0,_0%,_80%)]',
56
48
  ],
57
49
  secondary: [
58
50
  '[--themed-bg:_var(--ds-background-100)]',
59
51
  '[--themed-fg:_var(--ds-gray-1000)]',
60
52
  '[--themed-border:_var(--ds-gray-400)]',
61
53
  '[--themed-hover-bg:_var(--ds-gray-100)]',
62
- '[.dark_&]:[--themed-hover-bg:_var(--ds-gray-200)]',
63
- '[.dark-theme_&]:[--themed-hover-bg:_var(--ds-gray-200)]',
64
- '[[data-theme=dark]_&]:[--themed-hover-bg:_var(--ds-gray-200)]',
54
+ 'dark:[--themed-hover-bg:_var(--ds-gray-200)]',
65
55
  ],
66
56
  // Tertiary is the one variant allowed to go borderless when disabled;
67
- // it drops to 50% opacity instead.
57
+ // it keeps its text colour and drops to 50% opacity instead.
68
58
  tertiary: [
69
59
  '[--themed-bg:_transparent]',
70
60
  '[--themed-fg:_var(--ds-gray-1000)]',
71
61
  '[--themed-border:_transparent]',
72
62
  // The alpha token already flips with the theme.
73
63
  '[--themed-hover-bg:_var(--ds-gray-alpha-200)]',
74
- 'disabled:bg-transparent disabled:opacity-50 disabled:shadow-none disabled:hover:bg-transparent',
75
- 'aria-disabled:bg-transparent aria-disabled:opacity-50 aria-disabled:shadow-none aria-disabled:hover:bg-transparent',
64
+ 'disabled:bg-transparent disabled:text-gray-1000 disabled:opacity-50 disabled:shadow-none disabled:hover:bg-transparent',
65
+ 'aria-disabled:bg-transparent aria-disabled:text-gray-1000 aria-disabled:opacity-50 aria-disabled:shadow-none aria-disabled:hover:bg-transparent',
76
66
  ],
77
67
  },
78
- // Radii are literal rather than `rounded-md`/`rounded-lg`: apps that
79
- // still carry a shadcn theme redefine the `--radius-*` scale, and these
80
- // corners should not move with it.
81
68
  size: {
82
- tiny: 'h-6 gap-1 rounded-[4px] px-1.5 text-button-12 [&_svg]:size-3',
83
- small: 'h-8 rounded-[6px] px-3 text-button-14 [&_svg]:size-4',
84
- medium: 'h-9 rounded-[6px] px-4 text-button-14 [&_svg]:size-4',
85
- large: 'h-10 rounded-[8px] px-5 text-button-16 [&_svg]:size-4',
69
+ small:
70
+ 'h-8 rounded-md px-1.5 text-[14px] leading-normal [&_svg]:size-4',
71
+ medium:
72
+ 'h-9 rounded-md px-2.5 text-[14px] leading-normal [&_svg]:size-4',
73
+ large:
74
+ 'h-10 rounded-lg px-3.5 text-[16px] leading-normal [&_svg]:size-4',
86
75
  },
87
76
  // Icon-only buttons: square keeps the size's radius, circle is a pill.
88
77
  shape: {
@@ -97,29 +86,138 @@ const buttonVariants = cva(
97
86
  }
98
87
  );
99
88
 
100
- export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> &
89
+ type Size = NonNullable<VariantProps<typeof buttonVariants>['size']>;
90
+
91
+ const SPINNER_SIZE: Record<Size, SpinnerSize> = {
92
+ small: 'sm',
93
+ medium: 'md',
94
+ large: 'lg',
95
+ };
96
+
97
+ export type ButtonProps = Omit<
98
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
99
+ 'prefix'
100
+ > &
101
101
  VariantProps<typeof buttonVariants> & {
102
102
  /** Render the child element instead of a `<button>`, keeping the styles. */
103
103
  asChild?: boolean;
104
+ /**
105
+ * Show a spinner in place of `prefix`, disable the button and set
106
+ * `aria-busy`. The label stays, and with a `prefix` the width does not
107
+ * change, because the spinner takes the prefix's slot.
108
+ */
109
+ loading?: boolean;
110
+ /** Element before the label, usually an icon. */
111
+ prefix?: React.ReactNode;
112
+ /** Element after the label, usually an icon. */
113
+ suffix?: React.ReactNode;
104
114
  };
105
115
 
116
+ function ButtonContent({
117
+ size,
118
+ iconOnly,
119
+ loading,
120
+ prefix,
121
+ suffix,
122
+ children,
123
+ }: {
124
+ size: Size;
125
+ iconOnly: boolean;
126
+ loading: boolean;
127
+ prefix: React.ReactNode;
128
+ suffix: React.ReactNode;
129
+ children: React.ReactNode;
130
+ }) {
131
+ return (
132
+ <>
133
+ {loading || prefix != null ? (
134
+ <span
135
+ data-button-slot="prefix"
136
+ aria-hidden={loading || undefined}
137
+ className="mr-[3px] flex min-w-5 shrink-0 items-center justify-center"
138
+ >
139
+ {loading ? <Spinner size={SPINNER_SIZE[size]} /> : prefix}
140
+ </span>
141
+ ) : null}
142
+ <span
143
+ className={cn(
144
+ 'px-1.5',
145
+ iconOnly
146
+ ? 'inline-flex shrink-0 items-center justify-center'
147
+ : 'truncate'
148
+ )}
149
+ >
150
+ {children}
151
+ </span>
152
+ {suffix != null ? (
153
+ <span
154
+ data-button-slot="suffix"
155
+ className="mr-0.5 ml-1 flex shrink-0 items-center justify-center"
156
+ >
157
+ {suffix}
158
+ </span>
159
+ ) : null}
160
+ </>
161
+ );
162
+ }
163
+
106
164
  export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
107
165
  (
108
- { className, variant, size, shape, asChild = false, type, ...props },
166
+ {
167
+ className,
168
+ variant,
169
+ size,
170
+ shape,
171
+ asChild = false,
172
+ loading = false,
173
+ prefix,
174
+ suffix,
175
+ disabled,
176
+ type,
177
+ children,
178
+ ...props
179
+ },
109
180
  ref
110
181
  ) => {
111
- const Comp = asChild ? Slot : 'button';
182
+ const content = (label: React.ReactNode) => (
183
+ <ButtonContent
184
+ size={size ?? 'medium'}
185
+ iconOnly={shape != null}
186
+ loading={loading}
187
+ prefix={prefix}
188
+ suffix={suffix}
189
+ >
190
+ {label}
191
+ </ButtonContent>
192
+ );
193
+ const shared = {
194
+ ref,
195
+ className: cn(buttonVariants({ variant, size, shape }), className),
196
+ 'aria-busy': loading || undefined,
197
+ ...props,
198
+ };
199
+
200
+ // With `asChild`, the child element (a link, usually) becomes the button
201
+ // and its own children go in the label slot.
202
+ if (asChild) {
203
+ const child = React.Children.only(children) as React.ReactElement<{
204
+ children?: React.ReactNode;
205
+ }>;
206
+ return (
207
+ <Slot {...shared} aria-disabled={disabled || loading || undefined}>
208
+ {React.cloneElement(child, undefined, content(child.props.children))}
209
+ </Slot>
210
+ );
211
+ }
112
212
 
113
213
  return (
114
- <Comp
115
- ref={ref}
116
- // `type` only means anything on a real <button>; forwarding it to the
117
- // anchor (or whatever else) an `asChild` call site renders would be
118
- // invalid HTML.
119
- type={asChild ? type : (type ?? 'button')}
120
- className={cn(buttonVariants({ variant, size, shape, className }))}
121
- {...props}
122
- />
214
+ <button
215
+ {...shared}
216
+ type={type ?? 'button'}
217
+ disabled={disabled || loading}
218
+ >
219
+ {content(children)}
220
+ </button>
123
221
  );
124
222
  }
125
223
  );
@@ -274,7 +274,7 @@ export function ContextCardProvider({
274
274
  >
275
275
  <div
276
276
  className={cn(
277
- 'absolute bg-background-100 bg-clip-padding rounded-[6px] overflow-visible pointer-events-none z-[1000000] shadow-[var(--ds-shadow-tooltip),0_0_0_1px_var(--ds-background-100)] w-fit [--context-card-tip-stroke:#DBDBDB] dark-theme:[--context-card-tip-stroke:#252525]',
277
+ 'absolute bg-background-100 bg-clip-padding rounded-[6px] overflow-visible pointer-events-none z-[1000000] shadow-[var(--ds-shadow-tooltip)] w-fit',
278
278
  skipTransition
279
279
  ? '!transition-none'
280
280
  : 'transition-[transform,width,height] duration-[250ms] ease-[easing-function:cubic-bezier(0.29,0.31,0.05,0.96)] will-change-[transform,width,height] motion-reduce:!transition-none'
@@ -328,7 +328,7 @@ export function ContextCardProvider({
328
328
  <path
329
329
  d="M15 -0.5V0.5H12.9834L12.8184 0.508789C12.4377 0.550822 12.0853 0.738056 11.8359 1.03418L8.53027 4.95996C7.73114 5.90893 6.26886 5.90892 5.46973 4.95996L2.16406 1.03418C1.87905 0.695733 1.45907 0.5 1.0166 0.5H-1V-0.5H15Z"
330
330
  fill="var(--ds-background-100)"
331
- className="fill-background-100 stroke-[var(--context-card-tip-stroke)]"
331
+ className="fill-background-100 stroke-gray-alpha-400"
332
332
  />
333
333
  </g>
334
334
  <defs>
@@ -0,0 +1,86 @@
1
+ 'use client';
2
+
3
+ import { cva, type VariantProps } from 'class-variance-authority';
4
+ import { Check, Copy } from 'lucide-react';
5
+ import {
6
+ forwardRef,
7
+ type MouseEvent,
8
+ useEffect,
9
+ useRef,
10
+ useState,
11
+ } from 'react';
12
+ import { cn } from '../../lib/cn';
13
+ import { useToast } from '../../lib/toast';
14
+ import { IconButton, type IconButtonProps } from './icon-button';
15
+
16
+ const copyButtonVariants = cva('', {
17
+ variants: {
18
+ size: {
19
+ tiny: '',
20
+ small: '[&_svg]:size-3',
21
+ },
22
+ },
23
+ defaultVariants: {
24
+ size: 'tiny',
25
+ },
26
+ });
27
+
28
+ export type CopyButtonProps = Omit<IconButtonProps, 'children' | 'size'> &
29
+ VariantProps<typeof copyButtonVariants> & {
30
+ textToCopy: string;
31
+ };
32
+
33
+ const icon =
34
+ '[grid-area:1/1] transition-[opacity,scale] duration-200 ease-in-out';
35
+
36
+ export const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>(
37
+ ({ textToCopy, size, onClick, className, ...props }, ref) => {
38
+ const toast = useToast();
39
+ const [copied, setCopied] = useState(false);
40
+ const timeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined);
41
+
42
+ useEffect(() => () => clearTimeout(timeoutRef.current), []);
43
+
44
+ const copy = (e: MouseEvent<HTMLButtonElement>) => {
45
+ e.stopPropagation();
46
+ onClick?.(e);
47
+ clearTimeout(timeoutRef.current);
48
+ navigator.clipboard
49
+ .writeText(textToCopy)
50
+ .then(() => {
51
+ setCopied(true);
52
+ timeoutRef.current = setTimeout(() => setCopied(false), 1000);
53
+ })
54
+ .catch(() => toast.error('Failed to copy to clipboard'));
55
+ };
56
+
57
+ return (
58
+ <IconButton
59
+ ref={ref}
60
+ onClick={copy}
61
+ className={cn(copyButtonVariants({ size }), className)}
62
+ {...props}
63
+ >
64
+ <span className="grid">
65
+ <Check
66
+ className={cn(
67
+ icon,
68
+ copied ? 'scale-100 opacity-100' : 'scale-50 opacity-0'
69
+ )}
70
+ />
71
+ <Copy
72
+ className={cn(
73
+ icon,
74
+ copied ? 'scale-50 opacity-0' : 'scale-100 opacity-100'
75
+ )}
76
+ />
77
+ </span>
78
+ {/* biome-ignore lint/a11y/useSemanticElements: <output> is a form control */}
79
+ <span role="status" className="sr-only">
80
+ {copied ? 'Copied' : ''}
81
+ </span>
82
+ </IconButton>
83
+ );
84
+ }
85
+ );
86
+ CopyButton.displayName = 'CopyButton';