@sabrenski/spire-ui 0.0.1

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 (237) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -0
  3. package/dist/index.d.ts +4981 -0
  4. package/dist/spire-ui.css +1 -0
  5. package/dist/spire-ui.es.js +18403 -0
  6. package/dist/spire-ui.umd.js +45 -0
  7. package/package.json +83 -0
  8. package/src/components/Accordion/Accordion.test.ts +218 -0
  9. package/src/components/Accordion/AccordionContent.vue +112 -0
  10. package/src/components/Accordion/AccordionItem.vue +87 -0
  11. package/src/components/Accordion/AccordionRoot.vue +111 -0
  12. package/src/components/Accordion/AccordionTrigger.vue +125 -0
  13. package/src/components/Accordion/index.ts +11 -0
  14. package/src/components/Accordion/keys.ts +23 -0
  15. package/src/components/Avatar/Avatar.test.ts +181 -0
  16. package/src/components/Avatar/Avatar.vue +150 -0
  17. package/src/components/Avatar/index.ts +2 -0
  18. package/src/components/Badge/Badge.test.ts +141 -0
  19. package/src/components/Badge/Badge.vue +133 -0
  20. package/src/components/Badge/index.ts +2 -0
  21. package/src/components/BadgeContainer/BadgeContainer.test.ts +150 -0
  22. package/src/components/BadgeContainer/BadgeContainer.vue +90 -0
  23. package/src/components/BadgeContainer/index.ts +2 -0
  24. package/src/components/Breadcrumb/Breadcrumb.test.ts +342 -0
  25. package/src/components/Breadcrumb/BreadcrumbEllipsis.vue +96 -0
  26. package/src/components/Breadcrumb/BreadcrumbItem.vue +16 -0
  27. package/src/components/Breadcrumb/BreadcrumbLink.vue +67 -0
  28. package/src/components/Breadcrumb/BreadcrumbList.vue +20 -0
  29. package/src/components/Breadcrumb/BreadcrumbPage.vue +25 -0
  30. package/src/components/Breadcrumb/BreadcrumbRoot.vue +41 -0
  31. package/src/components/Breadcrumb/BreadcrumbSeparator.vue +63 -0
  32. package/src/components/Breadcrumb/index.ts +13 -0
  33. package/src/components/Breadcrumb/keys.ts +7 -0
  34. package/src/components/Button/Button.test.ts +231 -0
  35. package/src/components/Button/Button.vue +349 -0
  36. package/src/components/Button/index.ts +2 -0
  37. package/src/components/Callout/Callout.test.ts +260 -0
  38. package/src/components/Callout/Callout.vue +341 -0
  39. package/src/components/Callout/index.ts +2 -0
  40. package/src/components/Card/Card.test.ts +565 -0
  41. package/src/components/Card/Card.vue +209 -0
  42. package/src/components/Card/CardContent.vue +57 -0
  43. package/src/components/Card/CardFooter.vue +72 -0
  44. package/src/components/Card/CardHeader.vue +111 -0
  45. package/src/components/Card/CardImage.vue +124 -0
  46. package/src/components/Card/index.ts +14 -0
  47. package/src/components/Chart/BarChart.vue +208 -0
  48. package/src/components/Chart/BaseChart.vue +444 -0
  49. package/src/components/Chart/Chart.test.ts +359 -0
  50. package/src/components/Chart/DonutChart.vue +283 -0
  51. package/src/components/Chart/LineChart.vue +211 -0
  52. package/src/components/Chart/index.ts +20 -0
  53. package/src/components/Chart/useChartTheme.ts +192 -0
  54. package/src/components/Checkbox/Checkbox.test.ts +209 -0
  55. package/src/components/Checkbox/Checkbox.vue +285 -0
  56. package/src/components/Checkbox/index.ts +2 -0
  57. package/src/components/ChoiceChip/ChoiceChip.test.ts +142 -0
  58. package/src/components/ChoiceChip/ChoiceChip.vue +218 -0
  59. package/src/components/ChoiceChip/index.ts +2 -0
  60. package/src/components/ChoiceChipGroup/ChoiceChipGroup.test.ts +151 -0
  61. package/src/components/ChoiceChipGroup/ChoiceChipGroup.vue +70 -0
  62. package/src/components/ChoiceChipGroup/index.ts +2 -0
  63. package/src/components/ColorPicker/ColorArea.vue +159 -0
  64. package/src/components/ColorPicker/ColorPicker.test.ts +250 -0
  65. package/src/components/ColorPicker/ColorPicker.vue +339 -0
  66. package/src/components/ColorPicker/ColorSlider.vue +191 -0
  67. package/src/components/ColorPicker/index.ts +7 -0
  68. package/src/components/Combobox/Combobox.test.ts +891 -0
  69. package/src/components/Combobox/Combobox.vue +934 -0
  70. package/src/components/Combobox/index.ts +2 -0
  71. package/src/components/DataTable/DataTable.test.ts +1221 -0
  72. package/src/components/DataTable/DataTable.vue +1415 -0
  73. package/src/components/DataTable/index.ts +10 -0
  74. package/src/components/DatePicker/DatePicker.test.ts +625 -0
  75. package/src/components/DatePicker/DatePicker.vue +1586 -0
  76. package/src/components/DatePicker/index.ts +2 -0
  77. package/src/components/Drawer/Drawer.test.ts +336 -0
  78. package/src/components/Drawer/Drawer.vue +466 -0
  79. package/src/components/Drawer/index.ts +2 -0
  80. package/src/components/Dropdown/Dropdown.test.ts +607 -0
  81. package/src/components/Dropdown/Dropdown.vue +807 -0
  82. package/src/components/Dropdown/DropdownItem.vue +227 -0
  83. package/src/components/Dropdown/DropdownSeparator.vue +14 -0
  84. package/src/components/Dropdown/DropdownSub.vue +104 -0
  85. package/src/components/Dropdown/DropdownSubContent.vue +187 -0
  86. package/src/components/Dropdown/DropdownSubTrigger.vue +151 -0
  87. package/src/components/Dropdown/index.ts +14 -0
  88. package/src/components/EmptyState/EmptyState.test.ts +180 -0
  89. package/src/components/EmptyState/EmptyState.vue +137 -0
  90. package/src/components/EmptyState/index.ts +2 -0
  91. package/src/components/FileUpload/FileUpload.test.ts +1151 -0
  92. package/src/components/FileUpload/FileUpload.vue +1042 -0
  93. package/src/components/FileUpload/index.ts +2 -0
  94. package/src/components/Heading/Heading.test.ts +107 -0
  95. package/src/components/Heading/Heading.vue +67 -0
  96. package/src/components/Heading/index.ts +2 -0
  97. package/src/components/Icon/Icon.test.ts +157 -0
  98. package/src/components/Icon/Icon.vue +86 -0
  99. package/src/components/Icon/index.ts +2 -0
  100. package/src/components/Input/Input.test.ts +273 -0
  101. package/src/components/Input/Input.vue +388 -0
  102. package/src/components/Input/index.ts +2 -0
  103. package/src/components/Layout/Container.vue +67 -0
  104. package/src/components/Layout/Grid.vue +159 -0
  105. package/src/components/Layout/GridItem.vue +154 -0
  106. package/src/components/Layout/Layout.test.ts +202 -0
  107. package/src/components/Layout/Stack.vue +128 -0
  108. package/src/components/Layout/index.ts +9 -0
  109. package/src/components/Layout/keys.ts +7 -0
  110. package/src/components/Modal/Modal.test.ts +311 -0
  111. package/src/components/Modal/Modal.vue +336 -0
  112. package/src/components/Modal/index.ts +2 -0
  113. package/src/components/Pagination/Pagination.test.ts +303 -0
  114. package/src/components/Pagination/Pagination.vue +212 -0
  115. package/src/components/Pagination/index.ts +3 -0
  116. package/src/components/Pagination/utils.ts +86 -0
  117. package/src/components/Popover/Popover.test.ts +285 -0
  118. package/src/components/Popover/Popover.vue +441 -0
  119. package/src/components/Popover/index.ts +2 -0
  120. package/src/components/Progress/Progress.test.ts +361 -0
  121. package/src/components/Progress/Progress.vue +363 -0
  122. package/src/components/Progress/index.ts +7 -0
  123. package/src/components/Radio/Radio.test.ts +216 -0
  124. package/src/components/Radio/Radio.vue +214 -0
  125. package/src/components/Radio/index.ts +2 -0
  126. package/src/components/Rating/Rating.test.ts +319 -0
  127. package/src/components/Rating/Rating.vue +247 -0
  128. package/src/components/Rating/index.ts +2 -0
  129. package/src/components/SegmentedControl/SegmentedControl.test.ts +292 -0
  130. package/src/components/SegmentedControl/SegmentedControl.vue +288 -0
  131. package/src/components/SegmentedControl/index.ts +2 -0
  132. package/src/components/Select/Select.test.ts +589 -0
  133. package/src/components/Select/Select.vue +666 -0
  134. package/src/components/Select/index.ts +2 -0
  135. package/src/components/Sidebar/Sidebar.test.ts +301 -0
  136. package/src/components/Sidebar/SidebarGroup.vue +103 -0
  137. package/src/components/Sidebar/SidebarItem.vue +196 -0
  138. package/src/components/Sidebar/SidebarLayout.vue +42 -0
  139. package/src/components/Sidebar/SidebarRoot.vue +122 -0
  140. package/src/components/Sidebar/index.ts +11 -0
  141. package/src/components/Sidebar/keys.ts +14 -0
  142. package/src/components/Skeleton/Skeleton.test.ts +130 -0
  143. package/src/components/Skeleton/Skeleton.vue +104 -0
  144. package/src/components/Skeleton/index.ts +2 -0
  145. package/src/components/Slider/Slider.test.ts +416 -0
  146. package/src/components/Slider/Slider.vue +435 -0
  147. package/src/components/Slider/index.ts +2 -0
  148. package/src/components/Slider/utils.ts +91 -0
  149. package/src/components/Spinner/Spinner.test.ts +79 -0
  150. package/src/components/Spinner/Spinner.vue +159 -0
  151. package/src/components/Spinner/index.ts +2 -0
  152. package/src/components/SpireProvider/SpireProvider.vue +71 -0
  153. package/src/components/SpireProvider/index.ts +11 -0
  154. package/src/components/Stepper/Stepper.test.ts +221 -0
  155. package/src/components/Stepper/StepperContent.vue +51 -0
  156. package/src/components/Stepper/StepperItem.vue +89 -0
  157. package/src/components/Stepper/StepperRoot.vue +101 -0
  158. package/src/components/Stepper/StepperSeparator.vue +52 -0
  159. package/src/components/Stepper/StepperTrigger.vue +144 -0
  160. package/src/components/Stepper/index.ts +11 -0
  161. package/src/components/Stepper/keys.ts +27 -0
  162. package/src/components/Switch/Switch.test.ts +214 -0
  163. package/src/components/Switch/Switch.vue +235 -0
  164. package/src/components/Switch/index.ts +2 -0
  165. package/src/components/Tabs/Tabs.test.ts +363 -0
  166. package/src/components/Tabs/Tabs.vue +318 -0
  167. package/src/components/Tabs/index.ts +2 -0
  168. package/src/components/Text/Text.test.ts +154 -0
  169. package/src/components/Text/Text.vue +100 -0
  170. package/src/components/Text/index.ts +2 -0
  171. package/src/components/Textarea/Textarea.test.ts +432 -0
  172. package/src/components/Textarea/Textarea.vue +411 -0
  173. package/src/components/Textarea/index.ts +2 -0
  174. package/src/components/TimePicker/TimePicker.test.ts +352 -0
  175. package/src/components/TimePicker/TimePicker.vue +569 -0
  176. package/src/components/TimePicker/index.ts +2 -0
  177. package/src/components/Timeline/Timeline.test.ts +193 -0
  178. package/src/components/Timeline/Timeline.vue +111 -0
  179. package/src/components/Timeline/TimelineItem.vue +167 -0
  180. package/src/components/Timeline/index.ts +13 -0
  181. package/src/components/Timeline/keys.ts +21 -0
  182. package/src/components/Toast/ToastItem.test.ts +289 -0
  183. package/src/components/Toast/ToastItem.vue +370 -0
  184. package/src/components/Toast/ToastProvider.test.ts +158 -0
  185. package/src/components/Toast/ToastProvider.vue +181 -0
  186. package/src/components/Toast/index.ts +83 -0
  187. package/src/components/Toast/toastState.test.ts +165 -0
  188. package/src/components/Toast/toastState.ts +161 -0
  189. package/src/components/ToggleButton/ToggleButton.test.ts +166 -0
  190. package/src/components/ToggleButton/ToggleButton.vue +197 -0
  191. package/src/components/ToggleButton/index.ts +2 -0
  192. package/src/components/ToggleGroup/ToggleGroup.test.ts +181 -0
  193. package/src/components/ToggleGroup/ToggleGroup.vue +130 -0
  194. package/src/components/ToggleGroup/index.ts +2 -0
  195. package/src/components/Tooltip/Tooltip.test.ts +238 -0
  196. package/src/components/Tooltip/Tooltip.vue +217 -0
  197. package/src/components/Tooltip/index.ts +2 -0
  198. package/src/components/TreeView/TreeView.test.ts +357 -0
  199. package/src/components/TreeView/TreeView.vue +251 -0
  200. package/src/components/TreeView/TreeViewItem.vue +288 -0
  201. package/src/components/TreeView/index.ts +11 -0
  202. package/src/components/TreeView/keys.ts +35 -0
  203. package/src/composables/index.ts +12 -0
  204. package/src/composables/useClickOutside.ts +36 -0
  205. package/src/composables/useClipboard.ts +35 -0
  206. package/src/composables/useEventListener.ts +48 -0
  207. package/src/composables/useFocusTrap.ts +58 -0
  208. package/src/composables/useHoverReveal.ts +98 -0
  209. package/src/composables/useId.ts +10 -0
  210. package/src/composables/useMagnetic.ts +171 -0
  211. package/src/composables/useRelativePosition.ts +127 -0
  212. package/src/composables/useRipple.ts +146 -0
  213. package/src/composables/useScrollLock.ts +25 -0
  214. package/src/composables/useSpireConfig.ts +27 -0
  215. package/src/composables/useStagger.ts +224 -0
  216. package/src/config/icons.test.ts +115 -0
  217. package/src/config/icons.ts +170 -0
  218. package/src/index.ts +361 -0
  219. package/src/styles/depth.css +129 -0
  220. package/src/styles/effects.css +169 -0
  221. package/src/styles/fallback.css +152 -0
  222. package/src/styles/main.css +25 -0
  223. package/src/styles/mood.css +211 -0
  224. package/src/styles/motion.css +159 -0
  225. package/src/styles/reset.css +97 -0
  226. package/src/styles/theme.css +708 -0
  227. package/src/styles/tokens.css +183 -0
  228. package/src/utils/.gitkeep +0 -0
  229. package/src/utils/color.ts +277 -0
  230. package/src/utils/date.test.ts +522 -0
  231. package/src/utils/date.ts +380 -0
  232. package/src/utils/index.ts +23 -0
  233. package/src/utils/object.test.ts +80 -0
  234. package/src/utils/object.ts +25 -0
  235. package/src/utils/string.test.ts +64 -0
  236. package/src/utils/string.ts +32 -0
  237. package/src/utils/time.ts +156 -0
@@ -0,0 +1,289 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import ToastItem from './ToastItem.vue'
4
+ import type { Toast } from './toastState'
5
+
6
+ function createToast(overrides: Partial<Toast> = {}): Toast {
7
+ return {
8
+ id: 'test-id',
9
+ title: 'Test Title',
10
+ message: 'Test message',
11
+ variant: 'success',
12
+ duration: 5000,
13
+ createdAt: Date.now(),
14
+ ...overrides
15
+ }
16
+ }
17
+
18
+ describe('ToastItem', () => {
19
+ beforeEach(() => {
20
+ vi.useFakeTimers()
21
+ })
22
+
23
+ afterEach(() => {
24
+ vi.useRealTimers()
25
+ })
26
+
27
+ describe('Rendering', () => {
28
+ it('renders toast container', () => {
29
+ const wrapper = mount(ToastItem, {
30
+ props: { toast: createToast() }
31
+ })
32
+ expect(wrapper.find('.ui-toast').exists()).toBe(true)
33
+ })
34
+
35
+ it('renders title', () => {
36
+ const wrapper = mount(ToastItem, {
37
+ props: { toast: createToast({ title: 'My Title' }) }
38
+ })
39
+ expect(wrapper.find('.ui-toast__title').text()).toBe('My Title')
40
+ })
41
+
42
+ it('renders message', () => {
43
+ const wrapper = mount(ToastItem, {
44
+ props: { toast: createToast({ message: 'My message' }) }
45
+ })
46
+ expect(wrapper.find('.ui-toast__message').text()).toBe('My message')
47
+ })
48
+
49
+ it('does not render title if not provided', () => {
50
+ const wrapper = mount(ToastItem, {
51
+ props: { toast: createToast({ title: undefined }) }
52
+ })
53
+ expect(wrapper.find('.ui-toast__title').exists()).toBe(false)
54
+ })
55
+
56
+ it('does not render message if not provided', () => {
57
+ const wrapper = mount(ToastItem, {
58
+ props: { toast: createToast({ message: undefined }) }
59
+ })
60
+ expect(wrapper.find('.ui-toast__message').exists()).toBe(false)
61
+ })
62
+
63
+ it('renders icon', () => {
64
+ const wrapper = mount(ToastItem, {
65
+ props: { toast: createToast() }
66
+ })
67
+ expect(wrapper.find('.ui-toast__icon svg').exists()).toBe(true)
68
+ })
69
+
70
+ it('renders close button', () => {
71
+ const wrapper = mount(ToastItem, {
72
+ props: { toast: createToast() }
73
+ })
74
+ expect(wrapper.find('.ui-toast__close').exists()).toBe(true)
75
+ })
76
+
77
+ it('renders progress bar when duration > 0', () => {
78
+ const wrapper = mount(ToastItem, {
79
+ props: { toast: createToast({ duration: 5000 }) }
80
+ })
81
+ expect(wrapper.find('.ui-toast__progress').exists()).toBe(true)
82
+ })
83
+
84
+ it('does not render progress bar when duration is 0', () => {
85
+ const wrapper = mount(ToastItem, {
86
+ props: { toast: createToast({ duration: 0 }) }
87
+ })
88
+ expect(wrapper.find('.ui-toast__progress').exists()).toBe(false)
89
+ })
90
+ })
91
+
92
+ describe('Variants', () => {
93
+ it('applies success variant class', () => {
94
+ const wrapper = mount(ToastItem, {
95
+ props: { toast: createToast({ variant: 'success' }) }
96
+ })
97
+ expect(wrapper.find('.ui-toast').classes()).toContain('ui-toast--success')
98
+ })
99
+
100
+ it('applies error variant class', () => {
101
+ const wrapper = mount(ToastItem, {
102
+ props: { toast: createToast({ variant: 'error' }) }
103
+ })
104
+ expect(wrapper.find('.ui-toast').classes()).toContain('ui-toast--error')
105
+ })
106
+
107
+ it('applies warning variant class', () => {
108
+ const wrapper = mount(ToastItem, {
109
+ props: { toast: createToast({ variant: 'warning' }) }
110
+ })
111
+ expect(wrapper.find('.ui-toast').classes()).toContain('ui-toast--warning')
112
+ })
113
+
114
+ it('applies info variant class', () => {
115
+ const wrapper = mount(ToastItem, {
116
+ props: { toast: createToast({ variant: 'info' }) }
117
+ })
118
+ expect(wrapper.find('.ui-toast').classes()).toContain('ui-toast--info')
119
+ })
120
+ })
121
+
122
+ describe('Auto-dismiss', () => {
123
+ it('emits dismiss after duration', () => {
124
+ const wrapper = mount(ToastItem, {
125
+ props: { toast: createToast({ duration: 5000 }) }
126
+ })
127
+
128
+ expect(wrapper.emitted('dismiss')).toBeUndefined()
129
+
130
+ vi.advanceTimersByTime(5000)
131
+
132
+ expect(wrapper.emitted('dismiss')).toHaveLength(1)
133
+ expect(wrapper.emitted('dismiss')?.[0]).toEqual(['test-id'])
134
+ })
135
+
136
+ it('does not auto-dismiss when duration is 0', () => {
137
+ const wrapper = mount(ToastItem, {
138
+ props: { toast: createToast({ duration: 0 }) }
139
+ })
140
+
141
+ vi.advanceTimersByTime(10000)
142
+
143
+ expect(wrapper.emitted('dismiss')).toBeUndefined()
144
+ })
145
+ })
146
+
147
+ describe('Close button', () => {
148
+ it('emits dismiss when close button clicked', async () => {
149
+ const wrapper = mount(ToastItem, {
150
+ props: { toast: createToast() }
151
+ })
152
+
153
+ await wrapper.find('.ui-toast__close').trigger('click')
154
+
155
+ expect(wrapper.emitted('dismiss')).toHaveLength(1)
156
+ expect(wrapper.emitted('dismiss')?.[0]).toEqual(['test-id'])
157
+ })
158
+ })
159
+
160
+ describe('Pause on hover', () => {
161
+ it('pauses timer on mouseenter', async () => {
162
+ const wrapper = mount(ToastItem, {
163
+ props: { toast: createToast({ duration: 5000 }) }
164
+ })
165
+
166
+ // Advance 2 seconds
167
+ vi.advanceTimersByTime(2000)
168
+
169
+ // Hover - pause the timer
170
+ await wrapper.find('.ui-toast').trigger('mouseenter')
171
+
172
+ // Advance past original duration
173
+ vi.advanceTimersByTime(10000)
174
+
175
+ // Should NOT have dismissed
176
+ expect(wrapper.emitted('dismiss')).toBeUndefined()
177
+ })
178
+
179
+ it('resumes timer on mouseleave', async () => {
180
+ const wrapper = mount(ToastItem, {
181
+ props: { toast: createToast({ duration: 5000 }) }
182
+ })
183
+
184
+ // Advance 2 seconds (3 seconds remaining)
185
+ vi.advanceTimersByTime(2000)
186
+
187
+ // Hover
188
+ await wrapper.find('.ui-toast').trigger('mouseenter')
189
+
190
+ // Wait a bit while hovering
191
+ vi.advanceTimersByTime(5000)
192
+
193
+ // Leave - resume timer with remaining time
194
+ await wrapper.find('.ui-toast').trigger('mouseleave')
195
+
196
+ // Should not dismiss yet (need ~3 more seconds)
197
+ expect(wrapper.emitted('dismiss')).toBeUndefined()
198
+
199
+ // Now advance the remaining time
200
+ vi.advanceTimersByTime(3000)
201
+
202
+ expect(wrapper.emitted('dismiss')).toHaveLength(1)
203
+ })
204
+
205
+ it('adds paused class to progress bar on hover', async () => {
206
+ const wrapper = mount(ToastItem, {
207
+ props: { toast: createToast({ duration: 5000 }) }
208
+ })
209
+
210
+ expect(wrapper.find('.ui-toast__progress').classes()).not.toContain('ui-toast__progress--paused')
211
+
212
+ await wrapper.find('.ui-toast').trigger('mouseenter')
213
+
214
+ expect(wrapper.find('.ui-toast__progress').classes()).toContain('ui-toast__progress--paused')
215
+
216
+ await wrapper.find('.ui-toast').trigger('mouseleave')
217
+
218
+ expect(wrapper.find('.ui-toast__progress').classes()).not.toContain('ui-toast__progress--paused')
219
+ })
220
+ })
221
+
222
+ describe('Accessibility', () => {
223
+ it('has role="alert" for error variant', () => {
224
+ const wrapper = mount(ToastItem, {
225
+ props: { toast: createToast({ variant: 'error' }) }
226
+ })
227
+ expect(wrapper.find('.ui-toast').attributes('role')).toBe('alert')
228
+ })
229
+
230
+ it('has role="status" for success variant', () => {
231
+ const wrapper = mount(ToastItem, {
232
+ props: { toast: createToast({ variant: 'success' }) }
233
+ })
234
+ expect(wrapper.find('.ui-toast').attributes('role')).toBe('status')
235
+ })
236
+
237
+ it('has role="status" for info variant', () => {
238
+ const wrapper = mount(ToastItem, {
239
+ props: { toast: createToast({ variant: 'info' }) }
240
+ })
241
+ expect(wrapper.find('.ui-toast').attributes('role')).toBe('status')
242
+ })
243
+
244
+ it('has role="status" for warning variant', () => {
245
+ const wrapper = mount(ToastItem, {
246
+ props: { toast: createToast({ variant: 'warning' }) }
247
+ })
248
+ expect(wrapper.find('.ui-toast').attributes('role')).toBe('status')
249
+ })
250
+
251
+ it('has aria-live="assertive" for error variant', () => {
252
+ const wrapper = mount(ToastItem, {
253
+ props: { toast: createToast({ variant: 'error' }) }
254
+ })
255
+ expect(wrapper.find('.ui-toast').attributes('aria-live')).toBe('assertive')
256
+ })
257
+
258
+ it('has aria-live="polite" for success variant', () => {
259
+ const wrapper = mount(ToastItem, {
260
+ props: { toast: createToast({ variant: 'success' }) }
261
+ })
262
+ expect(wrapper.find('.ui-toast').attributes('aria-live')).toBe('polite')
263
+ })
264
+
265
+ it('close button has aria-label', () => {
266
+ const wrapper = mount(ToastItem, {
267
+ props: { toast: createToast() }
268
+ })
269
+ expect(wrapper.find('.ui-toast__close').attributes('aria-label')).toBe('Dismiss notification')
270
+ })
271
+
272
+ it('icon is aria-hidden', () => {
273
+ const wrapper = mount(ToastItem, {
274
+ props: { toast: createToast() }
275
+ })
276
+ expect(wrapper.find('.ui-toast__icon').attributes('aria-hidden')).toBe('true')
277
+ })
278
+ })
279
+
280
+ describe('Progress bar styling', () => {
281
+ it('sets duration CSS variable', () => {
282
+ const wrapper = mount(ToastItem, {
283
+ props: { toast: createToast({ duration: 3000 }) }
284
+ })
285
+ const progress = wrapper.find('.ui-toast__progress')
286
+ expect(progress.attributes('style')).toContain('--toast-duration: 3000ms')
287
+ })
288
+ })
289
+ })
@@ -0,0 +1,370 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed, onMounted, onUnmounted } from 'vue'
3
+ import Avatar from '../Avatar/Avatar.vue'
4
+ import type { Toast, ToastVariant } from './toastState'
5
+
6
+ export interface ToastItemProps {
7
+ /** Toast data */
8
+ toast: Toast
9
+ }
10
+
11
+ const props = defineProps<ToastItemProps>()
12
+
13
+ const emit = defineEmits<{
14
+ (e: 'dismiss', id: string): void
15
+ }>()
16
+
17
+ const isPaused = ref(false)
18
+ const remainingTime = ref(props.toast.duration)
19
+ let timerId: ReturnType<typeof setTimeout> | null = null
20
+ let startTime = 0
21
+
22
+ const isClickable = computed(() => !!props.toast.onClick)
23
+
24
+ const hasAvatar = computed(() => !!props.toast.avatar)
25
+
26
+ const ariaRole = computed(() => {
27
+ return props.toast.variant === 'error' ? 'alert' : 'status'
28
+ })
29
+
30
+ const ariaLive = computed(() => {
31
+ return props.toast.variant === 'error' ? 'assertive' : 'polite'
32
+ })
33
+
34
+ function startTimer() {
35
+ if (props.toast.duration <= 0) return
36
+ if (remainingTime.value <= 0) return
37
+
38
+ startTime = Date.now()
39
+ timerId = setTimeout(() => {
40
+ emit('dismiss', props.toast.id)
41
+ }, remainingTime.value)
42
+ }
43
+
44
+ function pauseTimer() {
45
+ if (timerId) {
46
+ clearTimeout(timerId)
47
+ timerId = null
48
+ const elapsed = Date.now() - startTime
49
+ remainingTime.value = Math.max(0, remainingTime.value - elapsed)
50
+ }
51
+ }
52
+
53
+ function handleMouseEnter() {
54
+ isPaused.value = true
55
+ pauseTimer()
56
+ }
57
+
58
+ function handleMouseLeave() {
59
+ isPaused.value = false
60
+ startTimer()
61
+ }
62
+
63
+ function handleClose(event: Event) {
64
+ event.stopPropagation()
65
+ emit('dismiss', props.toast.id)
66
+ }
67
+
68
+ function handleBodyClick() {
69
+ if (props.toast.onClick) {
70
+ props.toast.onClick()
71
+ emit('dismiss', props.toast.id)
72
+ }
73
+ }
74
+
75
+ function handleActionClick(event: Event) {
76
+ event.stopPropagation()
77
+ if (props.toast.action) {
78
+ props.toast.action.onClick()
79
+ emit('dismiss', props.toast.id)
80
+ }
81
+ }
82
+
83
+ onMounted(() => {
84
+ startTimer()
85
+ })
86
+
87
+ onUnmounted(() => {
88
+ if (timerId) {
89
+ clearTimeout(timerId)
90
+ }
91
+ })
92
+
93
+ const iconPaths: Record<ToastVariant, string> = {
94
+ success: 'M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z',
95
+ error: 'M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z',
96
+ warning: 'M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z',
97
+ info: 'M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z'
98
+ }
99
+ </script>
100
+
101
+ <template>
102
+ <div
103
+ class="ui-toast"
104
+ :class="[
105
+ `ui-toast--${toast.variant}`,
106
+ { 'ui-toast--clickable': isClickable }
107
+ ]"
108
+ :role="ariaRole"
109
+ :aria-live="ariaLive"
110
+ @mouseenter="handleMouseEnter"
111
+ @mouseleave="handleMouseLeave"
112
+ @click="handleBodyClick"
113
+ >
114
+ <div v-if="hasAvatar" class="ui-toast__avatar">
115
+ <Avatar
116
+ :src="toast.avatar?.src"
117
+ :name="toast.avatar?.name"
118
+ size="sm"
119
+ />
120
+ </div>
121
+ <div v-else class="ui-toast__icon" aria-hidden="true">
122
+ <svg
123
+ viewBox="0 0 24 24"
124
+ fill="none"
125
+ stroke="currentColor"
126
+ stroke-width="2"
127
+ stroke-linecap="round"
128
+ stroke-linejoin="round"
129
+ >
130
+ <path :d="iconPaths[toast.variant]" />
131
+ </svg>
132
+ </div>
133
+
134
+ <div class="ui-toast__content">
135
+ <div v-if="toast.title" class="ui-toast__title">{{ toast.title }}</div>
136
+ <div v-if="toast.message" class="ui-toast__message">{{ toast.message }}</div>
137
+
138
+ <button
139
+ v-if="toast.action"
140
+ type="button"
141
+ class="ui-toast__action"
142
+ @click="handleActionClick"
143
+ >
144
+ {{ toast.action.label }}
145
+ </button>
146
+ </div>
147
+
148
+ <button
149
+ type="button"
150
+ class="ui-toast__close"
151
+ aria-label="Dismiss notification"
152
+ @click="handleClose"
153
+ >
154
+ <svg
155
+ viewBox="0 0 24 24"
156
+ fill="none"
157
+ stroke="currentColor"
158
+ stroke-width="2"
159
+ stroke-linecap="round"
160
+ stroke-linejoin="round"
161
+ aria-hidden="true"
162
+ >
163
+ <path d="M6 18L18 6M6 6l12 12" />
164
+ </svg>
165
+ </button>
166
+
167
+ <div
168
+ v-if="toast.duration > 0"
169
+ class="ui-toast__progress"
170
+ :class="{ 'ui-toast__progress--paused': isPaused }"
171
+ :style="{ '--toast-duration': `${toast.duration}ms` }"
172
+ />
173
+ </div>
174
+ </template>
175
+
176
+ <style scoped>
177
+ .ui-toast {
178
+ position: relative;
179
+ display: flex;
180
+ align-items: center;
181
+ gap: var(--space-3);
182
+ width: 100%;
183
+ max-width: 400px;
184
+ padding: var(--space-4);
185
+ background: var(--toast-bg);
186
+ border: 1px solid var(--toast-border);
187
+ border-radius: var(--radius-lg);
188
+ box-shadow: var(--shadow-lg);
189
+ overflow: hidden;
190
+ pointer-events: auto;
191
+ }
192
+
193
+ .ui-toast--clickable {
194
+ cursor: pointer;
195
+ transition: background-color var(--duration-fast) var(--ease-default);
196
+ }
197
+
198
+ .ui-toast--clickable:hover {
199
+ background: var(--toast-bg-hover, var(--color-stone-50));
200
+ }
201
+
202
+ .ui-toast__avatar {
203
+ flex-shrink: 0;
204
+ }
205
+
206
+ .ui-toast__icon {
207
+ flex-shrink: 0;
208
+ width: 1.25rem;
209
+ height: 1.25rem;
210
+ margin-top: 1px;
211
+ }
212
+
213
+ .ui-toast__icon svg {
214
+ width: 100%;
215
+ height: 100%;
216
+ }
217
+
218
+ .ui-toast__content {
219
+ flex: 1;
220
+ min-width: 0;
221
+ }
222
+
223
+ .ui-toast__title {
224
+ font-family: var(--font-sans);
225
+ font-size: var(--text-sm);
226
+ font-weight: var(--font-semibold);
227
+ color: var(--toast-title);
228
+ line-height: 1.4;
229
+ }
230
+
231
+ .ui-toast__message {
232
+ font-family: var(--font-sans);
233
+ font-size: var(--text-sm);
234
+ color: var(--toast-message);
235
+ line-height: 1.4;
236
+ margin-top: var(--space-1);
237
+ }
238
+
239
+ .ui-toast__title + .ui-toast__message {
240
+ margin-top: var(--space-1);
241
+ }
242
+
243
+ .ui-toast__action {
244
+ display: inline-block;
245
+ margin-top: var(--space-2);
246
+ padding: 0;
247
+ background: none;
248
+ border: none;
249
+ font-family: var(--font-sans);
250
+ font-size: var(--text-sm);
251
+ font-weight: var(--font-medium);
252
+ color: var(--toast-action);
253
+ cursor: pointer;
254
+ text-decoration: none;
255
+ transition: color var(--duration-fast) var(--ease-default);
256
+ }
257
+
258
+ .ui-toast__action:hover {
259
+ color: var(--toast-action-hover);
260
+ text-decoration: underline;
261
+ }
262
+
263
+ .ui-toast__action:focus-visible {
264
+ outline: 2px solid var(--ring-color);
265
+ outline-offset: 2px;
266
+ border-radius: var(--radius-sm);
267
+ }
268
+
269
+ .ui-toast__close {
270
+ flex-shrink: 0;
271
+ display: flex;
272
+ align-items: center;
273
+ justify-content: center;
274
+ width: 1.5rem;
275
+ height: 1.5rem;
276
+ padding: 0;
277
+ margin: -0.25rem -0.25rem -0.25rem 0;
278
+ background: transparent;
279
+ border: none;
280
+ border-radius: var(--radius-sm);
281
+ color: var(--toast-close);
282
+ cursor: pointer;
283
+ transition:
284
+ background-color var(--duration-fast) var(--ease-default),
285
+ color var(--duration-fast) var(--ease-default);
286
+ }
287
+
288
+ .ui-toast__close:hover {
289
+ background: var(--toast-close-hover-bg);
290
+ color: var(--toast-close-hover);
291
+ }
292
+
293
+ .ui-toast__close:focus-visible {
294
+ outline: 2px solid var(--ring-color);
295
+ outline-offset: 2px;
296
+ }
297
+
298
+ .ui-toast__close svg {
299
+ width: 1rem;
300
+ height: 1rem;
301
+ }
302
+
303
+ .ui-toast__progress {
304
+ position: absolute;
305
+ bottom: 0;
306
+ left: 0;
307
+ right: 0;
308
+ height: 3px;
309
+ background: var(--toast-progress);
310
+ transform-origin: left;
311
+ animation: toast-progress var(--toast-duration) linear forwards;
312
+ }
313
+
314
+ .ui-toast__progress--paused {
315
+ animation-play-state: paused;
316
+ }
317
+
318
+ @keyframes toast-progress {
319
+ from {
320
+ transform: scaleX(1);
321
+ }
322
+ to {
323
+ transform: scaleX(0);
324
+ }
325
+ }
326
+
327
+ .ui-toast--success {
328
+ --toast-icon: var(--toast-success-icon);
329
+ --toast-progress: var(--toast-success-progress);
330
+ --toast-action: var(--toast-success-icon);
331
+ --toast-action-hover: var(--color-teal-700);
332
+ }
333
+
334
+ .ui-toast--success .ui-toast__icon {
335
+ color: var(--toast-icon);
336
+ }
337
+
338
+ .ui-toast--error {
339
+ --toast-icon: var(--toast-error-icon);
340
+ --toast-progress: var(--toast-error-progress);
341
+ --toast-action: var(--toast-error-icon);
342
+ --toast-action-hover: var(--color-coral-700);
343
+ }
344
+
345
+ .ui-toast--error .ui-toast__icon {
346
+ color: var(--toast-icon);
347
+ }
348
+
349
+ .ui-toast--warning {
350
+ --toast-icon: var(--toast-warning-icon);
351
+ --toast-progress: var(--toast-warning-progress);
352
+ --toast-action: var(--toast-warning-icon);
353
+ --toast-action-hover: var(--color-amber-600);
354
+ }
355
+
356
+ .ui-toast--warning .ui-toast__icon {
357
+ color: var(--toast-icon);
358
+ }
359
+
360
+ .ui-toast--info {
361
+ --toast-icon: var(--toast-info-icon);
362
+ --toast-progress: var(--toast-info-progress);
363
+ --toast-action: var(--toast-info-icon);
364
+ --toast-action-hover: var(--color-indigo-700);
365
+ }
366
+
367
+ .ui-toast--info .ui-toast__icon {
368
+ color: var(--toast-icon);
369
+ }
370
+ </style>