@slipstream-ui/core 0.7.0 → 0.8.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 (260) hide show
  1. package/dist/index.d.mts +135 -15
  2. package/dist/index.d.ts +135 -15
  3. package/dist/index.js +923 -710
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +922 -710
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/manifests/accordion.manifest.json +7 -1
  8. package/dist/manifests/alert.manifest.json +1 -1
  9. package/dist/manifests/announcement-bar.manifest.json +1 -1
  10. package/dist/manifests/app-shell.manifest.json +1 -1
  11. package/dist/manifests/applied-filters.manifest.json +1 -1
  12. package/dist/manifests/article-card.manifest.json +1 -1
  13. package/dist/manifests/auth-layout.manifest.json +19 -1
  14. package/dist/manifests/autocomplete.manifest.json +1 -1
  15. package/dist/manifests/avatar.manifest.json +1 -1
  16. package/dist/manifests/badge.manifest.json +13 -1
  17. package/dist/manifests/block.manifest.json +1 -1
  18. package/dist/manifests/bottom-nav.manifest.json +130 -0
  19. package/dist/manifests/breadcrumb.manifest.json +1 -1
  20. package/dist/manifests/button-group.manifest.json +1 -1
  21. package/dist/manifests/button.manifest.json +1 -1
  22. package/dist/manifests/card.manifest.json +1 -1
  23. package/dist/manifests/checkbox.manifest.json +1 -1
  24. package/dist/manifests/comparison-table.manifest.json +1 -1
  25. package/dist/manifests/confirm-dialog.manifest.json +1 -1
  26. package/dist/manifests/contact-strip.manifest.json +1 -1
  27. package/dist/manifests/container.manifest.json +1 -1
  28. package/dist/manifests/cta-section.manifest.json +1 -1
  29. package/dist/manifests/data-table.manifest.json +1 -1
  30. package/dist/manifests/date-picker.manifest.json +1 -1
  31. package/dist/manifests/date-range-picker.manifest.json +1 -1
  32. package/dist/manifests/deal-card.manifest.json +1 -1
  33. package/dist/manifests/dialog.manifest.json +1 -1
  34. package/dist/manifests/document-card.manifest.json +1 -1
  35. package/dist/manifests/drawer.manifest.json +48 -2
  36. package/dist/manifests/empty-state.manifest.json +1 -1
  37. package/dist/manifests/entity-card.manifest.json +1 -1
  38. package/dist/manifests/feature-grid.manifest.json +1 -1
  39. package/dist/manifests/feature-row.manifest.json +1 -1
  40. package/dist/manifests/fieldset.manifest.json +1 -1
  41. package/dist/manifests/file-upload.manifest.json +1 -1
  42. package/dist/manifests/filter-bar.manifest.json +1 -1
  43. package/dist/manifests/filter-chips.manifest.json +1 -1
  44. package/dist/manifests/filter-panel.manifest.json +1 -1
  45. package/dist/manifests/flex.manifest.json +1 -1
  46. package/dist/manifests/form-field.manifest.json +1 -1
  47. package/dist/manifests/form-layout.manifest.json +1 -1
  48. package/dist/manifests/form.manifest.json +1 -1
  49. package/dist/manifests/grid.manifest.json +1 -1
  50. package/dist/manifests/heading.manifest.json +1 -1
  51. package/dist/manifests/hero.manifest.json +1 -1
  52. package/dist/manifests/input-group.manifest.json +1 -1
  53. package/dist/manifests/input.manifest.json +1 -1
  54. package/dist/manifests/label.manifest.json +1 -1
  55. package/dist/manifests/link-tabs.manifest.json +1 -1
  56. package/dist/manifests/link.manifest.json +1 -1
  57. package/dist/manifests/list.manifest.json +1 -1
  58. package/dist/manifests/load-more.manifest.json +1 -1
  59. package/dist/manifests/logo-cloud.manifest.json +1 -1
  60. package/dist/manifests/menu.manifest.json +1 -1
  61. package/dist/manifests/metric-card.manifest.json +36 -4
  62. package/dist/manifests/multi-select.manifest.json +1 -1
  63. package/dist/manifests/newsletter.manifest.json +1 -1
  64. package/dist/manifests/page-header.manifest.json +7 -1
  65. package/dist/manifests/pagination.manifest.json +1 -1
  66. package/dist/manifests/password-input.manifest.json +1 -1
  67. package/dist/manifests/popover.manifest.json +1 -1
  68. package/dist/manifests/process-steps.manifest.json +1 -1
  69. package/dist/manifests/progress.manifest.json +1 -1
  70. package/dist/manifests/prose.manifest.json +1 -1
  71. package/dist/manifests/radio.manifest.json +1 -1
  72. package/dist/manifests/range-slider.manifest.json +1 -1
  73. package/dist/manifests/search.manifest.json +1 -1
  74. package/dist/manifests/section-heading.manifest.json +1 -1
  75. package/dist/manifests/section.manifest.json +1 -1
  76. package/dist/manifests/segmented-control.manifest.json +1 -1
  77. package/dist/manifests/select-menu.manifest.json +1 -1
  78. package/dist/manifests/select.manifest.json +1 -1
  79. package/dist/manifests/separator.manifest.json +1 -1
  80. package/dist/manifests/site-footer.manifest.json +1 -1
  81. package/dist/manifests/site-header.manifest.json +1 -1
  82. package/dist/manifests/skeleton.manifest.json +1 -1
  83. package/dist/manifests/spinner.manifest.json +1 -1
  84. package/dist/manifests/stat-band.manifest.json +1 -1
  85. package/dist/manifests/stepper.manifest.json +1 -1
  86. package/dist/manifests/switch.manifest.json +1 -1
  87. package/dist/manifests/table-card.manifest.json +1 -1
  88. package/dist/manifests/table-of-contents.manifest.json +1 -1
  89. package/dist/manifests/table.manifest.json +1 -1
  90. package/dist/manifests/tabs.manifest.json +1 -1
  91. package/dist/manifests/testimonial.manifest.json +1 -1
  92. package/dist/manifests/text.manifest.json +1 -1
  93. package/dist/manifests/textarea.manifest.json +1 -1
  94. package/dist/manifests/theme-toggle.manifest.json +1 -1
  95. package/dist/manifests/time-picker.manifest.json +1 -1
  96. package/dist/manifests/timeline.manifest.json +1 -1
  97. package/dist/manifests/toast.manifest.json +1 -1
  98. package/dist/manifests/tombstone-card.manifest.json +1 -1
  99. package/dist/manifests/tooltip.manifest.json +1 -1
  100. package/dist/src/components/accordion/Accordion.d.ts +17 -1
  101. package/dist/src/components/accordion/Accordion.js +5 -1
  102. package/dist/src/components/accordion/Accordion.js.map +1 -1
  103. package/dist/src/components/accordion/Accordion.mjs +5 -1
  104. package/dist/src/components/accordion/Accordion.mjs.map +1 -1
  105. package/dist/src/components/auth-layout/AuthLayout.d.ts +14 -2
  106. package/dist/src/components/auth-layout/AuthLayout.js +10 -2
  107. package/dist/src/components/auth-layout/AuthLayout.js.map +1 -1
  108. package/dist/src/components/auth-layout/AuthLayout.mjs +10 -2
  109. package/dist/src/components/auth-layout/AuthLayout.mjs.map +1 -1
  110. package/dist/src/components/badge/Badge.d.ts +2 -0
  111. package/dist/src/components/badge/Badge.js +9 -3
  112. package/dist/src/components/badge/Badge.js.map +1 -1
  113. package/dist/src/components/badge/Badge.mjs +9 -3
  114. package/dist/src/components/badge/Badge.mjs.map +1 -1
  115. package/dist/src/components/bottom-nav/BottomNav.d.ts +36 -0
  116. package/dist/src/components/bottom-nav/BottomNav.js +90 -0
  117. package/dist/src/components/bottom-nav/BottomNav.js.map +1 -0
  118. package/dist/src/components/bottom-nav/BottomNav.mjs +66 -0
  119. package/dist/src/components/bottom-nav/BottomNav.mjs.map +1 -0
  120. package/dist/src/components/bottom-nav/index.d.ts +1 -0
  121. package/dist/src/components/bottom-nav/index.js +23 -0
  122. package/dist/src/components/bottom-nav/index.js.map +1 -0
  123. package/dist/src/components/bottom-nav/index.mjs +2 -0
  124. package/dist/src/components/bottom-nav/index.mjs.map +1 -0
  125. package/dist/src/components/drawer/Drawer.d.ts +25 -2
  126. package/dist/src/components/drawer/Drawer.js +97 -6
  127. package/dist/src/components/drawer/Drawer.js.map +1 -1
  128. package/dist/src/components/drawer/Drawer.mjs +97 -6
  129. package/dist/src/components/drawer/Drawer.mjs.map +1 -1
  130. package/dist/src/components/empty-state/EmptyState.d.ts +13 -4
  131. package/dist/src/components/empty-state/EmptyState.js +13 -1
  132. package/dist/src/components/empty-state/EmptyState.js.map +1 -1
  133. package/dist/src/components/empty-state/EmptyState.mjs +13 -1
  134. package/dist/src/components/empty-state/EmptyState.mjs.map +1 -1
  135. package/dist/src/components/metric-card/MetricCard.d.ts +23 -4
  136. package/dist/src/components/metric-card/MetricCard.js +32 -5
  137. package/dist/src/components/metric-card/MetricCard.js.map +1 -1
  138. package/dist/src/components/metric-card/MetricCard.mjs +32 -5
  139. package/dist/src/components/metric-card/MetricCard.mjs.map +1 -1
  140. package/dist/src/components/page-header/PageHeader.d.ts +4 -0
  141. package/dist/src/components/page-header/PageHeader.js +3 -2
  142. package/dist/src/components/page-header/PageHeader.js.map +1 -1
  143. package/dist/src/components/page-header/PageHeader.mjs +3 -2
  144. package/dist/src/components/page-header/PageHeader.mjs.map +1 -1
  145. package/dist/src/components/separator/Separator.d.ts +3 -3
  146. package/dist/src/index.d.ts +1 -0
  147. package/dist/styles-full.css +1 -1
  148. package/dist/styles.css +1 -1
  149. package/package.json +3 -3
  150. package/src/components/accordion/Accordion.test.tsx +31 -0
  151. package/src/components/accordion/Accordion.tsx +27 -2
  152. package/src/components/auth-layout/AuthLayout.test.tsx +36 -0
  153. package/src/components/auth-layout/AuthLayout.tsx +20 -3
  154. package/src/components/badge/Badge.test.tsx +7 -0
  155. package/src/components/badge/Badge.tsx +8 -2
  156. package/src/components/bottom-nav/BottomNav.test.tsx +48 -0
  157. package/src/components/bottom-nav/BottomNav.tsx +117 -0
  158. package/src/components/bottom-nav/index.ts +1 -0
  159. package/src/components/drawer/Drawer.test.tsx +86 -1
  160. package/src/components/drawer/Drawer.tsx +135 -7
  161. package/src/components/empty-state/EmptyState.test.tsx +26 -1
  162. package/src/components/empty-state/EmptyState.tsx +40 -3
  163. package/src/components/metric-card/MetricCard.test.tsx +32 -0
  164. package/src/components/metric-card/MetricCard.tsx +45 -7
  165. package/src/components/page-header/PageHeader.test.tsx +13 -0
  166. package/src/components/page-header/PageHeader.tsx +5 -2
  167. package/src/index.ts +1 -0
  168. package/src/manifests/accordion.manifest.json +7 -1
  169. package/src/manifests/alert.manifest.json +1 -1
  170. package/src/manifests/announcement-bar.manifest.json +1 -1
  171. package/src/manifests/app-shell.manifest.json +1 -1
  172. package/src/manifests/applied-filters.manifest.json +1 -1
  173. package/src/manifests/article-card.manifest.json +1 -1
  174. package/src/manifests/auth-layout.manifest.json +19 -1
  175. package/src/manifests/autocomplete.manifest.json +1 -1
  176. package/src/manifests/avatar.manifest.json +1 -1
  177. package/src/manifests/badge.manifest.json +13 -1
  178. package/src/manifests/block.manifest.json +1 -1
  179. package/src/manifests/bottom-nav.manifest.json +130 -0
  180. package/src/manifests/breadcrumb.manifest.json +1 -1
  181. package/src/manifests/button-group.manifest.json +1 -1
  182. package/src/manifests/button.manifest.json +1 -1
  183. package/src/manifests/card.manifest.json +1 -1
  184. package/src/manifests/checkbox.manifest.json +1 -1
  185. package/src/manifests/comparison-table.manifest.json +1 -1
  186. package/src/manifests/confirm-dialog.manifest.json +1 -1
  187. package/src/manifests/contact-strip.manifest.json +1 -1
  188. package/src/manifests/container.manifest.json +1 -1
  189. package/src/manifests/cta-section.manifest.json +1 -1
  190. package/src/manifests/data-table.manifest.json +1 -1
  191. package/src/manifests/date-picker.manifest.json +1 -1
  192. package/src/manifests/date-range-picker.manifest.json +1 -1
  193. package/src/manifests/deal-card.manifest.json +1 -1
  194. package/src/manifests/dialog.manifest.json +1 -1
  195. package/src/manifests/document-card.manifest.json +1 -1
  196. package/src/manifests/drawer.manifest.json +48 -2
  197. package/src/manifests/empty-state.manifest.json +1 -1
  198. package/src/manifests/entity-card.manifest.json +1 -1
  199. package/src/manifests/feature-grid.manifest.json +1 -1
  200. package/src/manifests/feature-row.manifest.json +1 -1
  201. package/src/manifests/fieldset.manifest.json +1 -1
  202. package/src/manifests/file-upload.manifest.json +1 -1
  203. package/src/manifests/filter-bar.manifest.json +1 -1
  204. package/src/manifests/filter-chips.manifest.json +1 -1
  205. package/src/manifests/filter-panel.manifest.json +1 -1
  206. package/src/manifests/flex.manifest.json +1 -1
  207. package/src/manifests/form-field.manifest.json +1 -1
  208. package/src/manifests/form-layout.manifest.json +1 -1
  209. package/src/manifests/form.manifest.json +1 -1
  210. package/src/manifests/grid.manifest.json +1 -1
  211. package/src/manifests/heading.manifest.json +1 -1
  212. package/src/manifests/hero.manifest.json +1 -1
  213. package/src/manifests/input-group.manifest.json +1 -1
  214. package/src/manifests/input.manifest.json +1 -1
  215. package/src/manifests/label.manifest.json +1 -1
  216. package/src/manifests/link-tabs.manifest.json +1 -1
  217. package/src/manifests/link.manifest.json +1 -1
  218. package/src/manifests/list.manifest.json +1 -1
  219. package/src/manifests/load-more.manifest.json +1 -1
  220. package/src/manifests/logo-cloud.manifest.json +1 -1
  221. package/src/manifests/menu.manifest.json +1 -1
  222. package/src/manifests/metric-card.manifest.json +36 -4
  223. package/src/manifests/multi-select.manifest.json +1 -1
  224. package/src/manifests/newsletter.manifest.json +1 -1
  225. package/src/manifests/page-header.manifest.json +7 -1
  226. package/src/manifests/pagination.manifest.json +1 -1
  227. package/src/manifests/password-input.manifest.json +1 -1
  228. package/src/manifests/popover.manifest.json +1 -1
  229. package/src/manifests/process-steps.manifest.json +1 -1
  230. package/src/manifests/progress.manifest.json +1 -1
  231. package/src/manifests/prose.manifest.json +1 -1
  232. package/src/manifests/radio.manifest.json +1 -1
  233. package/src/manifests/range-slider.manifest.json +1 -1
  234. package/src/manifests/search.manifest.json +1 -1
  235. package/src/manifests/section-heading.manifest.json +1 -1
  236. package/src/manifests/section.manifest.json +1 -1
  237. package/src/manifests/segmented-control.manifest.json +1 -1
  238. package/src/manifests/select-menu.manifest.json +1 -1
  239. package/src/manifests/select.manifest.json +1 -1
  240. package/src/manifests/separator.manifest.json +1 -1
  241. package/src/manifests/site-footer.manifest.json +1 -1
  242. package/src/manifests/site-header.manifest.json +1 -1
  243. package/src/manifests/skeleton.manifest.json +1 -1
  244. package/src/manifests/spinner.manifest.json +1 -1
  245. package/src/manifests/stat-band.manifest.json +1 -1
  246. package/src/manifests/stepper.manifest.json +1 -1
  247. package/src/manifests/switch.manifest.json +1 -1
  248. package/src/manifests/table-card.manifest.json +1 -1
  249. package/src/manifests/table-of-contents.manifest.json +1 -1
  250. package/src/manifests/table.manifest.json +1 -1
  251. package/src/manifests/tabs.manifest.json +1 -1
  252. package/src/manifests/testimonial.manifest.json +1 -1
  253. package/src/manifests/text.manifest.json +1 -1
  254. package/src/manifests/textarea.manifest.json +1 -1
  255. package/src/manifests/theme-toggle.manifest.json +1 -1
  256. package/src/manifests/time-picker.manifest.json +1 -1
  257. package/src/manifests/timeline.manifest.json +1 -1
  258. package/src/manifests/toast.manifest.json +1 -1
  259. package/src/manifests/tombstone-card.manifest.json +1 -1
  260. package/src/manifests/tooltip.manifest.json +1 -1
@@ -32,6 +32,13 @@ const sizeClasses = {
32
32
  top: sideHeights,
33
33
  bottom: sideHeights
34
34
  };
35
+ const sizePx = {
36
+ sm: 288,
37
+ md: 384,
38
+ lg: 512,
39
+ xl: 640,
40
+ "2xl": 768
41
+ };
35
42
  function extentStyle(value) {
36
43
  if (value === void 0) return void 0;
37
44
  return typeof value === "number" ? `${value}px` : value;
@@ -51,6 +58,7 @@ const slideOut = {
51
58
  function Drawer({
52
59
  open,
53
60
  onOpenChange,
61
+ onClose,
54
62
  title,
55
63
  description,
56
64
  children,
@@ -58,6 +66,12 @@ function Drawer({
58
66
  size = "md",
59
67
  width,
60
68
  height,
69
+ resizable = false,
70
+ minWidth = 240,
71
+ maxWidth = 960,
72
+ defaultWidth,
73
+ onWidthChange,
74
+ resizeLabel = "Resize drawer",
61
75
  closeOnBackdrop = true,
62
76
  showClose = true,
63
77
  closeLabel = "Close drawer",
@@ -71,6 +85,65 @@ function Drawer({
71
85
  const descriptionId = React.useId();
72
86
  const { present, exiting } = usePresence(open, animate);
73
87
  const isTopLayer = useModalLayer(open);
88
+ const requestClose = React.useCallback(() => {
89
+ if (onOpenChange) onOpenChange(false);
90
+ else onClose?.();
91
+ }, [onOpenChange, onClose]);
92
+ const isVerticalSide = side === "top" || side === "bottom";
93
+ const canResize = resizable && !isVerticalSide;
94
+ const clampWidth = React.useCallback(
95
+ (next) => Math.min(maxWidth, Math.max(minWidth, Math.round(next))),
96
+ [minWidth, maxWidth]
97
+ );
98
+ const [resizedWidth, setResizedWidth] = React.useState(null);
99
+ const initialWidth = clampWidth(
100
+ defaultWidth ?? (typeof width === "number" ? width : sizePx[size])
101
+ );
102
+ const resizeWidth = resizedWidth ?? initialWidth;
103
+ const widthRef = React.useRef(resizeWidth);
104
+ widthRef.current = resizeWidth;
105
+ const onWidthChangeRef = React.useRef(onWidthChange);
106
+ onWidthChangeRef.current = onWidthChange;
107
+ const commitWidth = (next) => {
108
+ const clamped = clampWidth(next);
109
+ setResizedWidth(clamped);
110
+ onWidthChangeRef.current?.(clamped);
111
+ };
112
+ const onResizePointerDown = (event) => {
113
+ if (event.button !== 0) return;
114
+ event.preventDefault();
115
+ const startX = event.clientX;
116
+ const startWidth = resizeWidth;
117
+ const onMove = (moveEvent) => {
118
+ const delta = side === "right" ? startX - moveEvent.clientX : moveEvent.clientX - startX;
119
+ setResizedWidth(clampWidth(startWidth + delta));
120
+ };
121
+ const onUp = () => {
122
+ window.removeEventListener("pointermove", onMove);
123
+ window.removeEventListener("pointerup", onUp);
124
+ onWidthChangeRef.current?.(widthRef.current);
125
+ };
126
+ window.addEventListener("pointermove", onMove);
127
+ window.addEventListener("pointerup", onUp);
128
+ };
129
+ const onResizeKeyDown = (event) => {
130
+ const step = event.shiftKey ? 64 : 16;
131
+ const grow = side === "right" ? "ArrowLeft" : "ArrowRight";
132
+ const shrink = side === "right" ? "ArrowRight" : "ArrowLeft";
133
+ if (event.key === grow) {
134
+ event.preventDefault();
135
+ commitWidth(resizeWidth + step);
136
+ } else if (event.key === shrink) {
137
+ event.preventDefault();
138
+ commitWidth(resizeWidth - step);
139
+ } else if (event.key === "Home") {
140
+ event.preventDefault();
141
+ commitWidth(minWidth);
142
+ } else if (event.key === "End") {
143
+ event.preventDefault();
144
+ commitWidth(maxWidth);
145
+ }
146
+ };
74
147
  React.useEffect(() => {
75
148
  if (open) {
76
149
  previouslyFocused.current = document.activeElement;
@@ -91,7 +164,7 @@ function Drawer({
91
164
  if (event.key === "Escape") {
92
165
  if (!isTopLayer()) return;
93
166
  event.stopPropagation();
94
- onOpenChange(false);
167
+ requestClose();
95
168
  return;
96
169
  }
97
170
  if (event.key !== "Tab") return;
@@ -115,10 +188,9 @@ function Drawer({
115
188
  };
116
189
  document.addEventListener("keydown", onKeyDown);
117
190
  return () => document.removeEventListener("keydown", onKeyDown);
118
- }, [open, onOpenChange, isTopLayer]);
191
+ }, [open, requestClose, isTopLayer]);
119
192
  if (!present || typeof document === "undefined") return null;
120
- const isVerticalSide = side === "top" || side === "bottom";
121
- const customExtent = isVerticalSide ? extentStyle(height) : extentStyle(width);
193
+ const customExtent = canResize ? `${resizeWidth}px` : isVerticalSide ? extentStyle(height) : extentStyle(width);
122
194
  const motion = animate ? cn(
123
195
  "duration-200 motion-reduce:animate-none",
124
196
  exiting ? `animate-out ${slideOut[side]}` : `animate-in ${slideIn[side]}`
@@ -129,7 +201,7 @@ function Drawer({
129
201
  {
130
202
  className: "fixed inset-0 z-50",
131
203
  onMouseDown: (event) => {
132
- if (closeOnBackdrop && event.target === event.currentTarget) onOpenChange(false);
204
+ if (closeOnBackdrop && event.target === event.currentTarget) requestClose();
133
205
  },
134
206
  children: /* @__PURE__ */ jsxs(
135
207
  "div",
@@ -149,6 +221,25 @@ function Drawer({
149
221
  ),
150
222
  style: customExtent ? { [isVerticalSide ? "height" : "width"]: customExtent } : void 0,
151
223
  children: [
224
+ canResize && /* @__PURE__ */ jsx(
225
+ "div",
226
+ {
227
+ role: "separator",
228
+ "aria-orientation": "vertical",
229
+ "aria-label": resizeLabel,
230
+ "aria-valuenow": resizeWidth,
231
+ "aria-valuemin": minWidth,
232
+ "aria-valuemax": maxWidth,
233
+ tabIndex: 0,
234
+ onPointerDown: onResizePointerDown,
235
+ onKeyDown: onResizeKeyDown,
236
+ className: cn(
237
+ "absolute inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-sm bg-transparent",
238
+ "hover:bg-primary/20 focus-visible:bg-primary/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
239
+ side === "right" ? "-left-1" : "-right-1"
240
+ )
241
+ }
242
+ ),
152
243
  /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 border-b border-border px-5 py-4", children: [
153
244
  /* @__PURE__ */ jsxs("div", { children: [
154
245
  /* @__PURE__ */ jsx("h2", { id: titleId, className: "text-base font-semibold leading-tight", children: title }),
@@ -158,7 +249,7 @@ function Drawer({
158
249
  "button",
159
250
  {
160
251
  type: "button",
161
- onClick: () => onOpenChange(false),
252
+ onClick: requestClose,
162
253
  "aria-label": closeLabel,
163
254
  className: "-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
164
255
  children: "\u2715"
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/drawer/Drawer.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { cn } from '../../utils/cn';\nimport { usePresence } from '../../utils/presence';\nimport { useModalLayer } from '../../utils/modal-layer';\n\nexport type DrawerSide = 'left' | 'right' | 'top' | 'bottom';\nexport type DrawerSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nexport type DrawerProps = {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n title: string;\n description?: string;\n children?: React.ReactNode;\n /** Edge the drawer slides from (default 'right'). */\n side?: DrawerSide;\n /** Preset extent along the side axis (width for left/right, height for top/bottom). */\n size?: DrawerSize;\n /**\n * Custom extent for left/right drawers: pixels (480) or any CSS length\n * (\"70vw\"). Overrides `size`.\n */\n width?: number | string;\n /**\n * Custom extent for top/bottom drawers: pixels (320) or any CSS length\n * (\"60vh\"). Overrides `size`.\n */\n height?: number | string;\n /** Clicking the backdrop closes (default true). */\n closeOnBackdrop?: boolean;\n /** Hide the close (✕) button in the header (default true). */\n showClose?: boolean;\n /** Accessible label for the close button (default \"Close drawer\"). */\n closeLabel?: string;\n /** Focused when the drawer opens; defaults to the first focusable element. */\n initialFocusRef?: React.RefObject<HTMLElement | null>;\n /** Overrides the accessible name (defaults to the title). */\n ariaLabel?: string;\n /**\n * Slide the panel in from its edge and out on close (requires the\n * tailwindcss-animate plugin). Off by default; reduced-motion users\n * get animate-none automatically.\n */\n animate?: boolean;\n};\n\nconst FOCUSABLE =\n 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nconst sideClasses: Record<DrawerSide, string> = {\n right: 'inset-y-0 right-0 border-l',\n left: 'inset-y-0 left-0 border-r',\n top: 'inset-x-0 top-0 border-b',\n bottom: 'inset-x-0 bottom-0 border-t',\n};\n\nconst sideWidths: Record<DrawerSize, string> = {\n sm: 'w-72',\n md: 'w-96',\n lg: 'w-[32rem]',\n xl: 'w-[40rem]',\n '2xl': 'w-[48rem]',\n};\n\nconst sideHeights: Record<DrawerSize, string> = {\n sm: 'h-48',\n md: 'h-80',\n lg: 'h-[32rem]',\n xl: 'h-[40rem]',\n '2xl': 'h-[48rem]',\n};\n\nconst sizeClasses: Record<DrawerSide, Record<DrawerSize, string>> = {\n right: sideWidths,\n left: sideWidths,\n top: sideHeights,\n bottom: sideHeights,\n};\n\n/** Custom extent wins over the preset; numbers are pixels. */\nfunction extentStyle(value: number | string | undefined): string | undefined {\n if (value === undefined) return undefined;\n return typeof value === 'number' ? `${value}px` : value;\n}\n\n// Literal class maps so Tailwind's scanner keeps every slide utility.\nconst slideIn: Record<DrawerSide, string> = {\n right: 'slide-in-from-right',\n left: 'slide-in-from-left',\n top: 'slide-in-from-top',\n bottom: 'slide-in-from-bottom',\n};\nconst slideOut: Record<DrawerSide, string> = {\n right: 'slide-out-to-right',\n left: 'slide-out-to-left',\n top: 'slide-out-to-top',\n bottom: 'slide-out-to-bottom',\n};\n\n/**\n * Edge sheet for secondary flows (filters, detail panes, mobile nav).\n * Modal semantics identical to Dialog: portal, aria-modal + labelled by\n * title, Escape and backdrop dismissal, focus move + Tab trap + focus\n * restoration on close. Renders fixed to the chosen edge with a border\n * against the backdrop.\n */\nexport function Drawer({\n open,\n onOpenChange,\n title,\n description,\n children,\n side = 'right',\n size = 'md',\n width,\n height,\n closeOnBackdrop = true,\n showClose = true,\n closeLabel = 'Close drawer',\n initialFocusRef,\n ariaLabel,\n animate = false,\n}: DrawerProps) {\n const drawerRef = React.useRef<HTMLDivElement | null>(null);\n const previouslyFocused = React.useRef<HTMLElement | null>(null);\n const titleId = React.useId();\n const descriptionId = React.useId();\n const { present, exiting } = usePresence(open, animate);\n const isTopLayer = useModalLayer(open);\n\n // Capture the opener before the panel takes focus; restore the moment\n // open flips false — even while an exit animation keeps the DOM up.\n React.useEffect(() => {\n if (open) {\n previouslyFocused.current = document.activeElement as HTMLElement | null;\n return;\n }\n previouslyFocused.current?.focus?.();\n previouslyFocused.current = null;\n }, [open]);\n\n // Move focus in once the panel is actually mounted (present can lag\n // open by a render when the presence gate starts closed).\n React.useEffect(() => {\n if (!open || !present) return;\n const node = drawerRef.current;\n const target =\n initialFocusRef?.current ?? node?.querySelector<HTMLElement>(FOCUSABLE) ?? node;\n target?.focus();\n }, [open, present, initialFocusRef]);\n\n React.useEffect(() => {\n if (!open) return;\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n if (!isTopLayer()) return;\n event.stopPropagation();\n onOpenChange(false);\n return;\n }\n if (event.key !== 'Tab') return;\n const node = drawerRef.current;\n if (!node) return;\n const focusable = Array.from(node.querySelectorAll<HTMLElement>(FOCUSABLE));\n if (focusable.length === 0) {\n event.preventDefault();\n return;\n }\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n const active = document.activeElement;\n if (event.shiftKey && (active === first || !node.contains(active))) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n first.focus();\n }\n };\n document.addEventListener('keydown', onKeyDown);\n return () => document.removeEventListener('keydown', onKeyDown);\n }, [open, onOpenChange, isTopLayer]);\n\n if (!present || typeof document === 'undefined') return null;\n\n const isVerticalSide = side === 'top' || side === 'bottom';\n const customExtent = isVerticalSide ? extentStyle(height) : extentStyle(width);\n\n const motion = animate\n ? cn(\n 'duration-200 motion-reduce:animate-none',\n exiting ? `animate-out ${slideOut[side]}` : `animate-in ${slideIn[side]}`,\n )\n : undefined;\n\n return createPortal(\n <div\n className=\"fixed inset-0 z-50\"\n onMouseDown={(event) => {\n if (closeOnBackdrop && event.target === event.currentTarget) onOpenChange(false);\n }}\n >\n <div\n ref={drawerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={ariaLabel ?? title}\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n className={cn(\n 'fixed flex flex-col bg-background shadow-xl border-border',\n sideClasses[side],\n sizeClasses[side][size],\n motion\n )}\n style={customExtent ? { [isVerticalSide ? 'height' : 'width']: customExtent } : undefined}\n >\n <div className=\"flex items-start justify-between gap-4 border-b border-border px-5 py-4\">\n <div>\n <h2 id={titleId} className=\"text-base font-semibold leading-tight\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"mt-1 text-sm text-muted-foreground\">\n {description}\n </p>\n )}\n </div>\n {showClose && (\n <button\n type=\"button\"\n onClick={() => onOpenChange(false)}\n aria-label={closeLabel}\n className=\"-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n ✕\n </button>\n )}\n </div>\n <div className=\"flex-1 overflow-y-auto px-5 py-4\">{children}</div>\n </div>\n </div>,\n document.body\n );\n}\n"],"mappings":";AA8NU,SACE,KADF;AA5NV,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AA2C9B,MAAM,YACJ;AAEF,MAAM,cAA0C;AAAA,EAC9C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,KAAK;AAAA,EACL,QAAQ;AACV;AAEA,MAAM,aAAyC;AAAA,EAC7C,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,MAAM,cAA0C;AAAA,EAC9C,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT;AAEA,MAAM,cA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K;AAAA,QACjF;AAAA,QAEA;AAAA,UAAC;AAAA;AAAA,YACC,KAAK;AAAA,YACL,MAAK;AAAA,YACL,cAAW;AAAA,YACX,cAAY,aAAa;AAAA,YACzB,mBAAiB,QAAQ,UAAU;AAAA,YACnC,oBAAkB,cAAc,gBAAgB;AAAA,YAChD,UAAU;AAAA,YACV,WAAW;AAAA,cACT;AAAA,cACA,YAAY,IAAI;AAAA,cAChB,YAAY,IAAI,EAAE,IAAI;AAAA,cACtB;AAAA,YACF;AAAA,YACA,OAAO,eAAe,EAAE,CAAC,iBAAiB,WAAW,OAAO,GAAG,aAAa,IAAI;AAAA,YAEhF;AAAA,mCAAC,SAAI,WAAU,2EACb;AAAA,qCAAC,SACC;AAAA,sCAAC,QAAG,IAAI,SAAS,WAAU,yCACxB,iBACH;AAAA,kBACC,eACC,oBAAC,OAAE,IAAI,eAAe,WAAU,sCAC7B,uBACH;AAAA,mBAEJ;AAAA,gBACC,aACC;AAAA,kBAAC;AAAA;AAAA,oBACC,MAAK;AAAA,oBACL,SAAS,MAAM,aAAa,KAAK;AAAA,oBACjC,cAAY;AAAA,oBACZ,WAAU;AAAA,oBACX;AAAA;AAAA,gBAED;AAAA,iBAEJ;AAAA,cACA,oBAAC,SAAI,WAAU,oCAAoC,UAAS;AAAA;AAAA;AAAA,QAC9D;AAAA;AAAA,IACF;AAAA,IACA,SAAS;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/components/drawer/Drawer.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { cn } from '../../utils/cn';\nimport { usePresence } from '../../utils/presence';\nimport { useModalLayer } from '../../utils/modal-layer';\n\nexport type DrawerSide = 'left' | 'right' | 'top' | 'bottom';\nexport type DrawerSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';\n\nexport type DrawerProps = {\n open: boolean;\n /** Called with the next open state. Alias: onClose (close requests only). */\n onOpenChange?: (open: boolean) => void;\n /**\n * Called when the drawer asks to close: Escape, backdrop click or the close\n * button. Alias for `onOpenChange(false)`, used when only a close handler is\n * passed.\n */\n onClose?: () => void;\n title: string;\n description?: string;\n children?: React.ReactNode;\n /** Edge the drawer slides from (default 'right'). */\n side?: DrawerSide;\n /** Preset extent along the side axis (width for left/right, height for top/bottom). */\n size?: DrawerSize;\n /**\n * Custom extent for left/right drawers: pixels (480) or any CSS length\n * (\"70vw\"). Overrides `size`.\n */\n width?: number | string;\n /**\n * Custom extent for top/bottom drawers: pixels (320) or any CSS length\n * (\"60vh\"). Overrides `size`.\n */\n height?: number | string;\n /**\n * Drag the inner edge to resize a left/right drawer. Keyboard: Arrow keys\n * nudge 16px, Shift+Arrow 64px, Home/End jump to the bounds. Ignored for\n * top/bottom drawers.\n */\n resizable?: boolean;\n /** Lower bound in pixels while resizable (default 240). */\n minWidth?: number;\n /** Upper bound in pixels while resizable (default 960). */\n maxWidth?: number;\n /** Initial width in pixels while resizable; defaults to the `size` preset. */\n defaultWidth?: number;\n /** Fired with the next width in pixels when a resize commits. */\n onWidthChange?: (width: number) => void;\n /** Accessible label for the resize handle (default \"Resize drawer\"). */\n resizeLabel?: string;\n /** Clicking the backdrop closes (default true). */\n closeOnBackdrop?: boolean;\n /** Hide the close (✕) button in the header (default true). */\n showClose?: boolean;\n /** Accessible label for the close button (default \"Close drawer\"). */\n closeLabel?: string;\n /** Focused when the drawer opens; defaults to the first focusable element. */\n initialFocusRef?: React.RefObject<HTMLElement | null>;\n /** Overrides the accessible name (defaults to the title). */\n ariaLabel?: string;\n /**\n * Slide the panel in from its edge and out on close (requires the\n * tailwindcss-animate plugin). Off by default; reduced-motion users\n * get animate-none automatically.\n */\n animate?: boolean;\n};\n\nconst FOCUSABLE =\n 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nconst sideClasses: Record<DrawerSide, string> = {\n right: 'inset-y-0 right-0 border-l',\n left: 'inset-y-0 left-0 border-r',\n top: 'inset-x-0 top-0 border-b',\n bottom: 'inset-x-0 bottom-0 border-t',\n};\n\nconst sideWidths: Record<DrawerSize, string> = {\n sm: 'w-72',\n md: 'w-96',\n lg: 'w-[32rem]',\n xl: 'w-[40rem]',\n '2xl': 'w-[48rem]',\n};\n\nconst sideHeights: Record<DrawerSize, string> = {\n sm: 'h-48',\n md: 'h-80',\n lg: 'h-[32rem]',\n xl: 'h-[40rem]',\n '2xl': 'h-[48rem]',\n};\n\nconst sizeClasses: Record<DrawerSide, Record<DrawerSize, string>> = {\n right: sideWidths,\n left: sideWidths,\n top: sideHeights,\n bottom: sideHeights,\n};\n\n/** Pixel equivalents of the width presets, used as the resize starting point. */\nconst sizePx: Record<DrawerSize, number> = {\n sm: 288,\n md: 384,\n lg: 512,\n xl: 640,\n '2xl': 768,\n};\n\n/** Custom extent wins over the preset; numbers are pixels. */\nfunction extentStyle(value: number | string | undefined): string | undefined {\n if (value === undefined) return undefined;\n return typeof value === 'number' ? `${value}px` : value;\n}\n\n// Literal class maps so Tailwind's scanner keeps every slide utility.\nconst slideIn: Record<DrawerSide, string> = {\n right: 'slide-in-from-right',\n left: 'slide-in-from-left',\n top: 'slide-in-from-top',\n bottom: 'slide-in-from-bottom',\n};\nconst slideOut: Record<DrawerSide, string> = {\n right: 'slide-out-to-right',\n left: 'slide-out-to-left',\n top: 'slide-out-to-top',\n bottom: 'slide-out-to-bottom',\n};\n\n/**\n * Edge sheet for secondary flows (filters, detail panes, mobile nav).\n * Modal semantics identical to Dialog: portal, aria-modal + labelled by\n * title, Escape and backdrop dismissal, focus move + Tab trap + focus\n * restoration on close. Renders fixed to the chosen edge with a border\n * against the backdrop.\n */\nexport function Drawer({\n open,\n onOpenChange,\n onClose,\n title,\n description,\n children,\n side = 'right',\n size = 'md',\n width,\n height,\n resizable = false,\n minWidth = 240,\n maxWidth = 960,\n defaultWidth,\n onWidthChange,\n resizeLabel = 'Resize drawer',\n closeOnBackdrop = true,\n showClose = true,\n closeLabel = 'Close drawer',\n initialFocusRef,\n ariaLabel,\n animate = false,\n}: DrawerProps) {\n const drawerRef = React.useRef<HTMLDivElement | null>(null);\n const previouslyFocused = React.useRef<HTMLElement | null>(null);\n const titleId = React.useId();\n const descriptionId = React.useId();\n const { present, exiting } = usePresence(open, animate);\n const isTopLayer = useModalLayer(open);\n\n // Prefer onOpenChange; fall back to the onClose alias so a migration code\n // path that only passes onClose still dismisses without double-firing.\n const requestClose = React.useCallback(() => {\n if (onOpenChange) onOpenChange(false);\n else onClose?.();\n }, [onOpenChange, onClose]);\n\n // Resizable left/right drawers. Width is state-local so dragging stays\n // smooth; `onWidthChange` fires once a drag commits or a key is pressed.\n const isVerticalSide = side === 'top' || side === 'bottom';\n const canResize = resizable && !isVerticalSide;\n const clampWidth = React.useCallback(\n (next: number) => Math.min(maxWidth, Math.max(minWidth, Math.round(next))),\n [minWidth, maxWidth]\n );\n const [resizedWidth, setResizedWidth] = React.useState<number | null>(null);\n const initialWidth = clampWidth(\n defaultWidth ?? (typeof width === 'number' ? width : sizePx[size])\n );\n const resizeWidth = resizedWidth ?? initialWidth;\n const widthRef = React.useRef(resizeWidth);\n widthRef.current = resizeWidth;\n const onWidthChangeRef = React.useRef(onWidthChange);\n onWidthChangeRef.current = onWidthChange;\n\n const commitWidth = (next: number) => {\n const clamped = clampWidth(next);\n setResizedWidth(clamped);\n onWidthChangeRef.current?.(clamped);\n };\n\n const onResizePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {\n if (event.button !== 0) return;\n event.preventDefault();\n const startX = event.clientX;\n const startWidth = resizeWidth;\n const onMove = (moveEvent: PointerEvent) => {\n const delta = side === 'right' ? startX - moveEvent.clientX : moveEvent.clientX - startX;\n setResizedWidth(clampWidth(startWidth + delta));\n };\n const onUp = () => {\n window.removeEventListener('pointermove', onMove);\n window.removeEventListener('pointerup', onUp);\n onWidthChangeRef.current?.(widthRef.current);\n };\n window.addEventListener('pointermove', onMove);\n window.addEventListener('pointerup', onUp);\n };\n\n const onResizeKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n const step = event.shiftKey ? 64 : 16;\n const grow = side === 'right' ? 'ArrowLeft' : 'ArrowRight';\n const shrink = side === 'right' ? 'ArrowRight' : 'ArrowLeft';\n if (event.key === grow) {\n event.preventDefault();\n commitWidth(resizeWidth + step);\n } else if (event.key === shrink) {\n event.preventDefault();\n commitWidth(resizeWidth - step);\n } else if (event.key === 'Home') {\n event.preventDefault();\n commitWidth(minWidth);\n } else if (event.key === 'End') {\n event.preventDefault();\n commitWidth(maxWidth);\n }\n };\n\n // Capture the opener before the panel takes focus; restore the moment\n // open flips false — even while an exit animation keeps the DOM up.\n React.useEffect(() => {\n if (open) {\n previouslyFocused.current = document.activeElement as HTMLElement | null;\n return;\n }\n previouslyFocused.current?.focus?.();\n previouslyFocused.current = null;\n }, [open]);\n\n // Move focus in once the panel is actually mounted (present can lag\n // open by a render when the presence gate starts closed).\n React.useEffect(() => {\n if (!open || !present) return;\n const node = drawerRef.current;\n const target =\n initialFocusRef?.current ?? node?.querySelector<HTMLElement>(FOCUSABLE) ?? node;\n target?.focus();\n }, [open, present, initialFocusRef]);\n\n React.useEffect(() => {\n if (!open) return;\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n if (!isTopLayer()) return;\n event.stopPropagation();\n requestClose();\n return;\n }\n if (event.key !== 'Tab') return;\n const node = drawerRef.current;\n if (!node) return;\n const focusable = Array.from(node.querySelectorAll<HTMLElement>(FOCUSABLE));\n if (focusable.length === 0) {\n event.preventDefault();\n return;\n }\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n const active = document.activeElement;\n if (event.shiftKey && (active === first || !node.contains(active))) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && active === last) {\n event.preventDefault();\n first.focus();\n }\n };\n document.addEventListener('keydown', onKeyDown);\n return () => document.removeEventListener('keydown', onKeyDown);\n }, [open, requestClose, isTopLayer]);\n\n if (!present || typeof document === 'undefined') return null;\n\n const customExtent = canResize\n ? `${resizeWidth}px`\n : isVerticalSide\n ? extentStyle(height)\n : extentStyle(width);\n\n const motion = animate\n ? cn(\n 'duration-200 motion-reduce:animate-none',\n exiting ? `animate-out ${slideOut[side]}` : `animate-in ${slideIn[side]}`,\n )\n : undefined;\n\n return createPortal(\n <div\n className=\"fixed inset-0 z-50\"\n onMouseDown={(event) => {\n if (closeOnBackdrop && event.target === event.currentTarget) requestClose();\n }}\n >\n <div\n ref={drawerRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={ariaLabel ?? title}\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n tabIndex={-1}\n className={cn(\n 'fixed flex flex-col bg-background shadow-xl border-border',\n sideClasses[side],\n sizeClasses[side][size],\n motion\n )}\n style={customExtent ? { [isVerticalSide ? 'height' : 'width']: customExtent } : undefined}\n >\n {canResize && (\n <div\n role=\"separator\"\n aria-orientation=\"vertical\"\n aria-label={resizeLabel}\n aria-valuenow={resizeWidth}\n aria-valuemin={minWidth}\n aria-valuemax={maxWidth}\n tabIndex={0}\n onPointerDown={onResizePointerDown}\n onKeyDown={onResizeKeyDown}\n className={cn(\n 'absolute inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-sm bg-transparent',\n 'hover:bg-primary/20 focus-visible:bg-primary/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',\n side === 'right' ? '-left-1' : '-right-1'\n )}\n />\n )}\n <div className=\"flex items-start justify-between gap-4 border-b border-border px-5 py-4\">\n <div>\n <h2 id={titleId} className=\"text-base font-semibold leading-tight\">\n {title}\n </h2>\n {description && (\n <p id={descriptionId} className=\"mt-1 text-sm text-muted-foreground\">\n {description}\n </p>\n )}\n </div>\n {showClose && (\n <button\n type=\"button\"\n onClick={requestClose}\n aria-label={closeLabel}\n className=\"-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n ✕\n </button>\n )}\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onProps } from '../button/Button';
3
+ /** Object form of `action`: EmptyState renders the button/link for you. */
4
+ export type EmptyStateAction = {
5
+ label: React.ReactNode;
6
+ onClick?: () => void;
7
+ /** Renders an anchor (styled as a button) instead of a button. */
8
+ href?: string;
9
+ variant?: ButtonProps['variant'];
10
+ };
2
11
  export type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {
3
12
  /** Icon or illustration shown above the title. */
4
13
  icon?: React.ReactNode;
5
14
  title: string;
6
15
  description?: string;
7
- /** Primary action (button/link). */
8
- action?: React.ReactNode;
16
+ /** Primary action: a rendered node, or an action object. */
17
+ action?: React.ReactNode | EmptyStateAction;
9
18
  /** Alias for `action` for codebases that pass a list of actions. */
10
19
  actions?: React.ReactNode;
11
20
  /** Secondary action shown beside the primary one. */
@@ -25,8 +34,8 @@ export declare const EmptyState: React.ForwardRefExoticComponent<React.HTMLAttri
25
34
  icon?: React.ReactNode;
26
35
  title: string;
27
36
  description?: string;
28
- /** Primary action (button/link). */
29
- action?: React.ReactNode;
37
+ /** Primary action: a rendered node, or an action object. */
38
+ action?: React.ReactNode | EmptyStateAction;
30
39
  /** Alias for `action` for codebases that pass a list of actions. */
31
40
  actions?: React.ReactNode;
32
41
  /** Secondary action shown beside the primary one. */
@@ -34,6 +34,18 @@ module.exports = __toCommonJS(EmptyState_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var React = __toESM(require("react"));
36
36
  var import_cn = require("../../utils/cn.js");
37
+ var import_Button = require("../button/Button.js");
38
+ function isActionObject(value) {
39
+ return typeof value === "object" && value !== null && !React.isValidElement(value) && "label" in value;
40
+ }
41
+ function renderAction(action) {
42
+ if (!isActionObject(action)) return action;
43
+ const { label, onClick, href, variant } = action;
44
+ if (href) {
45
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { variant, asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href, children: label }) });
46
+ }
47
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.Button, { variant, onClick, children: label });
48
+ }
37
49
  const EmptyState = React.forwardRef(function EmptyState2({
38
50
  icon,
39
51
  title,
@@ -47,7 +59,7 @@ const EmptyState = React.forwardRef(function EmptyState2({
47
59
  children,
48
60
  ...props
49
61
  }, ref) {
50
- const primaryAction = action ?? actions;
62
+ const primaryAction = renderAction(action) ?? actions;
51
63
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
52
64
  "div",
53
65
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/empty-state/EmptyState.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {\n /** Icon or illustration shown above the title. */\n icon?: React.ReactNode;\n title: string;\n description?: string;\n /** Primary action (button/link). */\n action?: React.ReactNode;\n /** Alias for `action` for codebases that pass a list of actions. */\n actions?: React.ReactNode;\n /** Secondary action shown beside the primary one. */\n secondaryAction?: React.ReactNode;\n /** Heading level for the title. Defaults to a paragraph. */\n titleAs?: 'p' | 'h2' | 'h3' | 'h4';\n /** Compact padding for use inside panels and table bodies. */\n size?: 'sm' | 'md';\n};\n\n/**\n * Placeholder for empty collections, zero-result searches and unconfigured\n * features. Keeps the title/description/action hierarchy consistent across\n * the product.\n */\nexport const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(function EmptyState(\n {\n icon,\n title,\n description,\n action,\n actions,\n secondaryAction,\n titleAs: Title = 'p',\n size = 'md',\n className,\n children,\n ...props\n },\n ref\n) {\n const primaryAction = action ?? actions;\n return (\n <div\n ref={ref}\n className={cn(\n 'flex flex-col items-center justify-center rounded-lg border border-dashed border-border text-center',\n size === 'md' ? 'gap-3 px-6 py-12' : 'gap-2 px-4 py-6',\n className\n )}\n {...props}\n >\n {icon && <div className=\"text-muted-foreground [&_svg]:size-8\">{icon}</div>}\n <Title className={cn('font-semibold', size === 'md' ? 'text-base' : 'text-sm')}>{title}</Title>\n {description && <p className=\"max-w-sm text-sm text-muted-foreground\">{description}</p>}\n {children}\n {(primaryAction || secondaryAction) && (\n <div className=\"mt-1 flex flex-wrap items-center justify-center gap-2\">\n {primaryAction}\n {secondaryAction}\n </div>\n )}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDe;AApDf,YAAuB;AACvB,gBAAmB;AAwBZ,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS,QAAQ;AAAA,EACjB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,gBAAgB,UAAU;AAChC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,eAAW;AAAA,QACT;AAAA,QACA,SAAS,OAAO,qBAAqB;AAAA,QACrC;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,gBAAQ,4CAAC,SAAI,WAAU,wCAAwC,gBAAK;AAAA,QACrE,4CAAC,SAAM,eAAW,cAAG,iBAAiB,SAAS,OAAO,cAAc,SAAS,GAAI,iBAAM;AAAA,QACtF,eAAe,4CAAC,OAAE,WAAU,0CAA0C,uBAAY;AAAA,QAClF;AAAA,SACC,iBAAiB,oBACjB,6CAAC,SAAI,WAAU,yDACZ;AAAA;AAAA,UACA;AAAA,WACH;AAAA;AAAA;AAAA,EAEJ;AAEJ,CAAC;","names":["EmptyState"]}
1
+ {"version":3,"sources":["../../../../src/components/empty-state/EmptyState.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\nimport { Button, type ButtonProps } from '../button/Button';\n\n/** Object form of `action`: EmptyState renders the button/link for you. */\nexport type EmptyStateAction = {\n label: React.ReactNode;\n onClick?: () => void;\n /** Renders an anchor (styled as a button) instead of a button. */\n href?: string;\n variant?: ButtonProps['variant'];\n};\n\nexport type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {\n /** Icon or illustration shown above the title. */\n icon?: React.ReactNode;\n title: string;\n description?: string;\n /** Primary action: a rendered node, or an action object. */\n action?: React.ReactNode | EmptyStateAction;\n /** Alias for `action` for codebases that pass a list of actions. */\n actions?: React.ReactNode;\n /** Secondary action shown beside the primary one. */\n secondaryAction?: React.ReactNode;\n /** Heading level for the title. Defaults to a paragraph. */\n titleAs?: 'p' | 'h2' | 'h3' | 'h4';\n /** Compact padding for use inside panels and table bodies. */\n size?: 'sm' | 'md';\n};\n\nfunction isActionObject(value: unknown): value is EmptyStateAction {\n return (\n typeof value === 'object' &&\n value !== null &&\n !React.isValidElement(value) &&\n 'label' in value\n );\n}\n\n/** Normalizes the node and object forms into a single element. */\nfunction renderAction(action: React.ReactNode | EmptyStateAction | undefined): React.ReactNode {\n if (!isActionObject(action)) return action;\n const { label, onClick, href, variant } = action;\n if (href) {\n return (\n <Button variant={variant} asChild>\n <a href={href}>{label}</a>\n </Button>\n );\n }\n return (\n <Button variant={variant} onClick={onClick}>\n {label}\n </Button>\n );\n}\n\n/**\n * Placeholder for empty collections, zero-result searches and unconfigured\n * features. Keeps the title/description/action hierarchy consistent across\n * the product.\n */\nexport const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(function EmptyState(\n {\n icon,\n title,\n description,\n action,\n actions,\n secondaryAction,\n titleAs: Title = 'p',\n size = 'md',\n className,\n children,\n ...props\n },\n ref\n) {\n const primaryAction = renderAction(action) ?? actions;\n return (\n <div\n ref={ref}\n className={cn(\n 'flex flex-col items-center justify-center rounded-lg border border-dashed border-border text-center',\n size === 'md' ? 'gap-3 px-6 py-12' : 'gap-2 px-4 py-6',\n className\n )}\n {...props}\n >\n {icon && <div className=\"text-muted-foreground [&_svg]:size-8\">{icon}</div>}\n <Title className={cn('font-semibold', size === 'md' ? 'text-base' : 'text-sm')}>{title}</Title>\n {description && <p className=\"max-w-sm text-sm text-muted-foreground\">{description}</p>}\n {children}\n {(primaryAction || secondaryAction) && (\n <div className=\"mt-1 flex flex-wrap items-center justify-center gap-2\">\n {primaryAction}\n {secondaryAction}\n </div>\n )}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8CQ;AA9CR,YAAuB;AACvB,gBAAmB;AACnB,oBAAyC;AA4BzC,SAAS,eAAe,OAA2C;AACjE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,eAAe,KAAK,KAC3B,WAAW;AAEf;AAGA,SAAS,aAAa,QAAyE;AAC7F,MAAI,CAAC,eAAe,MAAM,EAAG,QAAO;AACpC,QAAM,EAAE,OAAO,SAAS,MAAM,QAAQ,IAAI;AAC1C,MAAI,MAAM;AACR,WACE,4CAAC,wBAAO,SAAkB,SAAO,MAC/B,sDAAC,OAAE,MAAa,iBAAM,GACxB;AAAA,EAEJ;AACA,SACE,4CAAC,wBAAO,SAAkB,SACvB,iBACH;AAEJ;AAOO,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS,QAAQ;AAAA,EACjB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,gBAAgB,aAAa,MAAM,KAAK;AAC9C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,eAAW;AAAA,QACT;AAAA,QACA,SAAS,OAAO,qBAAqB;AAAA,QACrC;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,gBAAQ,4CAAC,SAAI,WAAU,wCAAwC,gBAAK;AAAA,QACrE,4CAAC,SAAM,eAAW,cAAG,iBAAiB,SAAS,OAAO,cAAc,SAAS,GAAI,iBAAM;AAAA,QACtF,eAAe,4CAAC,OAAE,WAAU,0CAA0C,uBAAY;AAAA,QAClF;AAAA,SACC,iBAAiB,oBACjB,6CAAC,SAAI,WAAU,yDACZ;AAAA;AAAA,UACA;AAAA,WACH;AAAA;AAAA;AAAA,EAEJ;AAEJ,CAAC;","names":["EmptyState"]}
@@ -1,6 +1,18 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { cn } from "../../utils/cn.mjs";
4
+ import { Button } from "../button/Button.mjs";
5
+ function isActionObject(value) {
6
+ return typeof value === "object" && value !== null && !React.isValidElement(value) && "label" in value;
7
+ }
8
+ function renderAction(action) {
9
+ if (!isActionObject(action)) return action;
10
+ const { label, onClick, href, variant } = action;
11
+ if (href) {
12
+ return /* @__PURE__ */ jsx(Button, { variant, asChild: true, children: /* @__PURE__ */ jsx("a", { href, children: label }) });
13
+ }
14
+ return /* @__PURE__ */ jsx(Button, { variant, onClick, children: label });
15
+ }
4
16
  const EmptyState = React.forwardRef(function EmptyState2({
5
17
  icon,
6
18
  title,
@@ -14,7 +26,7 @@ const EmptyState = React.forwardRef(function EmptyState2({
14
26
  children,
15
27
  ...props
16
28
  }, ref) {
17
- const primaryAction = action ?? actions;
29
+ const primaryAction = renderAction(action) ?? actions;
18
30
  return /* @__PURE__ */ jsxs(
19
31
  "div",
20
32
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/empty-state/EmptyState.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {\n /** Icon or illustration shown above the title. */\n icon?: React.ReactNode;\n title: string;\n description?: string;\n /** Primary action (button/link). */\n action?: React.ReactNode;\n /** Alias for `action` for codebases that pass a list of actions. */\n actions?: React.ReactNode;\n /** Secondary action shown beside the primary one. */\n secondaryAction?: React.ReactNode;\n /** Heading level for the title. Defaults to a paragraph. */\n titleAs?: 'p' | 'h2' | 'h3' | 'h4';\n /** Compact padding for use inside panels and table bodies. */\n size?: 'sm' | 'md';\n};\n\n/**\n * Placeholder for empty collections, zero-result searches and unconfigured\n * features. Keeps the title/description/action hierarchy consistent across\n * the product.\n */\nexport const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(function EmptyState(\n {\n icon,\n title,\n description,\n action,\n actions,\n secondaryAction,\n titleAs: Title = 'p',\n size = 'md',\n className,\n children,\n ...props\n },\n ref\n) {\n const primaryAction = action ?? actions;\n return (\n <div\n ref={ref}\n className={cn(\n 'flex flex-col items-center justify-center rounded-lg border border-dashed border-border text-center',\n size === 'md' ? 'gap-3 px-6 py-12' : 'gap-2 px-4 py-6',\n className\n )}\n {...props}\n >\n {icon && <div className=\"text-muted-foreground [&_svg]:size-8\">{icon}</div>}\n <Title className={cn('font-semibold', size === 'md' ? 'text-base' : 'text-sm')}>{title}</Title>\n {description && <p className=\"max-w-sm text-sm text-muted-foreground\">{description}</p>}\n {children}\n {(primaryAction || secondaryAction) && (\n <div className=\"mt-1 flex flex-wrap items-center justify-center gap-2\">\n {primaryAction}\n {secondaryAction}\n </div>\n )}\n </div>\n );\n});\n"],"mappings":"AAoDe,cAKP,YALO;AApDf,YAAY,WAAW;AACvB,SAAS,UAAU;AAwBZ,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS,QAAQ;AAAA,EACjB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,gBAAgB,UAAU;AAChC,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA,SAAS,OAAO,qBAAqB;AAAA,QACrC;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,gBAAQ,oBAAC,SAAI,WAAU,wCAAwC,gBAAK;AAAA,QACrE,oBAAC,SAAM,WAAW,GAAG,iBAAiB,SAAS,OAAO,cAAc,SAAS,GAAI,iBAAM;AAAA,QACtF,eAAe,oBAAC,OAAE,WAAU,0CAA0C,uBAAY;AAAA,QAClF;AAAA,SACC,iBAAiB,oBACjB,qBAAC,SAAI,WAAU,yDACZ;AAAA;AAAA,UACA;AAAA,WACH;AAAA;AAAA;AAAA,EAEJ;AAEJ,CAAC;","names":["EmptyState"]}
1
+ {"version":3,"sources":["../../../../src/components/empty-state/EmptyState.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\nimport { Button, type ButtonProps } from '../button/Button';\n\n/** Object form of `action`: EmptyState renders the button/link for you. */\nexport type EmptyStateAction = {\n label: React.ReactNode;\n onClick?: () => void;\n /** Renders an anchor (styled as a button) instead of a button. */\n href?: string;\n variant?: ButtonProps['variant'];\n};\n\nexport type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {\n /** Icon or illustration shown above the title. */\n icon?: React.ReactNode;\n title: string;\n description?: string;\n /** Primary action: a rendered node, or an action object. */\n action?: React.ReactNode | EmptyStateAction;\n /** Alias for `action` for codebases that pass a list of actions. */\n actions?: React.ReactNode;\n /** Secondary action shown beside the primary one. */\n secondaryAction?: React.ReactNode;\n /** Heading level for the title. Defaults to a paragraph. */\n titleAs?: 'p' | 'h2' | 'h3' | 'h4';\n /** Compact padding for use inside panels and table bodies. */\n size?: 'sm' | 'md';\n};\n\nfunction isActionObject(value: unknown): value is EmptyStateAction {\n return (\n typeof value === 'object' &&\n value !== null &&\n !React.isValidElement(value) &&\n 'label' in value\n );\n}\n\n/** Normalizes the node and object forms into a single element. */\nfunction renderAction(action: React.ReactNode | EmptyStateAction | undefined): React.ReactNode {\n if (!isActionObject(action)) return action;\n const { label, onClick, href, variant } = action;\n if (href) {\n return (\n <Button variant={variant} asChild>\n <a href={href}>{label}</a>\n </Button>\n );\n }\n return (\n <Button variant={variant} onClick={onClick}>\n {label}\n </Button>\n );\n}\n\n/**\n * Placeholder for empty collections, zero-result searches and unconfigured\n * features. Keeps the title/description/action hierarchy consistent across\n * the product.\n */\nexport const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(function EmptyState(\n {\n icon,\n title,\n description,\n action,\n actions,\n secondaryAction,\n titleAs: Title = 'p',\n size = 'md',\n className,\n children,\n ...props\n },\n ref\n) {\n const primaryAction = renderAction(action) ?? actions;\n return (\n <div\n ref={ref}\n className={cn(\n 'flex flex-col items-center justify-center rounded-lg border border-dashed border-border text-center',\n size === 'md' ? 'gap-3 px-6 py-12' : 'gap-2 px-4 py-6',\n className\n )}\n {...props}\n >\n {icon && <div className=\"text-muted-foreground [&_svg]:size-8\">{icon}</div>}\n <Title className={cn('font-semibold', size === 'md' ? 'text-base' : 'text-sm')}>{title}</Title>\n {description && <p className=\"max-w-sm text-sm text-muted-foreground\">{description}</p>}\n {children}\n {(primaryAction || secondaryAction) && (\n <div className=\"mt-1 flex flex-wrap items-center justify-center gap-2\">\n {primaryAction}\n {secondaryAction}\n </div>\n )}\n </div>\n );\n});\n"],"mappings":"AA8CQ,cAgDA,YAhDA;AA9CR,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,cAAgC;AA4BzC,SAAS,eAAe,OAA2C;AACjE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,eAAe,KAAK,KAC3B,WAAW;AAEf;AAGA,SAAS,aAAa,QAAyE;AAC7F,MAAI,CAAC,eAAe,MAAM,EAAG,QAAO;AACpC,QAAM,EAAE,OAAO,SAAS,MAAM,QAAQ,IAAI;AAC1C,MAAI,MAAM;AACR,WACE,oBAAC,UAAO,SAAkB,SAAO,MAC/B,8BAAC,OAAE,MAAa,iBAAM,GACxB;AAAA,EAEJ;AACA,SACE,oBAAC,UAAO,SAAkB,SACvB,iBACH;AAEJ;AAOO,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS,QAAQ;AAAA,EACjB,OAAO;AAAA,EACP;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACA,KACA;AACA,QAAM,gBAAgB,aAAa,MAAM,KAAK;AAC9C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW;AAAA,QACT;AAAA,QACA,SAAS,OAAO,qBAAqB;AAAA,QACrC;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEH;AAAA,gBAAQ,oBAAC,SAAI,WAAU,wCAAwC,gBAAK;AAAA,QACrE,oBAAC,SAAM,WAAW,GAAG,iBAAiB,SAAS,OAAO,cAAc,SAAS,GAAI,iBAAM;AAAA,QACtF,eAAe,oBAAC,OAAE,WAAU,0CAA0C,uBAAY;AAAA,QAClF;AAAA,SACC,iBAAiB,oBACjB,qBAAC,SAAI,WAAU,yDACZ;AAAA;AAAA,UACA;AAAA,WACH;AAAA;AAAA;AAAA,EAEJ;AAEJ,CAAC;","names":["EmptyState"]}
@@ -1,14 +1,24 @@
1
1
  import * as React from 'react';
2
2
  export type MetricTrend = 'up' | 'down' | 'flat';
3
+ export type MetricTone = 'default' | 'success' | 'warning' | 'destructive';
3
4
  export type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> & {
4
- label: string;
5
+ /** Metric name. Alias: title. */
6
+ label?: string;
5
7
  value: string | number;
6
- /** Secondary line under the value. */
8
+ /** Secondary line under the value. Alias: description. */
7
9
  hint?: React.ReactNode;
10
+ /** Alias for `label` (migration-friendly). */
11
+ title?: string;
12
+ /** Alias for `hint` (migration-friendly). */
13
+ description?: React.ReactNode;
8
14
  /** Signed change, e.g. "+12.4%" or "-3". */
9
15
  delta?: string;
10
16
  /** Direction colors the delta (green up / red down / muted flat). */
11
17
  trend?: MetricTrend;
18
+ /** Semantic color for the value (not the delta). */
19
+ tone?: MetricTone;
20
+ /** Renders a skeleton instead of the value; sets aria-busy while true. */
21
+ loading?: boolean;
12
22
  icon?: React.ReactNode;
13
23
  };
14
24
  /**
@@ -17,13 +27,22 @@ export type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'
17
27
  * never communicated by color alone.
18
28
  */
19
29
  export declare const MetricCard: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "title"> & {
20
- label: string;
30
+ /** Metric name. Alias: title. */
31
+ label?: string;
21
32
  value: string | number;
22
- /** Secondary line under the value. */
33
+ /** Secondary line under the value. Alias: description. */
23
34
  hint?: React.ReactNode;
35
+ /** Alias for `label` (migration-friendly). */
36
+ title?: string;
37
+ /** Alias for `hint` (migration-friendly). */
38
+ description?: React.ReactNode;
24
39
  /** Signed change, e.g. "+12.4%" or "-3". */
25
40
  delta?: string;
26
41
  /** Direction colors the delta (green up / red down / muted flat). */
27
42
  trend?: MetricTrend;
43
+ /** Semantic color for the value (not the delta). */
44
+ tone?: MetricTone;
45
+ /** Renders a skeleton instead of the value; sets aria-busy while true. */
46
+ loading?: boolean;
28
47
  icon?: React.ReactNode;
29
48
  } & React.RefAttributes<HTMLDivElement>>;
@@ -39,21 +39,48 @@ const trendClasses = {
39
39
  down: "text-destructive",
40
40
  flat: "text-muted-foreground"
41
41
  };
42
+ const toneClasses = {
43
+ default: "",
44
+ success: "text-success",
45
+ warning: "text-warning-ink",
46
+ destructive: "text-destructive"
47
+ };
42
48
  const trendGlyph = { up: "\u2191", down: "\u2193", flat: "\u2192" };
43
- const MetricCard = React.forwardRef(function MetricCard2({ label, value, hint, delta, trend = "flat", icon, className, ...props }, ref) {
49
+ const MetricCard = React.forwardRef(function MetricCard2({ label, value, hint, title, description, delta, trend = "flat", tone = "default", loading = false, icon, className, ...props }, ref) {
50
+ const heading = label ?? title;
51
+ const supporting = hint ?? description;
52
+ if (loading) {
53
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
54
+ "div",
55
+ {
56
+ ref,
57
+ "aria-busy": "true",
58
+ className: (0, import_cn.cn)("rounded-xl border border-border bg-card p-5", className),
59
+ ...props,
60
+ children: [
61
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-start justify-between gap-3", children: [
62
+ heading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: heading }),
63
+ icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground [&_svg]:size-4", children: icon })
64
+ ] }),
65
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": "true", className: "mt-3 block h-7 w-24 animate-pulse rounded-md bg-muted" }),
66
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "sr-only", children: "Loading" })
67
+ ]
68
+ }
69
+ );
70
+ }
44
71
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref, className: (0, import_cn.cn)("rounded-xl border border-border bg-card p-5", className), ...props, children: [
45
72
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-start justify-between gap-3", children: [
46
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: label }),
73
+ heading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: heading }),
47
74
  icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground [&_svg]:size-4", children: icon })
48
75
  ] }),
49
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-2 text-2xl font-semibold tabular-nums", children: value }),
50
- (delta || hint) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "mt-1 flex items-center gap-2 text-sm", children: [
76
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: (0, import_cn.cn)("mt-2 text-2xl font-semibold tabular-nums", toneClasses[tone]), children: value }),
77
+ (delta || supporting) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "mt-1 flex items-center gap-2 text-sm", children: [
51
78
  delta && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: (0, import_cn.cn)("font-medium tabular-nums", trendClasses[trend]), children: [
52
79
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": "true", children: trendGlyph[trend] }),
53
80
  " ",
54
81
  delta
55
82
  ] }),
56
- hint && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground", children: hint })
83
+ supporting && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-muted-foreground", children: supporting })
57
84
  ] })
58
85
  ] });
59
86
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/metric-card/MetricCard.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type MetricTrend = 'up' | 'down' | 'flat';\n\nexport type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> & {\n label: string;\n value: string | number;\n /** Secondary line under the value. */\n hint?: React.ReactNode;\n /** Signed change, e.g. \"+12.4%\" or \"-3\". */\n delta?: string;\n /** Direction colors the delta (green up / red down / muted flat). */\n trend?: MetricTrend;\n icon?: React.ReactNode;\n};\n\nconst trendClasses: Record<MetricTrend, string> = {\n up: 'text-success',\n down: 'text-destructive',\n flat: 'text-muted-foreground',\n};\n\nconst trendGlyph: Record<MetricTrend, string> = { up: '↑', down: '↓', flat: '→' };\n\n/**\n * Compact KPI tile: label, value, optional delta with direction color and a\n * supporting hint. Deltas always carry an arrow glyph so the direction is\n * never communicated by color alone.\n */\nexport const MetricCard = React.forwardRef<HTMLDivElement, MetricCardProps>(function MetricCard(\n { label, value, hint, delta, trend = 'flat', icon, className, ...props },\n ref\n) {\n return (\n <div ref={ref} className={cn('rounded-xl border border-border bg-card p-5', className)} {...props}>\n <div className=\"flex items-start justify-between gap-3\">\n <p className=\"text-sm text-muted-foreground\">{label}</p>\n {icon && <span className=\"text-muted-foreground [&_svg]:size-4\">{icon}</span>}\n </div>\n <p className=\"mt-2 text-2xl font-semibold tabular-nums\">{value}</p>\n {(delta || hint) && (\n <p className=\"mt-1 flex items-center gap-2 text-sm\">\n {delta && (\n <span className={cn('font-medium tabular-nums', trendClasses[trend])}>\n <span aria-hidden=\"true\">{trendGlyph[trend]}</span> {delta}\n </span>\n )}\n {hint && <span className=\"text-muted-foreground\">{hint}</span>}\n </p>\n )}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCM;AApCN,YAAuB;AACvB,gBAAmB;AAgBnB,MAAM,eAA4C;AAAA,EAChD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,aAA0C,EAAE,IAAI,UAAK,MAAM,UAAK,MAAM,SAAI;AAOzE,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF,EAAE,OAAO,OAAO,MAAM,OAAO,QAAQ,QAAQ,MAAM,WAAW,GAAG,MAAM,GACvE,KACA;AACA,SACE,6CAAC,SAAI,KAAU,eAAW,cAAG,+CAA+C,SAAS,GAAI,GAAG,OAC1F;AAAA,iDAAC,SAAI,WAAU,0CACb;AAAA,kDAAC,OAAE,WAAU,iCAAiC,iBAAM;AAAA,MACnD,QAAQ,4CAAC,UAAK,WAAU,wCAAwC,gBAAK;AAAA,OACxE;AAAA,IACA,4CAAC,OAAE,WAAU,4CAA4C,iBAAM;AAAA,KAC7D,SAAS,SACT,6CAAC,OAAE,WAAU,wCACV;AAAA,eACC,6CAAC,UAAK,eAAW,cAAG,4BAA4B,aAAa,KAAK,CAAC,GACjE;AAAA,oDAAC,UAAK,eAAY,QAAQ,qBAAW,KAAK,GAAE;AAAA,QAAO;AAAA,QAAE;AAAA,SACvD;AAAA,MAED,QAAQ,4CAAC,UAAK,WAAU,yBAAyB,gBAAK;AAAA,OACzD;AAAA,KAEJ;AAEJ,CAAC;","names":["MetricCard"]}
1
+ {"version":3,"sources":["../../../../src/components/metric-card/MetricCard.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type MetricTrend = 'up' | 'down' | 'flat';\nexport type MetricTone = 'default' | 'success' | 'warning' | 'destructive';\n\nexport type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> & {\n /** Metric name. Alias: title. */\n label?: string;\n value: string | number;\n /** Secondary line under the value. Alias: description. */\n hint?: React.ReactNode;\n /** Alias for `label` (migration-friendly). */\n title?: string;\n /** Alias for `hint` (migration-friendly). */\n description?: React.ReactNode;\n /** Signed change, e.g. \"+12.4%\" or \"-3\". */\n delta?: string;\n /** Direction colors the delta (green up / red down / muted flat). */\n trend?: MetricTrend;\n /** Semantic color for the value (not the delta). */\n tone?: MetricTone;\n /** Renders a skeleton instead of the value; sets aria-busy while true. */\n loading?: boolean;\n icon?: React.ReactNode;\n};\n\nconst trendClasses: Record<MetricTrend, string> = {\n up: 'text-success',\n down: 'text-destructive',\n flat: 'text-muted-foreground',\n};\n\nconst toneClasses: Record<MetricTone, string> = {\n default: '',\n success: 'text-success',\n warning: 'text-warning-ink',\n destructive: 'text-destructive',\n};\n\nconst trendGlyph: Record<MetricTrend, string> = { up: '↑', down: '↓', flat: '→' };\n\n/**\n * Compact KPI tile: label, value, optional delta with direction color and a\n * supporting hint. Deltas always carry an arrow glyph so the direction is\n * never communicated by color alone.\n */\nexport const MetricCard = React.forwardRef<HTMLDivElement, MetricCardProps>(function MetricCard(\n { label, value, hint, title, description, delta, trend = 'flat', tone = 'default', loading = false, icon, className, ...props },\n ref\n) {\n const heading = label ?? title;\n const supporting = hint ?? description;\n\n if (loading) {\n return (\n <div\n ref={ref}\n aria-busy=\"true\"\n className={cn('rounded-xl border border-border bg-card p-5', className)}\n {...props}\n >\n <div className=\"flex items-start justify-between gap-3\">\n {heading && <p className=\"text-sm text-muted-foreground\">{heading}</p>}\n {icon && <span className=\"text-muted-foreground [&_svg]:size-4\">{icon}</span>}\n </div>\n <span aria-hidden=\"true\" className=\"mt-3 block h-7 w-24 animate-pulse rounded-md bg-muted\" />\n <span className=\"sr-only\">Loading</span>\n </div>\n );\n }\n\n return (\n <div ref={ref} className={cn('rounded-xl border border-border bg-card p-5', className)} {...props}>\n <div className=\"flex items-start justify-between gap-3\">\n {heading && <p className=\"text-sm text-muted-foreground\">{heading}</p>}\n {icon && <span className=\"text-muted-foreground [&_svg]:size-4\">{icon}</span>}\n </div>\n <p className={cn('mt-2 text-2xl font-semibold tabular-nums', toneClasses[tone])}>{value}</p>\n {(delta || supporting) && (\n <p className=\"mt-1 flex items-center gap-2 text-sm\">\n {delta && (\n <span className={cn('font-medium tabular-nums', trendClasses[trend])}>\n <span aria-hidden=\"true\">{trendGlyph[trend]}</span> {delta}\n </span>\n )}\n {supporting && <span className=\"text-muted-foreground\">{supporting}</span>}\n </p>\n )}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8DQ;AA9DR,YAAuB;AACvB,gBAAmB;AA0BnB,MAAM,eAA4C;AAAA,EAChD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,cAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AACf;AAEA,MAAM,aAA0C,EAAE,IAAI,UAAK,MAAM,UAAK,MAAM,SAAI;AAOzE,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF,EAAE,OAAO,OAAO,MAAM,OAAO,aAAa,OAAO,QAAQ,QAAQ,OAAO,WAAW,UAAU,OAAO,MAAM,WAAW,GAAG,MAAM,GAC9H,KACA;AACA,QAAM,UAAU,SAAS;AACzB,QAAM,aAAa,QAAQ;AAE3B,MAAI,SAAS;AACX,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,aAAU;AAAA,QACV,eAAW,cAAG,+CAA+C,SAAS;AAAA,QACrE,GAAG;AAAA,QAEJ;AAAA,uDAAC,SAAI,WAAU,0CACZ;AAAA,uBAAW,4CAAC,OAAE,WAAU,iCAAiC,mBAAQ;AAAA,YACjE,QAAQ,4CAAC,UAAK,WAAU,wCAAwC,gBAAK;AAAA,aACxE;AAAA,UACA,4CAAC,UAAK,eAAY,QAAO,WAAU,yDAAwD;AAAA,UAC3F,4CAAC,UAAK,WAAU,WAAU,qBAAO;AAAA;AAAA;AAAA,IACnC;AAAA,EAEJ;AAEA,SACE,6CAAC,SAAI,KAAU,eAAW,cAAG,+CAA+C,SAAS,GAAI,GAAG,OAC1F;AAAA,iDAAC,SAAI,WAAU,0CACZ;AAAA,iBAAW,4CAAC,OAAE,WAAU,iCAAiC,mBAAQ;AAAA,MACjE,QAAQ,4CAAC,UAAK,WAAU,wCAAwC,gBAAK;AAAA,OACxE;AAAA,IACA,4CAAC,OAAE,eAAW,cAAG,4CAA4C,YAAY,IAAI,CAAC,GAAI,iBAAM;AAAA,KACtF,SAAS,eACT,6CAAC,OAAE,WAAU,wCACV;AAAA,eACC,6CAAC,UAAK,eAAW,cAAG,4BAA4B,aAAa,KAAK,CAAC,GACjE;AAAA,oDAAC,UAAK,eAAY,QAAQ,qBAAW,KAAK,GAAE;AAAA,QAAO;AAAA,QAAE;AAAA,SACvD;AAAA,MAED,cAAc,4CAAC,UAAK,WAAU,yBAAyB,sBAAW;AAAA,OACrE;AAAA,KAEJ;AAEJ,CAAC;","names":["MetricCard"]}
@@ -6,21 +6,48 @@ const trendClasses = {
6
6
  down: "text-destructive",
7
7
  flat: "text-muted-foreground"
8
8
  };
9
+ const toneClasses = {
10
+ default: "",
11
+ success: "text-success",
12
+ warning: "text-warning-ink",
13
+ destructive: "text-destructive"
14
+ };
9
15
  const trendGlyph = { up: "\u2191", down: "\u2193", flat: "\u2192" };
10
- const MetricCard = React.forwardRef(function MetricCard2({ label, value, hint, delta, trend = "flat", icon, className, ...props }, ref) {
16
+ const MetricCard = React.forwardRef(function MetricCard2({ label, value, hint, title, description, delta, trend = "flat", tone = "default", loading = false, icon, className, ...props }, ref) {
17
+ const heading = label ?? title;
18
+ const supporting = hint ?? description;
19
+ if (loading) {
20
+ return /* @__PURE__ */ jsxs(
21
+ "div",
22
+ {
23
+ ref,
24
+ "aria-busy": "true",
25
+ className: cn("rounded-xl border border-border bg-card p-5", className),
26
+ ...props,
27
+ children: [
28
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
29
+ heading && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: heading }),
30
+ icon && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground [&_svg]:size-4", children: icon })
31
+ ] }),
32
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "mt-3 block h-7 w-24 animate-pulse rounded-md bg-muted" }),
33
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading" })
34
+ ]
35
+ }
36
+ );
37
+ }
11
38
  return /* @__PURE__ */ jsxs("div", { ref, className: cn("rounded-xl border border-border bg-card p-5", className), ...props, children: [
12
39
  /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
13
- /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: label }),
40
+ heading && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: heading }),
14
41
  icon && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground [&_svg]:size-4", children: icon })
15
42
  ] }),
16
- /* @__PURE__ */ jsx("p", { className: "mt-2 text-2xl font-semibold tabular-nums", children: value }),
17
- (delta || hint) && /* @__PURE__ */ jsxs("p", { className: "mt-1 flex items-center gap-2 text-sm", children: [
43
+ /* @__PURE__ */ jsx("p", { className: cn("mt-2 text-2xl font-semibold tabular-nums", toneClasses[tone]), children: value }),
44
+ (delta || supporting) && /* @__PURE__ */ jsxs("p", { className: "mt-1 flex items-center gap-2 text-sm", children: [
18
45
  delta && /* @__PURE__ */ jsxs("span", { className: cn("font-medium tabular-nums", trendClasses[trend]), children: [
19
46
  /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: trendGlyph[trend] }),
20
47
  " ",
21
48
  delta
22
49
  ] }),
23
- hint && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: hint })
50
+ supporting && /* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: supporting })
24
51
  ] })
25
52
  ] });
26
53
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/metric-card/MetricCard.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type MetricTrend = 'up' | 'down' | 'flat';\n\nexport type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> & {\n label: string;\n value: string | number;\n /** Secondary line under the value. */\n hint?: React.ReactNode;\n /** Signed change, e.g. \"+12.4%\" or \"-3\". */\n delta?: string;\n /** Direction colors the delta (green up / red down / muted flat). */\n trend?: MetricTrend;\n icon?: React.ReactNode;\n};\n\nconst trendClasses: Record<MetricTrend, string> = {\n up: 'text-success',\n down: 'text-destructive',\n flat: 'text-muted-foreground',\n};\n\nconst trendGlyph: Record<MetricTrend, string> = { up: '↑', down: '↓', flat: '→' };\n\n/**\n * Compact KPI tile: label, value, optional delta with direction color and a\n * supporting hint. Deltas always carry an arrow glyph so the direction is\n * never communicated by color alone.\n */\nexport const MetricCard = React.forwardRef<HTMLDivElement, MetricCardProps>(function MetricCard(\n { label, value, hint, delta, trend = 'flat', icon, className, ...props },\n ref\n) {\n return (\n <div ref={ref} className={cn('rounded-xl border border-border bg-card p-5', className)} {...props}>\n <div className=\"flex items-start justify-between gap-3\">\n <p className=\"text-sm text-muted-foreground\">{label}</p>\n {icon && <span className=\"text-muted-foreground [&_svg]:size-4\">{icon}</span>}\n </div>\n <p className=\"mt-2 text-2xl font-semibold tabular-nums\">{value}</p>\n {(delta || hint) && (\n <p className=\"mt-1 flex items-center gap-2 text-sm\">\n {delta && (\n <span className={cn('font-medium tabular-nums', trendClasses[trend])}>\n <span aria-hidden=\"true\">{trendGlyph[trend]}</span> {delta}\n </span>\n )}\n {hint && <span className=\"text-muted-foreground\">{hint}</span>}\n </p>\n )}\n </div>\n );\n});\n"],"mappings":"AAoCM,SACE,KADF;AApCN,YAAY,WAAW;AACvB,SAAS,UAAU;AAgBnB,MAAM,eAA4C;AAAA,EAChD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,aAA0C,EAAE,IAAI,UAAK,MAAM,UAAK,MAAM,SAAI;AAOzE,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF,EAAE,OAAO,OAAO,MAAM,OAAO,QAAQ,QAAQ,MAAM,WAAW,GAAG,MAAM,GACvE,KACA;AACA,SACE,qBAAC,SAAI,KAAU,WAAW,GAAG,+CAA+C,SAAS,GAAI,GAAG,OAC1F;AAAA,yBAAC,SAAI,WAAU,0CACb;AAAA,0BAAC,OAAE,WAAU,iCAAiC,iBAAM;AAAA,MACnD,QAAQ,oBAAC,UAAK,WAAU,wCAAwC,gBAAK;AAAA,OACxE;AAAA,IACA,oBAAC,OAAE,WAAU,4CAA4C,iBAAM;AAAA,KAC7D,SAAS,SACT,qBAAC,OAAE,WAAU,wCACV;AAAA,eACC,qBAAC,UAAK,WAAW,GAAG,4BAA4B,aAAa,KAAK,CAAC,GACjE;AAAA,4BAAC,UAAK,eAAY,QAAQ,qBAAW,KAAK,GAAE;AAAA,QAAO;AAAA,QAAE;AAAA,SACvD;AAAA,MAED,QAAQ,oBAAC,UAAK,WAAU,yBAAyB,gBAAK;AAAA,OACzD;AAAA,KAEJ;AAEJ,CAAC;","names":["MetricCard"]}
1
+ {"version":3,"sources":["../../../../src/components/metric-card/MetricCard.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cn } from '../../utils/cn';\n\nexport type MetricTrend = 'up' | 'down' | 'flat';\nexport type MetricTone = 'default' | 'success' | 'warning' | 'destructive';\n\nexport type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> & {\n /** Metric name. Alias: title. */\n label?: string;\n value: string | number;\n /** Secondary line under the value. Alias: description. */\n hint?: React.ReactNode;\n /** Alias for `label` (migration-friendly). */\n title?: string;\n /** Alias for `hint` (migration-friendly). */\n description?: React.ReactNode;\n /** Signed change, e.g. \"+12.4%\" or \"-3\". */\n delta?: string;\n /** Direction colors the delta (green up / red down / muted flat). */\n trend?: MetricTrend;\n /** Semantic color for the value (not the delta). */\n tone?: MetricTone;\n /** Renders a skeleton instead of the value; sets aria-busy while true. */\n loading?: boolean;\n icon?: React.ReactNode;\n};\n\nconst trendClasses: Record<MetricTrend, string> = {\n up: 'text-success',\n down: 'text-destructive',\n flat: 'text-muted-foreground',\n};\n\nconst toneClasses: Record<MetricTone, string> = {\n default: '',\n success: 'text-success',\n warning: 'text-warning-ink',\n destructive: 'text-destructive',\n};\n\nconst trendGlyph: Record<MetricTrend, string> = { up: '↑', down: '↓', flat: '→' };\n\n/**\n * Compact KPI tile: label, value, optional delta with direction color and a\n * supporting hint. Deltas always carry an arrow glyph so the direction is\n * never communicated by color alone.\n */\nexport const MetricCard = React.forwardRef<HTMLDivElement, MetricCardProps>(function MetricCard(\n { label, value, hint, title, description, delta, trend = 'flat', tone = 'default', loading = false, icon, className, ...props },\n ref\n) {\n const heading = label ?? title;\n const supporting = hint ?? description;\n\n if (loading) {\n return (\n <div\n ref={ref}\n aria-busy=\"true\"\n className={cn('rounded-xl border border-border bg-card p-5', className)}\n {...props}\n >\n <div className=\"flex items-start justify-between gap-3\">\n {heading && <p className=\"text-sm text-muted-foreground\">{heading}</p>}\n {icon && <span className=\"text-muted-foreground [&_svg]:size-4\">{icon}</span>}\n </div>\n <span aria-hidden=\"true\" className=\"mt-3 block h-7 w-24 animate-pulse rounded-md bg-muted\" />\n <span className=\"sr-only\">Loading</span>\n </div>\n );\n }\n\n return (\n <div ref={ref} className={cn('rounded-xl border border-border bg-card p-5', className)} {...props}>\n <div className=\"flex items-start justify-between gap-3\">\n {heading && <p className=\"text-sm text-muted-foreground\">{heading}</p>}\n {icon && <span className=\"text-muted-foreground [&_svg]:size-4\">{icon}</span>}\n </div>\n <p className={cn('mt-2 text-2xl font-semibold tabular-nums', toneClasses[tone])}>{value}</p>\n {(delta || supporting) && (\n <p className=\"mt-1 flex items-center gap-2 text-sm\">\n {delta && (\n <span className={cn('font-medium tabular-nums', trendClasses[trend])}>\n <span aria-hidden=\"true\">{trendGlyph[trend]}</span> {delta}\n </span>\n )}\n {supporting && <span className=\"text-muted-foreground\">{supporting}</span>}\n </p>\n )}\n </div>\n );\n});\n"],"mappings":"AA8DQ,SACc,KADd;AA9DR,YAAY,WAAW;AACvB,SAAS,UAAU;AA0BnB,MAAM,eAA4C;AAAA,EAChD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,cAA0C;AAAA,EAC9C,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AACf;AAEA,MAAM,aAA0C,EAAE,IAAI,UAAK,MAAM,UAAK,MAAM,SAAI;AAOzE,MAAM,aAAa,MAAM,WAA4C,SAASA,YACnF,EAAE,OAAO,OAAO,MAAM,OAAO,aAAa,OAAO,QAAQ,QAAQ,OAAO,WAAW,UAAU,OAAO,MAAM,WAAW,GAAG,MAAM,GAC9H,KACA;AACA,QAAM,UAAU,SAAS;AACzB,QAAM,aAAa,QAAQ;AAE3B,MAAI,SAAS;AACX,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,aAAU;AAAA,QACV,WAAW,GAAG,+CAA+C,SAAS;AAAA,QACrE,GAAG;AAAA,QAEJ;AAAA,+BAAC,SAAI,WAAU,0CACZ;AAAA,uBAAW,oBAAC,OAAE,WAAU,iCAAiC,mBAAQ;AAAA,YACjE,QAAQ,oBAAC,UAAK,WAAU,wCAAwC,gBAAK;AAAA,aACxE;AAAA,UACA,oBAAC,UAAK,eAAY,QAAO,WAAU,yDAAwD;AAAA,UAC3F,oBAAC,UAAK,WAAU,WAAU,qBAAO;AAAA;AAAA;AAAA,IACnC;AAAA,EAEJ;AAEA,SACE,qBAAC,SAAI,KAAU,WAAW,GAAG,+CAA+C,SAAS,GAAI,GAAG,OAC1F;AAAA,yBAAC,SAAI,WAAU,0CACZ;AAAA,iBAAW,oBAAC,OAAE,WAAU,iCAAiC,mBAAQ;AAAA,MACjE,QAAQ,oBAAC,UAAK,WAAU,wCAAwC,gBAAK;AAAA,OACxE;AAAA,IACA,oBAAC,OAAE,WAAW,GAAG,4CAA4C,YAAY,IAAI,CAAC,GAAI,iBAAM;AAAA,KACtF,SAAS,eACT,qBAAC,OAAE,WAAU,wCACV;AAAA,eACC,qBAAC,UAAK,WAAW,GAAG,4BAA4B,aAAa,KAAK,CAAC,GACjE;AAAA,4BAAC,UAAK,eAAY,QAAQ,qBAAW,KAAK,GAAE;AAAA,QAAO;AAAA,QAAE;AAAA,SACvD;AAAA,MAED,cAAc,oBAAC,UAAK,WAAU,yBAAyB,sBAAW;AAAA,OACrE;AAAA,KAEJ;AAEJ,CAAC;","names":["MetricCard"]}
@@ -2,6 +2,8 @@ import * as React from 'react';
2
2
  export type PageHeaderProps = React.HTMLAttributes<HTMLDivElement> & {
3
3
  title: string;
4
4
  description?: string;
5
+ /** Alias for `description` (migration-friendly). */
6
+ subtitle?: string;
5
7
  /** Breadcrumbs/eyebrow above the title. */
6
8
  breadcrumbs?: React.ReactNode;
7
9
  /** Right-aligned actions (buttons, menus). */
@@ -29,6 +31,8 @@ export type PageHeaderProps = React.HTMLAttributes<HTMLDivElement> & {
29
31
  export declare const PageHeader: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
30
32
  title: string;
31
33
  description?: string;
34
+ /** Alias for `description` (migration-friendly). */
35
+ subtitle?: string;
32
36
  /** Breadcrumbs/eyebrow above the title. */
33
37
  breadcrumbs?: React.ReactNode;
34
38
  /** Right-aligned actions (buttons, menus). */