@slipstream-ui/core 0.3.0 → 0.5.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 (181) hide show
  1. package/dist/index.d.mts +957 -56
  2. package/dist/index.d.ts +957 -56
  3. package/dist/index.js +2554 -777
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +2524 -777
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/manifests/app-shell.manifest.json +206 -0
  8. package/dist/manifests/auth-layout.manifest.json +99 -0
  9. package/dist/manifests/autocomplete.manifest.json +53 -5
  10. package/dist/manifests/badge.manifest.json +20 -3
  11. package/dist/manifests/breadcrumb.manifest.json +6 -0
  12. package/dist/manifests/button.manifest.json +20 -2
  13. package/dist/manifests/card.manifest.json +53 -6
  14. package/dist/manifests/confirm-dialog.manifest.json +132 -0
  15. package/dist/manifests/data-table.manifest.json +50 -0
  16. package/dist/manifests/date-picker.manifest.json +87 -0
  17. package/dist/manifests/dialog.manifest.json +56 -4
  18. package/dist/manifests/drawer.manifest.json +25 -4
  19. package/dist/manifests/empty-state.manifest.json +108 -0
  20. package/dist/manifests/file-upload.manifest.json +103 -0
  21. package/dist/manifests/filter-bar.manifest.json +100 -0
  22. package/dist/manifests/link.manifest.json +106 -0
  23. package/dist/manifests/menu.manifest.json +13 -1
  24. package/dist/manifests/metric-card.manifest.json +105 -0
  25. package/dist/manifests/page-header.manifest.json +124 -0
  26. package/dist/manifests/pagination.manifest.json +68 -34
  27. package/dist/manifests/password-input.manifest.json +75 -0
  28. package/dist/manifests/prose.manifest.json +75 -0
  29. package/dist/manifests/search.manifest.json +41 -9
  30. package/dist/manifests/section-heading.manifest.json +108 -0
  31. package/dist/manifests/select-menu.manifest.json +142 -0
  32. package/dist/manifests/select.manifest.json +55 -12
  33. package/dist/manifests/site-footer.manifest.json +94 -0
  34. package/dist/manifests/site-header.manifest.json +130 -0
  35. package/dist/manifests/stepper.manifest.json +95 -0
  36. package/dist/manifests/table-card.manifest.json +123 -0
  37. package/dist/manifests/table-of-contents.manifest.json +87 -0
  38. package/dist/manifests/time-picker.manifest.json +86 -0
  39. package/dist/manifests/timeline.manifest.json +69 -0
  40. package/dist/manifests/toast.manifest.json +101 -25
  41. package/package.json +2 -2
  42. package/src/components/alert/Alert.tsx +2 -2
  43. package/src/components/app-shell/AppShell.test.tsx +148 -0
  44. package/src/components/app-shell/AppShell.tsx +266 -0
  45. package/src/components/app-shell/index.ts +1 -0
  46. package/src/components/auth-layout/AuthLayout.test.tsx +34 -0
  47. package/src/components/auth-layout/AuthLayout.tsx +47 -0
  48. package/src/components/auth-layout/index.ts +1 -0
  49. package/src/components/autocomplete/Autocomplete.test.tsx +53 -0
  50. package/src/components/autocomplete/Autocomplete.tsx +160 -41
  51. package/src/components/badge/Badge.test.tsx +35 -0
  52. package/src/components/badge/Badge.tsx +16 -4
  53. package/src/components/breadcrumb/Breadcrumb.test.tsx +16 -0
  54. package/src/components/breadcrumb/Breadcrumb.tsx +10 -5
  55. package/src/components/button/Button.test.tsx +67 -0
  56. package/src/components/button/Button.tsx +37 -3
  57. package/src/components/button-group/ButtonGroup.test.tsx +6 -8
  58. package/src/components/button-group/ButtonGroup.tsx +17 -9
  59. package/src/components/card/Card.test.tsx +14 -0
  60. package/src/components/card/Card.tsx +15 -8
  61. package/src/components/confirm-dialog/ConfirmDialog.test.tsx +46 -0
  62. package/src/components/confirm-dialog/ConfirmDialog.tsx +86 -0
  63. package/src/components/confirm-dialog/index.ts +1 -0
  64. package/src/components/data-table/DataTable.test.tsx +92 -0
  65. package/src/components/data-table/DataTable.tsx +98 -7
  66. package/src/components/date-picker/DatePicker.test.tsx +30 -0
  67. package/src/components/date-picker/DatePicker.tsx +57 -0
  68. package/src/components/date-picker/index.ts +1 -0
  69. package/src/components/dialog/Dialog.test.tsx +71 -1
  70. package/src/components/dialog/Dialog.tsx +116 -23
  71. package/src/components/dialog/index.ts +1 -2
  72. package/src/components/drawer/Drawer.test.tsx +59 -0
  73. package/src/components/drawer/Drawer.tsx +49 -8
  74. package/src/components/empty-state/EmptyState.test.tsx +30 -0
  75. package/src/components/empty-state/EmptyState.tsx +48 -0
  76. package/src/components/empty-state/index.ts +1 -0
  77. package/src/components/file-upload/FileUpload.test.tsx +43 -0
  78. package/src/components/file-upload/FileUpload.tsx +143 -0
  79. package/src/components/file-upload/index.ts +1 -0
  80. package/src/components/filter-bar/FilterBar.test.tsx +32 -0
  81. package/src/components/filter-bar/FilterBar.tsx +71 -0
  82. package/src/components/filter-bar/index.ts +1 -0
  83. package/src/components/input/Input.tsx +1 -0
  84. package/src/components/input-group/InputGroup.test.tsx +6 -3
  85. package/src/components/input-group/InputGroup.tsx +9 -6
  86. package/src/components/link/Link.test.tsx +60 -0
  87. package/src/components/link/Link.tsx +85 -0
  88. package/src/components/link/index.ts +1 -0
  89. package/src/components/menu/Menu.test.tsx +21 -0
  90. package/src/components/menu/Menu.tsx +8 -3
  91. package/src/components/metric-card/MetricCard.test.tsx +28 -0
  92. package/src/components/metric-card/MetricCard.tsx +54 -0
  93. package/src/components/metric-card/index.ts +1 -0
  94. package/src/components/page-header/PageHeader.test.tsx +48 -0
  95. package/src/components/page-header/PageHeader.tsx +53 -0
  96. package/src/components/page-header/index.ts +1 -0
  97. package/src/components/pagination/Pagination.test.tsx +33 -0
  98. package/src/components/pagination/Pagination.tsx +69 -18
  99. package/src/components/password-input/PasswordInput.test.tsx +29 -0
  100. package/src/components/password-input/PasswordInput.tsx +41 -0
  101. package/src/components/password-input/index.ts +1 -0
  102. package/src/components/prose/Prose.test.tsx +35 -0
  103. package/src/components/prose/Prose.tsx +61 -0
  104. package/src/components/prose/index.ts +1 -0
  105. package/src/components/search/Search.test.tsx +16 -0
  106. package/src/components/search/Search.tsx +11 -2
  107. package/src/components/section-heading/SectionHeading.test.tsx +32 -0
  108. package/src/components/section-heading/SectionHeading.tsx +54 -0
  109. package/src/components/section-heading/index.ts +1 -0
  110. package/src/components/select/Select.test.tsx +40 -1
  111. package/src/components/select/Select.tsx +54 -14
  112. package/src/components/select/index.ts +1 -1
  113. package/src/components/select-menu/SelectMenu.test.tsx +105 -0
  114. package/src/components/select-menu/SelectMenu.tsx +368 -0
  115. package/src/components/select-menu/index.ts +1 -0
  116. package/src/components/site-footer/SiteFooter.test.tsx +30 -0
  117. package/src/components/site-footer/SiteFooter.tsx +79 -0
  118. package/src/components/site-footer/index.ts +1 -0
  119. package/src/components/site-header/SiteHeader.test.tsx +53 -0
  120. package/src/components/site-header/SiteHeader.tsx +124 -0
  121. package/src/components/site-header/index.ts +1 -0
  122. package/src/components/stepper/Stepper.test.tsx +35 -0
  123. package/src/components/stepper/Stepper.tsx +91 -0
  124. package/src/components/stepper/index.ts +1 -0
  125. package/src/components/switch/Switch.test.tsx +10 -0
  126. package/src/components/switch/Switch.tsx +8 -3
  127. package/src/components/table-card/TableCard.test.tsx +59 -0
  128. package/src/components/table-card/TableCard.tsx +48 -0
  129. package/src/components/table-card/index.ts +1 -0
  130. package/src/components/table-of-contents/TableOfContents.test.tsx +31 -0
  131. package/src/components/table-of-contents/TableOfContents.tsx +100 -0
  132. package/src/components/table-of-contents/index.ts +1 -0
  133. package/src/components/textarea/Textarea.tsx +1 -0
  134. package/src/components/time-picker/TimePicker.test.tsx +30 -0
  135. package/src/components/time-picker/TimePicker.tsx +56 -0
  136. package/src/components/time-picker/index.ts +1 -0
  137. package/src/components/timeline/Timeline.test.tsx +26 -0
  138. package/src/components/timeline/Timeline.tsx +53 -0
  139. package/src/components/timeline/index.ts +1 -0
  140. package/src/components/toast/Toast.test.tsx +5 -0
  141. package/src/components/toast/Toast.tsx +2 -16
  142. package/src/components/toast/Toaster.test.tsx +84 -0
  143. package/src/components/toast/Toaster.tsx +116 -0
  144. package/src/components/toast/index.ts +4 -0
  145. package/src/components/toast/toast-store.ts +117 -0
  146. package/src/index.ts +21 -0
  147. package/src/manifests/app-shell.manifest.json +206 -0
  148. package/src/manifests/auth-layout.manifest.json +99 -0
  149. package/src/manifests/autocomplete.manifest.json +53 -5
  150. package/src/manifests/badge.manifest.json +20 -3
  151. package/src/manifests/breadcrumb.manifest.json +6 -0
  152. package/src/manifests/button.manifest.json +20 -2
  153. package/src/manifests/card.manifest.json +53 -6
  154. package/src/manifests/confirm-dialog.manifest.json +132 -0
  155. package/src/manifests/data-table.manifest.json +50 -0
  156. package/src/manifests/date-picker.manifest.json +87 -0
  157. package/src/manifests/dialog.manifest.json +56 -4
  158. package/src/manifests/drawer.manifest.json +25 -4
  159. package/src/manifests/empty-state.manifest.json +108 -0
  160. package/src/manifests/file-upload.manifest.json +103 -0
  161. package/src/manifests/filter-bar.manifest.json +100 -0
  162. package/src/manifests/link.manifest.json +106 -0
  163. package/src/manifests/menu.manifest.json +13 -1
  164. package/src/manifests/metric-card.manifest.json +105 -0
  165. package/src/manifests/page-header.manifest.json +124 -0
  166. package/src/manifests/pagination.manifest.json +68 -34
  167. package/src/manifests/password-input.manifest.json +75 -0
  168. package/src/manifests/prose.manifest.json +75 -0
  169. package/src/manifests/search.manifest.json +41 -9
  170. package/src/manifests/section-heading.manifest.json +108 -0
  171. package/src/manifests/select-menu.manifest.json +142 -0
  172. package/src/manifests/select.manifest.json +55 -12
  173. package/src/manifests/site-footer.manifest.json +94 -0
  174. package/src/manifests/site-header.manifest.json +130 -0
  175. package/src/manifests/stepper.manifest.json +95 -0
  176. package/src/manifests/table-card.manifest.json +123 -0
  177. package/src/manifests/table-of-contents.manifest.json +87 -0
  178. package/src/manifests/time-picker.manifest.json +86 -0
  179. package/src/manifests/timeline.manifest.json +69 -0
  180. package/src/manifests/toast.manifest.json +101 -25
  181. package/src/test/tailwind-v4.test.ts +103 -0
@@ -0,0 +1,57 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { cn } from '../../utils/cn';
5
+ import { Input, type InputProps } from '../input/Input';
6
+
7
+ export type DatePickerProps = Omit<InputProps, 'type' | 'onChange' | 'value' | 'defaultValue'> & {
8
+ /** ISO date string (YYYY-MM-DD) — controlled. */
9
+ value?: string;
10
+ /** ISO date string — initial value when uncontrolled. */
11
+ defaultValue?: string;
12
+ /** Fired with the ISO string ('' when cleared). */
13
+ onValueChange?: (value: string) => void;
14
+ /** Show a clear button once a date is selected. */
15
+ clearable?: boolean;
16
+ };
17
+
18
+ /**
19
+ * Native date field with an ISO-string contract. Uses the platform picker
20
+ * (mobile date wheels, keyboard editing, locale formatting) rather than a
21
+ * custom calendar, so accessibility and input methods come for free.
22
+ */
23
+ export const DatePicker = React.forwardRef<HTMLInputElement, DatePickerProps>(function DatePicker(
24
+ { value, defaultValue, onValueChange, clearable = false, className, ...props },
25
+ ref
26
+ ) {
27
+ const [internal, setInternal] = React.useState(defaultValue ?? '');
28
+ const current = value ?? internal;
29
+
30
+ const commit = (next: string) => {
31
+ if (value === undefined) setInternal(next);
32
+ onValueChange?.(next);
33
+ };
34
+
35
+ return (
36
+ <div className={cn('relative flex items-center', className)}>
37
+ <Input
38
+ ref={ref}
39
+ type="date"
40
+ value={current}
41
+ onChange={(event) => commit(event.target.value)}
42
+ className={clearable && current ? 'pr-9' : undefined}
43
+ {...props}
44
+ />
45
+ {clearable && current && (
46
+ <button
47
+ type="button"
48
+ onClick={() => commit('')}
49
+ aria-label="Clear date"
50
+ className="absolute right-2 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
51
+ >
52
+ ✕
53
+ </button>
54
+ )}
55
+ </div>
56
+ );
57
+ });
@@ -0,0 +1 @@
1
+ export * from './DatePicker';
@@ -3,7 +3,7 @@ import { 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';
6
- import { Dialog } from './Dialog';
6
+ import { Dialog, DialogBody, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from './Dialog';
7
7
 
8
8
  function Harness(props: { onOpenChange?: (open: boolean) => void; closeOnBackdrop?: boolean }) {
9
9
  const [open, setOpen] = useState(true);
@@ -184,3 +184,73 @@ describe('Dialog animate (optional fade)', () => {
184
184
  expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
185
185
  });
186
186
  });
187
+
188
+
189
+ describe('Dialog sizes, slots and compound parts', () => {
190
+ it('applies size presets', () => {
191
+ const { rerender } = render(
192
+ <Dialog open onOpenChange={vi.fn()} title="Sized" size="2xl">
193
+ body
194
+ </Dialog>
195
+ );
196
+ expect(screen.getByRole('dialog')).toHaveClass('max-w-2xl');
197
+ rerender(
198
+ <Dialog open onOpenChange={vi.fn()} title="Sized" size="sm">
199
+ body
200
+ </Dialog>
201
+ );
202
+ expect(screen.getByRole('dialog')).toHaveClass('max-w-sm');
203
+ });
204
+
205
+ it('wires a composed header through DialogTitle/DialogDescription', () => {
206
+ render(
207
+ <Dialog
208
+ open
209
+ onOpenChange={vi.fn()}
210
+ header={
211
+ <DialogHeader>
212
+ <DialogTitle>Publish release</DialogTitle>
213
+ </DialogHeader>
214
+ }
215
+ >
216
+ <DialogDescription>Tag and publish the workspace.</DialogDescription>
217
+ <DialogBody>Body content</DialogBody>
218
+ </Dialog>
219
+ );
220
+ const dialog = screen.getByRole('dialog', { name: 'Publish release' });
221
+ expect(dialog).toBeInTheDocument();
222
+ expect(screen.getByText('Body content')).toBeInTheDocument();
223
+ });
224
+
225
+ it('renders the footer slot inside the panel', () => {
226
+ render(
227
+ <Dialog
228
+ open
229
+ onOpenChange={vi.fn()}
230
+ title="Confirm"
231
+ footer={<DialogFooter><button type="button">Save</button></DialogFooter>}
232
+ >
233
+ body
234
+ </Dialog>
235
+ );
236
+ expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
237
+ });
238
+
239
+ it('caps and scrolls the body when scrollable', () => {
240
+ render(
241
+ <Dialog open onOpenChange={vi.fn()} title="Long" scrollable>
242
+ <p>scrollable body</p>
243
+ </Dialog>
244
+ );
245
+ const body = screen.getByText('scrollable body').parentElement!;
246
+ expect(body.className).toContain('max-h-[60vh]');
247
+ expect(body.className).toContain('overflow-y-auto');
248
+ });
249
+ });
250
+
251
+ describe('localized labels', () => {
252
+ it('uses the closeLabel override', () => {
253
+ render(<Dialog open onOpenChange={() => undefined} title="Title" closeLabel="Fermer">Body</Dialog>);
254
+ expect(screen.getByRole('button', { name: 'Fermer' })).toBeInTheDocument();
255
+ });
256
+ });
@@ -5,17 +5,36 @@ import { createPortal } from 'react-dom';
5
5
  import { cn } from '../../utils/cn';
6
6
  import { usePresence } from '../../utils/presence';
7
7
 
8
+ export type DialogSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
9
+
8
10
  export type DialogProps = {
9
11
  open: boolean;
10
12
  onOpenChange: (open: boolean) => void;
11
- title: string;
13
+ /** Accessible name + default header title. Optional when composing a custom header. */
14
+ title?: string;
12
15
  description?: string;
13
16
  children?: React.ReactNode;
17
+ /** Panel max-width preset (default 'md'). */
18
+ size?: DialogSize;
19
+ /**
20
+ * Replaces the default header row. Compose with `<DialogHeader>` /
21
+ * `<DialogTitle>` / `<DialogDescription>` — those parts pick up the
22
+ * dialog's aria ids automatically.
23
+ */
24
+ header?: React.ReactNode;
25
+ /** Action row pinned under the body. */
26
+ footer?: React.ReactNode;
27
+ /** Cap the body height and scroll inside the panel. */
28
+ scrollable?: boolean;
29
+ bodyClassName?: string;
14
30
  closeOnBackdrop?: boolean;
15
31
  /** Hide the close (✕) button in the header; Escape and backdrop still close. */
16
32
  showClose?: boolean;
33
+ /** Accessible label for the close button (default "Close dialog"). */
34
+ closeLabel?: string;
17
35
  /** Focused when the dialog opens; defaults to the first focusable element. */
18
36
  initialFocusRef?: React.RefObject<HTMLElement | null>;
37
+ /** Accessible name when `title` is omitted (required with a custom header). */
19
38
  ariaLabel?: string;
20
39
  /**
21
40
  * Fade the backdrop and panel in on open and out on close (requires
@@ -28,10 +47,61 @@ export type DialogProps = {
28
47
  const FOCUSABLE =
29
48
  'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
30
49
 
50
+ const sizeClasses: Record<DialogSize, string> = {
51
+ sm: 'max-w-sm',
52
+ md: 'max-w-md',
53
+ lg: 'max-w-lg',
54
+ xl: 'max-w-xl',
55
+ '2xl': 'max-w-2xl',
56
+ };
57
+
58
+ const DialogIdsContext = React.createContext<{ titleId: string; descriptionId: string } | null>(null);
59
+
60
+ export type DialogHeaderProps = React.HTMLAttributes<HTMLDivElement>;
61
+
62
+ /** Header row for composed dialogs. */
63
+ function DialogHeader({ className, ...props }: DialogHeaderProps) {
64
+ return <div className={cn('flex items-start justify-between gap-4', className)} {...props} />;
65
+ }
66
+
67
+ export type DialogTitleProps = React.HTMLAttributes<HTMLHeadingElement>;
68
+
69
+ /** Dialog heading; automatically wired to aria-labelledby. */
70
+ function DialogTitle({ className, ...props }: DialogTitleProps) {
71
+ const ids = React.useContext(DialogIdsContext);
72
+ return <h2 id={ids?.titleId} className={cn('text-lg font-semibold', className)} {...props} />;
73
+ }
74
+
75
+ export type DialogDescriptionProps = React.HTMLAttributes<HTMLParagraphElement>;
76
+
77
+ /** Supporting line; automatically wired to aria-describedby. */
78
+ function DialogDescription({ className, ...props }: DialogDescriptionProps) {
79
+ const ids = React.useContext(DialogIdsContext);
80
+ return <p id={ids?.descriptionId} className={cn('mt-2 text-sm text-muted-foreground', className)} {...props} />;
81
+ }
82
+
83
+ export type DialogBodyProps = React.HTMLAttributes<HTMLDivElement>;
84
+
85
+ /** Body wrapper for composed dialogs. */
86
+ function DialogBody({ className, ...props }: DialogBodyProps) {
87
+ return <div className={cn('mt-4', className)} {...props} />;
88
+ }
89
+
90
+ export type DialogFooterProps = React.HTMLAttributes<HTMLDivElement>;
91
+
92
+ /** Action row pinned to the bottom of the panel. */
93
+ function DialogFooter({ className, ...props }: DialogFooterProps) {
94
+ return <div className={cn('mt-6 flex items-center justify-end gap-2', className)} {...props} />;
95
+ }
96
+
31
97
  /**
32
98
  * Accessible modal dialog: portal, aria-modal + labelled/describedby wiring,
33
99
  * Escape and backdrop dismissal, initial focus on open and focus restoration
34
100
  * on close, plus a Tab/Shift+Tab focus trap.
101
+ *
102
+ * Use `title`/`description` for the default header, or pass `header` with
103
+ * `<DialogHeader>`/`<DialogTitle>`/`<DialogDescription>` (and an
104
+ * `ariaLabel` fallback) for full control.
35
105
  */
36
106
  export function Dialog({
37
107
  open,
@@ -39,9 +109,16 @@ export function Dialog({
39
109
  title,
40
110
  description,
41
111
  children,
112
+ size = 'md',
113
+ header,
114
+ footer,
115
+ scrollable = false,
116
+ bodyClassName,
42
117
  closeOnBackdrop = true,
43
118
  showClose = true,
119
+ closeLabel = 'Close dialog',
44
120
  initialFocusRef,
121
+ ariaLabel,
45
122
  animate = false,
46
123
  }: DialogProps) {
47
124
  const dialogRef = React.useRef<HTMLDivElement | null>(null);
@@ -119,34 +196,50 @@ export function Dialog({
119
196
  ref={dialogRef}
120
197
  role="dialog"
121
198
  aria-modal="true"
122
- aria-labelledby={titleId}
199
+ aria-labelledby={ariaLabel ? undefined : titleId}
200
+ aria-label={ariaLabel}
123
201
  aria-describedby={description ? descriptionId : undefined}
124
202
  tabIndex={-1}
125
- className={cn('w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-xl', motion)}
203
+ className={cn(
204
+ 'flex w-full flex-col rounded-xl border border-border bg-card p-6 shadow-xl',
205
+ sizeClasses[size],
206
+ motion,
207
+ )}
126
208
  >
127
- <div className="flex items-start justify-between gap-4">
128
- <h2 id={titleId} className="text-lg font-semibold">
129
- {title}
130
- </h2>
131
- {showClose && (
132
- <button
133
- type="button"
134
- onClick={() => onOpenChange(false)}
135
- aria-label="Close dialog"
136
- className="rounded p-1 text-muted-foreground hover:text-foreground"
137
- >
138
- ✕
139
- </button>
209
+ <DialogIdsContext.Provider value={{ titleId, descriptionId }}>
210
+ {header ?? (
211
+ <DialogHeader>
212
+ <div className="min-w-0">
213
+ {title && <DialogTitle>{title}</DialogTitle>}
214
+ {description && <DialogDescription>{description}</DialogDescription>}
215
+ </div>
216
+ {showClose && (
217
+ <button
218
+ type="button"
219
+ onClick={() => onOpenChange(false)}
220
+ aria-label={closeLabel}
221
+ className="rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
222
+ >
223
+ ✕
224
+ </button>
225
+ )}
226
+ </DialogHeader>
140
227
  )}
141
- </div>
142
- {description && (
143
- <p id={descriptionId} className="mt-2 text-sm text-muted-foreground">
144
- {description}
145
- </p>
146
- )}
147
- {children && <div className="mt-4">{children}</div>}
228
+ <div
229
+ className={cn(
230
+ 'mt-4 min-h-0',
231
+ scrollable && 'max-h-[60vh] overflow-y-auto pr-1',
232
+ bodyClassName,
233
+ )}
234
+ >
235
+ {children}
236
+ </div>
237
+ {footer && <DialogFooter>{footer}</DialogFooter>}
238
+ </DialogIdsContext.Provider>
148
239
  </div>
149
240
  </div>,
150
241
  document.body,
151
242
  );
152
243
  }
244
+
245
+ export { DialogHeader, DialogTitle, DialogDescription, DialogBody, DialogFooter };
@@ -1,2 +1 @@
1
- export { Dialog } from './Dialog';
2
- export type { DialogProps } from './Dialog';
1
+ export * from './Dialog';
@@ -122,3 +122,62 @@ describe('Drawer animate (optional slide)', () => {
122
122
  });
123
123
  });
124
124
  });
125
+
126
+ describe('Drawer sizes and custom extents', () => {
127
+ it('supports xl and 2xl presets on each axis', () => {
128
+ const { rerender } = render(
129
+ <Drawer open onOpenChange={vi.fn()} title="Wide" side="right" size="xl">
130
+ body
131
+ </Drawer>
132
+ );
133
+ expect(screen.getByRole('dialog')).toHaveClass('w-[40rem]');
134
+ rerender(
135
+ <Drawer open onOpenChange={vi.fn()} title="Wide" side="right" size="2xl">
136
+ body
137
+ </Drawer>
138
+ );
139
+ expect(screen.getByRole('dialog')).toHaveClass('w-[48rem]');
140
+ rerender(
141
+ <Drawer open onOpenChange={vi.fn()} title="Tall" side="bottom" size="2xl">
142
+ body
143
+ </Drawer>
144
+ );
145
+ expect(screen.getByRole('dialog')).toHaveClass('h-[48rem]');
146
+ });
147
+
148
+ it('accepts a pixel width and overrides the preset', () => {
149
+ render(
150
+ <Drawer open onOpenChange={vi.fn()} title="Custom" side="right" width={560}>
151
+ body
152
+ </Drawer>
153
+ );
154
+ expect(screen.getByRole('dialog')).toHaveStyle({ width: '560px' });
155
+ });
156
+
157
+ it('accepts a CSS length height for top/bottom drawers', () => {
158
+ // Use an absolute length: jsdom 30 drops relative units (vh/vw) from the
159
+ // CSSStyleDeclaration, so a vh assertion tests jsdom rather than us.
160
+ render(
161
+ <Drawer open onOpenChange={vi.fn()} title="Custom" side="top" height="320px">
162
+ body
163
+ </Drawer>
164
+ );
165
+ expect(screen.getByRole('dialog')).toHaveStyle({ height: '320px' });
166
+ });
167
+
168
+ it('ignores width/height that do not match the side axis', () => {
169
+ render(
170
+ <Drawer open onOpenChange={vi.fn()} title="Mismatch" side="bottom" width={400}>
171
+ body
172
+ </Drawer>
173
+ );
174
+ expect(screen.getByRole('dialog')).not.toHaveAttribute('style');
175
+ });
176
+ });
177
+
178
+ describe('localized labels', () => {
179
+ it('uses the closeLabel override', () => {
180
+ render(<Drawer open onOpenChange={() => undefined} title="Title" closeLabel="Fermer">Body</Drawer>);
181
+ expect(screen.getByRole('button', { name: 'Fermer' })).toBeInTheDocument();
182
+ });
183
+ });
@@ -6,7 +6,7 @@ import { cn } from '../../utils/cn';
6
6
  import { usePresence } from '../../utils/presence';
7
7
 
8
8
  export type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
9
- export type DrawerSize = 'sm' | 'md' | 'lg';
9
+ export type DrawerSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
10
10
 
11
11
  export type DrawerProps = {
12
12
  open: boolean;
@@ -16,12 +16,24 @@ export type DrawerProps = {
16
16
  children?: React.ReactNode;
17
17
  /** Edge the drawer slides from (default 'right'). */
18
18
  side?: DrawerSide;
19
- /** Extent along the side axis (width for left/right, height for top/bottom). */
19
+ /** Preset extent along the side axis (width for left/right, height for top/bottom). */
20
20
  size?: DrawerSize;
21
+ /**
22
+ * Custom extent for left/right drawers: pixels (480) or any CSS length
23
+ * ("70vw"). Overrides `size`.
24
+ */
25
+ width?: number | string;
26
+ /**
27
+ * Custom extent for top/bottom drawers: pixels (320) or any CSS length
28
+ * ("60vh"). Overrides `size`.
29
+ */
30
+ height?: number | string;
21
31
  /** Clicking the backdrop closes (default true). */
22
32
  closeOnBackdrop?: boolean;
23
33
  /** Hide the close (✕) button in the header (default true). */
24
34
  showClose?: boolean;
35
+ /** Accessible label for the close button (default "Close drawer"). */
36
+ closeLabel?: string;
25
37
  /** Focused when the drawer opens; defaults to the first focusable element. */
26
38
  initialFocusRef?: React.RefObject<HTMLElement | null>;
27
39
  /** Overrides the accessible name (defaults to the title). */
@@ -44,13 +56,35 @@ const sideClasses: Record<DrawerSide, string> = {
44
56
  bottom: 'inset-x-0 bottom-0 border-t',
45
57
  };
46
58
 
59
+ const sideWidths: Record<DrawerSize, string> = {
60
+ sm: 'w-72',
61
+ md: 'w-96',
62
+ lg: 'w-[32rem]',
63
+ xl: 'w-[40rem]',
64
+ '2xl': 'w-[48rem]',
65
+ };
66
+
67
+ const sideHeights: Record<DrawerSize, string> = {
68
+ sm: 'h-48',
69
+ md: 'h-80',
70
+ lg: 'h-[32rem]',
71
+ xl: 'h-[40rem]',
72
+ '2xl': 'h-[48rem]',
73
+ };
74
+
47
75
  const sizeClasses: Record<DrawerSide, Record<DrawerSize, string>> = {
48
- right: { sm: 'w-72', md: 'w-96', lg: 'w-[32rem]' },
49
- left: { sm: 'w-72', md: 'w-96', lg: 'w-[32rem]' },
50
- top: { sm: 'h-48', md: 'h-80', lg: 'h-[32rem]' },
51
- bottom: { sm: 'h-48', md: 'h-80', lg: 'h-[32rem]' },
76
+ right: sideWidths,
77
+ left: sideWidths,
78
+ top: sideHeights,
79
+ bottom: sideHeights,
52
80
  };
53
81
 
82
+ /** Custom extent wins over the preset; numbers are pixels. */
83
+ function extentStyle(value: number | string | undefined): string | undefined {
84
+ if (value === undefined) return undefined;
85
+ return typeof value === 'number' ? `${value}px` : value;
86
+ }
87
+
54
88
  // Literal class maps so Tailwind's scanner keeps every slide utility.
55
89
  const slideIn: Record<DrawerSide, string> = {
56
90
  right: 'slide-in-from-right',
@@ -80,8 +114,11 @@ export function Drawer({
80
114
  children,
81
115
  side = 'right',
82
116
  size = 'md',
117
+ width,
118
+ height,
83
119
  closeOnBackdrop = true,
84
120
  showClose = true,
121
+ closeLabel = 'Close drawer',
85
122
  initialFocusRef,
86
123
  ariaLabel,
87
124
  animate = false,
@@ -146,6 +183,9 @@ export function Drawer({
146
183
 
147
184
  if (!present || typeof document === 'undefined') return null;
148
185
 
186
+ const isVerticalSide = side === 'top' || side === 'bottom';
187
+ const customExtent = isVerticalSide ? extentStyle(height) : extentStyle(width);
188
+
149
189
  const motion = animate
150
190
  ? cn(
151
191
  'duration-200 motion-reduce:animate-none',
@@ -174,6 +214,7 @@ export function Drawer({
174
214
  sizeClasses[side][size],
175
215
  motion
176
216
  )}
217
+ style={customExtent ? { [isVerticalSide ? 'height' : 'width']: customExtent } : undefined}
177
218
  >
178
219
  <div className="flex items-start justify-between gap-4 border-b border-border px-5 py-4">
179
220
  <div>
@@ -190,8 +231,8 @@ export function Drawer({
190
231
  <button
191
232
  type="button"
192
233
  onClick={() => onOpenChange(false)}
193
- aria-label="Close drawer"
194
- className="-mr-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
234
+ aria-label={closeLabel}
235
+ className="-me-1 rounded p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
195
236
  >
196
237
  ✕
197
238
  </button>
@@ -0,0 +1,30 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { axe } from 'jest-axe';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { EmptyState } from './EmptyState';
5
+
6
+ describe('EmptyState', () => {
7
+ it('renders title, description and actions', () => {
8
+ render(
9
+ <EmptyState
10
+ title="No classes yet"
11
+ description="Create your first class to get started."
12
+ action={<button type="button">New class</button>}
13
+ secondaryAction={<a href="/docs">Learn more</a>}
14
+ />
15
+ );
16
+ expect(screen.getByText('No classes yet')).toBeInTheDocument();
17
+ expect(screen.getByRole('button', { name: 'New class' })).toBeInTheDocument();
18
+ expect(screen.getByRole('link', { name: 'Learn more' })).toBeInTheDocument();
19
+ });
20
+
21
+ it('supports a compact size', () => {
22
+ const { container } = render(<EmptyState size="sm" title="Nothing here" />);
23
+ expect(container.firstChild).toHaveClass('py-6');
24
+ });
25
+
26
+ it('has no accessibility violations', async () => {
27
+ const { container } = render(<EmptyState title="Empty" description="Nothing to show" />);
28
+ expect(await axe(container)).toHaveNoViolations();
29
+ });
30
+ });
@@ -0,0 +1,48 @@
1
+ import * as React from 'react';
2
+ import { cn } from '../../utils/cn';
3
+
4
+ export type EmptyStateProps = React.HTMLAttributes<HTMLDivElement> & {
5
+ /** Icon or illustration shown above the title. */
6
+ icon?: React.ReactNode;
7
+ title: string;
8
+ description?: string;
9
+ /** Primary action (button/link). */
10
+ action?: React.ReactNode;
11
+ /** Secondary action shown beside the primary one. */
12
+ secondaryAction?: React.ReactNode;
13
+ /** Compact padding for use inside panels and table bodies. */
14
+ size?: 'sm' | 'md';
15
+ };
16
+
17
+ /**
18
+ * Placeholder for empty collections, zero-result searches and unconfigured
19
+ * features. Keeps the title/description/action hierarchy consistent across
20
+ * the product.
21
+ */
22
+ export const EmptyState = React.forwardRef<HTMLDivElement, EmptyStateProps>(function EmptyState(
23
+ { icon, title, description, action, secondaryAction, size = 'md', className, children, ...props },
24
+ ref
25
+ ) {
26
+ return (
27
+ <div
28
+ ref={ref}
29
+ className={cn(
30
+ 'flex flex-col items-center justify-center rounded-lg border border-dashed border-border text-center',
31
+ size === 'md' ? 'gap-3 px-6 py-12' : 'gap-2 px-4 py-6',
32
+ className
33
+ )}
34
+ {...props}
35
+ >
36
+ {icon && <div className="text-muted-foreground [&_svg]:size-8">{icon}</div>}
37
+ <p className={cn('font-semibold', size === 'md' ? 'text-base' : 'text-sm')}>{title}</p>
38
+ {description && <p className="max-w-sm text-sm text-muted-foreground">{description}</p>}
39
+ {children}
40
+ {(action || secondaryAction) && (
41
+ <div className="mt-1 flex flex-wrap items-center justify-center gap-2">
42
+ {action}
43
+ {secondaryAction}
44
+ </div>
45
+ )}
46
+ </div>
47
+ );
48
+ });
@@ -0,0 +1 @@
1
+ export * from './EmptyState';
@@ -0,0 +1,43 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { axe } from 'jest-axe';
4
+ import { describe, expect, it, vi } from 'vitest';
5
+ import { FileUpload } from './FileUpload';
6
+
7
+ function file(name: string, size = 4) {
8
+ return new File([new Uint8Array(size)], name, { type: 'text/plain' });
9
+ }
10
+
11
+ describe('FileUpload', () => {
12
+ it('lists selected files and reports changes', async () => {
13
+ const user = userEvent.setup();
14
+ const onFilesChange = vi.fn();
15
+ render(<FileUpload aria-label="Attachments" onFilesChange={onFilesChange} />);
16
+ await user.upload(screen.getByLabelText(/Drop files here/), [file('a.txt'), file('b.txt')]);
17
+ expect(onFilesChange).toHaveBeenCalledTimes(1);
18
+ expect(screen.getByText('a.txt')).toBeInTheDocument();
19
+ expect(screen.getByText('b.txt')).toBeInTheDocument();
20
+ });
21
+
22
+ it('removes a file and shows progress', async () => {
23
+ const user = userEvent.setup();
24
+ const onFilesChange = vi.fn();
25
+ render(
26
+ <FileUpload
27
+ aria-label="Uploads"
28
+ defaultFiles={[file('report.pdf')]}
29
+ progress={{ 'report.pdf': 42 }}
30
+ onFilesChange={onFilesChange}
31
+ />
32
+ );
33
+ expect(screen.getByRole('progressbar', { name: 'Uploading report.pdf' })).toHaveAttribute('aria-valuenow', '42');
34
+ await user.click(screen.getByRole('button', { name: 'Remove report.pdf' }));
35
+ expect(onFilesChange).toHaveBeenCalledWith([]);
36
+ expect(screen.queryByText('report.pdf')).not.toBeInTheDocument();
37
+ });
38
+
39
+ it('has no accessibility violations', async () => {
40
+ const { container } = render(<FileUpload aria-label="Files" />);
41
+ expect(await axe(container)).toHaveNoViolations();
42
+ });
43
+ });