@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
@@ -9,13 +9,25 @@ const buttonVariants = cva(
9
9
  variants: {
10
10
  variant: {
11
11
  default: 'bg-primary text-primary-foreground hover:bg-primary/90',
12
+ primary: 'bg-primary text-primary-foreground hover:bg-primary/90',
12
13
  destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
14
+ danger: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
13
15
  // Semantic status variants — foregrounds are the paired AA tokens
14
16
  // (white on dark green, ink on amber/cyan) in both themes.
15
17
  success: 'bg-success text-success-foreground hover:bg-success/90',
16
18
  warning: 'bg-warning text-warning-foreground hover:bg-warning/90',
17
19
  info: 'bg-info text-info-foreground hover:bg-info/90',
18
20
  outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
21
+ // Colored outlines: semantic border + AA ink label on the page
22
+ // surface, with a faint tint on hover - mirrors the Alert recipe.
23
+ 'outline-destructive':
24
+ 'border border-destructive/50 bg-background text-destructive hover:border-destructive hover:bg-destructive/10',
25
+ 'outline-success':
26
+ 'border border-success/50 bg-background text-success hover:border-success hover:bg-success/10',
27
+ 'outline-warning':
28
+ 'border border-warning/50 bg-background text-warning-ink hover:border-warning hover:bg-warning/10',
29
+ 'outline-info':
30
+ 'border border-info/50 bg-background text-info-ink hover:border-info hover:bg-info/10',
19
31
  secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
20
32
  ghost: 'hover:bg-accent hover:text-accent-foreground',
21
33
  link: 'text-primary underline-offset-4 hover:underline',
@@ -36,17 +48,39 @@ const buttonVariants = cva(
36
48
 
37
49
  export type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & VariantProps<typeof buttonVariants> & {
38
50
  asChild?: boolean;
51
+ /** Shows a spinner, disables the button and sets aria-busy while an action runs. */
52
+ loading?: boolean;
53
+ /** Screen-reader text while loading (default "Loading"). */
54
+ loadingLabel?: string;
39
55
  };
40
56
 
41
57
  const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
42
- ({ className, variant, size, asChild = false, ...props }, ref) => {
58
+ ({ className, variant, size, asChild = false, loading = false, loadingLabel = 'Loading', disabled, children, ...props }, ref) => {
43
59
  const Comp = asChild ? Slot : 'button';
60
+ if (asChild) {
61
+ return (
62
+ <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props}>
63
+ {children}
64
+ </Comp>
65
+ );
66
+ }
44
67
  return (
45
- <Comp
68
+ <button
46
69
  className={cn(buttonVariants({ variant, size, className }))}
47
70
  ref={ref}
71
+ disabled={disabled || loading}
72
+ aria-busy={loading || undefined}
48
73
  {...props}
49
- />
74
+ >
75
+ {loading && (
76
+ <span
77
+ aria-hidden="true"
78
+ className="h-4 w-4 shrink-0 animate-spin rounded-full border-2 border-current border-t-transparent"
79
+ />
80
+ )}
81
+ {loading && <span className="sr-only">{loadingLabel}</span>}
82
+ {children}
83
+ </button>
50
84
  );
51
85
  }
52
86
  );
@@ -15,13 +15,12 @@ describe('ButtonGroup', () => {
15
15
  </ButtonGroup>
16
16
  );
17
17
  const group = container.querySelector('[data-slot="button-group"]')!;
18
- expect(group).toHaveClass('-space-x-px');
18
+ // The group owns the single outline and clips the outer radius.
19
+ expect(group).toHaveClass('overflow-hidden', 'rounded-md', 'border', 'border-border');
19
20
  expect(group.querySelectorAll('button')).toHaveLength(3);
20
- // First/last keep outer corners; middles square off — the join rules
21
- // live as descendant tokens on the group's class.
22
- expect(group.className).toContain('[&>*:first-child]:rounded-l-md');
23
- expect(group.className).toContain('[&>*:last-child]:rounded-r-md');
24
21
  expect(group.className).toContain('[&>*]:rounded-none');
22
+ expect(group.className).toContain('[&>*]:border-0');
23
+ expect(group).toHaveClass('divide-x', 'divide-border');
25
24
  });
26
25
 
27
26
  it('vertical orientation stacks with collapsed borders', () => {
@@ -32,9 +31,8 @@ describe('ButtonGroup', () => {
32
31
  </ButtonGroup>
33
32
  );
34
33
  const group = container.querySelector('[data-slot="button-group"]')!;
35
- expect(group).toHaveClass('-space-y-px');
36
- expect(group.className).toContain('[&>*:first-child]:rounded-t-md');
37
- expect(group.className).toContain('[&>*:last-child]:rounded-b-md');
34
+ expect(group).toHaveClass('flex-col');
35
+ expect(group).toHaveClass('divide-y', 'divide-border');
38
36
  });
39
37
 
40
38
  it('exposes a group role and forwards aria-label', () => {
@@ -7,11 +7,16 @@ export type ButtonGroupProps = React.HTMLAttributes<HTMLDivElement> & {
7
7
  };
8
8
 
9
9
  /**
10
- * Joins buttons into one segmented control: adjacent borders collapse
11
- * (negative spacing), middle corners square off, and only the outer
12
- * corners stay rounded — a single outline around the whole group.
13
- * Use border-bearing variants (default/outline/secondary); ghost
14
- * buttons have no border and would break the joined outline.
10
+ * Joins buttons into one segmented control.
11
+ *
12
+ * The group owns the outline: a single border, one outer radius (children
13
+ * are clipped by overflow-hidden), and 1px separators drawn between
14
+ * segments. Children lose their own borders and radii, so mixed variants
15
+ * (default/outline/secondary/ghost) still read as one instrument — a
16
+ * borderless variant no longer leaves the seam misaligned the way
17
+ * negative-margin border collapsing did.
18
+ *
19
+ * Focus rings render inset so they are never clipped at the edges.
15
20
  */
16
21
  const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
17
22
  ({ orientation = 'horizontal', className, ...props }, ref) => (
@@ -20,11 +25,14 @@ const ButtonGroup = React.forwardRef<HTMLDivElement, ButtonGroupProps>(
20
25
  data-slot="button-group"
21
26
  role="group"
22
27
  className={cn(
23
- 'inline-flex',
28
+ 'inline-flex overflow-hidden rounded-md border border-border bg-background',
29
+ '[&>*]:rounded-none [&>*]:border-0',
30
+ '[&>*:focus-visible]:ring-inset [&>*:focus-visible]:ring-offset-0',
31
+ // divide-* compiles to `.group > * ~ * { border-left/top }` — higher
32
+ // specificity than the lead-strip above, so seams stay exact.
24
33
  orientation === 'horizontal'
25
- ? '-space-x-px [&>*:first-child]:rounded-l-md [&>*:last-child]:rounded-r-md'
26
- : '-space-y-px [&>*:first-child]:rounded-t-md [&>*:last-child]:rounded-b-md',
27
- '[&>*]:rounded-none [&>*]:focus-visible:relative [&>*]:focus-visible:z-10',
34
+ ? 'divide-x divide-border'
35
+ : 'flex-col divide-y divide-border',
28
36
  className
29
37
  )}
30
38
  {...props}
@@ -44,3 +44,17 @@ describe('Card', () => {
44
44
  expect(await axe(container)).toHaveNoViolations();
45
45
  });
46
46
  });
47
+
48
+
49
+ describe('Card asChild', () => {
50
+ it('renders the child element with card styling', () => {
51
+ render(
52
+ <Card asChild>
53
+ <a href="/post">Read post</a>
54
+ </Card>
55
+ );
56
+ const link = screen.getByRole('link', { name: 'Read post' });
57
+ expect(link.tagName).toBe('A');
58
+ expect(link).toHaveClass('rounded-xl', 'border-border', 'bg-card');
59
+ });
60
+ });
@@ -1,17 +1,24 @@
1
1
  import * as React from 'react';
2
+ import { Slot } from '@radix-ui/react-slot';
2
3
  import { cn } from '../../utils/cn';
3
4
 
4
- export type CardProps = React.HTMLAttributes<HTMLDivElement>;
5
+ export type CardProps = React.HTMLAttributes<HTMLDivElement> & {
6
+ /** Render the child element (e.g. a router Link) with card styling. */
7
+ asChild?: boolean;
8
+ };
5
9
 
6
10
  /** Content container with a subtle border and surface styling. */
7
11
  const Card = React.forwardRef<HTMLDivElement, CardProps>(
8
- ({ className, ...props }, ref) => (
9
- <div
10
- ref={ref}
11
- className={cn('rounded-xl border border-border bg-card text-card-foreground shadow-sm', className)}
12
- {...props}
13
- />
14
- )
12
+ ({ className, asChild = false, ...props }, ref) => {
13
+ const Comp = asChild ? Slot : 'div';
14
+ return (
15
+ <Comp
16
+ ref={ref}
17
+ className={cn('rounded-xl border border-border bg-card text-card-foreground shadow-sm', className)}
18
+ {...props}
19
+ />
20
+ );
21
+ }
15
22
  );
16
23
  Card.displayName = 'Card';
17
24
 
@@ -0,0 +1,46 @@
1
+ import { render, screen, waitFor } 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 { ConfirmDialog } from './ConfirmDialog';
6
+
7
+ describe('ConfirmDialog', () => {
8
+ it('renders title, description and actions', () => {
9
+ render(
10
+ <ConfirmDialog open onOpenChange={vi.fn()} title="Delete project" description="This cannot be undone." onConfirm={vi.fn()} />
11
+ );
12
+ expect(screen.getByRole('dialog', { name: 'Delete project' })).toBeInTheDocument();
13
+ expect(screen.getByRole('button', { name: 'Confirm' })).toBeInTheDocument();
14
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
15
+ });
16
+
17
+ it('runs onConfirm, shows pending and closes', async () => {
18
+ const user = userEvent.setup();
19
+ let resolve!: () => void;
20
+ const onConfirm = vi.fn(
21
+ () =>
22
+ new Promise<void>((done) => {
23
+ resolve = done;
24
+ })
25
+ );
26
+ const onOpenChange = vi.fn();
27
+ render(<ConfirmDialog open onOpenChange={onOpenChange} title="Publish" onConfirm={onConfirm} confirmLabel="Publish now" />);
28
+ await user.click(screen.getByRole('button', { name: 'Publish now' }));
29
+ expect(onConfirm).toHaveBeenCalledOnce();
30
+ expect(screen.getByRole('button', { name: /Publish now/ })).toHaveAttribute('aria-busy', 'true');
31
+ resolve();
32
+ await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false));
33
+ });
34
+
35
+ it('marks destructive confirms', () => {
36
+ render(<ConfirmDialog open onOpenChange={vi.fn()} title="Delete" destructive onConfirm={vi.fn()} confirmLabel="Delete" />);
37
+ expect(screen.getByRole('button', { name: 'Delete' })).toHaveClass('bg-destructive');
38
+ });
39
+
40
+ it('has no accessibility violations', async () => {
41
+ const { baseElement } = render(
42
+ <ConfirmDialog open onOpenChange={vi.fn()} title="Confirm" description="Sure?" onConfirm={vi.fn()} />
43
+ );
44
+ expect(await axe(baseElement)).toHaveNoViolations();
45
+ });
46
+ });
@@ -0,0 +1,86 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { Button } from '../button/Button';
5
+ import { Dialog, DialogFooter } from '../dialog/Dialog';
6
+
7
+ export type ConfirmDialogProps = {
8
+ open: boolean;
9
+ onOpenChange: (open: boolean) => void;
10
+ title: string;
11
+ description?: string;
12
+ /** Confirm button label. Default 'Confirm'. */
13
+ confirmLabel?: string;
14
+ /** Cancel button label. Default 'Cancel'. */
15
+ cancelLabel?: string;
16
+ /** Destructive confirmation (red confirm button + destructive panel accent). */
17
+ destructive?: boolean;
18
+ /**
19
+ * Confirm handler. Return a promise to show a pending state; the dialog
20
+ * closes automatically when it resolves unless `closeOnConfirm` is false.
21
+ */
22
+ onConfirm: () => void | Promise<void>;
23
+ closeOnConfirm?: boolean;
24
+ /** Extra body content above the actions. */
25
+ children?: React.ReactNode;
26
+ };
27
+
28
+ /**
29
+ * Accessible confirmation dialog built on Dialog: focus trap, Escape,
30
+ * backdrop dismissal and focus restoration come from the primitive, plus a
31
+ * pending state for async confirmations (79 hand-rolled confirm modals in
32
+ * the audited apps use this exact shape).
33
+ */
34
+ export function ConfirmDialog({
35
+ open,
36
+ onOpenChange,
37
+ title,
38
+ description,
39
+ confirmLabel = 'Confirm',
40
+ cancelLabel = 'Cancel',
41
+ destructive = false,
42
+ onConfirm,
43
+ closeOnConfirm = true,
44
+ children,
45
+ }: ConfirmDialogProps) {
46
+ const [pending, setPending] = React.useState(false);
47
+
48
+ const handleConfirm = async () => {
49
+ try {
50
+ setPending(true);
51
+ await onConfirm();
52
+ if (closeOnConfirm) onOpenChange(false);
53
+ } finally {
54
+ setPending(false);
55
+ }
56
+ };
57
+
58
+ return (
59
+ <Dialog
60
+ open={open}
61
+ onOpenChange={(next) => {
62
+ if (pending) return;
63
+ onOpenChange(next);
64
+ }}
65
+ title={title}
66
+ description={description}
67
+ size="sm"
68
+ footer={
69
+ <DialogFooter>
70
+ <Button variant="ghost" onClick={() => onOpenChange(false)} disabled={pending}>
71
+ {cancelLabel}
72
+ </Button>
73
+ <Button
74
+ variant={destructive ? 'destructive' : 'default'}
75
+ onClick={handleConfirm}
76
+ loading={pending}
77
+ >
78
+ {confirmLabel}
79
+ </Button>
80
+ </DialogFooter>
81
+ }
82
+ >
83
+ {children}
84
+ </Dialog>
85
+ );
86
+ }
@@ -0,0 +1 @@
1
+ export * from './ConfirmDialog';
@@ -1,4 +1,5 @@
1
1
  import { fireEvent, render, screen, within } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
2
3
  import { axe } from 'jest-axe';
3
4
  import { describe, expect, it, vi } from 'vitest';
4
5
  import { DataTable, type DataTableColumn } from './DataTable';
@@ -142,3 +143,94 @@ describe('DataTable loading and zebra', () => {
142
143
  expect(screen.getByText('updown')).toBeInTheDocument();
143
144
  });
144
145
  });
146
+
147
+
148
+ describe('DataTable selection', () => {
149
+ const rows: Row[] = [
150
+ { id: '1', name: 'Alpha', messages: 1 },
151
+ { id: '2', name: 'Beta', messages: 2 },
152
+ { id: '3', name: 'Gamma', messages: 3 },
153
+ ];
154
+ const cols: DataTableColumn<Row>[] = [
155
+ { key: 'name', header: 'Name' },
156
+ { key: 'messages', header: 'Messages' },
157
+ ];
158
+
159
+ it('renders selection checkboxes and select-all', async () => {
160
+ const user = userEvent.setup();
161
+ const onSelectedRowIdsChange = vi.fn();
162
+ render(
163
+ <DataTable
164
+ columns={cols}
165
+ data={rows}
166
+ rowId={(row) => row.id}
167
+ selectedRowIds={[]}
168
+ onSelectedRowIdsChange={onSelectedRowIdsChange}
169
+ caption="Runs"
170
+ />
171
+ );
172
+ expect(screen.getByRole('checkbox', { name: 'Select all rows' })).toBeInTheDocument();
173
+ await user.click(screen.getByRole('checkbox', { name: 'Select row 2' }));
174
+ expect(onSelectedRowIdsChange).toHaveBeenCalledWith(['2']);
175
+ });
176
+
177
+ it('selects all visible rows and shows bulk actions', async () => {
178
+ const user = userEvent.setup();
179
+ const onSelectedRowIdsChange = vi.fn();
180
+ render(
181
+ <DataTable
182
+ columns={cols}
183
+ data={rows}
184
+ rowId={(row) => row.id}
185
+ selectedRowIds={['2']}
186
+ onSelectedRowIdsChange={onSelectedRowIdsChange}
187
+ bulkActions={<button type="button">Archive</button>}
188
+ caption="Runs"
189
+ />
190
+ );
191
+ expect(screen.getByText('1 selected')).toBeInTheDocument();
192
+ expect(screen.getByRole('button', { name: 'Archive' })).toBeInTheDocument();
193
+ await user.click(screen.getByRole('checkbox', { name: 'Select all rows' }));
194
+ expect(onSelectedRowIdsChange).toHaveBeenCalledWith(['2', '1', '3']);
195
+ });
196
+
197
+ it('respects isRowSelectable', () => {
198
+ render(
199
+ <DataTable
200
+ columns={cols}
201
+ data={rows}
202
+ rowId={(row) => row.id}
203
+ selectedRowIds={[]}
204
+ onSelectedRowIdsChange={() => undefined}
205
+ isRowSelectable={(row) => row.id !== '2'}
206
+ caption="Runs"
207
+ />
208
+ );
209
+ expect(screen.getByRole('checkbox', { name: 'Select row 2' })).toBeDisabled();
210
+ });
211
+ });
212
+
213
+ describe('DataTable manual pagination', () => {
214
+ const rows: Row[] = [
215
+ { id: '1', name: 'Alpha', messages: 1 },
216
+ { id: '2', name: 'Beta', messages: 2 },
217
+ ];
218
+ const cols: DataTableColumn<Row>[] = [{ key: 'name', header: 'Name' }];
219
+
220
+ it('renders the current page as-is and uses total for the summary', () => {
221
+ render(
222
+ <DataTable
223
+ columns={cols}
224
+ data={rows}
225
+ rowId={(row) => row.id}
226
+ pageSize={25}
227
+ page={2}
228
+ total={312}
229
+ manualPagination
230
+ caption="Runs"
231
+ />
232
+ );
233
+ expect(document.body.textContent).toContain('26–50 of 312');
234
+ expect(screen.getAllByRole('row')).toHaveLength(3); // header + 2
235
+ });
236
+ });
@@ -4,6 +4,7 @@ import * as React from 'react';
4
4
  import { cn } from '../../utils/cn';
5
5
  import { Pagination } from '../pagination/Pagination';
6
6
  import { Skeleton } from '../skeleton/Skeleton';
7
+ import { Checkbox } from '../checkbox/Checkbox';
7
8
 
8
9
  export type DataTableColumn<T> = {
9
10
  /** Unique column key; also the value passed to onSortChange when sortable. */
@@ -51,12 +52,28 @@ export type DataTableProps<T> = {
51
52
  pageSize?: number;
52
53
  /** Controlled page (1-based) when pageSize is set. */
53
54
  page?: number;
55
+ /** Total page count (manual/server pagination). */
56
+ pageCount?: number;
57
+ /** Total row count across all pages (summary + derived page count). */
58
+ total?: number;
59
+ /** Server pagination: render `data` as-is; don't slice or sort client-side. */
60
+ manualPagination?: boolean;
61
+ /** Selected row ids (controlled). Enables the leading selection column. */
62
+ selectedRowIds?: string[];
63
+ /** Fires with the full selection after a row or select-all toggle. */
64
+ onSelectedRowIdsChange?: (ids: string[]) => void;
65
+ /** Disable selection for individual rows. */
66
+ isRowSelectable?: (row: T) => boolean;
67
+ /** Rendered above the table while at least one row is selected. */
68
+ bulkActions?: React.ReactNode;
54
69
  /** Fires on page change (controlled or not). */
55
70
  onPageChange?: (page: number) => void;
56
71
  /** Click/keyboard activation on a row. */
57
72
  onRowClick?: (row: T) => void;
58
73
  /** Message shown when data is empty. */
59
74
  emptyMessage?: string;
75
+ /** Accessible label for the select-all checkbox (default "Select all rows"). */
76
+ selectAllLabel?: string;
60
77
  /** Pin the header while the body scrolls (needs a max-height on the wrapper via className). */
61
78
  stickyHeader?: boolean;
62
79
  /** Compact row density. */
@@ -103,8 +120,16 @@ export function DataTable<T>({
103
120
  pageSize,
104
121
  page,
105
122
  onPageChange,
123
+ pageCount: pageCountProp,
124
+ total,
125
+ manualPagination = false,
126
+ selectedRowIds,
127
+ onSelectedRowIdsChange,
128
+ isRowSelectable,
129
+ bulkActions,
106
130
  onRowClick,
107
131
  emptyMessage = 'No results.',
132
+ selectAllLabel = 'Select all rows',
108
133
  stickyHeader,
109
134
  density = 'default',
110
135
  zebra,
@@ -154,11 +179,41 @@ export function DataTable<T>({
154
179
  return copy;
155
180
  }, [data, sort, columns]);
156
181
 
157
- const pageCount = pageSize ? Math.max(1, Math.ceil(sorted.length / pageSize)) : 0;
182
+ const effectiveTotal = total ?? sorted.length;
183
+ const computedPageCount = pageSize ? Math.max(1, Math.ceil(effectiveTotal / pageSize)) : 0;
184
+ const pageCount = pageCountProp ?? computedPageCount;
158
185
  const safePage = Math.min(currentPage, pageCount || 1);
159
- const visible = pageSize
160
- ? sorted.slice((safePage - 1) * pageSize, safePage * pageSize)
161
- : sorted;
186
+ const visible = manualPagination
187
+ ? data
188
+ : pageSize
189
+ ? sorted.slice((safePage - 1) * pageSize, safePage * pageSize)
190
+ : sorted;
191
+
192
+ // ----- Row selection (controlled or uncontrolled) -----
193
+ const [internalSelected, setInternalSelected] = React.useState<string[]>([]);
194
+ const selectionEnabled = selectedRowIds !== undefined || onSelectedRowIdsChange !== undefined;
195
+ const selectedIds = selectedRowIds ?? internalSelected;
196
+ const selectedSet = React.useMemo(() => new Set(selectedIds), [selectedIds]);
197
+ const selectableVisible = isRowSelectable ? visible.filter(isRowSelectable) : visible;
198
+ const allSelected = selectableVisible.length > 0 && selectableVisible.every((row) => selectedSet.has(rowId(row)));
199
+ const someSelected = selectableVisible.some((row) => selectedSet.has(rowId(row)));
200
+
201
+ const commitSelection = (next: string[]) => {
202
+ if (selectedRowIds === undefined) setInternalSelected(next);
203
+ onSelectedRowIdsChange?.(next);
204
+ };
205
+ const toggleAll = () => {
206
+ if (allSelected) {
207
+ const visibleIds = new Set(selectableVisible.map((row) => rowId(row)));
208
+ commitSelection(selectedIds.filter((id) => !visibleIds.has(id)));
209
+ return;
210
+ }
211
+ const merged = new Set([...selectedIds, ...selectableVisible.map((row) => rowId(row))]);
212
+ commitSelection([...merged]);
213
+ };
214
+ const toggleRow = (id: string) => {
215
+ commitSelection(selectedSet.has(id) ? selectedIds.filter((entry) => entry !== id) : [...selectedIds, id]);
216
+ };
162
217
 
163
218
  const cellValue = (row: T, column: DataTableColumn<T>, index: number): React.ReactNode => {
164
219
  if (column.cell) return column.cell(row, index);
@@ -173,6 +228,12 @@ export function DataTable<T>({
173
228
 
174
229
  return (
175
230
  <div className={cn('w-full space-y-3', className)}>
231
+ {selectionEnabled && selectedIds.length > 0 && bulkActions && (
232
+ <div className="flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-muted/40 px-3 py-2 text-sm">
233
+ <span className="font-medium">{selectedIds.length} selected</span>
234
+ <div className="flex flex-wrap items-center gap-2">{bulkActions}</div>
235
+ </div>
236
+ )}
176
237
  <div className="w-full overflow-x-auto rounded-lg border border-border">
177
238
  <table
178
239
  className={cn('w-full caption-bottom', density === 'compact' ? 'text-xs' : 'text-sm')}
@@ -180,6 +241,18 @@ export function DataTable<T>({
180
241
  {caption && <caption className="px-3 py-2 text-left text-xs text-muted-foreground">{caption}</caption>}
181
242
  <thead className={cn('bg-muted/50', stickyHeader && 'sticky top-0 z-10 bg-background')}>
182
243
  <tr>
244
+ {selectionEnabled && (
245
+ <th scope="col" className="w-10 border-b border-border px-3 py-2">
246
+ <Checkbox
247
+ aria-label={selectAllLabel}
248
+ checked={allSelected}
249
+ ref={(node) => {
250
+ if (node) node.indeterminate = someSelected && !allSelected;
251
+ }}
252
+ onCheckedChange={toggleAll}
253
+ />
254
+ </th>
255
+ )}
183
256
  {columns.map((column) => {
184
257
  const isSorted = sort?.key === column.key;
185
258
  const ariaSort = !column.sortable
@@ -231,6 +304,11 @@ export function DataTable<T>({
231
304
  { length: (loadingRows ?? pageSize ?? Math.min(visible.length, 5)) || 5 },
232
305
  (_, skeletonRow) => (
233
306
  <tr key={`skeleton-${skeletonRow}`}>
307
+ {selectionEnabled && (
308
+ <td className={cn('px-3 py-2', density === 'compact' && 'px-2 py-1')}>
309
+ <Skeleton className="h-4 w-4" />
310
+ </td>
311
+ )}
234
312
  {columns.map((column) => (
235
313
  <td key={column.key} className={cn('px-3 py-2', density === 'compact' && 'px-2 py-1')}>
236
314
  {/* Height tracks density so skeleton rows match real row
@@ -244,7 +322,7 @@ export function DataTable<T>({
244
322
  ) : visible.length === 0 ? (
245
323
  <tr>
246
324
  <td
247
- colSpan={columns.length}
325
+ colSpan={columns.length + (selectionEnabled ? 1 : 0)}
248
326
  className="px-3 py-8 text-center text-sm text-muted-foreground"
249
327
  >
250
328
  {emptyMessage}
@@ -273,6 +351,19 @@ export function DataTable<T>({
273
351
  'cursor-pointer transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring'
274
352
  )}
275
353
  >
354
+ {selectionEnabled && (
355
+ <td
356
+ className={cn('align-middle', density === 'compact' ? 'px-2 py-1' : 'px-3 py-2')}
357
+ onClick={(event) => event.stopPropagation()}
358
+ >
359
+ <Checkbox
360
+ aria-label={`Select row ${rowId(row)}`}
361
+ checked={selectedSet.has(rowId(row))}
362
+ disabled={isRowSelectable ? !isRowSelectable(row) : undefined}
363
+ onCheckedChange={() => toggleRow(rowId(row))}
364
+ />
365
+ </td>
366
+ )}
276
367
  {columns.map((column) => (
277
368
  <td
278
369
  key={column.key}
@@ -308,8 +399,8 @@ export function DataTable<T>({
308
399
  className="min-h-8 leading-none text-xs text-muted-foreground"
309
400
  aria-live="polite"
310
401
  >
311
- {(safePage - 1) * pageSize + 1}–{Math.min(safePage * pageSize, sorted.length)} of{' '}
312
- {sorted.length}
402
+ {(safePage - 1) * pageSize + 1}–{Math.min(safePage * pageSize, effectiveTotal)} of{' '}
403
+ {effectiveTotal}
313
404
  </p>
314
405
  <Pagination page={safePage} pageCount={pageCount} onPageChange={setPage} />
315
406
  </div>
@@ -0,0 +1,30 @@
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 { DatePicker } from './DatePicker';
6
+
7
+ describe('DatePicker', () => {
8
+ it('reports ISO value changes', async () => {
9
+ const user = userEvent.setup();
10
+ const onValueChange = vi.fn();
11
+ render(<DatePicker aria-label="Start date" onValueChange={onValueChange} />);
12
+ const input = screen.getByLabelText('Start date');
13
+ await user.type(input, '2026-11-03');
14
+ expect(onValueChange).toHaveBeenCalled();
15
+ expect(input).toHaveAttribute('type', 'date');
16
+ });
17
+
18
+ it('clears the value', async () => {
19
+ const user = userEvent.setup();
20
+ const onValueChange = vi.fn();
21
+ render(<DatePicker aria-label="Due" clearable defaultValue="2026-11-03" onValueChange={onValueChange} />);
22
+ await user.click(screen.getByRole('button', { name: 'Clear date' }));
23
+ expect(onValueChange).toHaveBeenCalledWith('');
24
+ });
25
+
26
+ it('has no accessibility violations', async () => {
27
+ const { container } = render(<DatePicker aria-label="Date" />);
28
+ expect(await axe(container)).toHaveNoViolations();
29
+ });
30
+ });