numori-ui 0.1.0

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 (130) hide show
  1. package/LICENSE +651 -0
  2. package/README.md +466 -0
  3. package/dist/components/Alert.js +137 -0
  4. package/dist/components/Alert.js.map +1 -0
  5. package/dist/components/Avatar.js +133 -0
  6. package/dist/components/Avatar.js.map +1 -0
  7. package/dist/components/Badge.js +93 -0
  8. package/dist/components/Badge.js.map +1 -0
  9. package/dist/components/Button.js +428 -0
  10. package/dist/components/Button.js.map +1 -0
  11. package/dist/components/ButtonsGroup.js +153 -0
  12. package/dist/components/ButtonsGroup.js.map +1 -0
  13. package/dist/components/Checkbox.js +93 -0
  14. package/dist/components/Checkbox.js.map +1 -0
  15. package/dist/components/Divider.js +79 -0
  16. package/dist/components/Divider.js.map +1 -0
  17. package/dist/components/Dropdown.js +166 -0
  18. package/dist/components/Dropdown.js.map +1 -0
  19. package/dist/components/DropdownItem.js +106 -0
  20. package/dist/components/DropdownItem.js.map +1 -0
  21. package/dist/components/DropdownRow.js +41 -0
  22. package/dist/components/DropdownRow.js.map +1 -0
  23. package/dist/components/DropdownSubmenu.js +142 -0
  24. package/dist/components/DropdownSubmenu.js.map +1 -0
  25. package/dist/components/FileInput.js +122 -0
  26. package/dist/components/FileInput.js.map +1 -0
  27. package/dist/components/FormField.js +112 -0
  28. package/dist/components/FormField.js.map +1 -0
  29. package/dist/components/Input.js +603 -0
  30. package/dist/components/Input.js.map +1 -0
  31. package/dist/components/Kbd.js +35 -0
  32. package/dist/components/Kbd.js.map +1 -0
  33. package/dist/components/ListMenu.js +143 -0
  34. package/dist/components/ListMenu.js.map +1 -0
  35. package/dist/components/ListMenuItem.js +189 -0
  36. package/dist/components/ListMenuItem.js.map +1 -0
  37. package/dist/components/Modal.js +206 -0
  38. package/dist/components/Modal.js.map +1 -0
  39. package/dist/components/Numpad.js +123 -0
  40. package/dist/components/Numpad.js.map +1 -0
  41. package/dist/components/Popup.js +170 -0
  42. package/dist/components/Popup.js.map +1 -0
  43. package/dist/components/ProgressBar.js +118 -0
  44. package/dist/components/ProgressBar.js.map +1 -0
  45. package/dist/components/Prompt.js +201 -0
  46. package/dist/components/Prompt.js.map +1 -0
  47. package/dist/components/Radio.js +81 -0
  48. package/dist/components/Radio.js.map +1 -0
  49. package/dist/components/Select.js +441 -0
  50. package/dist/components/Select.js.map +1 -0
  51. package/dist/components/Slider.js +116 -0
  52. package/dist/components/Slider.js.map +1 -0
  53. package/dist/components/Stepper.js +65 -0
  54. package/dist/components/Stepper.js.map +1 -0
  55. package/dist/components/Toggle.js +133 -0
  56. package/dist/components/Toggle.js.map +1 -0
  57. package/dist/components/Tooltip.js +120 -0
  58. package/dist/components/Tooltip.js.map +1 -0
  59. package/dist/components/index.js +81 -0
  60. package/dist/components/index.js.map +1 -0
  61. package/dist/composables/onClickOutside.js +51 -0
  62. package/dist/composables/onClickOutside.js.map +1 -0
  63. package/dist/composables/useBackButton.js +98 -0
  64. package/dist/composables/useBackButton.js.map +1 -0
  65. package/dist/composables/useEventListener.js +63 -0
  66. package/dist/composables/useEventListener.js.map +1 -0
  67. package/dist/icons/Icon.js +120 -0
  68. package/dist/icons/Icon.js.map +1 -0
  69. package/dist/icons/mdi.js +69 -0
  70. package/dist/icons/mdi.js.map +1 -0
  71. package/dist/icons/registry.js +63 -0
  72. package/dist/icons/registry.js.map +1 -0
  73. package/dist/icons/resolver.js +49 -0
  74. package/dist/icons/resolver.js.map +1 -0
  75. package/dist/index.d.ts +108 -0
  76. package/dist/index.js +157 -0
  77. package/dist/index.js.map +1 -0
  78. package/dist/manifest.js +89 -0
  79. package/dist/manifest.js.map +1 -0
  80. package/dist/numori-ui.css +184 -0
  81. package/dist/nuxt.d.ts +35 -0
  82. package/dist/nuxt.mjs +243 -0
  83. package/dist/nuxt.mjs.map +1 -0
  84. package/dist/vite.d.ts +29 -0
  85. package/dist/vite.mjs +187 -0
  86. package/dist/vite.mjs.map +1 -0
  87. package/package.json +138 -0
  88. package/src/components/Alert.vue +127 -0
  89. package/src/components/Avatar.vue +100 -0
  90. package/src/components/Badge.vue +77 -0
  91. package/src/components/Button.vue +419 -0
  92. package/src/components/ButtonsGroup.vue +140 -0
  93. package/src/components/Checkbox.vue +81 -0
  94. package/src/components/Divider.vue +64 -0
  95. package/src/components/Dropdown.vue +150 -0
  96. package/src/components/DropdownItem.vue +78 -0
  97. package/src/components/DropdownRow.vue +37 -0
  98. package/src/components/DropdownSubmenu.vue +127 -0
  99. package/src/components/FileInput.vue +107 -0
  100. package/src/components/FormField.vue +86 -0
  101. package/src/components/Input.vue +619 -0
  102. package/src/components/Kbd.vue +30 -0
  103. package/src/components/ListMenu.vue +127 -0
  104. package/src/components/ListMenuItem.vue +171 -0
  105. package/src/components/Modal.vue +209 -0
  106. package/src/components/Numpad.vue +118 -0
  107. package/src/components/Popup.vue +156 -0
  108. package/src/components/ProgressBar.vue +107 -0
  109. package/src/components/Prompt.vue +161 -0
  110. package/src/components/Radio.vue +50 -0
  111. package/src/components/Select.vue +470 -0
  112. package/src/components/Slider.vue +93 -0
  113. package/src/components/Stepper.vue +53 -0
  114. package/src/components/Toggle.vue +125 -0
  115. package/src/components/Tooltip.vue +113 -0
  116. package/src/components/index.js +109 -0
  117. package/src/composables/onClickOutside.js +61 -0
  118. package/src/composables/useBackButton.js +98 -0
  119. package/src/composables/useEventListener.js +65 -0
  120. package/src/icons/Icon.vue +139 -0
  121. package/src/icons/mdi.js +67 -0
  122. package/src/icons/registry.js +64 -0
  123. package/src/icons/resolver.js +48 -0
  124. package/src/index.js +167 -0
  125. package/src/manifest.js +86 -0
  126. package/src/nuxt.js +315 -0
  127. package/src/style.css +20 -0
  128. package/src/tailwind.css +18 -0
  129. package/src/theme.css +172 -0
  130. package/src/vite.js +235 -0
@@ -0,0 +1,470 @@
1
+ <template>
2
+ <div ref="containerRef" class="relative" :class="!block ? 'inline-block' : ''">
3
+ <!-- Hidden sizer: measures the widest option label so the trigger never shrinks below it -->
4
+ <div
5
+ ref="sizerRef"
6
+ aria-hidden="true"
7
+ class="invisible absolute h-0 overflow-hidden pointer-events-none whitespace-nowrap"
8
+ :class="sizerTextClass"
9
+ >
10
+ <span v-for="opt in normalizedOptions" :key="opt.value" class="block">
11
+ <span class="inline-flex items-center gap-2">
12
+ <span v-if="opt.icon" class="w-4" />
13
+ {{ opt.label }}
14
+ <!-- account for chevron + padding -->
15
+ <span class="w-4" />
16
+ </span>
17
+ </span>
18
+ </div>
19
+
20
+ <!-- Trigger button: shows selected value, placeholder, or loading spinner -->
21
+ <button
22
+ ref="triggerRef"
23
+ type="button"
24
+ :disabled="disabled || loading"
25
+ :aria-label="ariaLabel"
26
+ :class="[triggerClasses, disabled || loading ? 'opacity-50 cursor-not-allowed' : '']"
27
+ :style="autoMinWidth"
28
+ @click="toggleOpen"
29
+ >
30
+ <span
31
+ v-if="loading"
32
+ class="flex items-center gap-2 truncate text-gray-400 dark:text-gray-500"
33
+ >
34
+ <UiIcon :name="spinner" class="w-4 h-4 animate-spin shrink-0" />
35
+ <span>{{ loadingText }}</span>
36
+ </span>
37
+ <template v-else>
38
+ <span
39
+ class="flex items-center gap-2 truncate"
40
+ :class="selectedLabel ? '' : 'text-gray-400 dark:text-gray-500'"
41
+ >
42
+ <UiIcon v-if="selectedIcon" :name="selectedIcon" class="w-4 h-4 shrink-0" />
43
+ {{ selectedLabel || placeholder || 'Select...' }}
44
+ </span>
45
+ </template>
46
+ <UiIcon
47
+ name="mdi:chevron-down"
48
+ class="w-4 h-4 shrink-0 text-gray-400 transition-transform"
49
+ :class="{ 'rotate-180': isOpen }"
50
+ />
51
+ </button>
52
+
53
+ <!-- Dropdown panel: teleported to <body> and fixed-positioned so it is never
54
+ clipped by an ancestor with overflow (e.g. a scrollable modal body). -->
55
+ <Teleport to="body">
56
+ <Transition
57
+ enter-active-class="transition duration-100 ease-out"
58
+ enter-from-class="opacity-0 scale-95"
59
+ enter-to-class="opacity-100 scale-100"
60
+ leave-active-class="transition duration-75 ease-in"
61
+ leave-from-class="opacity-100 scale-100"
62
+ leave-to-class="opacity-0 scale-95"
63
+ >
64
+ <div
65
+ v-show="isOpen"
66
+ ref="panelRef"
67
+ class="fixed z-[60] bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg overflow-hidden"
68
+ :style="panelStyle"
69
+ >
70
+ <!-- Search input for filtering options -->
71
+ <div v-if="searchable" class="p-1.5">
72
+ <input
73
+ ref="searchRef"
74
+ v-model="searchQuery"
75
+ type="text"
76
+ placeholder="Search..."
77
+ class="w-full px-2.5 py-1.5 text-sm border border-gray-200 dark:border-gray-700 rounded-md bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-gray-300 outline-none focus:ring-1 focus:ring-primary-500 placeholder-gray-400"
78
+ @keydown.escape="close"
79
+ @keydown.enter.prevent="selectFirst"
80
+ />
81
+ </div>
82
+ <!-- Options list: ungrouped flat list or grouped sections -->
83
+ <ul class="max-h-64 overflow-y-auto py-1">
84
+ <li
85
+ v-if="filteredOptions.length === 0 && filteredGroups.length === 0"
86
+ class="px-3 py-2 text-sm text-gray-400 dark:text-gray-500"
87
+ >
88
+ No results
89
+ </li>
90
+
91
+ <!-- Ungrouped options -->
92
+ <template v-if="filteredGroups.length === 0">
93
+ <li
94
+ v-for="opt in filteredOptions"
95
+ :key="opt.value"
96
+ class="flex items-center gap-2 px-3 cursor-pointer transition-colors"
97
+ :class="[optionClass(opt.value), opt.subtitle ? 'py-1.5' : 'py-1.5']"
98
+ @click="select(opt.value)"
99
+ >
100
+ <UiIcon v-if="opt.icon" :name="opt.icon" class="w-4 h-4 shrink-0" />
101
+ <div class="min-w-0">
102
+ <span class="block truncate text-sm">{{ opt.label }}</span>
103
+ <span
104
+ v-if="opt.subtitle"
105
+ class="block truncate text-[11px] text-gray-400 dark:text-gray-500 leading-tight"
106
+ >{{ opt.subtitle }}</span
107
+ >
108
+ </div>
109
+ </li>
110
+ </template>
111
+
112
+ <!-- Grouped options -->
113
+ <template v-else>
114
+ <template v-for="group in filteredGroups" :key="group.label">
115
+ <li
116
+ class="px-3 pt-2 pb-1 text-[11px] font-semibold uppercase tracking-wider text-gray-400 dark:text-gray-500 select-none"
117
+ >
118
+ {{ group.label }}
119
+ </li>
120
+ <li
121
+ v-for="opt in group.options"
122
+ :key="opt.value"
123
+ class="flex items-center gap-2 px-3 cursor-pointer transition-colors"
124
+ :class="[optionClass(opt.value), opt.subtitle ? 'py-1.5' : 'py-1.5']"
125
+ @click="select(opt.value)"
126
+ >
127
+ <UiIcon v-if="opt.icon" :name="opt.icon" class="w-4 h-4 shrink-0" />
128
+ <div class="min-w-0">
129
+ <span class="block truncate text-sm">{{ opt.label }}</span>
130
+ <span
131
+ v-if="opt.subtitle"
132
+ class="block truncate text-[11px] text-gray-400 dark:text-gray-500 leading-tight"
133
+ >{{ opt.subtitle }}</span
134
+ >
135
+ </div>
136
+ </li>
137
+ </template>
138
+ </template>
139
+ </ul>
140
+ </div>
141
+ </Transition>
142
+ </Teleport>
143
+ </div>
144
+ </template>
145
+
146
+ <script setup>
147
+ /**
148
+ * UiSelect — Custom dropdown select component with search, grouping, icons, and loading state.
149
+ *
150
+ * Renders a styled trigger button that opens a dropdown panel with filterable options.
151
+ * Supports flat option lists and grouped options (via `group` key on option objects).
152
+ * Includes keyboard navigation (Escape to close, Enter to select first match),
153
+ * automatic drop-up when near the bottom of the viewport, and a loading spinner state.
154
+ *
155
+ * @example Basic select
156
+ * <UiSelect v-model="color" :options="['Red', 'Green', 'Blue']" placeholder="Pick a color" />
157
+ *
158
+ * @example Searchable select with object options
159
+ * <UiSelect v-model="lang" :options="[{ value: 'en', label: 'English' }, { value: 'es', label: 'Spanish' }]" searchable />
160
+ *
161
+ * @example Grouped options with icons
162
+ * <UiSelect v-model="tool" :options="[
163
+ * { value: 'pen', label: 'Pen', icon: 'mdi:pen', group: 'Drawing' },
164
+ * { value: 'eraser', label: 'Eraser', icon: 'mdi:eraser', group: 'Drawing' },
165
+ * { value: 'text', label: 'Text', icon: 'mdi:format-text', group: 'Insert' },
166
+ * ]" searchable />
167
+ *
168
+ * @example Loading state
169
+ * <UiSelect v-model="val" :options="[]" :loading="true" loading-text="Fetching..." />
170
+ *
171
+ * @emits {string | number | boolean} update:modelValue — Emitted when an option is selected
172
+ */
173
+ import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
174
+ import UiIcon from '../icons/Icon.vue'
175
+ const props = defineProps({
176
+ /**
177
+ * Currently selected value (v-model).
178
+ * @type {string | number | boolean | null}
179
+ * @default ''
180
+ */
181
+ modelValue: { type: [String, Number, Boolean, null], default: '' },
182
+
183
+ /**
184
+ * Array of selectable options. Each item can be:
185
+ * - A primitive (string/number) used as both value and label
186
+ * - An object: `{ value, label, icon?, group? }`
187
+ * @type {Array}
188
+ * @default []
189
+ */
190
+ options: { type: Array, default: () => [] },
191
+
192
+ /**
193
+ * Placeholder text shown when no option is selected.
194
+ * @type {string}
195
+ * @default ''
196
+ */
197
+ placeholder: { type: String, default: '' },
198
+
199
+ /**
200
+ * Enable a search input inside the dropdown for filtering options.
201
+ * @type {boolean}
202
+ * @default false
203
+ */
204
+ searchable: { type: Boolean, default: false },
205
+
206
+ /**
207
+ * Disabled state — dims the trigger and prevents opening.
208
+ * @type {boolean}
209
+ * @default false
210
+ */
211
+ disabled: { type: Boolean, default: false },
212
+
213
+ /**
214
+ * Trigger button size controlling padding and font.
215
+ * @type {string}
216
+ * @default 'md'
217
+ * @values 'xs' | 'sm' | 'md'
218
+ */
219
+ size: { type: String, default: 'md' },
220
+
221
+ /**
222
+ * Full-width mode — trigger stretches to fill its container.
223
+ * @type {boolean}
224
+ * @default true
225
+ */
226
+ block: { type: Boolean, default: true },
227
+
228
+ /**
229
+ * Accessible label for the trigger button.
230
+ * @type {string}
231
+ * @default undefined
232
+ */
233
+ ariaLabel: { type: String, default: undefined },
234
+
235
+ /**
236
+ * Loading state — shows a spinner and disables interaction.
237
+ * @type {boolean}
238
+ * @default false
239
+ */
240
+ loading: { type: Boolean, default: false },
241
+
242
+ /**
243
+ * Text displayed next to the spinner during loading.
244
+ * @type {string}
245
+ * @default 'Loading...'
246
+ */
247
+ loadingText: { type: String, default: 'Loading...' },
248
+
249
+ /**
250
+ * MDI icon name for the loading spinner.
251
+ * @type {string}
252
+ * @default 'mdi:loading'
253
+ */
254
+ spinner: { type: String, default: 'mdi:loading' },
255
+ })
256
+
257
+ const emit = defineEmits(['update:modelValue'])
258
+
259
+ const containerRef = ref(null)
260
+ const triggerRef = ref(null)
261
+ const searchRef = ref(null)
262
+ const sizerRef = ref(null)
263
+ const panelRef = ref(null)
264
+ const isOpen = ref(false)
265
+ const searchQuery = ref('')
266
+ const measuredWidth = ref(0)
267
+ const panelStyle = ref({})
268
+
269
+ // Position the teleported panel under (or above) the trigger using fixed
270
+ // coordinates so it overlays everything and is never clipped by a scrollable
271
+ // ancestor. Re-run on scroll/resize while open so it stays anchored.
272
+ const reposition = () => {
273
+ const el = triggerRef.value
274
+ if (!el) return
275
+ const rect = el.getBoundingClientRect()
276
+ const spaceBelow = window.innerHeight - rect.bottom
277
+ const openUp = spaceBelow < 260 && rect.top > spaceBelow
278
+ const style = { left: `${rect.left}px`, minWidth: `${rect.width}px` }
279
+ if (props.block) style.width = `${rect.width}px`
280
+ if (openUp) style.bottom = `${window.innerHeight - rect.top + 4}px`
281
+ else style.top = `${rect.bottom + 4}px`
282
+ panelStyle.value = style
283
+ }
284
+
285
+ const startTracking = () => {
286
+ window.addEventListener('scroll', reposition, true)
287
+ window.addEventListener('resize', reposition)
288
+ }
289
+ const stopTracking = () => {
290
+ window.removeEventListener('scroll', reposition, true)
291
+ window.removeEventListener('resize', reposition)
292
+ }
293
+
294
+ // Text class for the hidden sizer — must match the trigger's font size
295
+ const sizerTextClass = computed(() => {
296
+ const map = { xs: 'text-xs', sm: 'text-sm', md: 'text-sm' }
297
+ return map[props.size] || 'text-sm'
298
+ })
299
+
300
+ // Measure the widest option on mount and when options change
301
+ const measureSizer = () => {
302
+ if (!sizerRef.value) {
303
+ measuredWidth.value = 0
304
+ return
305
+ }
306
+ measuredWidth.value = sizerRef.value.scrollWidth
307
+ }
308
+
309
+ onMounted(measureSizer)
310
+ watch(
311
+ () => props.options,
312
+ () => nextTick(measureSizer),
313
+ { deep: true },
314
+ )
315
+
316
+ // Auto min-width style: ensures trigger never shrinks below the widest option
317
+ const autoMinWidth = computed(() => {
318
+ if (!measuredWidth.value) return undefined
319
+ // Add padding for the trigger's horizontal padding + border
320
+ const padMap = { xs: 28, sm: 24, md: 30 }
321
+ const pad = padMap[props.size] || 30
322
+ return { minWidth: `${measuredWidth.value + pad}px` }
323
+ })
324
+
325
+ // ── Normalize options ────────────────────────────────────
326
+ // Convert primitive options (string/number) into { value, label, subtitle, icon, group } objects
327
+ const normalizedOptions = computed(() =>
328
+ props.options.map((opt) =>
329
+ typeof opt === 'object' && opt !== null
330
+ ? {
331
+ value: opt.value,
332
+ label: opt.label ?? String(opt.value),
333
+ subtitle: opt.subtitle || '',
334
+ icon: opt.icon || '',
335
+ group: opt.group || '',
336
+ }
337
+ : { value: opt, label: String(opt), subtitle: '', icon: '', group: '' },
338
+ ),
339
+ )
340
+
341
+ // ── Filtering ────────────────────────────────────────────
342
+ // Apply search query filter against option labels (case-insensitive)
343
+ const filteredNormalized = computed(() => {
344
+ if (!searchQuery.value) return normalizedOptions.value
345
+ const q = searchQuery.value.toLowerCase()
346
+ return normalizedOptions.value.filter(
347
+ (opt) => opt.label.toLowerCase().includes(q) || opt.subtitle.toLowerCase().includes(q),
348
+ )
349
+ })
350
+
351
+ // ── Grouping ─────────────────────────────────────────────
352
+ // Detect if any option has a group key to enable grouped rendering
353
+ const hasGroups = computed(() => normalizedOptions.value.some((o) => o.group))
354
+
355
+ // Build grouped structure: Map<groupLabel, { label, options[] }>
356
+ const filteredGroups = computed(() => {
357
+ if (!hasGroups.value) return []
358
+ const map = new Map()
359
+ for (const opt of filteredNormalized.value) {
360
+ const key = opt.group || ''
361
+ if (!map.has(key)) map.set(key, { label: key, options: [] })
362
+ map.get(key).options.push(opt)
363
+ }
364
+ return [...map.values()].filter((g) => g.options.length > 0)
365
+ })
366
+
367
+ const filteredOptions = computed(() => {
368
+ if (hasGroups.value) return []
369
+ return filteredNormalized.value
370
+ })
371
+
372
+ // ── Selected display ─────────────────────────────────────
373
+ const selectedOpt = computed(() =>
374
+ normalizedOptions.value.find((o) => o.value === props.modelValue),
375
+ )
376
+ const selectedLabel = computed(() => selectedOpt.value?.label || '')
377
+ const selectedIcon = computed(() => selectedOpt.value?.icon || '')
378
+
379
+ // ── Styling ──────────────────────────────────────────────
380
+ const triggerClasses = computed(() => {
381
+ const base =
382
+ 'flex items-center justify-between gap-2 text-left border bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-400 outline-none transition-colors focus:ring-2 focus:ring-primary-500 focus:border-primary-500'
383
+ const width = props.block ? 'w-full' : ''
384
+ const sizeMap = {
385
+ xs: 'px-2.5 py-1.5 text-xs rounded-md border-gray-200 dark:border-gray-700',
386
+ sm: 'px-2 py-1 text-sm rounded-lg border-gray-300 dark:border-gray-600',
387
+ md: 'px-3 py-2 text-sm rounded-lg border-gray-300 dark:border-gray-700',
388
+ }
389
+ return `${base} ${width} ${sizeMap[props.size] || sizeMap.md}`
390
+ })
391
+
392
+ const optionClass = (value) =>
393
+ props.modelValue === value
394
+ ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'
395
+ : 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700'
396
+
397
+ // ── Interactions ─────────────────────────────────────────
398
+ // Toggle dropdown open/close, auto-detect drop direction, and focus search input
399
+ const toggleOpen = () => {
400
+ if (props.disabled || props.loading) return
401
+ isOpen.value = !isOpen.value
402
+ if (isOpen.value) {
403
+ searchQuery.value = ''
404
+ reposition()
405
+ startTracking()
406
+ nextTick(() => {
407
+ reposition()
408
+ if (props.searchable) searchRef.value?.focus()
409
+ })
410
+ } else {
411
+ stopTracking()
412
+ }
413
+ }
414
+
415
+ const select = (value) => {
416
+ emit('update:modelValue', value)
417
+ close()
418
+ }
419
+
420
+ const selectFirst = () => {
421
+ const pool = hasGroups.value
422
+ ? filteredGroups.value.flatMap((g) => g.options)
423
+ : filteredOptions.value
424
+ if (pool.length) select(pool[0].value)
425
+ }
426
+
427
+ const close = () => {
428
+ isOpen.value = false
429
+ searchQuery.value = ''
430
+ stopTracking()
431
+ }
432
+
433
+ // Programmatic toggle for parent row clicks.
434
+ // Uses a skip flag to prevent the race with the document click handler:
435
+ // when the row is clicked, the capture-phase listener fires first (closing the dropdown),
436
+ // then the row handler calls toggle(). The flag lets us detect this and skip the re-open.
437
+ let skipNextOpen = false
438
+ const toggle = () => {
439
+ if (props.disabled || props.loading) return
440
+ if (skipNextOpen) {
441
+ skipNextOpen = false
442
+ return
443
+ }
444
+ toggleOpen()
445
+ }
446
+
447
+ const closeFromOutside = () => {
448
+ if (isOpen.value) skipNextOpen = true
449
+ close()
450
+ setTimeout(() => {
451
+ skipNextOpen = false
452
+ }, 0)
453
+ }
454
+
455
+ const onDocumentClick = (e) => {
456
+ // The panel is teleported to <body>, so clicks inside it are NOT inside the
457
+ // container — check both before treating a click as "outside".
458
+ if (containerRef.value?.contains(e.target)) return
459
+ if (panelRef.value?.contains(e.target)) return
460
+ closeFromOutside()
461
+ }
462
+
463
+ onMounted(() => document.addEventListener('click', onDocumentClick, true))
464
+ onBeforeUnmount(() => {
465
+ document.removeEventListener('click', onDocumentClick, true)
466
+ stopTracking()
467
+ })
468
+
469
+ defineExpose({ toggle, close, isOpen })
470
+ </script>
@@ -0,0 +1,93 @@
1
+ <template>
2
+ <input
3
+ type="range"
4
+ :min="min"
5
+ :max="max"
6
+ :step="step"
7
+ :value="modelValue"
8
+ :disabled="disabled"
9
+ class="accent-primary-500"
10
+ :class="widthClass"
11
+ @input="onInput"
12
+ />
13
+ </template>
14
+
15
+ <script setup>
16
+ /**
17
+ * UiSlider — Native HTML range slider with primary color accent and width options.
18
+ *
19
+ * Wraps a `<input type="range">` with Tailwind accent color and configurable
20
+ * width mode. Emits both `update:modelValue` for v-model and a raw `input` event.
21
+ *
22
+ * @example Basic slider
23
+ * <UiSlider v-model="volume" :min="0" :max="100" />
24
+ *
25
+ * @example Flex slider with custom step
26
+ * <UiSlider v-model="opacity" :min="0" :max="1" :step="0.01" width="flex" />
27
+ *
28
+ * @emits {number} update:modelValue — Emitted when the slider value changes (v-model)
29
+ * @emits {Event} input — Emitted with the native input event on each change
30
+ */
31
+ import { computed } from 'vue'
32
+ const props = defineProps({
33
+ /**
34
+ * Current slider value (v-model).
35
+ * @type {number}
36
+ * @default 0
37
+ */
38
+ modelValue: { type: Number, default: 0 },
39
+
40
+ /**
41
+ * Minimum allowed value.
42
+ * @type {number | string}
43
+ * @default 0
44
+ */
45
+ min: { type: [Number, String], default: 0 },
46
+
47
+ /**
48
+ * Maximum allowed value.
49
+ * @type {number | string}
50
+ * @default 100
51
+ */
52
+ max: { type: [Number, String], default: 100 },
53
+
54
+ /**
55
+ * Step increment between values.
56
+ * @type {number | string}
57
+ * @default 1
58
+ */
59
+ step: { type: [Number, String], default: 1 },
60
+
61
+ /**
62
+ * Disabled state — prevents interaction.
63
+ * @type {boolean}
64
+ * @default false
65
+ */
66
+ disabled: { type: Boolean, default: false },
67
+
68
+ /**
69
+ * Width mode: 'full' applies w-full, 'flex' applies flex-1 with reduced height.
70
+ * @type {string}
71
+ * @default 'full'
72
+ * @values 'full' | 'flex'
73
+ */
74
+ width: { type: String, default: 'full' },
75
+ })
76
+
77
+ const emit = defineEmits(['update:modelValue', 'input'])
78
+
79
+ const widthClass = computed(() => {
80
+ switch (props.width) {
81
+ case 'flex':
82
+ return 'flex-1 h-1.5'
83
+ default:
84
+ return 'w-full'
85
+ }
86
+ })
87
+
88
+ function onInput(e) {
89
+ const val = Number(e.target.value)
90
+ emit('update:modelValue', val)
91
+ emit('input', e)
92
+ }
93
+ </script>
@@ -0,0 +1,53 @@
1
+ <template>
2
+ <div class="flex justify-center gap-2">
3
+ <button
4
+ v-for="i in steps"
5
+ :key="i"
6
+ class="rounded-full transition-all duration-200"
7
+ :class="dotClasses(i)"
8
+ @click="$emit('update:modelValue', i)"
9
+ />
10
+ </div>
11
+ </template>
12
+
13
+ <script setup>
14
+ /**
15
+ * UiStepper — Dot-based step indicator for wizards and multi-step flows.
16
+ *
17
+ * Renders a row of clickable dots representing steps. The current step is
18
+ * highlighted and wider, completed steps use a muted accent, and future
19
+ * steps are gray. Clicking a dot emits the step number via v-model.
20
+ *
21
+ * @example Basic 4-step wizard
22
+ * <UiStepper v-model="currentStep" :steps="4" />
23
+ *
24
+ * @example Non-interactive indicator
25
+ * <UiStepper :model-value="step" :steps="3" />
26
+ *
27
+ * @emits {number} update:modelValue — Emitted when a step dot is clicked
28
+ */
29
+ const props = defineProps({
30
+ /**
31
+ * Current active step (v-model). 1-indexed.
32
+ * @type {number}
33
+ * @default 1
34
+ */
35
+ modelValue: { type: Number, default: 1 },
36
+
37
+ /**
38
+ * Total number of steps.
39
+ * @type {number}
40
+ * @required
41
+ */
42
+ steps: { type: Number, required: true },
43
+ })
44
+
45
+ defineEmits(['update:modelValue'])
46
+
47
+ const dotClasses = (i) => {
48
+ const base = 'h-2'
49
+ if (i === props.modelValue) return `${base} w-6 bg-primary-500`
50
+ if (i < props.modelValue) return `${base} w-2 bg-primary-300 dark:bg-primary-700`
51
+ return `${base} w-2 bg-gray-300 dark:bg-gray-700`
52
+ }
53
+ </script>