@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
@@ -0,0 +1,117 @@
1
+ import * as React from 'react';
2
+ import { cn } from '../../utils/cn';
3
+
4
+ export type BottomNavItem = {
5
+ /** Destination URL for the tab. */
6
+ href: string;
7
+ /** Visible tab label. */
8
+ label: string;
9
+ /** Icon shown above the label; always rendered aria-hidden. */
10
+ icon?: React.ReactNode;
11
+ /** Marks the current tab and sets aria-current="page". */
12
+ active?: boolean;
13
+ /** Small count or dot shown in the tab's top corner. */
14
+ badge?: React.ReactNode;
15
+ /** Renders the tab as non-interactive. */
16
+ disabled?: boolean;
17
+ };
18
+
19
+ export type BottomNavProps = React.HTMLAttributes<HTMLElement> & {
20
+ /** Tabs in order. Keep to 3-5 so every target stays thumb-reachable. */
21
+ items: BottomNavItem[];
22
+ /** Router link component (Next Link, react-router Link). */
23
+ linkComponent?: React.ElementType;
24
+ /** Prop used to pass the destination to `linkComponent`. */
25
+ linkHrefProp?: 'href' | 'to';
26
+ /** Landmark label. Default "Primary". */
27
+ label?: string;
28
+ /** Pin the bar to the bottom edge with safe-area padding (default true). */
29
+ fixed?: boolean;
30
+ /** Hide the bar from the md breakpoint up (default true). */
31
+ mobileOnly?: boolean;
32
+ };
33
+
34
+ const tabClass =
35
+ 'relative flex min-h-14 w-full flex-col items-center justify-center gap-0.5 px-2 py-2 text-[11px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset';
36
+
37
+ /**
38
+ * Mobile bottom tab bar for the 3-5 primary destinations of an app shell.
39
+ * A nav landmark with aria-current="page" on the active tab, 44px minimum
40
+ * targets, an optional count badge and safe-area padding so the bar clears
41
+ * the iOS home indicator.
42
+ */
43
+ export function BottomNav({
44
+ items,
45
+ linkComponent,
46
+ linkHrefProp = 'href',
47
+ label = 'Primary',
48
+ fixed = true,
49
+ mobileOnly = true,
50
+ className,
51
+ ...props
52
+ }: BottomNavProps) {
53
+ const LinkEl = linkComponent ?? 'a';
54
+ const destination = (href: string) => (linkHrefProp === 'to' ? { to: href } : { href });
55
+
56
+ return (
57
+ <nav
58
+ aria-label={label}
59
+ className={cn(
60
+ 'w-full border-t border-border bg-background pb-[env(safe-area-inset-bottom)]',
61
+ fixed && 'fixed inset-x-0 bottom-0 z-40',
62
+ mobileOnly && 'md:hidden',
63
+ className
64
+ )}
65
+ {...props}
66
+ >
67
+ <ul
68
+ className="mx-auto grid w-full max-w-lg"
69
+ style={{ gridTemplateColumns: `repeat(${Math.max(items.length, 1)}, minmax(0, 1fr))` }}
70
+ >
71
+ {items.map((item) => {
72
+ const content = (
73
+ <>
74
+ {item.icon && (
75
+ <span aria-hidden="true" className="[&_svg]:size-5">
76
+ {item.icon}
77
+ </span>
78
+ )}
79
+ <span>{item.label}</span>
80
+ {item.badge != null && (
81
+ <span className="absolute right-1/4 top-1 rounded-full bg-primary px-1.5 text-[10px] font-semibold leading-4 text-primary-foreground">
82
+ {item.badge}
83
+ </span>
84
+ )}
85
+ </>
86
+ );
87
+
88
+ return (
89
+ <li key={item.href}>
90
+ {item.disabled ? (
91
+ <span
92
+ aria-disabled="true"
93
+ className={cn(tabClass, 'text-muted-foreground opacity-50')}
94
+ >
95
+ {content}
96
+ </span>
97
+ ) : (
98
+ <LinkEl
99
+ {...destination(item.href)}
100
+ aria-current={item.active ? 'page' : undefined}
101
+ className={cn(
102
+ tabClass,
103
+ item.active
104
+ ? 'text-primary'
105
+ : 'text-muted-foreground hover:text-foreground'
106
+ )}
107
+ >
108
+ {content}
109
+ </LinkEl>
110
+ )}
111
+ </li>
112
+ );
113
+ })}
114
+ </ul>
115
+ </nav>
116
+ );
117
+ }
@@ -0,0 +1 @@
1
+ export * from './BottomNav';
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react';
2
- import { render, screen, waitFor } from '@testing-library/react';
2
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { axe } from 'jest-axe';
5
5
  import { describe, expect, it, vi } from 'vitest';
@@ -181,3 +181,88 @@ describe('localized labels', () => {
181
181
  expect(screen.getByRole('button', { name: 'Fermer' })).toBeInTheDocument();
182
182
  });
183
183
  });
184
+
185
+ describe('onClose alias', () => {
186
+ it('closes through onClose when onOpenChange is absent', async () => {
187
+ const user = userEvent.setup();
188
+ const onClose = vi.fn();
189
+ render(<Drawer open title="Filters" onClose={onClose}>Body</Drawer>);
190
+ await user.keyboard('{Escape}');
191
+ expect(onClose).toHaveBeenCalledTimes(1);
192
+ await user.click(screen.getByRole('button', { name: 'Close drawer' }));
193
+ expect(onClose).toHaveBeenCalledTimes(2);
194
+ });
195
+
196
+ it('prefers onOpenChange when both handlers are passed', async () => {
197
+ const user = userEvent.setup();
198
+ const onOpenChange = vi.fn();
199
+ const onClose = vi.fn();
200
+ render(<Drawer open title="Filters" onOpenChange={onOpenChange} onClose={onClose}>Body</Drawer>);
201
+ await user.click(screen.getByRole('button', { name: 'Close drawer' }));
202
+ expect(onOpenChange).toHaveBeenCalledWith(false);
203
+ expect(onClose).not.toHaveBeenCalled();
204
+ });
205
+ });
206
+
207
+ describe('resizable', () => {
208
+ it('renders a separator with the width bounds and seeds the size preset', () => {
209
+ render(<Drawer open onOpenChange={vi.fn()} title="Details" resizable>Body</Drawer>);
210
+ const handle = screen.getByRole('separator', { name: 'Resize drawer' });
211
+ expect(handle).toHaveAttribute('aria-valuenow', '384');
212
+ expect(handle).toHaveAttribute('aria-valuemin', '240');
213
+ expect(handle).toHaveAttribute('aria-valuemax', '960');
214
+ expect(screen.getByRole('dialog')).toHaveStyle({ width: '384px' });
215
+ });
216
+
217
+ it('honours defaultWidth and clamps it to the bounds', () => {
218
+ render(
219
+ <Drawer open onOpenChange={vi.fn()} title="Details" resizable defaultWidth={100}>
220
+ Body
221
+ </Drawer>
222
+ );
223
+ expect(screen.getByRole('separator')).toHaveAttribute('aria-valuenow', '240');
224
+ });
225
+
226
+ it('grows and shrinks from the keyboard, with Home/End jumps', () => {
227
+ const onWidthChange = vi.fn();
228
+ render(
229
+ <Drawer open onOpenChange={vi.fn()} title="Details" resizable onWidthChange={onWidthChange}>
230
+ Body
231
+ </Drawer>
232
+ );
233
+ const handle = screen.getByRole('separator');
234
+ fireEvent.keyDown(handle, { key: 'ArrowLeft' });
235
+ expect(handle).toHaveAttribute('aria-valuenow', '400');
236
+ fireEvent.keyDown(handle, { key: 'ArrowLeft', shiftKey: true });
237
+ expect(handle).toHaveAttribute('aria-valuenow', '464');
238
+ fireEvent.keyDown(handle, { key: 'End' });
239
+ expect(handle).toHaveAttribute('aria-valuenow', '960');
240
+ fireEvent.keyDown(handle, { key: 'Home' });
241
+ expect(handle).toHaveAttribute('aria-valuenow', '240');
242
+ expect(onWidthChange).toHaveBeenLastCalledWith(240);
243
+ });
244
+
245
+ it('resizes while dragging the handle', () => {
246
+ const onWidthChange = vi.fn();
247
+ render(
248
+ <Drawer open onOpenChange={vi.fn()} title="Details" resizable onWidthChange={onWidthChange}>
249
+ Body
250
+ </Drawer>
251
+ );
252
+ const handle = screen.getByRole('separator');
253
+ fireEvent.pointerDown(handle, { button: 0, clientX: 500 });
254
+ fireEvent.pointerMove(window, { clientX: 400 });
255
+ expect(handle).toHaveAttribute('aria-valuenow', '484');
256
+ fireEvent.pointerUp(window);
257
+ expect(onWidthChange).toHaveBeenCalledWith(484);
258
+ });
259
+
260
+ it('does not render a handle for top/bottom drawers or when resizable is false', () => {
261
+ const { rerender } = render(
262
+ <Drawer open onOpenChange={vi.fn()} title="Sheet" side="bottom" resizable>Body</Drawer>
263
+ );
264
+ expect(screen.queryByRole('separator')).not.toBeInTheDocument();
265
+ rerender(<Drawer open onOpenChange={vi.fn()} title="Sheet">Body</Drawer>);
266
+ expect(screen.queryByRole('separator')).not.toBeInTheDocument();
267
+ });
268
+ });
@@ -11,7 +11,14 @@ export type DrawerSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
11
11
 
12
12
  export type DrawerProps = {
13
13
  open: boolean;
14
- onOpenChange: (open: boolean) => void;
14
+ /** Called with the next open state. Alias: onClose (close requests only). */
15
+ onOpenChange?: (open: boolean) => void;
16
+ /**
17
+ * Called when the drawer asks to close: Escape, backdrop click or the close
18
+ * button. Alias for `onOpenChange(false)`, used when only a close handler is
19
+ * passed.
20
+ */
21
+ onClose?: () => void;
15
22
  title: string;
16
23
  description?: string;
17
24
  children?: React.ReactNode;
@@ -29,6 +36,22 @@ export type DrawerProps = {
29
36
  * ("60vh"). Overrides `size`.
30
37
  */
31
38
  height?: number | string;
39
+ /**
40
+ * Drag the inner edge to resize a left/right drawer. Keyboard: Arrow keys
41
+ * nudge 16px, Shift+Arrow 64px, Home/End jump to the bounds. Ignored for
42
+ * top/bottom drawers.
43
+ */
44
+ resizable?: boolean;
45
+ /** Lower bound in pixels while resizable (default 240). */
46
+ minWidth?: number;
47
+ /** Upper bound in pixels while resizable (default 960). */
48
+ maxWidth?: number;
49
+ /** Initial width in pixels while resizable; defaults to the `size` preset. */
50
+ defaultWidth?: number;
51
+ /** Fired with the next width in pixels when a resize commits. */
52
+ onWidthChange?: (width: number) => void;
53
+ /** Accessible label for the resize handle (default "Resize drawer"). */
54
+ resizeLabel?: string;
32
55
  /** Clicking the backdrop closes (default true). */
33
56
  closeOnBackdrop?: boolean;
34
57
  /** Hide the close (✕) button in the header (default true). */
@@ -80,6 +103,15 @@ const sizeClasses: Record<DrawerSide, Record<DrawerSize, string>> = {
80
103
  bottom: sideHeights,
81
104
  };
82
105
 
106
+ /** Pixel equivalents of the width presets, used as the resize starting point. */
107
+ const sizePx: Record<DrawerSize, number> = {
108
+ sm: 288,
109
+ md: 384,
110
+ lg: 512,
111
+ xl: 640,
112
+ '2xl': 768,
113
+ };
114
+
83
115
  /** Custom extent wins over the preset; numbers are pixels. */
84
116
  function extentStyle(value: number | string | undefined): string | undefined {
85
117
  if (value === undefined) return undefined;
@@ -110,6 +142,7 @@ const slideOut: Record<DrawerSide, string> = {
110
142
  export function Drawer({
111
143
  open,
112
144
  onOpenChange,
145
+ onClose,
113
146
  title,
114
147
  description,
115
148
  children,
@@ -117,6 +150,12 @@ export function Drawer({
117
150
  size = 'md',
118
151
  width,
119
152
  height,
153
+ resizable = false,
154
+ minWidth = 240,
155
+ maxWidth = 960,
156
+ defaultWidth,
157
+ onWidthChange,
158
+ resizeLabel = 'Resize drawer',
120
159
  closeOnBackdrop = true,
121
160
  showClose = true,
122
161
  closeLabel = 'Close drawer',
@@ -131,6 +170,74 @@ export function Drawer({
131
170
  const { present, exiting } = usePresence(open, animate);
132
171
  const isTopLayer = useModalLayer(open);
133
172
 
173
+ // Prefer onOpenChange; fall back to the onClose alias so a migration code
174
+ // path that only passes onClose still dismisses without double-firing.
175
+ const requestClose = React.useCallback(() => {
176
+ if (onOpenChange) onOpenChange(false);
177
+ else onClose?.();
178
+ }, [onOpenChange, onClose]);
179
+
180
+ // Resizable left/right drawers. Width is state-local so dragging stays
181
+ // smooth; `onWidthChange` fires once a drag commits or a key is pressed.
182
+ const isVerticalSide = side === 'top' || side === 'bottom';
183
+ const canResize = resizable && !isVerticalSide;
184
+ const clampWidth = React.useCallback(
185
+ (next: number) => Math.min(maxWidth, Math.max(minWidth, Math.round(next))),
186
+ [minWidth, maxWidth]
187
+ );
188
+ const [resizedWidth, setResizedWidth] = React.useState<number | null>(null);
189
+ const initialWidth = clampWidth(
190
+ defaultWidth ?? (typeof width === 'number' ? width : sizePx[size])
191
+ );
192
+ const resizeWidth = resizedWidth ?? initialWidth;
193
+ const widthRef = React.useRef(resizeWidth);
194
+ widthRef.current = resizeWidth;
195
+ const onWidthChangeRef = React.useRef(onWidthChange);
196
+ onWidthChangeRef.current = onWidthChange;
197
+
198
+ const commitWidth = (next: number) => {
199
+ const clamped = clampWidth(next);
200
+ setResizedWidth(clamped);
201
+ onWidthChangeRef.current?.(clamped);
202
+ };
203
+
204
+ const onResizePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {
205
+ if (event.button !== 0) return;
206
+ event.preventDefault();
207
+ const startX = event.clientX;
208
+ const startWidth = resizeWidth;
209
+ const onMove = (moveEvent: PointerEvent) => {
210
+ const delta = side === 'right' ? startX - moveEvent.clientX : moveEvent.clientX - startX;
211
+ setResizedWidth(clampWidth(startWidth + delta));
212
+ };
213
+ const onUp = () => {
214
+ window.removeEventListener('pointermove', onMove);
215
+ window.removeEventListener('pointerup', onUp);
216
+ onWidthChangeRef.current?.(widthRef.current);
217
+ };
218
+ window.addEventListener('pointermove', onMove);
219
+ window.addEventListener('pointerup', onUp);
220
+ };
221
+
222
+ const onResizeKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
223
+ const step = event.shiftKey ? 64 : 16;
224
+ const grow = side === 'right' ? 'ArrowLeft' : 'ArrowRight';
225
+ const shrink = side === 'right' ? 'ArrowRight' : 'ArrowLeft';
226
+ if (event.key === grow) {
227
+ event.preventDefault();
228
+ commitWidth(resizeWidth + step);
229
+ } else if (event.key === shrink) {
230
+ event.preventDefault();
231
+ commitWidth(resizeWidth - step);
232
+ } else if (event.key === 'Home') {
233
+ event.preventDefault();
234
+ commitWidth(minWidth);
235
+ } else if (event.key === 'End') {
236
+ event.preventDefault();
237
+ commitWidth(maxWidth);
238
+ }
239
+ };
240
+
134
241
  // Capture the opener before the panel takes focus; restore the moment
135
242
  // open flips false — even while an exit animation keeps the DOM up.
136
243
  React.useEffect(() => {
@@ -158,7 +265,7 @@ export function Drawer({
158
265
  if (event.key === 'Escape') {
159
266
  if (!isTopLayer()) return;
160
267
  event.stopPropagation();
161
- onOpenChange(false);
268
+ requestClose();
162
269
  return;
163
270
  }
164
271
  if (event.key !== 'Tab') return;
@@ -182,12 +289,15 @@ export function Drawer({
182
289
  };
183
290
  document.addEventListener('keydown', onKeyDown);
184
291
  return () => document.removeEventListener('keydown', onKeyDown);
185
- }, [open, onOpenChange, isTopLayer]);
292
+ }, [open, requestClose, isTopLayer]);
186
293
 
187
294
  if (!present || typeof document === 'undefined') return null;
188
295
 
189
- const isVerticalSide = side === 'top' || side === 'bottom';
190
- const customExtent = isVerticalSide ? extentStyle(height) : extentStyle(width);
296
+ const customExtent = canResize
297
+ ? `${resizeWidth}px`
298
+ : isVerticalSide
299
+ ? extentStyle(height)
300
+ : extentStyle(width);
191
301
 
192
302
  const motion = animate
193
303
  ? cn(
@@ -200,7 +310,7 @@ export function Drawer({
200
310
  <div
201
311
  className="fixed inset-0 z-50"
202
312
  onMouseDown={(event) => {
203
- if (closeOnBackdrop && event.target === event.currentTarget) onOpenChange(false);
313
+ if (closeOnBackdrop && event.target === event.currentTarget) requestClose();
204
314
  }}
205
315
  >
206
316
  <div
@@ -219,6 +329,24 @@ export function Drawer({
219
329
  )}
220
330
  style={customExtent ? { [isVerticalSide ? 'height' : 'width']: customExtent } : undefined}
221
331
  >
332
+ {canResize && (
333
+ <div
334
+ role="separator"
335
+ aria-orientation="vertical"
336
+ aria-label={resizeLabel}
337
+ aria-valuenow={resizeWidth}
338
+ aria-valuemin={minWidth}
339
+ aria-valuemax={maxWidth}
340
+ tabIndex={0}
341
+ onPointerDown={onResizePointerDown}
342
+ onKeyDown={onResizeKeyDown}
343
+ className={cn(
344
+ 'absolute inset-y-0 z-10 w-2 cursor-col-resize touch-none rounded-sm bg-transparent',
345
+ 'hover:bg-primary/20 focus-visible:bg-primary/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
346
+ side === 'right' ? '-left-1' : '-right-1'
347
+ )}
348
+ />
349
+ )}
222
350
  <div className="flex items-start justify-between gap-4 border-b border-border px-5 py-4">
223
351
  <div>
224
352
  <h2 id={titleId} className="text-base font-semibold leading-tight">
@@ -233,7 +361,7 @@ export function Drawer({
233
361
  {showClose && (
234
362
  <button
235
363
  type="button"
236
- onClick={() => onOpenChange(false)}
364
+ onClick={requestClose}
237
365
  aria-label={closeLabel}
238
366
  className="-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
239
367
  >
@@ -1,6 +1,7 @@
1
1
  import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
2
3
  import { axe } from 'jest-axe';
3
- import { describe, expect, it } from 'vitest';
4
+ import { describe, expect, it, vi } from 'vitest';
4
5
  import { EmptyState } from './EmptyState';
5
6
 
6
7
  describe('EmptyState', () => {
@@ -40,3 +41,27 @@ describe('EmptyState', () => {
40
41
  expect(await axe(container)).toHaveNoViolations();
41
42
  });
42
43
  });
44
+
45
+ describe('action object form', () => {
46
+ it('renders a button from { label, onClick }', async () => {
47
+ const user = userEvent.setup();
48
+ const onClick = vi.fn();
49
+ render(<EmptyState title="No results" action={{ label: 'Clear filters', onClick, variant: 'outline' }} />);
50
+ const button = screen.getByRole('button', { name: 'Clear filters' });
51
+ expect(button).toHaveClass('border');
52
+ await user.click(button);
53
+ expect(onClick).toHaveBeenCalledTimes(1);
54
+ });
55
+
56
+ it('renders a link when href is provided', () => {
57
+ render(<EmptyState title="No results" action={{ label: 'Create one', href: '/new' }} />);
58
+ const link = screen.getByRole('link', { name: 'Create one' });
59
+ expect(link).toHaveAttribute('href', '/new');
60
+ expect(screen.queryByRole('button', { name: 'Create one' })).not.toBeInTheDocument();
61
+ });
62
+
63
+ it('still accepts a rendered node', () => {
64
+ render(<EmptyState title="No results" action={<button type="button">Custom</button>} />);
65
+ expect(screen.getByRole('button', { name: 'Custom' })).toBeInTheDocument();
66
+ });
67
+ });
@@ -1,13 +1,23 @@
1
1
  import * as React from 'react';
2
2
  import { cn } from '../../utils/cn';
3
+ import { Button, type ButtonProps } from '../button/Button';
4
+
5
+ /** Object form of `action`: EmptyState renders the button/link for you. */
6
+ export type EmptyStateAction = {
7
+ label: React.ReactNode;
8
+ onClick?: () => void;
9
+ /** Renders an anchor (styled as a button) instead of a button. */
10
+ href?: string;
11
+ variant?: ButtonProps['variant'];
12
+ };
3
13
 
4
14
  export type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {
5
15
  /** Icon or illustration shown above the title. */
6
16
  icon?: React.ReactNode;
7
17
  title: string;
8
18
  description?: string;
9
- /** Primary action (button/link). */
10
- action?: React.ReactNode;
19
+ /** Primary action: a rendered node, or an action object. */
20
+ action?: React.ReactNode | EmptyStateAction;
11
21
  /** Alias for `action` for codebases that pass a list of actions. */
12
22
  actions?: React.ReactNode;
13
23
  /** Secondary action shown beside the primary one. */
@@ -18,6 +28,33 @@ export type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {
18
28
  size?: 'sm' | 'md';
19
29
  };
20
30
 
31
+ function isActionObject(value: unknown): value is EmptyStateAction {
32
+ return (
33
+ typeof value === 'object' &&
34
+ value !== null &&
35
+ !React.isValidElement(value) &&
36
+ 'label' in value
37
+ );
38
+ }
39
+
40
+ /** Normalizes the node and object forms into a single element. */
41
+ function renderAction(action: React.ReactNode | EmptyStateAction | undefined): React.ReactNode {
42
+ if (!isActionObject(action)) return action;
43
+ const { label, onClick, href, variant } = action;
44
+ if (href) {
45
+ return (
46
+ <Button variant={variant} asChild>
47
+ <a href={href}>{label}</a>
48
+ </Button>
49
+ );
50
+ }
51
+ return (
52
+ <Button variant={variant} onClick={onClick}>
53
+ {label}
54
+ </Button>
55
+ );
56
+ }
57
+
21
58
  /**
22
59
  * Placeholder for empty collections, zero-result searches and unconfigured
23
60
  * features. Keeps the title/description/action hierarchy consistent across
@@ -39,7 +76,7 @@ export const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(func
39
76
  },
40
77
  ref
41
78
  ) {
42
- const primaryAction = action ?? actions;
79
+ const primaryAction = renderAction(action) ?? actions;
43
80
  return (
44
81
  <div
45
82
  ref={ref}
@@ -26,3 +26,35 @@ describe('MetricCard', () => {
26
26
  expect(await axe(container)).toHaveNoViolations();
27
27
  });
28
28
  });
29
+
30
+ describe('MetricCard migration aliases', () => {
31
+ it('reads title and description when label and hint are absent', () => {
32
+ render(<MetricCard title="Revenue" value="$1" description="vs last month" />);
33
+ expect(screen.getByText('Revenue')).toBeInTheDocument();
34
+ expect(screen.getByText('vs last month')).toBeInTheDocument();
35
+ });
36
+
37
+ it('prefers label and hint when both forms are passed', () => {
38
+ render(<MetricCard label="Canonical" title="Alias" value="1" hint="Hint line" description="Alt line" />);
39
+ expect(screen.getByText('Canonical')).toBeInTheDocument();
40
+ expect(screen.queryByText('Alias')).not.toBeInTheDocument();
41
+ expect(screen.getByText('Hint line')).toBeInTheDocument();
42
+ expect(screen.queryByText('Alt line')).not.toBeInTheDocument();
43
+ });
44
+ });
45
+
46
+ describe('MetricCard tone and loading', () => {
47
+ it('colors the value by tone', () => {
48
+ const { rerender } = render(<MetricCard label="Revenue" value="$1" tone="success" />);
49
+ expect(screen.getByText('$1')).toHaveClass('text-success');
50
+ rerender(<MetricCard label="Revenue" value="$1" tone="destructive" />);
51
+ expect(screen.getByText('$1')).toHaveClass('text-destructive');
52
+ });
53
+
54
+ it('renders a skeleton with aria-busy while loading', () => {
55
+ const { container } = render(<MetricCard label="Revenue" value="$1" loading />);
56
+ expect(container.firstChild).toHaveAttribute('aria-busy', 'true');
57
+ expect(screen.queryByText('$1')).not.toBeInTheDocument();
58
+ expect(screen.getByText('Loading')).toBeInTheDocument();
59
+ });
60
+ });
@@ -2,16 +2,26 @@ import * as React from 'react';
2
2
  import { cn } from '../../utils/cn';
3
3
 
4
4
  export type MetricTrend = 'up' | 'down' | 'flat';
5
+ export type MetricTone = 'default' | 'success' | 'warning' | 'destructive';
5
6
 
6
7
  export type MetricCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> & {
7
- label: string;
8
+ /** Metric name. Alias: title. */
9
+ label?: string;
8
10
  value: string | number;
9
- /** Secondary line under the value. */
11
+ /** Secondary line under the value. Alias: description. */
10
12
  hint?: React.ReactNode;
13
+ /** Alias for `label` (migration-friendly). */
14
+ title?: string;
15
+ /** Alias for `hint` (migration-friendly). */
16
+ description?: React.ReactNode;
11
17
  /** Signed change, e.g. "+12.4%" or "-3". */
12
18
  delta?: string;
13
19
  /** Direction colors the delta (green up / red down / muted flat). */
14
20
  trend?: MetricTrend;
21
+ /** Semantic color for the value (not the delta). */
22
+ tone?: MetricTone;
23
+ /** Renders a skeleton instead of the value; sets aria-busy while true. */
24
+ loading?: boolean;
15
25
  icon?: React.ReactNode;
16
26
  };
17
27
 
@@ -21,6 +31,13 @@ const trendClasses: Record<MetricTrend, string> = {
21
31
  flat: 'text-muted-foreground',
22
32
  };
23
33
 
34
+ const toneClasses: Record<MetricTone, string> = {
35
+ default: '',
36
+ success: 'text-success',
37
+ warning: 'text-warning-ink',
38
+ destructive: 'text-destructive',
39
+ };
40
+
24
41
  const trendGlyph: Record<MetricTrend, string> = { up: '↑', down: '↓', flat: '→' };
25
42
 
26
43
  /**
@@ -29,24 +46,45 @@ const trendGlyph: Record<MetricTrend, string> = { up: '↑', down: '↓', flat:
29
46
  * never communicated by color alone.
30
47
  */
31
48
  export const MetricCard = React.forwardRef<HTMLDivElement, MetricCardProps>(function MetricCard(
32
- { label, value, hint, delta, trend = 'flat', icon, className, ...props },
49
+ { label, value, hint, title, description, delta, trend = 'flat', tone = 'default', loading = false, icon, className, ...props },
33
50
  ref
34
51
  ) {
52
+ const heading = label ?? title;
53
+ const supporting = hint ?? description;
54
+
55
+ if (loading) {
56
+ return (
57
+ <div
58
+ ref={ref}
59
+ aria-busy="true"
60
+ className={cn('rounded-xl border border-border bg-card p-5', className)}
61
+ {...props}
62
+ >
63
+ <div className="flex items-start justify-between gap-3">
64
+ {heading && <p className="text-sm text-muted-foreground">{heading}</p>}
65
+ {icon && <span className="text-muted-foreground [&_svg]:size-4">{icon}</span>}
66
+ </div>
67
+ <span aria-hidden="true" className="mt-3 block h-7 w-24 animate-pulse rounded-md bg-muted" />
68
+ <span className="sr-only">Loading</span>
69
+ </div>
70
+ );
71
+ }
72
+
35
73
  return (
36
74
  <div ref={ref} className={cn('rounded-xl border border-border bg-card p-5', className)} {...props}>
37
75
  <div className="flex items-start justify-between gap-3">
38
- <p className="text-sm text-muted-foreground">{label}</p>
76
+ {heading && <p className="text-sm text-muted-foreground">{heading}</p>}
39
77
  {icon && <span className="text-muted-foreground [&_svg]:size-4">{icon}</span>}
40
78
  </div>
41
- <p className="mt-2 text-2xl font-semibold tabular-nums">{value}</p>
42
- {(delta || hint) && (
79
+ <p className={cn('mt-2 text-2xl font-semibold tabular-nums', toneClasses[tone])}>{value}</p>
80
+ {(delta || supporting) && (
43
81
  <p className="mt-1 flex items-center gap-2 text-sm">
44
82
  {delta && (
45
83
  <span className={cn('font-medium tabular-nums', trendClasses[trend])}>
46
84
  <span aria-hidden="true">{trendGlyph[trend]}</span> {delta}
47
85
  </span>
48
86
  )}
49
- {hint && <span className="text-muted-foreground">{hint}</span>}
87
+ {supporting && <span className="text-muted-foreground">{supporting}</span>}
50
88
  </p>
51
89
  )}
52
90
  </div>