@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,214 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { useId } from '../../composables'
4
+
5
+ export interface RadioProps {
6
+ /** Selected value (v-model) - shared across radio group */
7
+ modelValue?: string | number | boolean
8
+ /** Value of this radio option */
9
+ value: string | number | boolean
10
+ /** Radio size */
11
+ size?: 'sm' | 'md' | 'lg'
12
+ /** Disabled state */
13
+ disabled?: boolean
14
+ /** Visible label text */
15
+ label?: string
16
+ /** Description text below label */
17
+ description?: string
18
+ /** HTML name for radio group (required for native behavior) */
19
+ name?: string
20
+ /** ID for label association */
21
+ id?: string
22
+ }
23
+
24
+ const props = withDefaults(defineProps<RadioProps>(), {
25
+ size: 'md',
26
+ disabled: false
27
+ })
28
+
29
+ const emit = defineEmits<{
30
+ (e: 'update:modelValue', value: string | number | boolean): void
31
+ (e: 'change', value: string | number | boolean): void
32
+ }>()
33
+
34
+ const uid = useId('radio')
35
+ const radioId = computed(() => props.id || uid)
36
+
37
+ const isChecked = computed(() => props.modelValue === props.value)
38
+
39
+ function handleChange() {
40
+ if (props.disabled) return
41
+ emit('update:modelValue', props.value)
42
+ emit('change', props.value)
43
+ }
44
+ </script>
45
+
46
+ <template>
47
+ <label
48
+ class="ui-radio"
49
+ :class="[
50
+ `ui-radio--${size}`,
51
+ {
52
+ 'ui-radio--disabled': disabled,
53
+ 'ui-radio--checked': isChecked
54
+ }
55
+ ]"
56
+ >
57
+ <input
58
+ :id="radioId"
59
+ type="radio"
60
+ :checked="isChecked"
61
+ :disabled="disabled"
62
+ :name="name"
63
+ :value="value"
64
+ class="ui-radio__input"
65
+ @change="handleChange"
66
+ />
67
+
68
+ <span class="ui-radio__box" aria-hidden="true">
69
+ <span v-if="isChecked" class="ui-radio__dot" />
70
+ </span>
71
+
72
+ <span v-if="label || description" class="ui-radio__content">
73
+ <span v-if="label" class="ui-radio__label">{{ label }}</span>
74
+ <span v-if="description" class="ui-radio__description">{{ description }}</span>
75
+ </span>
76
+ </label>
77
+ </template>
78
+
79
+ <style scoped>
80
+ .ui-radio {
81
+ display: inline-flex;
82
+ align-items: flex-start;
83
+ gap: var(--space-2);
84
+ cursor: pointer;
85
+ font-family: var(--font-sans);
86
+ -webkit-tap-highlight-color: transparent;
87
+ }
88
+
89
+ .ui-radio--disabled {
90
+ cursor: not-allowed;
91
+ opacity: 0.5;
92
+ }
93
+
94
+ .ui-radio__input {
95
+ position: absolute;
96
+ width: 1px;
97
+ height: 1px;
98
+ padding: 0;
99
+ margin: -1px;
100
+ overflow: hidden;
101
+ clip: rect(0, 0, 0, 0);
102
+ white-space: nowrap;
103
+ border: 0;
104
+ }
105
+
106
+ .ui-radio__box {
107
+ position: relative;
108
+ display: flex;
109
+ align-items: center;
110
+ justify-content: center;
111
+ flex-shrink: 0;
112
+ border: 2px solid var(--radio-border);
113
+ border-radius: var(--radius-full);
114
+ background-color: var(--radio-bg);
115
+ transition:
116
+ border-color var(--duration-fast) var(--ease-default),
117
+ box-shadow var(--duration-fast) var(--ease-default);
118
+ }
119
+
120
+ .ui-radio--checked .ui-radio__box {
121
+ border-color: var(--radio-checked);
122
+ }
123
+
124
+ .ui-radio:not(.ui-radio--disabled):hover .ui-radio__box {
125
+ border-color: var(--radio-border-hover);
126
+ }
127
+
128
+ .ui-radio--checked:not(.ui-radio--disabled):hover .ui-radio__box {
129
+ border-color: var(--radio-checked-hover);
130
+ }
131
+
132
+ .ui-radio__input:focus-visible + .ui-radio__box {
133
+ outline: 2px solid var(--ring-color);
134
+ outline-offset: 2px;
135
+ }
136
+
137
+ .ui-radio--sm .ui-radio__box {
138
+ width: 1rem;
139
+ height: 1rem;
140
+ }
141
+
142
+ .ui-radio--md .ui-radio__box {
143
+ width: 1.25rem;
144
+ height: 1.25rem;
145
+ }
146
+
147
+ .ui-radio--lg .ui-radio__box {
148
+ width: 1.5rem;
149
+ height: 1.5rem;
150
+ }
151
+
152
+ .ui-radio__dot {
153
+ position: absolute;
154
+ border-radius: var(--radius-full);
155
+ background-color: var(--radio-checked);
156
+ animation: radio-scale 0.15s var(--ease-out-back) forwards;
157
+ }
158
+
159
+ .ui-radio--sm .ui-radio__dot {
160
+ width: 0.5rem;
161
+ height: 0.5rem;
162
+ }
163
+
164
+ .ui-radio--md .ui-radio__dot {
165
+ width: 0.625rem;
166
+ height: 0.625rem;
167
+ }
168
+
169
+ .ui-radio--lg .ui-radio__dot {
170
+ width: 0.75rem;
171
+ height: 0.75rem;
172
+ }
173
+
174
+ @keyframes radio-scale {
175
+ from {
176
+ transform: scale(0);
177
+ }
178
+ to {
179
+ transform: scale(1);
180
+ }
181
+ }
182
+
183
+ .ui-radio__content {
184
+ display: flex;
185
+ flex-direction: column;
186
+ gap: var(--space-1);
187
+ padding-top: 1px;
188
+ }
189
+
190
+ .ui-radio__label {
191
+ font-size: var(--text-sm);
192
+ font-weight: var(--font-medium);
193
+ color: var(--radio-label);
194
+ line-height: var(--leading-tight);
195
+ }
196
+
197
+ .ui-radio__description {
198
+ font-size: var(--text-xs);
199
+ color: var(--radio-description);
200
+ line-height: var(--leading-normal);
201
+ }
202
+
203
+ .ui-radio--sm .ui-radio__label {
204
+ font-size: var(--text-xs);
205
+ }
206
+
207
+ .ui-radio--lg .ui-radio__label {
208
+ font-size: var(--text-md);
209
+ }
210
+
211
+ .ui-radio--lg .ui-radio__description {
212
+ font-size: var(--text-sm);
213
+ }
214
+ </style>
@@ -0,0 +1,2 @@
1
+ export { default as Radio } from './Radio.vue'
2
+ export type { RadioProps } from './Radio.vue'
@@ -0,0 +1,319 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import Rating from './Rating.vue'
4
+
5
+ describe('Rating', () => {
6
+ describe('Rendering', () => {
7
+ it('renders with default props', () => {
8
+ const wrapper = mount(Rating, {
9
+ props: { modelValue: 3 }
10
+ })
11
+ expect(wrapper.find('.ui-rating').exists()).toBe(true)
12
+ })
13
+
14
+ it('renders correct number of stars based on max', () => {
15
+ const wrapper = mount(Rating, {
16
+ props: { modelValue: 0, max: 7 }
17
+ })
18
+ const stars = wrapper.findAll('.ui-rating__star')
19
+ expect(stars).toHaveLength(7)
20
+ })
21
+
22
+ it('defaults to 5 stars', () => {
23
+ const wrapper = mount(Rating, {
24
+ props: { modelValue: 0 }
25
+ })
26
+ const stars = wrapper.findAll('.ui-rating__star')
27
+ expect(stars).toHaveLength(5)
28
+ })
29
+
30
+ it('applies size classes', () => {
31
+ const sm = mount(Rating, { props: { modelValue: 3, size: 'sm' } })
32
+ const lg = mount(Rating, { props: { modelValue: 3, size: 'lg' } })
33
+
34
+ expect(sm.find('.ui-rating--sm').exists()).toBe(true)
35
+ expect(lg.find('.ui-rating--lg').exists()).toBe(true)
36
+ })
37
+
38
+ it('applies readonly class', () => {
39
+ const wrapper = mount(Rating, {
40
+ props: { modelValue: 3, readonly: true }
41
+ })
42
+ expect(wrapper.find('.ui-rating--readonly').exists()).toBe(true)
43
+ })
44
+ })
45
+
46
+ describe('Star states', () => {
47
+ it('shows full stars for rating value', () => {
48
+ const wrapper = mount(Rating, {
49
+ props: { modelValue: 3 }
50
+ })
51
+ const stars = wrapper.findAll('.ui-rating__star')
52
+ expect(stars[0].classes()).toContain('ui-rating__star--full')
53
+ expect(stars[1].classes()).toContain('ui-rating__star--full')
54
+ expect(stars[2].classes()).toContain('ui-rating__star--full')
55
+ expect(stars[3].classes()).toContain('ui-rating__star--empty')
56
+ expect(stars[4].classes()).toContain('ui-rating__star--empty')
57
+ })
58
+
59
+ it('shows half star when allowHalf is true', () => {
60
+ const wrapper = mount(Rating, {
61
+ props: { modelValue: 2.5, allowHalf: true }
62
+ })
63
+ const stars = wrapper.findAll('.ui-rating__star')
64
+ expect(stars[0].classes()).toContain('ui-rating__star--full')
65
+ expect(stars[1].classes()).toContain('ui-rating__star--full')
66
+ expect(stars[2].classes()).toContain('ui-rating__star--half')
67
+ expect(stars[3].classes()).toContain('ui-rating__star--empty')
68
+ })
69
+
70
+ it('treats half values as empty when allowHalf is false', () => {
71
+ const wrapper = mount(Rating, {
72
+ props: { modelValue: 2.5, allowHalf: false }
73
+ })
74
+ const stars = wrapper.findAll('.ui-rating__star')
75
+ expect(stars[0].classes()).toContain('ui-rating__star--full')
76
+ expect(stars[1].classes()).toContain('ui-rating__star--full')
77
+ expect(stars[2].classes()).toContain('ui-rating__star--empty')
78
+ })
79
+
80
+ it('shows all empty stars for zero rating', () => {
81
+ const wrapper = mount(Rating, {
82
+ props: { modelValue: 0 }
83
+ })
84
+ const stars = wrapper.findAll('.ui-rating__star')
85
+ stars.forEach(star => {
86
+ expect(star.classes()).toContain('ui-rating__star--empty')
87
+ })
88
+ })
89
+
90
+ it('shows all full stars for max rating', () => {
91
+ const wrapper = mount(Rating, {
92
+ props: { modelValue: 5, max: 5 }
93
+ })
94
+ const stars = wrapper.findAll('.ui-rating__star')
95
+ stars.forEach(star => {
96
+ expect(star.classes()).toContain('ui-rating__star--full')
97
+ })
98
+ })
99
+ })
100
+
101
+ describe('Mouse interaction', () => {
102
+ it('emits update:modelValue on click', async () => {
103
+ const wrapper = mount(Rating, {
104
+ props: { modelValue: 0 }
105
+ })
106
+ const stars = wrapper.findAll('.ui-rating__star')
107
+ await stars[2].trigger('click', { clientX: 100 })
108
+
109
+ expect(wrapper.emitted('update:modelValue')).toBeTruthy()
110
+ })
111
+
112
+ it('emits hover event on mousemove', async () => {
113
+ const wrapper = mount(Rating, {
114
+ props: { modelValue: 0 }
115
+ })
116
+ const star = wrapper.findAll('.ui-rating__star')[2]
117
+ await star.trigger('mousemove', { clientX: 100 })
118
+
119
+ expect(wrapper.emitted('hover')).toBeTruthy()
120
+ })
121
+
122
+ it('emits hover with null on mouseleave', async () => {
123
+ const wrapper = mount(Rating, {
124
+ props: { modelValue: 3 }
125
+ })
126
+ await wrapper.find('.ui-rating').trigger('mouseleave')
127
+
128
+ const hoverEvents = wrapper.emitted('hover')
129
+ expect(hoverEvents).toBeTruthy()
130
+ expect(hoverEvents![hoverEvents!.length - 1]).toEqual([null])
131
+ })
132
+
133
+ it('does not emit on click when readonly', async () => {
134
+ const wrapper = mount(Rating, {
135
+ props: { modelValue: 3, readonly: true }
136
+ })
137
+ const star = wrapper.findAll('.ui-rating__star')[0]
138
+ await star.trigger('click', { clientX: 50 })
139
+
140
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy()
141
+ })
142
+
143
+ it('does not emit hover when readonly', async () => {
144
+ const wrapper = mount(Rating, {
145
+ props: { modelValue: 3, readonly: true }
146
+ })
147
+ const star = wrapper.findAll('.ui-rating__star')[0]
148
+ await star.trigger('mousemove', { clientX: 50 })
149
+
150
+ expect(wrapper.emitted('hover')).toBeFalsy()
151
+ })
152
+ })
153
+
154
+ describe('Keyboard navigation', () => {
155
+ it('increases value with ArrowRight', async () => {
156
+ const wrapper = mount(Rating, {
157
+ props: { modelValue: 3 }
158
+ })
159
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowRight' })
160
+
161
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([4])
162
+ })
163
+
164
+ it('decreases value with ArrowLeft', async () => {
165
+ const wrapper = mount(Rating, {
166
+ props: { modelValue: 3 }
167
+ })
168
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowLeft' })
169
+
170
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([2])
171
+ })
172
+
173
+ it('increases value with ArrowUp', async () => {
174
+ const wrapper = mount(Rating, {
175
+ props: { modelValue: 3 }
176
+ })
177
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowUp' })
178
+
179
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([4])
180
+ })
181
+
182
+ it('decreases value with ArrowDown', async () => {
183
+ const wrapper = mount(Rating, {
184
+ props: { modelValue: 3 }
185
+ })
186
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowDown' })
187
+
188
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([2])
189
+ })
190
+
191
+ it('goes to min with Home', async () => {
192
+ const wrapper = mount(Rating, {
193
+ props: { modelValue: 3 }
194
+ })
195
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'Home' })
196
+
197
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([0])
198
+ })
199
+
200
+ it('goes to max with End', async () => {
201
+ const wrapper = mount(Rating, {
202
+ props: { modelValue: 3, max: 5 }
203
+ })
204
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'End' })
205
+
206
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([5])
207
+ })
208
+
209
+ it('uses 0.5 step when allowHalf is true', async () => {
210
+ const wrapper = mount(Rating, {
211
+ props: { modelValue: 3, allowHalf: true }
212
+ })
213
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowRight' })
214
+
215
+ expect(wrapper.emitted('update:modelValue')![0]).toEqual([3.5])
216
+ })
217
+
218
+ it('clamps at max', async () => {
219
+ const wrapper = mount(Rating, {
220
+ props: { modelValue: 5, max: 5 }
221
+ })
222
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowRight' })
223
+
224
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy()
225
+ })
226
+
227
+ it('clamps at min (0)', async () => {
228
+ const wrapper = mount(Rating, {
229
+ props: { modelValue: 0 }
230
+ })
231
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowLeft' })
232
+
233
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy()
234
+ })
235
+
236
+ it('does not respond when readonly', async () => {
237
+ const wrapper = mount(Rating, {
238
+ props: { modelValue: 3, readonly: true }
239
+ })
240
+ await wrapper.find('.ui-rating').trigger('keydown', { key: 'ArrowRight' })
241
+
242
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy()
243
+ })
244
+ })
245
+
246
+ describe('Accessibility', () => {
247
+ it('has slider role', () => {
248
+ const wrapper = mount(Rating, {
249
+ props: { modelValue: 3 }
250
+ })
251
+ expect(wrapper.find('.ui-rating').attributes('role')).toBe('slider')
252
+ })
253
+
254
+ it('has correct ARIA attributes', () => {
255
+ const wrapper = mount(Rating, {
256
+ props: { modelValue: 3, max: 5 }
257
+ })
258
+ const rating = wrapper.find('.ui-rating')
259
+ expect(rating.attributes('aria-valuemin')).toBe('0')
260
+ expect(rating.attributes('aria-valuemax')).toBe('5')
261
+ expect(rating.attributes('aria-valuenow')).toBe('3')
262
+ })
263
+
264
+ it('has aria-label', () => {
265
+ const wrapper = mount(Rating, {
266
+ props: { modelValue: 3, label: 'Product rating' }
267
+ })
268
+ expect(wrapper.find('.ui-rating').attributes('aria-label')).toBe('Product rating')
269
+ })
270
+
271
+ it('has default aria-label', () => {
272
+ const wrapper = mount(Rating, {
273
+ props: { modelValue: 3 }
274
+ })
275
+ expect(wrapper.find('.ui-rating').attributes('aria-label')).toBe('Rating')
276
+ })
277
+
278
+ it('has aria-readonly when readonly', () => {
279
+ const wrapper = mount(Rating, {
280
+ props: { modelValue: 3, readonly: true }
281
+ })
282
+ expect(wrapper.find('.ui-rating').attributes('aria-readonly')).toBe('true')
283
+ })
284
+
285
+ it('is focusable when not readonly', () => {
286
+ const wrapper = mount(Rating, {
287
+ props: { modelValue: 3 }
288
+ })
289
+ expect(wrapper.find('.ui-rating').attributes('tabindex')).toBe('0')
290
+ })
291
+
292
+ it('is not focusable when readonly', () => {
293
+ const wrapper = mount(Rating, {
294
+ props: { modelValue: 3, readonly: true }
295
+ })
296
+ expect(wrapper.find('.ui-rating').attributes('tabindex')).toBe('-1')
297
+ })
298
+ })
299
+
300
+ describe('Edge cases', () => {
301
+ it('handles zero max gracefully', () => {
302
+ const wrapper = mount(Rating, {
303
+ props: { modelValue: 0, max: 0 }
304
+ })
305
+ expect(wrapper.findAll('.ui-rating__star')).toHaveLength(0)
306
+ })
307
+
308
+ it('handles decimal values', () => {
309
+ const wrapper = mount(Rating, {
310
+ props: { modelValue: 3.7, allowHalf: true }
311
+ })
312
+ const stars = wrapper.findAll('.ui-rating__star')
313
+ expect(stars[0].classes()).toContain('ui-rating__star--full')
314
+ expect(stars[1].classes()).toContain('ui-rating__star--full')
315
+ expect(stars[2].classes()).toContain('ui-rating__star--full')
316
+ expect(stars[3].classes()).toContain('ui-rating__star--half')
317
+ })
318
+ })
319
+ })