@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,339 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed, watch } from 'vue'
3
+ import Popover from '../Popover/Popover.vue'
4
+ import Input from '../Input/Input.vue'
5
+ import ColorArea from './ColorArea.vue'
6
+ import ColorSlider from './ColorSlider.vue'
7
+ import {
8
+ parseColorString,
9
+ formatColor,
10
+ hsvToHex,
11
+ hsvToRgb,
12
+ formatRgb,
13
+ type HSV
14
+ } from '../../utils/color'
15
+
16
+ export type ColorFormat = 'hex' | 'rgb' | 'oklch'
17
+
18
+ export interface ColorPickerProps {
19
+ /** Current color value */
20
+ modelValue: string
21
+ /** Output format */
22
+ format?: ColorFormat
23
+ /** Disable the picker */
24
+ disabled?: boolean
25
+ /** Show only the swatch, hide text input */
26
+ swatchOnly?: boolean
27
+ /** Show alpha channel slider */
28
+ alpha?: boolean
29
+ }
30
+
31
+ const props = withDefaults(defineProps<ColorPickerProps>(), {
32
+ format: 'hex',
33
+ disabled: false,
34
+ swatchOnly: false,
35
+ alpha: false
36
+ })
37
+
38
+ const emit = defineEmits<{
39
+ 'update:modelValue': [value: string]
40
+ }>()
41
+
42
+ const internalHsv = ref<HSV>({ h: 0, s: 1, v: 1 })
43
+ const internalAlpha = ref(1)
44
+ const textInput = ref('')
45
+ const isPopoverOpen = ref(false)
46
+
47
+ const swatchColor = computed(() => {
48
+ const rgb = hsvToRgb(internalHsv.value)
49
+ if (props.alpha && internalAlpha.value < 1) {
50
+ return formatRgb(rgb, internalAlpha.value)
51
+ }
52
+ return hsvToHex(internalHsv.value)
53
+ })
54
+
55
+ const hueSliderColor = computed(() => hsvToHex({ ...internalHsv.value, s: 1, v: 1 }))
56
+
57
+ watch(() => props.modelValue, (newValue) => {
58
+ if (!newValue) return
59
+
60
+ const parsed = parseColorString(newValue)
61
+ if (parsed) {
62
+ internalHsv.value = parsed.hsv
63
+ internalAlpha.value = parsed.alpha
64
+ textInput.value = newValue
65
+ }
66
+ }, { immediate: true })
67
+
68
+ function emitColor() {
69
+ const color = formatColor(internalHsv.value, internalAlpha.value, props.format)
70
+ textInput.value = color
71
+ emit('update:modelValue', color)
72
+ }
73
+
74
+ function handleHueChange(hue: number) {
75
+ internalHsv.value = { ...internalHsv.value, h: hue }
76
+ emitColor()
77
+ }
78
+
79
+ function handleSaturationChange(saturation: number) {
80
+ internalHsv.value = { ...internalHsv.value, s: saturation }
81
+ emitColor()
82
+ }
83
+
84
+ function handleValueChange(value: number) {
85
+ internalHsv.value = { ...internalHsv.value, v: value }
86
+ emitColor()
87
+ }
88
+
89
+ function handleAlphaChange(alpha: number) {
90
+ internalAlpha.value = alpha
91
+ emitColor()
92
+ }
93
+
94
+ function handleTextInput(event: Event) {
95
+ const value = (event.target as HTMLInputElement).value
96
+ textInput.value = value
97
+
98
+ const parsed = parseColorString(value)
99
+ if (parsed) {
100
+ internalHsv.value = parsed.hsv
101
+ internalAlpha.value = parsed.alpha
102
+ emit('update:modelValue', value)
103
+ }
104
+ }
105
+
106
+ function handleTextBlur() {
107
+ const parsed = parseColorString(textInput.value)
108
+ if (!parsed) {
109
+ textInput.value = formatColor(internalHsv.value, internalAlpha.value, props.format)
110
+ }
111
+ }
112
+
113
+ async function handleEyeDropper() {
114
+ if (!('EyeDropper' in window)) return
115
+
116
+ try {
117
+ // @ts-expect-error EyeDropper is not in TS lib yet
118
+ const eyeDropper = new EyeDropper()
119
+ const result = await eyeDropper.open()
120
+
121
+ if (result.sRGBHex) {
122
+ const parsed = parseColorString(result.sRGBHex)
123
+ if (parsed) {
124
+ internalHsv.value = parsed.hsv
125
+ internalAlpha.value = 1
126
+ emitColor()
127
+ }
128
+ }
129
+ } catch {
130
+ // User cancelled or error
131
+ }
132
+ }
133
+
134
+ const hasEyeDropper = computed(() => 'EyeDropper' in window)
135
+ </script>
136
+
137
+ <template>
138
+ <Popover
139
+ placement="bottom-start"
140
+ :disabled="disabled"
141
+ :width="240"
142
+ @open="isPopoverOpen = true"
143
+ @close="isPopoverOpen = false"
144
+ >
145
+ <template #trigger>
146
+ <div
147
+ class="ui-color-picker__trigger"
148
+ :class="{ 'ui-color-picker__trigger--disabled': disabled }"
149
+ >
150
+ <div
151
+ class="ui-color-picker__swatch"
152
+ :style="{ backgroundColor: swatchColor }"
153
+ >
154
+ <div class="ui-color-picker__swatch-checkerboard" />
155
+ </div>
156
+ <Input
157
+ v-if="!swatchOnly"
158
+ :model-value="textInput"
159
+ :disabled="disabled"
160
+ class="ui-color-picker__input"
161
+ @input="handleTextInput"
162
+ @blur="handleTextBlur"
163
+ />
164
+ </div>
165
+ </template>
166
+
167
+ <div class="ui-color-picker__panel">
168
+ <ColorArea
169
+ :hue="internalHsv.h"
170
+ :saturation="internalHsv.s"
171
+ :value="internalHsv.v"
172
+ @update:saturation="handleSaturationChange"
173
+ @update:value="handleValueChange"
174
+ />
175
+
176
+ <div class="ui-color-picker__sliders">
177
+ <ColorSlider
178
+ :model-value="internalHsv.h"
179
+ type="hue"
180
+ @update:model-value="handleHueChange"
181
+ />
182
+
183
+ <ColorSlider
184
+ v-if="alpha"
185
+ :model-value="internalAlpha"
186
+ type="alpha"
187
+ :color="hueSliderColor"
188
+ @update:model-value="handleAlphaChange"
189
+ />
190
+ </div>
191
+
192
+ <div class="ui-color-picker__footer">
193
+ <div class="ui-color-picker__preview">
194
+ <div
195
+ class="ui-color-picker__preview-swatch"
196
+ :style="{ backgroundColor: swatchColor }"
197
+ >
198
+ <div class="ui-color-picker__swatch-checkerboard" />
199
+ </div>
200
+ <span class="ui-color-picker__preview-text">{{ textInput }}</span>
201
+ </div>
202
+
203
+ <button
204
+ v-if="hasEyeDropper"
205
+ type="button"
206
+ class="ui-color-picker__eyedropper"
207
+ title="Pick color from screen"
208
+ @click="handleEyeDropper"
209
+ >
210
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
211
+ <path d="M2 22l1-1h3l9-9" />
212
+ <path d="M3 21v-3l9-9" />
213
+ <path d="M14.5 6.5l3-3a2.12 2.12 0 0 1 3 3l-3 3" />
214
+ <path d="M12 9l3 3" />
215
+ </svg>
216
+ </button>
217
+ </div>
218
+ </div>
219
+ </Popover>
220
+ </template>
221
+
222
+ <style scoped>
223
+ .ui-color-picker__trigger {
224
+ display: inline-flex;
225
+ align-items: center;
226
+ gap: var(--space-2);
227
+ }
228
+
229
+ .ui-color-picker__trigger--disabled {
230
+ opacity: 0.5;
231
+ pointer-events: none;
232
+ }
233
+
234
+ .ui-color-picker__swatch {
235
+ position: relative;
236
+ width: 32px;
237
+ height: 32px;
238
+ border-radius: var(--radius-md);
239
+ border: 1px solid var(--border-default);
240
+ cursor: pointer;
241
+ overflow: hidden;
242
+ flex-shrink: 0;
243
+ }
244
+
245
+ .ui-color-picker__swatch-checkerboard {
246
+ position: absolute;
247
+ inset: 0;
248
+ z-index: -1;
249
+ background-image:
250
+ linear-gradient(45deg, var(--bg-tertiary) 25%, transparent 25%),
251
+ linear-gradient(-45deg, var(--bg-tertiary) 25%, transparent 25%),
252
+ linear-gradient(45deg, transparent 75%, var(--bg-tertiary) 75%),
253
+ linear-gradient(-45deg, transparent 75%, var(--bg-tertiary) 75%);
254
+ background-size: 8px 8px;
255
+ background-position: 0 0, 0 4px, 4px -4px, -4px 0;
256
+ background-color: var(--bg-primary);
257
+ }
258
+
259
+ .ui-color-picker__input {
260
+ width: 100px;
261
+ }
262
+
263
+ .ui-color-picker__input :deep(input) {
264
+ font-family: var(--font-mono);
265
+ font-size: var(--text-sm);
266
+ }
267
+
268
+ .ui-color-picker__panel {
269
+ display: flex;
270
+ flex-direction: column;
271
+ gap: var(--space-3);
272
+ padding: var(--space-3);
273
+ }
274
+
275
+ .ui-color-picker__sliders {
276
+ display: flex;
277
+ flex-direction: column;
278
+ gap: var(--space-2);
279
+ }
280
+
281
+ .ui-color-picker__footer {
282
+ display: flex;
283
+ align-items: center;
284
+ justify-content: space-between;
285
+ gap: var(--space-2);
286
+ }
287
+
288
+ .ui-color-picker__preview {
289
+ display: flex;
290
+ align-items: center;
291
+ gap: var(--space-2);
292
+ flex: 1;
293
+ min-width: 0;
294
+ }
295
+
296
+ .ui-color-picker__preview-swatch {
297
+ position: relative;
298
+ width: 24px;
299
+ height: 24px;
300
+ border-radius: var(--radius-sm);
301
+ border: 1px solid var(--border-default);
302
+ overflow: hidden;
303
+ flex-shrink: 0;
304
+ }
305
+
306
+ .ui-color-picker__preview-text {
307
+ font-family: var(--font-mono);
308
+ font-size: var(--text-xs);
309
+ color: var(--text-secondary);
310
+ overflow: hidden;
311
+ text-overflow: ellipsis;
312
+ white-space: nowrap;
313
+ }
314
+
315
+ .ui-color-picker__eyedropper {
316
+ display: flex;
317
+ align-items: center;
318
+ justify-content: center;
319
+ width: 28px;
320
+ height: 28px;
321
+ border: none;
322
+ background: var(--bg-tertiary);
323
+ border-radius: var(--radius-md);
324
+ color: var(--text-secondary);
325
+ cursor: pointer;
326
+ transition: background-color var(--duration-fast) var(--ease-default),
327
+ color var(--duration-fast) var(--ease-default);
328
+ }
329
+
330
+ .ui-color-picker__eyedropper:hover {
331
+ background: var(--bg-secondary);
332
+ color: var(--text-primary);
333
+ }
334
+
335
+ .ui-color-picker__eyedropper:focus-visible {
336
+ outline: 2px solid var(--ring-color);
337
+ outline-offset: 2px;
338
+ }
339
+ </style>
@@ -0,0 +1,191 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed, onUnmounted } from 'vue'
3
+ import { clamp } from '../../utils/color'
4
+
5
+ export interface ColorSliderProps {
6
+ /** Current value (0-1 for alpha, 0-360 for hue) */
7
+ modelValue: number
8
+ /** Slider type */
9
+ type: 'hue' | 'alpha'
10
+ /** Current color for alpha gradient (hex without alpha) */
11
+ color?: string
12
+ }
13
+
14
+ const props = withDefaults(defineProps<ColorSliderProps>(), {
15
+ color: '#ff0000'
16
+ })
17
+
18
+ const emit = defineEmits<{
19
+ 'update:modelValue': [value: number]
20
+ }>()
21
+
22
+ const trackRef = ref<HTMLDivElement | null>(null)
23
+ const isDragging = ref(false)
24
+
25
+ const thumbPosition = computed(() => {
26
+ if (props.type === 'hue') {
27
+ return (props.modelValue / 360) * 100
28
+ }
29
+ return props.modelValue * 100
30
+ })
31
+
32
+ const alphaGradient = computed(() => {
33
+ if (props.type !== 'alpha') return ''
34
+ return `linear-gradient(to right, transparent, ${props.color})`
35
+ })
36
+
37
+ function updateValue(clientX: number) {
38
+ if (!trackRef.value) return
39
+
40
+ const rect = trackRef.value.getBoundingClientRect()
41
+ const x = clientX - rect.left
42
+ const ratio = clamp(x / rect.width, 0, 1)
43
+
44
+ if (props.type === 'hue') {
45
+ emit('update:modelValue', Math.round(ratio * 360))
46
+ } else {
47
+ emit('update:modelValue', ratio)
48
+ }
49
+ }
50
+
51
+ function handleMouseDown(event: MouseEvent) {
52
+ event.preventDefault()
53
+ isDragging.value = true
54
+ updateValue(event.clientX)
55
+
56
+ document.addEventListener('mousemove', handleMouseMove)
57
+ document.addEventListener('mouseup', handleMouseUp)
58
+ }
59
+
60
+ function handleMouseMove(event: MouseEvent) {
61
+ if (!isDragging.value) return
62
+ updateValue(event.clientX)
63
+ }
64
+
65
+ function handleMouseUp() {
66
+ isDragging.value = false
67
+ document.removeEventListener('mousemove', handleMouseMove)
68
+ document.removeEventListener('mouseup', handleMouseUp)
69
+ }
70
+
71
+ function handleTouchStart(event: TouchEvent) {
72
+ event.preventDefault()
73
+ isDragging.value = true
74
+ updateValue(event.touches[0].clientX)
75
+
76
+ document.addEventListener('touchmove', handleTouchMove, { passive: false })
77
+ document.addEventListener('touchend', handleTouchEnd)
78
+ }
79
+
80
+ function handleTouchMove(event: TouchEvent) {
81
+ event.preventDefault()
82
+ if (!isDragging.value) return
83
+ updateValue(event.touches[0].clientX)
84
+ }
85
+
86
+ function handleTouchEnd() {
87
+ isDragging.value = false
88
+ document.removeEventListener('touchmove', handleTouchMove)
89
+ document.removeEventListener('touchend', handleTouchEnd)
90
+ }
91
+
92
+ onUnmounted(() => {
93
+ document.removeEventListener('mousemove', handleMouseMove)
94
+ document.removeEventListener('mouseup', handleMouseUp)
95
+ document.removeEventListener('touchmove', handleTouchMove)
96
+ document.removeEventListener('touchend', handleTouchEnd)
97
+ })
98
+ </script>
99
+
100
+ <template>
101
+ <div
102
+ ref="trackRef"
103
+ class="ui-color-slider"
104
+ :class="[
105
+ `ui-color-slider--${type}`,
106
+ { 'ui-color-slider--dragging': isDragging }
107
+ ]"
108
+ @mousedown="handleMouseDown"
109
+ @touchstart="handleTouchStart"
110
+ >
111
+ <div
112
+ v-if="type === 'alpha'"
113
+ class="ui-color-slider__checkerboard"
114
+ />
115
+ <div
116
+ class="ui-color-slider__gradient"
117
+ :style="type === 'alpha' ? { background: alphaGradient } : undefined"
118
+ />
119
+ <div
120
+ class="ui-color-slider__thumb"
121
+ :style="{ left: `${thumbPosition}%` }"
122
+ />
123
+ </div>
124
+ </template>
125
+
126
+ <style scoped>
127
+ .ui-color-slider {
128
+ position: relative;
129
+ height: 12px;
130
+ border-radius: var(--radius-full);
131
+ cursor: pointer;
132
+ user-select: none;
133
+ touch-action: none;
134
+ }
135
+
136
+ .ui-color-slider__checkerboard {
137
+ position: absolute;
138
+ inset: 0;
139
+ border-radius: inherit;
140
+ background-image:
141
+ linear-gradient(45deg, var(--bg-tertiary) 25%, transparent 25%),
142
+ linear-gradient(-45deg, var(--bg-tertiary) 25%, transparent 25%),
143
+ linear-gradient(45deg, transparent 75%, var(--bg-tertiary) 75%),
144
+ linear-gradient(-45deg, transparent 75%, var(--bg-tertiary) 75%);
145
+ background-size: 8px 8px;
146
+ background-position: 0 0, 0 4px, 4px -4px, -4px 0;
147
+ background-color: var(--bg-primary);
148
+ }
149
+
150
+ .ui-color-slider__gradient {
151
+ position: absolute;
152
+ inset: 0;
153
+ border-radius: inherit;
154
+ }
155
+
156
+ .ui-color-slider--hue .ui-color-slider__gradient {
157
+ background: linear-gradient(
158
+ to right,
159
+ hsl(0, 100%, 50%),
160
+ hsl(60, 100%, 50%),
161
+ hsl(120, 100%, 50%),
162
+ hsl(180, 100%, 50%),
163
+ hsl(240, 100%, 50%),
164
+ hsl(300, 100%, 50%),
165
+ hsl(360, 100%, 50%)
166
+ );
167
+ }
168
+
169
+ .ui-color-slider__thumb {
170
+ position: absolute;
171
+ top: 50%;
172
+ width: 16px;
173
+ height: 16px;
174
+ border-radius: var(--radius-full);
175
+ background: var(--bg-primary);
176
+ border: 2px solid var(--bg-primary);
177
+ box-shadow: 0 0 0 1px var(--border-default), var(--shadow-md);
178
+ transform: translate(-50%, -50%);
179
+ transition: box-shadow var(--duration-fast) var(--ease-default);
180
+ }
181
+
182
+ .ui-color-slider:hover .ui-color-slider__thumb,
183
+ .ui-color-slider--dragging .ui-color-slider__thumb {
184
+ box-shadow: 0 0 0 1px var(--border-default), var(--shadow-lg);
185
+ }
186
+
187
+ .ui-color-slider:focus-visible {
188
+ outline: 2px solid var(--ring-color);
189
+ outline-offset: 2px;
190
+ }
191
+ </style>
@@ -0,0 +1,7 @@
1
+ export { default as ColorPicker } from './ColorPicker.vue'
2
+ export { default as ColorArea } from './ColorArea.vue'
3
+ export { default as ColorSlider } from './ColorSlider.vue'
4
+
5
+ export type { ColorPickerProps, ColorFormat } from './ColorPicker.vue'
6
+ export type { ColorAreaProps } from './ColorArea.vue'
7
+ export type { ColorSliderProps } from './ColorSlider.vue'