@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
@@ -2,47 +2,99 @@
2
2
  "id": "toast",
3
3
  "name": "Toast",
4
4
  "tier": "molecule",
5
- "description": "Accessible app-level notifications announced through a polite live region, with auto-dismiss, stacking and optional actions",
6
- "designIntent": "Applications need lightweight feedback that does not steal focus. Toasts render into a labelled polite live region so screen readers announce them, stack newest-first, auto-dismiss on a timer, and support one optional action (typically undo).",
5
+ "description": "Accessible notifications: tree-scoped provider/hook plus an imperative toast() API rendered by <Toaster />.",
6
+ "designIntent": "Toasts announce status changes without stealing focus. The provider/useToast pair covers tree-scoped usage; the module-level toast() + <Toaster /> covers event handlers and data layers where threading a hook is impossible (e.g. 1000+ call sites). A polite live region and auto-dismiss keep the queue quiet.",
7
7
  "props": [
8
8
  {
9
9
  "name": "title",
10
10
  "type": "string",
11
11
  "required": true,
12
- "description": "Short heading announced with the toast"
12
+ "description": "Toast heading.",
13
+ "examples": [
14
+ "Saved",
15
+ "Upload failed"
16
+ ]
13
17
  },
14
18
  {
15
19
  "name": "description",
16
20
  "type": "string",
17
21
  "required": false,
18
- "description": "Optional supporting detail"
22
+ "description": "Supporting line under the title."
23
+ },
24
+ {
25
+ "name": "variant",
26
+ "type": "'default' | 'success' | 'error' | 'warning' | 'info'",
27
+ "required": false,
28
+ "defaultValue": "default",
29
+ "description": "Status accent (dot + optional rich tint).",
30
+ "enum": [
31
+ "default",
32
+ "success",
33
+ "error",
34
+ "warning",
35
+ "info"
36
+ ],
37
+ "examples": [
38
+ "success",
39
+ "error"
40
+ ]
19
41
  },
20
42
  {
21
43
  "name": "action",
22
44
  "type": "{ label: string; onClick: () => void }",
23
45
  "required": false,
24
- "description": "Optional inline action; invoking it dismisses the toast"
46
+ "description": "Single inline action; dismisses the toast after running."
25
47
  },
26
48
  {
27
49
  "name": "duration",
28
50
  "type": "number",
29
- "defaultValue": 5000,
30
51
  "required": false,
31
- "description": "Auto-dismiss delay in ms; 0 keeps the toast until dismissed",
32
- "enum": ["0", "5000"],
33
- "examples": [0, 3000, 5000]
52
+ "defaultValue": "5000",
53
+ "description": "Auto-dismiss delay in ms; 0 keeps the toast until dismissed."
54
+ },
55
+ {
56
+ "name": "position",
57
+ "type": "'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'",
58
+ "required": false,
59
+ "defaultValue": "bottom-right",
60
+ "description": "Toaster placement (Toaster component).",
61
+ "enum": [
62
+ "top-left",
63
+ "top-center",
64
+ "top-right",
65
+ "bottom-left",
66
+ "bottom-center",
67
+ "bottom-right"
68
+ ],
69
+ "examples": [
70
+ "top-right"
71
+ ]
72
+ },
73
+ {
74
+ "name": "richColors",
75
+ "type": "boolean",
76
+ "required": false,
77
+ "defaultValue": "false",
78
+ "description": "Tint the toast surface with its status color (Toaster component)."
79
+ },
80
+ {
81
+ "name": "label",
82
+ "type": "string",
83
+ "required": false,
84
+ "defaultValue": "Notifications",
85
+ "description": "Accessible name of the live region (Toaster component)."
34
86
  }
35
87
  ],
36
88
  "examples": [
37
89
  {
38
- "title": "Basic toast with useToast",
39
- "code": "'use client';\n\nimport { ToastProvider, useToast } from '@/components/slipstream/toast';\n\nfunction SaveButton() {\n const { toast } = useToast();\n return (\n <button onClick={() => toast({ title: 'Saved', description: 'Your changes are live.' })}>\n Save\n </button>\n );\n}\n\nexport function App() {\n return (\n <ToastProvider>\n <SaveButton />\n </ToastProvider>\n );\n}",
40
- "description": "Wrap your app in ToastProvider once; call toast() anywhere below it."
90
+ "title": "Imperative API",
91
+ "code": "import { Toaster, toast } from '@slipstream-ui/core';\n\n<Toaster position=\"bottom-right\" richColors />\n\ntoast.success('Saved', 'Your changes are live');\ntoast.error('Upload failed', 'Check your connection');\ntoast({ title: 'Heads up', duration: 0 });",
92
+ "description": "Fire from event handlers or data layers — no hook needed."
41
93
  },
42
94
  {
43
- "title": "Undo action",
44
- "code": "toast({\n title: 'License revoked',\n action: { label: 'Undo', onClick: restore },\n duration: 0,\n});",
45
- "description": "duration: 0 keeps the toast until the user acts or dismisses it."
95
+ "title": "Tree-scoped provider",
96
+ "code": "<ToastProvider>\n <App />\n</ToastProvider>;\n\nconst { toast, dismiss } = useToast();\ntoast({ title: 'Saved' });",
97
+ "description": "Existing provider/hook pair for component-scoped usage."
46
98
  }
47
99
  ],
48
100
  "antiPatterns": [
@@ -53,29 +105,53 @@
53
105
  ],
54
106
  "accessibility": [
55
107
  {
56
- "feature": "Screen reader announcements",
57
- "implementation": "Each toast renders inside role=status (implicit aria-live=polite) within a labelled list container."
108
+ "feature": "Polite live region",
109
+ "implementation": "Each toast renders role=status inside a labelled list; announcements never steal focus",
110
+ "userRequirements": "Keep messages short and actionable"
58
111
  },
59
112
  {
60
- "feature": "Keyboard dismiss",
61
- "implementation": "Toast content is regular DOM; buttons inside toasts are reachable and activatable with the keyboard."
113
+ "feature": "Dismiss control",
114
+ "implementation": "Every toast has a labelled dismiss button (Dismiss <title>)",
115
+ "userRequirements": "Don't remove the dismiss button"
116
+ },
117
+ {
118
+ "feature": "Auto-dismiss timing",
119
+ "implementation": "5s default; duration 0 keeps sticky toasts",
120
+ "userRequirements": "Use duration 0 for errors that need a decision"
62
121
  }
63
122
  ],
64
123
  "contentGuidelines": [
65
124
  {
66
125
  "contentType": "toast title",
67
- "guidelines": ["State what happened in past tense", "Keep under ~60 characters"],
68
- "goodExamples": ["Saved", "License revoked"],
69
- "badExamples": ["Oops!"]
126
+ "guidelines": [
127
+ "State what happened in past tense",
128
+ "Keep under ~60 characters"
129
+ ],
130
+ "goodExamples": [
131
+ "Saved",
132
+ "License revoked"
133
+ ],
134
+ "badExamples": [
135
+ "Oops!"
136
+ ]
70
137
  }
71
138
  ],
72
139
  "compositionRules": [
73
140
  {
74
- "component": "Confirmation",
75
- "relationship": "Use Confirmation for destructive actions before they happen; use Toast to report the result after."
141
+ "component": "Toaster",
142
+ "relationship": "Mount once near the app root next to your router; keep it outside transforms so fixed positioning is not affected",
143
+ "example": "<App><Toaster /></App>"
144
+ },
145
+ {
146
+ "component": "ToastProvider",
147
+ "relationship": "Use the provider/hook pair when the call site is inside the React tree",
148
+ "example": "<ToastProvider><App /></ToastProvider>"
76
149
  }
77
150
  ],
78
- "relatedComponents": ["Confirmation", "Button"],
151
+ "relatedComponents": [
152
+ "Confirmation",
153
+ "Button"
154
+ ],
79
155
  "package": "@slipstream-ui/core",
80
156
  "importPath": "@slipstream-ui/core",
81
157
  "version": "0.0.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slipstream-ui/core",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/michaelmcshinsky/slipstream-ui.git",
@@ -40,7 +40,7 @@
40
40
  "@types/react": "^18.2.0",
41
41
  "eslint": "^8.56.0",
42
42
  "jest-axe": "^9.0.0",
43
- "jsdom": "^24.0.0",
43
+ "jsdom": "^30.1.3",
44
44
  "tailwindcss": "^3.4.0",
45
45
  "tailwindcss-animate": "^1.0.7",
46
46
  "tsup": "^8.0.0",
@@ -10,8 +10,8 @@ const alertVariants = cva(
10
10
  default: 'bg-background text-foreground border-border',
11
11
  destructive: 'border-destructive/50 text-destructive bg-destructive/10 [&>svg]:text-destructive',
12
12
  success: 'border-success/50 text-success bg-success/10 [&>svg]:text-success',
13
- warning: 'border-warning/50 text-warning bg-warning/10 [&>svg]:text-warning',
14
- info: 'border-info/50 text-info bg-info/10 [&>svg]:text-info',
13
+ warning: 'border-warning/50 text-warning-ink bg-warning/10 [&>svg]:text-warning-ink',
14
+ info: 'border-info/50 text-info-ink bg-info/10 [&>svg]:text-info-ink',
15
15
  },
16
16
  },
17
17
  defaultVariants: {
@@ -0,0 +1,148 @@
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 { AppShell, Sidebar, type SidebarSection } from './AppShell';
6
+
7
+ const sections: SidebarSection[] = [
8
+ {
9
+ title: 'Workspace',
10
+ items: [
11
+ { href: '/dashboard', label: 'Dashboard' },
12
+ { href: '/classes', label: 'Classes', badge: '4' },
13
+ ],
14
+ },
15
+ {
16
+ items: [{ href: '/settings', label: 'Settings' }],
17
+ },
18
+ ];
19
+
20
+ describe('Sidebar', () => {
21
+ it('renders sections, headings and marks the active route', () => {
22
+ render(<Sidebar sections={sections} activeHref="/classes" />);
23
+ expect(screen.getByRole('navigation', { name: 'Primary' })).toBeInTheDocument();
24
+ expect(screen.getByText('Workspace')).toBeInTheDocument();
25
+ const active = screen.getByRole('link', { name: /Classes/ });
26
+ expect(active).toHaveAttribute('aria-current', 'page');
27
+ expect(screen.getByRole('link', { name: 'Dashboard' })).not.toHaveAttribute('aria-current');
28
+ expect(screen.getByText('4')).toBeInTheDocument();
29
+ });
30
+
31
+ it('uses a custom router link component', () => {
32
+ function RouterLink({ href, children, ...props }: React.ComponentProps<'a'>) {
33
+ return (
34
+ <a data-router href={href} {...props}>
35
+ {children}
36
+ </a>
37
+ );
38
+ }
39
+ render(<Sidebar sections={sections} linkComponent={RouterLink} />);
40
+ expect(screen.getByRole('link', { name: 'Dashboard' })).toHaveAttribute('data-router');
41
+ });
42
+
43
+ it('honours an explicit active flag', () => {
44
+ render(
45
+ <Sidebar
46
+ sections={[{ items: [{ href: '/x', label: 'X', active: true }] }]}
47
+ activeHref="/elsewhere"
48
+ />
49
+ );
50
+ expect(screen.getByRole('link', { name: 'X' })).toHaveAttribute('aria-current', 'page');
51
+ });
52
+
53
+ it('has no accessibility violations', async () => {
54
+ const { container } = render(<Sidebar sections={sections} activeHref="/dashboard" />);
55
+ expect(await axe(container)).toHaveNoViolations();
56
+ });
57
+ });
58
+
59
+ describe('AppShell', () => {
60
+ it('renders the rail, sticky header and main content', () => {
61
+ render(
62
+ <AppShell sidebar={<Sidebar sections={sections} />} header={<span>Top bar</span>}>
63
+ <p>Page body</p>
64
+ </AppShell>
65
+ );
66
+ expect(screen.getByText('Page body')).toBeInTheDocument();
67
+ expect(screen.getAllByRole('link', { name: 'Dashboard' }).length).toBeGreaterThan(0);
68
+ expect(screen.getByText('Top bar')).toBeInTheDocument();
69
+ });
70
+
71
+ it('opens the sidebar in a drawer on mobile', async () => {
72
+ const user = userEvent.setup();
73
+ render(
74
+ <AppShell sidebar={<Sidebar sections={sections} />}>
75
+ <p>Body</p>
76
+ </AppShell>
77
+ );
78
+ await user.click(screen.getByRole('button', { name: 'Open navigation' }));
79
+ expect(screen.getByRole('dialog', { name: 'Navigation' })).toBeInTheDocument();
80
+ });
81
+
82
+ it('hides the built-in menu button when requested', () => {
83
+ render(
84
+ <AppShell sidebar={<Sidebar sections={sections} />} hideMobileMenu>
85
+ <p>Body</p>
86
+ </AppShell>
87
+ );
88
+ expect(screen.queryByRole('button', { name: 'Open navigation' })).not.toBeInTheDocument();
89
+ });
90
+
91
+ it('can render without a sidebar', () => {
92
+ render(
93
+ <AppShell header={<span>Only header</span>}>
94
+ <p>Body</p>
95
+ </AppShell>
96
+ );
97
+ expect(screen.queryByRole('button', { name: 'Open navigation' })).not.toBeInTheDocument();
98
+ expect(screen.getByText('Only header')).toBeInTheDocument();
99
+ });
100
+ });
101
+
102
+
103
+ describe('Sidebar nesting and collapse', () => {
104
+ const nested: SidebarSection[] = [
105
+ {
106
+ items: [
107
+ {
108
+ href: '/classes',
109
+ label: 'Classes',
110
+ children: [
111
+ { href: '/classes/today', label: 'Today' },
112
+ { href: '/classes/week', label: 'This week' },
113
+ ],
114
+ },
115
+ { href: '/settings', label: 'Settings' },
116
+ ],
117
+ },
118
+ ];
119
+
120
+ it('renders nested groups with aria-expanded and opens the active group', () => {
121
+ render(<Sidebar sections={nested} activeHref="/classes/today" />);
122
+ const group = screen.getByRole('button', { name: 'Classes' });
123
+ expect(group).toHaveAttribute('aria-expanded', 'true');
124
+ expect(screen.getByRole('link', { name: 'This week' })).toBeInTheDocument();
125
+ });
126
+
127
+ it('toggles nested groups', async () => {
128
+ const user = userEvent.setup();
129
+ render(<Sidebar sections={nested} activeHref="/settings" />);
130
+ const group = screen.getByRole('button', { name: 'Classes' });
131
+ expect(group).toHaveAttribute('aria-expanded', 'false');
132
+ await user.click(group);
133
+ expect(group).toHaveAttribute('aria-expanded', 'true');
134
+ expect(screen.getByRole('link', { name: 'Today' })).toBeInTheDocument();
135
+ });
136
+
137
+ it('collapses to an icon rail and reports the change', async () => {
138
+ const user = userEvent.setup();
139
+ const onCollapsedChange = vi.fn();
140
+ const { container } = render(
141
+ <Sidebar sections={nested} collapsible onCollapsedChange={onCollapsedChange} />
142
+ );
143
+ await user.click(screen.getByRole('button', { name: 'Collapse navigation' }));
144
+ expect(onCollapsedChange).toHaveBeenCalledWith(true);
145
+ expect(container.firstChild).toHaveAttribute('data-collapsed', 'true');
146
+ expect(screen.getByRole('button', { name: 'Expand navigation' })).toBeInTheDocument();
147
+ });
148
+ });
@@ -0,0 +1,266 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { cn } from '../../utils/cn';
5
+ import { Drawer } from '../drawer/Drawer';
6
+
7
+ export type SidebarItem = {
8
+ href: string;
9
+ label: string;
10
+ icon?: React.ReactNode;
11
+ /** Trailing slot — count, status dot, shortcut. */
12
+ badge?: React.ReactNode;
13
+ /** Force the active state (otherwise activeHref is compared). */
14
+ active?: boolean;
15
+ /** Nested items — renders a collapsible group with aria-expanded. */
16
+ children?: SidebarItem[];
17
+ };
18
+
19
+ export type SidebarSection = {
20
+ title?: string;
21
+ items: SidebarItem[];
22
+ };
23
+
24
+ export type SidebarProps = Omit<React.HTMLAttributes<HTMLElement>, 'children'> & {
25
+ sections: SidebarSection[];
26
+ /** Brand/mark rendered at the top. */
27
+ heading?: React.ReactNode;
28
+ /** Rendered at the bottom (user menu, upgrade CTA). */
29
+ footer?: React.ReactNode;
30
+ /** Current route — items with a matching href get aria-current="page". */
31
+ activeHref?: string;
32
+ /** Custom link element for routers (react-router `Link`, Next `Link`). */
33
+ linkComponent?: React.ElementType;
34
+ /** Accessible name of the nav landmark. Default 'Primary'. */
35
+ label?: string;
36
+ /** Show the collapse/expand control (icon-only rail when collapsed). */
37
+ collapsible?: boolean;
38
+ /** Initial collapsed state when uncontrolled. */
39
+ defaultCollapsed?: boolean;
40
+ /** Controlled collapsed state. */
41
+ collapsed?: boolean;
42
+ onCollapsedChange?: (collapsed: boolean) => void;
43
+ /** Groups open initially (in addition to groups containing the active route). */
44
+ defaultExpanded?: string[];
45
+ };
46
+
47
+ function containsActive(item: SidebarItem, activeHref: string | undefined): boolean {
48
+ if (!activeHref) return false;
49
+ if (item.href === activeHref) return true;
50
+ return (item.children ?? []).some((child) => containsActive(child, activeHref));
51
+ }
52
+
53
+ const itemClass =
54
+ 'flex w-full items-center gap-2.5 rounded-md px-2.5 py-2 text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
55
+ const activeClass = 'bg-primary/10 font-medium text-primary';
56
+ const idleClass = 'text-muted-foreground hover:bg-accent hover:text-accent-foreground';
57
+
58
+ /**
59
+ * Sectioned navigation rail — now with nested groups and a collapsible
60
+ * icon-only mode. Purely presentational: you pass the active route and a
61
+ * router link component, so it stays stateless about routing.
62
+ */
63
+ export function Sidebar({
64
+ sections,
65
+ heading,
66
+ footer,
67
+ activeHref,
68
+ linkComponent,
69
+ label = 'Primary',
70
+ collapsible = false,
71
+ defaultCollapsed = false,
72
+ collapsed: collapsedProp,
73
+ onCollapsedChange,
74
+ defaultExpanded = [],
75
+ className,
76
+ ...props
77
+ }: SidebarProps) {
78
+ const Link = linkComponent ?? 'a';
79
+ const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed);
80
+ const collapsed = collapsedProp ?? internalCollapsed;
81
+ const [openGroups, setOpenGroups] = React.useState<string[]>(defaultExpanded);
82
+
83
+ const isOpen = (item: SidebarItem) =>
84
+ collapsed ? false : openGroups.includes(item.href) || containsActive(item, activeHref);
85
+
86
+ const toggleGroup = (href: string) => {
87
+ setOpenGroups((current) =>
88
+ current.includes(href) ? current.filter((entry) => entry !== href) : [...current, href]
89
+ );
90
+ };
91
+
92
+ const toggleCollapsed = () => {
93
+ const next = !collapsed;
94
+ if (collapsedProp === undefined) setInternalCollapsed(next);
95
+ onCollapsedChange?.(next);
96
+ };
97
+
98
+ const renderItems = (items: SidebarItem[], depth = 0): React.ReactNode => (
99
+ <ul className={cn('space-y-0.5', depth > 0 && 'ml-3.5 border-l border-border pl-2.5')}>
100
+ {items.map((item) => {
101
+ const active = item.active ?? containsActive(item, activeHref);
102
+ const hasChildren = Boolean(item.children?.length);
103
+ const expanded = hasChildren && isOpen(item);
104
+ const panelId = `sidebar-group-${item.href.replace(/[^a-z0-9-]/gi, '-')}`;
105
+
106
+ if (hasChildren) {
107
+ return (
108
+ <li key={item.href}>
109
+ <button
110
+ type="button"
111
+ aria-expanded={expanded}
112
+ aria-controls={expanded ? panelId : undefined}
113
+ onClick={() => toggleGroup(item.href)}
114
+ title={collapsed ? item.label : undefined}
115
+ className={cn(itemClass, active ? activeClass : idleClass, collapsed && 'justify-center px-0')}
116
+ >
117
+ {item.icon && <span className="shrink-0 [&_svg]:size-4">{item.icon}</span>}
118
+ <span className={cn('min-w-0 flex-1 truncate text-left', collapsed && 'sr-only')}>{item.label}</span>
119
+ {!collapsed && (
120
+ <span aria-hidden="true" className={cn('shrink-0 text-xs transition-transform', expanded && 'rotate-90')}>
121
+ ›
122
+ </span>
123
+ )}
124
+ </button>
125
+ {expanded && <div id={panelId}>{renderItems(item.children!, depth + 1)}</div>}
126
+ </li>
127
+ );
128
+ }
129
+
130
+ return (
131
+ <li key={item.href}>
132
+ <Link
133
+ href={item.href}
134
+ aria-current={active ? 'page' : undefined}
135
+ title={collapsed ? item.label : undefined}
136
+ className={cn(itemClass, active ? activeClass : idleClass, collapsed && 'justify-center px-0')}
137
+ >
138
+ {item.icon && <span className="shrink-0 [&_svg]:size-4">{item.icon}</span>}
139
+ <span className={cn('min-w-0 flex-1 truncate', collapsed && 'sr-only')}>{item.label}</span>
140
+ {!collapsed && item.badge && <span className="shrink-0 text-xs">{item.badge}</span>}
141
+ </Link>
142
+ </li>
143
+ );
144
+ })}
145
+ </ul>
146
+ );
147
+
148
+ return (
149
+ <div
150
+ data-collapsed={collapsed || undefined}
151
+ className={cn('flex h-full min-h-0 flex-col gap-5 p-3', className)}
152
+ {...props}
153
+ >
154
+ {heading && <div className={cn('px-1', collapsed && 'sr-only')}>{heading}</div>}
155
+ <nav aria-label={label} className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto">
156
+ {sections.map((section, index) => (
157
+ <div key={section.title ?? `section-${index}`}>
158
+ {section.title && (
159
+ <p className={cn('mb-1.5 px-2 text-xs font-medium uppercase tracking-wide text-muted-foreground', collapsed && 'sr-only')}>
160
+ {section.title}
161
+ </p>
162
+ )}
163
+ {renderItems(section.items)}
164
+ </div>
165
+ ))}
166
+ </nav>
167
+ {collapsible && (
168
+ <button
169
+ type="button"
170
+ onClick={toggleCollapsed}
171
+ aria-expanded={!collapsed}
172
+ aria-label={collapsed ? 'Expand navigation' : 'Collapse navigation'}
173
+ className={cn(itemClass, idleClass, 'justify-center')}
174
+ >
175
+ <span aria-hidden="true" className={cn('transition-transform', collapsed && 'rotate-180')}>
176
+ «
177
+ </span>
178
+ </button>
179
+ )}
180
+ {footer && !collapsed && <div className="border-t border-border pt-3">{footer}</div>}
181
+ </div>
182
+ );
183
+ }
184
+
185
+ export type AppShellProps = React.HTMLAttributes<HTMLDivElement> & {
186
+ /** Desktop rail; also rendered inside a mobile drawer. */
187
+ sidebar?: React.ReactNode;
188
+ /** Sticky top bar content. */
189
+ header?: React.ReactNode;
190
+ /** Hide the built-in mobile menu button (e.g. when the header owns one). */
191
+ hideMobileMenu?: boolean;
192
+ /** Tailwind width class for the desktop rail. Default 'w-64'. */
193
+ sidebarWidth?: string;
194
+ /** Breakpoint at which the rail switches to the mobile drawer. Default 'md'. */
195
+ mobileBreakpoint?: 'sm' | 'md' | 'lg';
196
+ };
197
+
198
+ const hideAt: Record<NonNullable<AppShellProps['mobileBreakpoint']>, string> = {
199
+ sm: 'hidden sm:block',
200
+ md: 'hidden md:block',
201
+ lg: 'hidden lg:block',
202
+ };
203
+
204
+ const showBelow: Record<NonNullable<AppShellProps['mobileBreakpoint']>, string> = {
205
+ sm: 'sm:hidden',
206
+ md: 'md:hidden',
207
+ lg: 'lg:hidden',
208
+ };
209
+
210
+ /**
211
+ * Application frame: fixed-height sidebar, sticky header, scrolling main.
212
+ * On small screens the sidebar becomes a left Drawer opened by a burger
213
+ * button, so pages never need their own responsive nav wiring. A collapsed
214
+ * Sidebar (data-collapsed) shrinks the desktop rail automatically.
215
+ */
216
+ export function AppShell({
217
+ sidebar,
218
+ header,
219
+ hideMobileMenu = false,
220
+ sidebarWidth = 'w-64',
221
+ mobileBreakpoint = 'md',
222
+ className,
223
+ children,
224
+ ...props
225
+ }: AppShellProps) {
226
+ const [mobileOpen, setMobileOpen] = React.useState(false);
227
+
228
+ return (
229
+ <div className={cn('flex min-h-screen bg-background text-foreground', className)} {...props}>
230
+ {sidebar && (
231
+ <aside
232
+ className={cn(
233
+ 'shrink-0 border-r border-border has-[[data-collapsed]]:w-16',
234
+ hideAt[mobileBreakpoint],
235
+ sidebarWidth
236
+ )}
237
+ >
238
+ {sidebar}
239
+ </aside>
240
+ )}
241
+ <div className="flex min-w-0 flex-1 flex-col">
242
+ {(header || (sidebar && !hideMobileMenu)) && (
243
+ <header className="sticky top-0 z-30 flex h-14 items-center gap-3 border-b border-border bg-background/80 px-4 backdrop-blur supports-[backdrop-filter]:bg-background/60">
244
+ {sidebar && !hideMobileMenu && (
245
+ <button
246
+ type="button"
247
+ onClick={() => setMobileOpen(true)}
248
+ aria-label="Open navigation"
249
+ className={cn('rounded-md border border-border p-2 text-muted-foreground hover:bg-muted', showBelow[mobileBreakpoint])}
250
+ >
251
+ <span aria-hidden="true">☰</span>
252
+ </button>
253
+ )}
254
+ <div className="min-w-0 flex-1">{header}</div>
255
+ </header>
256
+ )}
257
+ <main className="min-w-0 flex-1">{children}</main>
258
+ </div>
259
+ {sidebar && (
260
+ <Drawer open={mobileOpen} onOpenChange={setMobileOpen} title="Navigation" side="left" size="sm" animate>
261
+ {sidebar}
262
+ </Drawer>
263
+ )}
264
+ </div>
265
+ );
266
+ }
@@ -0,0 +1 @@
1
+ export * from './AppShell';
@@ -0,0 +1,34 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import { axe } from 'jest-axe';
3
+ import { describe, expect, it } from 'vitest';
4
+ import { AuthLayout } from './AuthLayout';
5
+
6
+ describe('AuthLayout', () => {
7
+ it('renders brand, heading, description and footer', () => {
8
+ render(
9
+ <AuthLayout
10
+ title="Sign in"
11
+ description="Welcome back."
12
+ brand={<span>Acme</span>}
13
+ footer={<a href="/signup">Create account</a>}
14
+ >
15
+ <form aria-label="Sign in form" />
16
+ </AuthLayout>
17
+ );
18
+ expect(screen.getByText('Acme')).toBeInTheDocument();
19
+ expect(screen.getByRole('heading', { level: 1, name: 'Sign in' })).toBeInTheDocument();
20
+ expect(screen.getByText('Welcome back.')).toBeInTheDocument();
21
+ expect(screen.getByRole('form', { name: 'Sign in form' })).toBeInTheDocument();
22
+ expect(screen.getByRole('link', { name: 'Create account' })).toBeInTheDocument();
23
+ });
24
+
25
+ it('supports size presets', () => {
26
+ const { container } = render(<AuthLayout size="lg" title="Reset"><span /></AuthLayout>);
27
+ expect(container.querySelector('.max-w-lg')).not.toBeNull();
28
+ });
29
+
30
+ it('has no accessibility violations', async () => {
31
+ const { container } = render(<AuthLayout title="Sign up"><input aria-label="Email" /></AuthLayout>);
32
+ expect(await axe(container)).toHaveNoViolations();
33
+ });
34
+ });