@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,158 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import ToastProvider from './ToastProvider.vue'
4
+ import { toastActions } from './toastState'
5
+
6
+ describe('ToastProvider', () => {
7
+ beforeEach(() => {
8
+ toastActions.clear()
9
+ })
10
+
11
+ describe('Rendering', () => {
12
+ it('renders provider container', () => {
13
+ const wrapper = mount(ToastProvider, {
14
+ global: {
15
+ stubs: {
16
+ Teleport: true
17
+ }
18
+ }
19
+ })
20
+ expect(wrapper.find('.ui-toast-provider').exists()).toBe(true)
21
+ })
22
+
23
+ it('renders toasts from state', () => {
24
+ toastActions.success('Toast 1')
25
+ toastActions.error('Toast 2')
26
+
27
+ const wrapper = mount(ToastProvider, {
28
+ global: {
29
+ stubs: {
30
+ Teleport: true
31
+ }
32
+ }
33
+ })
34
+
35
+ const toasts = wrapper.findAll('.ui-toast')
36
+ expect(toasts.length).toBe(2)
37
+ })
38
+ })
39
+
40
+ describe('Positions', () => {
41
+ it('applies top-right position by default', () => {
42
+ const wrapper = mount(ToastProvider, {
43
+ global: {
44
+ stubs: {
45
+ Teleport: true
46
+ }
47
+ }
48
+ })
49
+ expect(wrapper.find('.ui-toast-provider').classes()).toContain('ui-toast-provider--top-right')
50
+ })
51
+
52
+ it('applies top-left position', () => {
53
+ const wrapper = mount(ToastProvider, {
54
+ props: { position: 'top-left' },
55
+ global: {
56
+ stubs: {
57
+ Teleport: true
58
+ }
59
+ }
60
+ })
61
+ expect(wrapper.find('.ui-toast-provider').classes()).toContain('ui-toast-provider--top-left')
62
+ })
63
+
64
+ it('applies bottom-right position', () => {
65
+ const wrapper = mount(ToastProvider, {
66
+ props: { position: 'bottom-right' },
67
+ global: {
68
+ stubs: {
69
+ Teleport: true
70
+ }
71
+ }
72
+ })
73
+ expect(wrapper.find('.ui-toast-provider').classes()).toContain('ui-toast-provider--bottom-right')
74
+ })
75
+
76
+ it('applies bottom-left position', () => {
77
+ const wrapper = mount(ToastProvider, {
78
+ props: { position: 'bottom-left' },
79
+ global: {
80
+ stubs: {
81
+ Teleport: true
82
+ }
83
+ }
84
+ })
85
+ expect(wrapper.find('.ui-toast-provider').classes()).toContain('ui-toast-provider--bottom-left')
86
+ })
87
+
88
+ it('applies top-center position', () => {
89
+ const wrapper = mount(ToastProvider, {
90
+ props: { position: 'top-center' },
91
+ global: {
92
+ stubs: {
93
+ Teleport: true
94
+ }
95
+ }
96
+ })
97
+ expect(wrapper.find('.ui-toast-provider').classes()).toContain('ui-toast-provider--top-center')
98
+ })
99
+
100
+ it('applies bottom-center position', () => {
101
+ const wrapper = mount(ToastProvider, {
102
+ props: { position: 'bottom-center' },
103
+ global: {
104
+ stubs: {
105
+ Teleport: true
106
+ }
107
+ }
108
+ })
109
+ expect(wrapper.find('.ui-toast-provider').classes()).toContain('ui-toast-provider--bottom-center')
110
+ })
111
+ })
112
+
113
+ describe('Accessibility', () => {
114
+ it('has role="region"', () => {
115
+ const wrapper = mount(ToastProvider, {
116
+ global: {
117
+ stubs: {
118
+ Teleport: true
119
+ }
120
+ }
121
+ })
122
+ expect(wrapper.find('.ui-toast-provider').attributes('role')).toBe('region')
123
+ })
124
+
125
+ it('has aria-label="Notifications"', () => {
126
+ const wrapper = mount(ToastProvider, {
127
+ global: {
128
+ stubs: {
129
+ Teleport: true
130
+ }
131
+ }
132
+ })
133
+ expect(wrapper.find('.ui-toast-provider').attributes('aria-label')).toBe('Notifications')
134
+ })
135
+ })
136
+
137
+ describe('Dismiss handling', () => {
138
+ it('removes toast when dismiss event is emitted', async () => {
139
+ const id = toastActions.success('Test toast')
140
+
141
+ const wrapper = mount(ToastProvider, {
142
+ global: {
143
+ stubs: {
144
+ Teleport: true
145
+ }
146
+ }
147
+ })
148
+
149
+ expect(wrapper.findAll('.ui-toast').length).toBe(1)
150
+
151
+ // Find the close button and click it
152
+ await wrapper.find('.ui-toast__close').trigger('click')
153
+
154
+ // Toast should be removed
155
+ expect(wrapper.findAll('.ui-toast').length).toBe(0)
156
+ })
157
+ })
158
+ })
@@ -0,0 +1,181 @@
1
+ <script setup lang="ts">
2
+ import { toasts, toastActions } from './toastState'
3
+ import ToastItem from './ToastItem.vue'
4
+
5
+ export interface ToastProviderProps {
6
+ /** Position of the toast container */
7
+ position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center'
8
+ }
9
+
10
+ withDefaults(defineProps<ToastProviderProps>(), {
11
+ position: 'top-right'
12
+ })
13
+
14
+ function handleDismiss(id: string) {
15
+ toastActions.remove(id)
16
+ }
17
+ </script>
18
+
19
+ <template>
20
+ <Teleport to="body">
21
+ <div
22
+ class="ui-toast-provider"
23
+ :class="[`ui-toast-provider--${position}`]"
24
+ role="region"
25
+ aria-label="Notifications"
26
+ >
27
+ <TransitionGroup name="toast">
28
+ <ToastItem
29
+ v-for="toast in toasts"
30
+ :key="toast.id"
31
+ :toast="toast"
32
+ @dismiss="handleDismiss"
33
+ />
34
+ </TransitionGroup>
35
+ </div>
36
+ </Teleport>
37
+ </template>
38
+
39
+ <style scoped>
40
+ .ui-toast-provider {
41
+ position: fixed;
42
+ z-index: 9999;
43
+ display: flex;
44
+ flex-direction: column;
45
+ gap: var(--space-3);
46
+ padding: var(--space-4);
47
+ pointer-events: none;
48
+ }
49
+
50
+ .ui-toast-provider--top-right {
51
+ top: 0;
52
+ right: 0;
53
+ align-items: flex-end;
54
+ }
55
+
56
+ .ui-toast-provider--top-left {
57
+ top: 0;
58
+ left: 0;
59
+ align-items: flex-start;
60
+ }
61
+
62
+ .ui-toast-provider--bottom-right {
63
+ bottom: 0;
64
+ right: 0;
65
+ align-items: flex-end;
66
+ flex-direction: column-reverse;
67
+ }
68
+
69
+ .ui-toast-provider--bottom-left {
70
+ bottom: 0;
71
+ left: 0;
72
+ align-items: flex-start;
73
+ flex-direction: column-reverse;
74
+ }
75
+
76
+ .ui-toast-provider--top-center {
77
+ top: 0;
78
+ left: 50%;
79
+ transform: translateX(-50%);
80
+ align-items: center;
81
+ }
82
+
83
+ .ui-toast-provider--bottom-center {
84
+ bottom: 0;
85
+ left: 50%;
86
+ transform: translateX(-50%);
87
+ align-items: center;
88
+ flex-direction: column-reverse;
89
+ }
90
+
91
+ .toast-enter-from {
92
+ opacity: 0;
93
+ transform: translateX(100%);
94
+ }
95
+
96
+ .toast-enter-active {
97
+ transition:
98
+ opacity var(--duration-normal) var(--ease-out),
99
+ transform var(--duration-normal) var(--ease-out-back);
100
+ }
101
+
102
+ .toast-enter-to {
103
+ opacity: 1;
104
+ transform: translateX(0);
105
+ }
106
+
107
+ .toast-leave-from {
108
+ opacity: 1;
109
+ transform: scale(1);
110
+ }
111
+
112
+ .toast-leave-active {
113
+ position: absolute;
114
+ transition:
115
+ opacity var(--duration-fast) var(--ease-default),
116
+ transform var(--duration-fast) var(--ease-default);
117
+ }
118
+
119
+ .toast-leave-to {
120
+ opacity: 0;
121
+ transform: scale(0.9);
122
+ }
123
+
124
+ .toast-move {
125
+ transition: transform var(--duration-normal) var(--ease-out);
126
+ }
127
+
128
+ .ui-toast-provider--top-left .toast-enter-from,
129
+ .ui-toast-provider--bottom-left .toast-enter-from {
130
+ transform: translateX(-100%);
131
+ }
132
+
133
+ .ui-toast-provider--top-center .toast-enter-from,
134
+ .ui-toast-provider--bottom-center .toast-enter-from {
135
+ transform: translateY(-100%) scale(0.9);
136
+ }
137
+
138
+ .ui-toast-provider--bottom-right .toast-enter-from,
139
+ .ui-toast-provider--bottom-left .toast-enter-from {
140
+ transform: translateY(100%);
141
+ }
142
+
143
+ .ui-toast-provider--bottom-right .toast-enter-from {
144
+ transform: translateX(100%);
145
+ }
146
+
147
+ @media (max-width: 480px) {
148
+ .ui-toast-provider {
149
+ left: 0 !important;
150
+ right: 0 !important;
151
+ transform: none !important;
152
+ padding: var(--space-3);
153
+ }
154
+
155
+ .ui-toast-provider--top-right,
156
+ .ui-toast-provider--top-left,
157
+ .ui-toast-provider--top-center {
158
+ top: 0;
159
+ bottom: auto;
160
+ align-items: stretch;
161
+ }
162
+
163
+ .ui-toast-provider--bottom-right,
164
+ .ui-toast-provider--bottom-left,
165
+ .ui-toast-provider--bottom-center {
166
+ bottom: 0;
167
+ top: auto;
168
+ align-items: stretch;
169
+ }
170
+
171
+ .toast-enter-from {
172
+ transform: translateY(-20px);
173
+ }
174
+
175
+ .ui-toast-provider--bottom-right .toast-enter-from,
176
+ .ui-toast-provider--bottom-left .toast-enter-from,
177
+ .ui-toast-provider--bottom-center .toast-enter-from {
178
+ transform: translateY(20px);
179
+ }
180
+ }
181
+ </style>
@@ -0,0 +1,83 @@
1
+ export { default as ToastProvider } from './ToastProvider.vue'
2
+ export type { ToastProviderProps } from './ToastProvider.vue'
3
+
4
+ export { default as ToastItem } from './ToastItem.vue'
5
+ export type { ToastItemProps } from './ToastItem.vue'
6
+
7
+ import { toastActions } from './toastState'
8
+ export { toasts, toastActions } from './toastState'
9
+ export type { Toast, ToastOptions, ToastVariant, ToastAction } from './toastState'
10
+
11
+ /**
12
+ * Composable for triggering toast notifications.
13
+ * Can be used anywhere - components, stores, API interceptors.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const toast = useToast()
18
+ *
19
+ * // Simple usage
20
+ * toast.success('Saved!')
21
+ * toast.error('Something went wrong')
22
+ *
23
+ * // With message
24
+ * toast.success('Profile updated', { message: 'Your changes have been saved.' })
25
+ *
26
+ * // Custom duration (ms)
27
+ * toast.info('Heads up', { duration: 10000 })
28
+ *
29
+ * // No auto-dismiss
30
+ * toast.warning('Action required', { duration: 0 })
31
+ *
32
+ * // Manual dismiss
33
+ * const id = toast.info('Processing...')
34
+ * // later...
35
+ * toast.dismiss(id)
36
+ * ```
37
+ */
38
+ export function useToast() {
39
+ return {
40
+ /**
41
+ * Show a success toast
42
+ * @param title - Toast title
43
+ * @param options - Additional options (message, duration)
44
+ * @returns Toast ID for manual dismissal
45
+ */
46
+ success: toastActions.success,
47
+
48
+ /**
49
+ * Show an error toast
50
+ * @param title - Toast title
51
+ * @param options - Additional options (message, duration)
52
+ * @returns Toast ID for manual dismissal
53
+ */
54
+ error: toastActions.error,
55
+
56
+ /**
57
+ * Show a warning toast
58
+ * @param title - Toast title
59
+ * @param options - Additional options (message, duration)
60
+ * @returns Toast ID for manual dismissal
61
+ */
62
+ warning: toastActions.warning,
63
+
64
+ /**
65
+ * Show an info toast
66
+ * @param title - Toast title
67
+ * @param options - Additional options (message, duration)
68
+ * @returns Toast ID for manual dismissal
69
+ */
70
+ info: toastActions.info,
71
+
72
+ /**
73
+ * Dismiss a specific toast
74
+ * @param id - Toast ID returned from success/error/warning/info
75
+ */
76
+ dismiss: toastActions.remove,
77
+
78
+ /**
79
+ * Dismiss all toasts
80
+ */
81
+ clear: toastActions.clear
82
+ }
83
+ }
@@ -0,0 +1,165 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest'
2
+ import { toasts, toastActions } from './toastState'
3
+
4
+ describe('toastState', () => {
5
+ beforeEach(() => {
6
+ // Clear all toasts before each test
7
+ toastActions.clear()
8
+ })
9
+
10
+ describe('add', () => {
11
+ it('adds a toast with required properties', () => {
12
+ const id = toastActions.add({ variant: 'success', title: 'Test' })
13
+
14
+ expect(toasts.length).toBe(1)
15
+ expect(toasts[0].id).toBe(id)
16
+ expect(toasts[0].variant).toBe('success')
17
+ expect(toasts[0].title).toBe('Test')
18
+ })
19
+
20
+ it('adds toast with message', () => {
21
+ toastActions.add({ variant: 'info', title: 'Title', message: 'Description' })
22
+
23
+ expect(toasts[0].message).toBe('Description')
24
+ })
25
+
26
+ it('uses default duration of 5000ms', () => {
27
+ toastActions.add({ variant: 'success', title: 'Test' })
28
+
29
+ expect(toasts[0].duration).toBe(5000)
30
+ })
31
+
32
+ it('uses custom duration', () => {
33
+ toastActions.add({ variant: 'success', title: 'Test', duration: 10000 })
34
+
35
+ expect(toasts[0].duration).toBe(10000)
36
+ })
37
+
38
+ it('generates unique IDs', () => {
39
+ const id1 = toastActions.add({ variant: 'success', title: 'Test 1' })
40
+ const id2 = toastActions.add({ variant: 'success', title: 'Test 2' })
41
+
42
+ expect(id1).not.toBe(id2)
43
+ })
44
+
45
+ it('sets createdAt timestamp', () => {
46
+ const before = Date.now()
47
+ toastActions.add({ variant: 'success', title: 'Test' })
48
+ const after = Date.now()
49
+
50
+ expect(toasts[0].createdAt).toBeGreaterThanOrEqual(before)
51
+ expect(toasts[0].createdAt).toBeLessThanOrEqual(after)
52
+ })
53
+
54
+ it('enforces max limit of 5 toasts', () => {
55
+ for (let i = 0; i < 7; i++) {
56
+ toastActions.add({ variant: 'info', title: `Toast ${i}` })
57
+ }
58
+
59
+ expect(toasts.length).toBe(5)
60
+ // Oldest should be removed
61
+ expect(toasts[0].title).toBe('Toast 2')
62
+ expect(toasts[4].title).toBe('Toast 6')
63
+ })
64
+
65
+ it('returns toast ID', () => {
66
+ const id = toastActions.add({ variant: 'success', title: 'Test' })
67
+
68
+ expect(typeof id).toBe('string')
69
+ expect(id.length).toBeGreaterThan(0)
70
+ })
71
+ })
72
+
73
+ describe('remove', () => {
74
+ it('removes toast by ID', () => {
75
+ const id = toastActions.add({ variant: 'success', title: 'Test' })
76
+ expect(toasts.length).toBe(1)
77
+
78
+ toastActions.remove(id)
79
+ expect(toasts.length).toBe(0)
80
+ })
81
+
82
+ it('does nothing if ID not found', () => {
83
+ toastActions.add({ variant: 'success', title: 'Test' })
84
+ expect(toasts.length).toBe(1)
85
+
86
+ toastActions.remove('non-existent-id')
87
+ expect(toasts.length).toBe(1)
88
+ })
89
+
90
+ it('removes correct toast from multiple', () => {
91
+ toastActions.add({ variant: 'success', title: 'Toast 1' })
92
+ const id2 = toastActions.add({ variant: 'error', title: 'Toast 2' })
93
+ toastActions.add({ variant: 'info', title: 'Toast 3' })
94
+
95
+ toastActions.remove(id2)
96
+
97
+ expect(toasts.length).toBe(2)
98
+ expect(toasts[0].title).toBe('Toast 1')
99
+ expect(toasts[1].title).toBe('Toast 3')
100
+ })
101
+ })
102
+
103
+ describe('clear', () => {
104
+ it('removes all toasts', () => {
105
+ toastActions.add({ variant: 'success', title: 'Test 1' })
106
+ toastActions.add({ variant: 'error', title: 'Test 2' })
107
+ toastActions.add({ variant: 'info', title: 'Test 3' })
108
+ expect(toasts.length).toBe(3)
109
+
110
+ toastActions.clear()
111
+ expect(toasts.length).toBe(0)
112
+ })
113
+
114
+ it('does nothing if already empty', () => {
115
+ expect(toasts.length).toBe(0)
116
+ toastActions.clear()
117
+ expect(toasts.length).toBe(0)
118
+ })
119
+ })
120
+
121
+ describe('convenience methods', () => {
122
+ it('success() creates success toast', () => {
123
+ toastActions.success('Success!')
124
+
125
+ expect(toasts[0].variant).toBe('success')
126
+ expect(toasts[0].title).toBe('Success!')
127
+ })
128
+
129
+ it('error() creates error toast', () => {
130
+ toastActions.error('Error!')
131
+
132
+ expect(toasts[0].variant).toBe('error')
133
+ expect(toasts[0].title).toBe('Error!')
134
+ })
135
+
136
+ it('warning() creates warning toast', () => {
137
+ toastActions.warning('Warning!')
138
+
139
+ expect(toasts[0].variant).toBe('warning')
140
+ expect(toasts[0].title).toBe('Warning!')
141
+ })
142
+
143
+ it('info() creates info toast', () => {
144
+ toastActions.info('Info!')
145
+
146
+ expect(toasts[0].variant).toBe('info')
147
+ expect(toasts[0].title).toBe('Info!')
148
+ })
149
+
150
+ it('convenience methods accept options', () => {
151
+ toastActions.success('Title', { message: 'Message', duration: 3000 })
152
+
153
+ expect(toasts[0].title).toBe('Title')
154
+ expect(toasts[0].message).toBe('Message')
155
+ expect(toasts[0].duration).toBe(3000)
156
+ })
157
+
158
+ it('convenience methods return ID', () => {
159
+ const id = toastActions.success('Test')
160
+
161
+ expect(typeof id).toBe('string')
162
+ expect(toasts[0].id).toBe(id)
163
+ })
164
+ })
165
+ })