@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,231 @@
1
+ import { describe, it, expect, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { h, defineComponent, markRaw } from 'vue'
4
+ import Button from './Button.vue'
5
+
6
+ // Mock icon component
7
+ const MockIcon = markRaw(defineComponent({
8
+ name: 'MockIcon',
9
+ render() {
10
+ return h('svg', { 'data-testid': 'mock-icon' })
11
+ }
12
+ }))
13
+
14
+ describe('Button', () => {
15
+ describe('Rendering', () => {
16
+ it('renders as button by default', () => {
17
+ const wrapper = mount(Button, {
18
+ slots: { default: 'Click me' }
19
+ })
20
+ expect(wrapper.element.tagName.toLowerCase()).toBe('button')
21
+ })
22
+
23
+ it('renders slot content', () => {
24
+ const wrapper = mount(Button, {
25
+ slots: { default: 'Click me' }
26
+ })
27
+ expect(wrapper.text()).toContain('Click me')
28
+ })
29
+
30
+ it('renders as custom element via "as" prop', () => {
31
+ const wrapper = mount(Button, {
32
+ props: { as: 'a' },
33
+ slots: { default: 'Link' }
34
+ })
35
+ expect(wrapper.element.tagName.toLowerCase()).toBe('a')
36
+ })
37
+
38
+ it('has type="button" by default', () => {
39
+ const wrapper = mount(Button)
40
+ expect(wrapper.attributes('type')).toBe('button')
41
+ })
42
+
43
+ it('accepts type prop', () => {
44
+ const wrapper = mount(Button, {
45
+ props: { type: 'submit' }
46
+ })
47
+ expect(wrapper.attributes('type')).toBe('submit')
48
+ })
49
+ })
50
+
51
+ describe('Variants', () => {
52
+ const variants = ['primary', 'secondary', 'destructive', 'ghost', 'outline'] as const
53
+
54
+ variants.forEach(variant => {
55
+ it(`applies ${variant} variant class`, () => {
56
+ const wrapper = mount(Button, {
57
+ props: { variant },
58
+ slots: { default: 'Button' }
59
+ })
60
+ expect(wrapper.classes()).toContain(`ui-button--${variant}`)
61
+ })
62
+ })
63
+
64
+ it('defaults to primary variant', () => {
65
+ const wrapper = mount(Button)
66
+ expect(wrapper.classes()).toContain('ui-button--primary')
67
+ })
68
+ })
69
+
70
+ describe('Sizes', () => {
71
+ const sizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const
72
+
73
+ sizes.forEach(size => {
74
+ it(`applies ${size} size class`, () => {
75
+ const wrapper = mount(Button, {
76
+ props: { size },
77
+ slots: { default: 'Button' }
78
+ })
79
+ expect(wrapper.classes()).toContain(`ui-button--${size}`)
80
+ })
81
+ })
82
+
83
+ it('defaults to md size', () => {
84
+ const wrapper = mount(Button)
85
+ expect(wrapper.classes()).toContain('ui-button--md')
86
+ })
87
+ })
88
+
89
+ describe('Disabled state', () => {
90
+ it('applies disabled class when disabled', () => {
91
+ const wrapper = mount(Button, {
92
+ props: { disabled: true }
93
+ })
94
+ expect(wrapper.classes()).toContain('ui-button--disabled')
95
+ })
96
+
97
+ it('sets disabled attribute on button', () => {
98
+ const wrapper = mount(Button, {
99
+ props: { disabled: true }
100
+ })
101
+ expect(wrapper.attributes('disabled')).toBeDefined()
102
+ })
103
+
104
+ it('sets aria-disabled when disabled', () => {
105
+ const wrapper = mount(Button, {
106
+ props: { disabled: true }
107
+ })
108
+ expect(wrapper.attributes('aria-disabled')).toBe('true')
109
+ })
110
+
111
+ it('does not emit click when disabled', async () => {
112
+ const wrapper = mount(Button, {
113
+ props: { disabled: true }
114
+ })
115
+ await wrapper.trigger('click')
116
+ expect(wrapper.emitted('click')).toBeUndefined()
117
+ })
118
+ })
119
+
120
+ describe('Loading state', () => {
121
+ it('applies loading class when loading', () => {
122
+ const wrapper = mount(Button, {
123
+ props: { loading: true }
124
+ })
125
+ expect(wrapper.classes()).toContain('ui-button--loading')
126
+ })
127
+
128
+ it('shows spinner when loading', () => {
129
+ const wrapper = mount(Button, {
130
+ props: { loading: true }
131
+ })
132
+ expect(wrapper.find('.ui-button__loader').exists()).toBe(true)
133
+ })
134
+
135
+ it('sets aria-busy when loading', () => {
136
+ const wrapper = mount(Button, {
137
+ props: { loading: true }
138
+ })
139
+ expect(wrapper.attributes('aria-busy')).toBe('true')
140
+ })
141
+
142
+ it('is disabled when loading', () => {
143
+ const wrapper = mount(Button, {
144
+ props: { loading: true }
145
+ })
146
+ expect(wrapper.attributes('aria-disabled')).toBe('true')
147
+ })
148
+
149
+ it('does not emit click when loading', async () => {
150
+ const wrapper = mount(Button, {
151
+ props: { loading: true }
152
+ })
153
+ await wrapper.trigger('click')
154
+ expect(wrapper.emitted('click')).toBeUndefined()
155
+ })
156
+ })
157
+
158
+ describe('Icons', () => {
159
+ it('renders left icon', () => {
160
+ const wrapper = mount(Button, {
161
+ props: { iconLeft: MockIcon },
162
+ slots: { default: 'Button' }
163
+ })
164
+ expect(wrapper.find('.ui-button__icon--left').exists()).toBe(true)
165
+ })
166
+
167
+ it('renders right icon', () => {
168
+ const wrapper = mount(Button, {
169
+ props: { iconRight: MockIcon },
170
+ slots: { default: 'Button' }
171
+ })
172
+ expect(wrapper.find('.ui-button__icon--right').exists()).toBe(true)
173
+ })
174
+
175
+ it('applies icon-only class when only icon provided', () => {
176
+ const wrapper = mount(Button, {
177
+ props: { iconLeft: MockIcon }
178
+ })
179
+ expect(wrapper.classes()).toContain('ui-button--icon-only')
180
+ })
181
+
182
+ it('keeps icon in DOM but fades content when loading (overlay pattern)', () => {
183
+ const wrapper = mount(Button, {
184
+ props: { iconLeft: MockIcon, loading: true },
185
+ slots: { default: 'Button' }
186
+ })
187
+ // Icon stays in DOM to preserve width
188
+ expect(wrapper.find('.ui-button__icon--left').exists()).toBe(true)
189
+ // Inner content has hidden class (opacity: 0)
190
+ expect(wrapper.find('.ui-button__inner--hidden').exists()).toBe(true)
191
+ // Spinner overlay is shown
192
+ expect(wrapper.find('.ui-button__loader').exists()).toBe(true)
193
+ })
194
+ })
195
+
196
+ describe('Block mode', () => {
197
+ it('applies block class when block prop is true', () => {
198
+ const wrapper = mount(Button, {
199
+ props: { block: true }
200
+ })
201
+ expect(wrapper.classes()).toContain('ui-button--block')
202
+ })
203
+ })
204
+
205
+ describe('Events', () => {
206
+ it('emits click event', async () => {
207
+ const wrapper = mount(Button)
208
+ await wrapper.trigger('click')
209
+ expect(wrapper.emitted('click')).toHaveLength(1)
210
+ })
211
+
212
+ it('passes event object to click handler', async () => {
213
+ const wrapper = mount(Button)
214
+ await wrapper.trigger('click')
215
+ const emitted = wrapper.emitted('click')
216
+ expect(emitted?.[0]?.[0]).toBeInstanceOf(MouseEvent)
217
+ })
218
+ })
219
+
220
+ describe('Accessibility', () => {
221
+ it('has highlight element for visual effect', () => {
222
+ const wrapper = mount(Button)
223
+ expect(wrapper.find('.ui-button__highlight').exists()).toBe(true)
224
+ })
225
+
226
+ it('highlight is hidden from screen readers', () => {
227
+ const wrapper = mount(Button)
228
+ expect(wrapper.find('.ui-button__highlight').attributes('aria-hidden')).toBe('true')
229
+ })
230
+ })
231
+ })
@@ -0,0 +1,349 @@
1
+ <script setup lang="ts">
2
+ import { computed, useSlots, type Component, type Slots } from 'vue'
3
+ import Spinner from '../Spinner/Spinner.vue'
4
+ import Icon from '../Icon/Icon.vue'
5
+ import type { IconInput } from '../Icon/Icon.vue'
6
+
7
+ export interface ButtonProps {
8
+ /** Visual style variant */
9
+ variant?: 'primary' | 'secondary' | 'destructive' | 'ghost' | 'outline'
10
+ /** Button size */
11
+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
12
+ /** Render as different element or component (e.g., router-link) */
13
+ as?: string | Component
14
+ /** Show loading spinner and disable interactions */
15
+ loading?: boolean
16
+ /** Disable button */
17
+ disabled?: boolean
18
+ /** Icon to show before text (any format supported by Icon component) */
19
+ iconLeft?: IconInput
20
+ /** Icon to show after text (any format supported by Icon component) */
21
+ iconRight?: IconInput
22
+ /** Make button full width */
23
+ block?: boolean
24
+ /** Button type attribute */
25
+ type?: 'button' | 'submit' | 'reset'
26
+ }
27
+
28
+ const props = withDefaults(defineProps<ButtonProps>(), {
29
+ variant: 'primary',
30
+ size: 'md',
31
+ as: 'button',
32
+ type: 'button',
33
+ loading: false,
34
+ disabled: false,
35
+ block: false
36
+ })
37
+
38
+ const emit = defineEmits<{
39
+ (e: 'click', event: MouseEvent): void
40
+ }>()
41
+
42
+ const slots: Slots = useSlots()
43
+
44
+ const isDisabled = computed<boolean>(() => props.disabled || props.loading)
45
+ const hasIconOnly = computed<boolean>(() => !slots.default && !!(props.iconLeft || props.iconRight))
46
+
47
+ function handleClick(event: MouseEvent) {
48
+ if (isDisabled.value) {
49
+ event.preventDefault()
50
+ return
51
+ }
52
+ emit('click', event)
53
+ }
54
+
55
+ const iconSizeMap: Record<string, string> = {
56
+ xs: 'var(--text-xs)',
57
+ sm: 'var(--text-sm)',
58
+ md: 'var(--text-md)',
59
+ lg: 'var(--text-lg)',
60
+ xl: 'var(--text-xl)'
61
+ }
62
+
63
+ const iconSize = computed(() => iconSizeMap[props.size])
64
+ </script>
65
+
66
+ <template>
67
+ <component
68
+ :is="as"
69
+ :type="as === 'button' ? type : undefined"
70
+ :disabled="as === 'button' ? isDisabled : undefined"
71
+ :aria-disabled="isDisabled"
72
+ :aria-busy="loading"
73
+ class="ui-button"
74
+ :class="[
75
+ `ui-button--${variant}`,
76
+ `ui-button--${size}`,
77
+ {
78
+ 'ui-button--loading': loading,
79
+ 'ui-button--disabled': isDisabled,
80
+ 'ui-button--block': block,
81
+ 'ui-button--icon-only': hasIconOnly
82
+ }
83
+ ]"
84
+ @click="handleClick"
85
+ >
86
+ <span class="ui-button__highlight" aria-hidden="true" />
87
+
88
+ <span class="ui-button__inner" :class="{ 'ui-button__inner--hidden': loading }">
89
+ <span v-if="iconLeft" class="ui-button__icon ui-button__icon--left" aria-hidden="true">
90
+ <Icon :icon="iconLeft" :size="iconSize" />
91
+ </span>
92
+
93
+ <span v-if="$slots.default" class="ui-button__content">
94
+ <slot />
95
+ </span>
96
+
97
+ <span v-if="iconRight" class="ui-button__icon ui-button__icon--right" aria-hidden="true">
98
+ <Icon :icon="iconRight" :size="iconSize" />
99
+ </span>
100
+ </span>
101
+
102
+ <span v-if="loading" class="ui-button__loader" aria-hidden="true">
103
+ <Spinner :size="iconSize" :speed="0.8" label="Loading" />
104
+ </span>
105
+ </component>
106
+ </template>
107
+
108
+ <style scoped>
109
+ .ui-button {
110
+ position: relative;
111
+ display: inline-flex;
112
+ align-items: center;
113
+ justify-content: center;
114
+ font-family: var(--font-sans);
115
+ font-weight: var(--font-medium);
116
+ text-decoration: none;
117
+ white-space: nowrap;
118
+ cursor: pointer;
119
+ user-select: none;
120
+ overflow: hidden;
121
+ transition:
122
+ background-color var(--transition-fast) var(--ease-default),
123
+ box-shadow var(--transition-fast) var(--ease-default),
124
+ transform var(--transition-fast) var(--ease-default);
125
+ }
126
+
127
+ .ui-button__highlight {
128
+ position: absolute;
129
+ inset: 0;
130
+ background: linear-gradient(
131
+ to bottom,
132
+ oklch(1 0 0 / var(--depth-highlight-opacity, 0.12)),
133
+ transparent 25%
134
+ );
135
+ pointer-events: none;
136
+ border-radius: inherit;
137
+ }
138
+
139
+ .ui-button__inner {
140
+ display: inline-flex;
141
+ align-items: center;
142
+ justify-content: center;
143
+ gap: var(--space-2);
144
+ transition: opacity var(--transition-fast) var(--ease-default);
145
+ }
146
+
147
+ .ui-button__inner--hidden {
148
+ opacity: 0;
149
+ }
150
+
151
+ .ui-button__loader {
152
+ position: absolute;
153
+ inset: 0;
154
+ display: flex;
155
+ align-items: center;
156
+ justify-content: center;
157
+ }
158
+
159
+ .ui-button--xs {
160
+ height: var(--input-height-xs);
161
+ padding: 0 var(--space-1);
162
+ font-size: var(--text-xs);
163
+ border-radius: var(--radius-sm);
164
+ }
165
+
166
+ .ui-button--sm {
167
+ height: var(--input-height-sm);
168
+ padding: 0 var(--space-2);
169
+ font-size: var(--text-sm);
170
+ border-radius: var(--radius-md);
171
+ }
172
+
173
+ .ui-button--md {
174
+ height: var(--input-height-md);
175
+ padding: 0 var(--space-3);
176
+ font-size: var(--text-sm);
177
+ border-radius: var(--radius-md);
178
+ }
179
+
180
+ .ui-button--lg {
181
+ height: var(--input-height-lg);
182
+ padding: 0 var(--space-4);
183
+ font-size: var(--text-base);
184
+ border-radius: var(--radius-md);
185
+ }
186
+
187
+ .ui-button--xl {
188
+ height: var(--input-height-xl);
189
+ padding: 0 var(--space-5);
190
+ font-size: var(--text-base);
191
+ border-radius: var(--radius-lg);
192
+ }
193
+
194
+ .ui-button--icon-only.ui-button--xs { width: var(--input-height-xs); padding: 0; }
195
+ .ui-button--icon-only.ui-button--sm { width: var(--input-height-sm); padding: 0; }
196
+ .ui-button--icon-only.ui-button--md { width: var(--input-height-md); padding: 0; }
197
+ .ui-button--icon-only.ui-button--lg { width: var(--input-height-lg); padding: 0; }
198
+ .ui-button--icon-only.ui-button--xl { width: var(--input-height-xl); padding: 0; }
199
+
200
+ .ui-button--primary {
201
+ background-color: var(--action-primary);
202
+ color: var(--action-primary-text);
203
+ border: 1px solid var(--action-primary-hover);
204
+ box-shadow:
205
+ 0 1px 2px 0 oklch(0 0 0 / var(--depth-shadow-opacity, 0.1)),
206
+ 0 1px 3px 0 oklch(0 0 0 / calc(var(--depth-shadow-opacity, 0.1) * 0.8)),
207
+ inset 0 1px 0 0 oklch(1 0 0 / var(--depth-highlight-opacity, 0.1));
208
+ }
209
+
210
+ .ui-button--primary:hover:not(.ui-button--disabled) {
211
+ background-color: var(--action-primary-hover);
212
+ }
213
+
214
+ .ui-button--primary:active:not(.ui-button--disabled) {
215
+ background-color: var(--action-primary-active);
216
+ box-shadow: inset 0 2px 4px 0 oklch(0 0 0 / calc(var(--depth-inset-opacity, 0.06) * 2.5));
217
+ transform: translateY(1px) scale(0.98);
218
+ }
219
+
220
+ .ui-button--primary:active:not(.ui-button--disabled) .ui-button__highlight {
221
+ opacity: 0;
222
+ }
223
+
224
+ .ui-button--secondary {
225
+ background-color: var(--action-secondary);
226
+ color: var(--action-secondary-text);
227
+ border: 1px solid var(--border-default);
228
+ box-shadow:
229
+ 0 1px 2px 0 oklch(0 0 0 / calc(var(--depth-shadow-opacity, 0.1) * 0.5)),
230
+ inset 0 1px 0 0 oklch(1 0 0 / calc(var(--depth-highlight-opacity, 0.12) * 0.4));
231
+ }
232
+
233
+ .ui-button--secondary:hover:not(.ui-button--disabled) {
234
+ background-color: var(--action-secondary-hover);
235
+ border-color: var(--border-hover);
236
+ }
237
+
238
+ .ui-button--secondary:active:not(.ui-button--disabled) {
239
+ background-color: var(--action-secondary-active);
240
+ box-shadow: inset 0 2px 4px 0 oklch(0 0 0 / calc(var(--depth-inset-opacity, 0.06) * 1.3));
241
+ transform: translateY(1px) scale(0.98);
242
+ }
243
+
244
+ .ui-button--secondary:active:not(.ui-button--disabled) .ui-button__highlight {
245
+ opacity: 0;
246
+ }
247
+
248
+ .ui-button--destructive {
249
+ background-color: var(--action-destructive);
250
+ color: var(--action-destructive-text);
251
+ border: 1px solid var(--action-destructive-hover);
252
+ box-shadow:
253
+ 0 1px 2px 0 oklch(0 0 0 / var(--depth-shadow-opacity, 0.1)),
254
+ 0 1px 3px 0 oklch(0 0 0 / calc(var(--depth-shadow-opacity, 0.1) * 0.8)),
255
+ inset 0 1px 0 0 oklch(1 0 0 / var(--depth-highlight-opacity, 0.1));
256
+ }
257
+
258
+ .ui-button--destructive:hover:not(.ui-button--disabled) {
259
+ background-color: var(--action-destructive-hover);
260
+ }
261
+
262
+ .ui-button--destructive:active:not(.ui-button--disabled) {
263
+ background-color: var(--action-destructive-active);
264
+ box-shadow: inset 0 2px 4px 0 oklch(0 0 0 / calc(var(--depth-inset-opacity, 0.06) * 2.5));
265
+ transform: translateY(1px) scale(0.98);
266
+ }
267
+
268
+ .ui-button--destructive:active:not(.ui-button--disabled) .ui-button__highlight {
269
+ opacity: 0;
270
+ }
271
+
272
+ .ui-button--ghost {
273
+ background-color: transparent;
274
+ color: var(--text-primary);
275
+ border: 1px solid transparent;
276
+ box-shadow: none;
277
+ }
278
+
279
+ .ui-button--ghost .ui-button__highlight {
280
+ display: none;
281
+ }
282
+
283
+ .ui-button--ghost:hover:not(.ui-button--disabled) {
284
+ background-color: var(--action-secondary);
285
+ }
286
+
287
+ .ui-button--ghost:active:not(.ui-button--disabled) {
288
+ background-color: var(--action-secondary-hover);
289
+ transform: scale(0.98);
290
+ }
291
+
292
+ .ui-button--outline {
293
+ background-color: transparent;
294
+ color: var(--text-primary);
295
+ border: 1px solid var(--border-default);
296
+ box-shadow: none;
297
+ }
298
+
299
+ .ui-button--outline .ui-button__highlight {
300
+ display: none;
301
+ }
302
+
303
+ .ui-button--outline:hover:not(.ui-button--disabled) {
304
+ background-color: var(--action-secondary);
305
+ border-color: var(--border-hover);
306
+ }
307
+
308
+ .ui-button--outline:active:not(.ui-button--disabled) {
309
+ background-color: var(--action-secondary-hover);
310
+ transform: scale(0.98);
311
+ }
312
+
313
+ .ui-button--disabled {
314
+ opacity: 0.5;
315
+ cursor: not-allowed;
316
+ }
317
+
318
+ .ui-button--loading {
319
+ cursor: wait;
320
+ }
321
+
322
+ .ui-button--block {
323
+ display: flex;
324
+ width: 100%;
325
+ }
326
+
327
+ .ui-button:focus-visible {
328
+ outline: 2px solid var(--ring-color);
329
+ outline-offset: 2px;
330
+ }
331
+
332
+ .ui-button__content {
333
+ display: inline-flex;
334
+ align-items: center;
335
+ line-height: 1;
336
+ text-box: trim-both cap alphabetic;
337
+ }
338
+
339
+ .ui-button__icon {
340
+ display: inline-flex;
341
+ align-items: center;
342
+ justify-content: center;
343
+ flex-shrink: 0;
344
+ }
345
+
346
+ .ui-button__icon svg {
347
+ color: currentColor;
348
+ }
349
+ </style>
@@ -0,0 +1,2 @@
1
+ export { default as Button } from './Button.vue'
2
+ export type { ButtonProps } from './Button.vue'