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.
- package/LICENSE +651 -0
- package/README.md +466 -0
- package/dist/components/Alert.js +137 -0
- package/dist/components/Alert.js.map +1 -0
- package/dist/components/Avatar.js +133 -0
- package/dist/components/Avatar.js.map +1 -0
- package/dist/components/Badge.js +93 -0
- package/dist/components/Badge.js.map +1 -0
- package/dist/components/Button.js +428 -0
- package/dist/components/Button.js.map +1 -0
- package/dist/components/ButtonsGroup.js +153 -0
- package/dist/components/ButtonsGroup.js.map +1 -0
- package/dist/components/Checkbox.js +93 -0
- package/dist/components/Checkbox.js.map +1 -0
- package/dist/components/Divider.js +79 -0
- package/dist/components/Divider.js.map +1 -0
- package/dist/components/Dropdown.js +166 -0
- package/dist/components/Dropdown.js.map +1 -0
- package/dist/components/DropdownItem.js +106 -0
- package/dist/components/DropdownItem.js.map +1 -0
- package/dist/components/DropdownRow.js +41 -0
- package/dist/components/DropdownRow.js.map +1 -0
- package/dist/components/DropdownSubmenu.js +142 -0
- package/dist/components/DropdownSubmenu.js.map +1 -0
- package/dist/components/FileInput.js +122 -0
- package/dist/components/FileInput.js.map +1 -0
- package/dist/components/FormField.js +112 -0
- package/dist/components/FormField.js.map +1 -0
- package/dist/components/Input.js +603 -0
- package/dist/components/Input.js.map +1 -0
- package/dist/components/Kbd.js +35 -0
- package/dist/components/Kbd.js.map +1 -0
- package/dist/components/ListMenu.js +143 -0
- package/dist/components/ListMenu.js.map +1 -0
- package/dist/components/ListMenuItem.js +189 -0
- package/dist/components/ListMenuItem.js.map +1 -0
- package/dist/components/Modal.js +206 -0
- package/dist/components/Modal.js.map +1 -0
- package/dist/components/Numpad.js +123 -0
- package/dist/components/Numpad.js.map +1 -0
- package/dist/components/Popup.js +170 -0
- package/dist/components/Popup.js.map +1 -0
- package/dist/components/ProgressBar.js +118 -0
- package/dist/components/ProgressBar.js.map +1 -0
- package/dist/components/Prompt.js +201 -0
- package/dist/components/Prompt.js.map +1 -0
- package/dist/components/Radio.js +81 -0
- package/dist/components/Radio.js.map +1 -0
- package/dist/components/Select.js +441 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Slider.js +116 -0
- package/dist/components/Slider.js.map +1 -0
- package/dist/components/Stepper.js +65 -0
- package/dist/components/Stepper.js.map +1 -0
- package/dist/components/Toggle.js +133 -0
- package/dist/components/Toggle.js.map +1 -0
- package/dist/components/Tooltip.js +120 -0
- package/dist/components/Tooltip.js.map +1 -0
- package/dist/components/index.js +81 -0
- package/dist/components/index.js.map +1 -0
- package/dist/composables/onClickOutside.js +51 -0
- package/dist/composables/onClickOutside.js.map +1 -0
- package/dist/composables/useBackButton.js +98 -0
- package/dist/composables/useBackButton.js.map +1 -0
- package/dist/composables/useEventListener.js +63 -0
- package/dist/composables/useEventListener.js.map +1 -0
- package/dist/icons/Icon.js +120 -0
- package/dist/icons/Icon.js.map +1 -0
- package/dist/icons/mdi.js +69 -0
- package/dist/icons/mdi.js.map +1 -0
- package/dist/icons/registry.js +63 -0
- package/dist/icons/registry.js.map +1 -0
- package/dist/icons/resolver.js +49 -0
- package/dist/icons/resolver.js.map +1 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +157 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.js +89 -0
- package/dist/manifest.js.map +1 -0
- package/dist/numori-ui.css +184 -0
- package/dist/nuxt.d.ts +35 -0
- package/dist/nuxt.mjs +243 -0
- package/dist/nuxt.mjs.map +1 -0
- package/dist/vite.d.ts +29 -0
- package/dist/vite.mjs +187 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +138 -0
- package/src/components/Alert.vue +127 -0
- package/src/components/Avatar.vue +100 -0
- package/src/components/Badge.vue +77 -0
- package/src/components/Button.vue +419 -0
- package/src/components/ButtonsGroup.vue +140 -0
- package/src/components/Checkbox.vue +81 -0
- package/src/components/Divider.vue +64 -0
- package/src/components/Dropdown.vue +150 -0
- package/src/components/DropdownItem.vue +78 -0
- package/src/components/DropdownRow.vue +37 -0
- package/src/components/DropdownSubmenu.vue +127 -0
- package/src/components/FileInput.vue +107 -0
- package/src/components/FormField.vue +86 -0
- package/src/components/Input.vue +619 -0
- package/src/components/Kbd.vue +30 -0
- package/src/components/ListMenu.vue +127 -0
- package/src/components/ListMenuItem.vue +171 -0
- package/src/components/Modal.vue +209 -0
- package/src/components/Numpad.vue +118 -0
- package/src/components/Popup.vue +156 -0
- package/src/components/ProgressBar.vue +107 -0
- package/src/components/Prompt.vue +161 -0
- package/src/components/Radio.vue +50 -0
- package/src/components/Select.vue +470 -0
- package/src/components/Slider.vue +93 -0
- package/src/components/Stepper.vue +53 -0
- package/src/components/Toggle.vue +125 -0
- package/src/components/Tooltip.vue +113 -0
- package/src/components/index.js +109 -0
- package/src/composables/onClickOutside.js +61 -0
- package/src/composables/useBackButton.js +98 -0
- package/src/composables/useEventListener.js +65 -0
- package/src/icons/Icon.vue +139 -0
- package/src/icons/mdi.js +67 -0
- package/src/icons/registry.js +64 -0
- package/src/icons/resolver.js +48 -0
- package/src/index.js +167 -0
- package/src/manifest.js +86 -0
- package/src/nuxt.js +315 -0
- package/src/style.css +20 -0
- package/src/tailwind.css +18 -0
- package/src/theme.css +172 -0
- package/src/vite.js +235 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="w-full">
|
|
3
|
+
<div class="relative flex">
|
|
4
|
+
<!-- Number stepper: minus button on left (both-sides layout) -->
|
|
5
|
+
<button
|
|
6
|
+
v-if="isNumber && stepperLayout === 'both-sides'"
|
|
7
|
+
type="button"
|
|
8
|
+
tabindex="-1"
|
|
9
|
+
class="flex items-center justify-center w-9 rounded-l-lg border border-r-0 border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors select-none"
|
|
10
|
+
:class="{ 'opacity-50 pointer-events-none': disabled }"
|
|
11
|
+
aria-label="Decrease value"
|
|
12
|
+
@click="stepDown"
|
|
13
|
+
>
|
|
14
|
+
<UiIcon name="mdi:minus" class="w-4 h-4" />
|
|
15
|
+
</button>
|
|
16
|
+
|
|
17
|
+
<!-- Number stepper: stacked up/down buttons on left -->
|
|
18
|
+
<div
|
|
19
|
+
v-if="isNumber && stepperLayout === 'stacked-left'"
|
|
20
|
+
class="flex flex-col w-6 border border-r-0 border-gray-300 dark:border-gray-600 rounded-l-lg overflow-hidden"
|
|
21
|
+
:class="{ 'opacity-50 pointer-events-none': disabled }"
|
|
22
|
+
>
|
|
23
|
+
<button
|
|
24
|
+
type="button"
|
|
25
|
+
tabindex="-1"
|
|
26
|
+
class="grid place-items-center w-4 flex-1 bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors select-none border-b border-gray-300 dark:border-gray-600"
|
|
27
|
+
aria-label="Increase value"
|
|
28
|
+
@click="stepUp"
|
|
29
|
+
>
|
|
30
|
+
<UiIcon name="mdi:chevron-up" class="block w-3 h-3" />
|
|
31
|
+
</button>
|
|
32
|
+
<button
|
|
33
|
+
type="button"
|
|
34
|
+
tabindex="-1"
|
|
35
|
+
class="grid place-items-center w-4 flex-1 bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors select-none"
|
|
36
|
+
aria-label="Decrease value"
|
|
37
|
+
@click="stepDown"
|
|
38
|
+
>
|
|
39
|
+
<UiIcon name="mdi:chevron-down" class="block w-3 h-3" />
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<!-- Textarea mode: multi-line text input with custom scrollbar styling -->
|
|
44
|
+
<textarea
|
|
45
|
+
v-if="isTextarea"
|
|
46
|
+
ref="inputRef"
|
|
47
|
+
:value="modelValue"
|
|
48
|
+
:placeholder="placeholder"
|
|
49
|
+
:required="required"
|
|
50
|
+
:disabled="disabled"
|
|
51
|
+
:readonly="readonly"
|
|
52
|
+
:rows="rows"
|
|
53
|
+
:maxlength="maxlength"
|
|
54
|
+
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-400 focus:ring-2 focus:ring-primary-500 focus:border-primary-500 outline-none text-sm transition-colors [scrollbar-width:thin] [scrollbar-color:var(--color-gray-300)_transparent] dark:[scrollbar-color:var(--color-gray-600)_transparent] [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-gray-300 dark:[&::-webkit-scrollbar-thumb]:bg-gray-600 hover:[&::-webkit-scrollbar-thumb]:bg-gray-400 dark:hover:[&::-webkit-scrollbar-thumb]:bg-gray-500"
|
|
55
|
+
:class="resizeClass"
|
|
56
|
+
:style="textareaStyle"
|
|
57
|
+
@input="onInput"
|
|
58
|
+
@blur="onBlur"
|
|
59
|
+
/>
|
|
60
|
+
|
|
61
|
+
<!-- The actual input element (text, number, password, email, phone) -->
|
|
62
|
+
<!-- Left icon/image slot -->
|
|
63
|
+
<span
|
|
64
|
+
v-if="!isTextarea && ($slots.left || iconLeft)"
|
|
65
|
+
class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-gray-400 dark:text-gray-500"
|
|
66
|
+
>
|
|
67
|
+
<slot name="left">
|
|
68
|
+
<UiIcon v-if="iconLeft" :name="iconLeft" class="w-4 h-4" />
|
|
69
|
+
</slot>
|
|
70
|
+
</span>
|
|
71
|
+
|
|
72
|
+
<input
|
|
73
|
+
v-if="!isTextarea"
|
|
74
|
+
ref="inputRef"
|
|
75
|
+
:type="computedType"
|
|
76
|
+
:value="modelValue"
|
|
77
|
+
:placeholder="placeholder"
|
|
78
|
+
:required="required"
|
|
79
|
+
:disabled="disabled"
|
|
80
|
+
:readonly="readonly"
|
|
81
|
+
:autocomplete="autocomplete"
|
|
82
|
+
:minlength="minlength"
|
|
83
|
+
:maxlength="maxlength"
|
|
84
|
+
:inputmode="computedInputMode"
|
|
85
|
+
:min="min"
|
|
86
|
+
:max="max"
|
|
87
|
+
:step="step"
|
|
88
|
+
:pattern="pattern"
|
|
89
|
+
class="w-full py-2 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-400 focus:ring-2 focus:ring-primary-500 focus:border-primary-500 outline-none text-sm transition-colors"
|
|
90
|
+
:class="inputClasses"
|
|
91
|
+
@input="onInput"
|
|
92
|
+
@blur="onBlur"
|
|
93
|
+
@keydown="onKeydown"
|
|
94
|
+
/>
|
|
95
|
+
|
|
96
|
+
<!-- Right icon/image slot (hidden when clear button or password toggle is shown) -->
|
|
97
|
+
<span
|
|
98
|
+
v-if="
|
|
99
|
+
!isTextarea &&
|
|
100
|
+
($slots.right || iconRight) &&
|
|
101
|
+
!(clearable && modelValue) &&
|
|
102
|
+
!(isPassword && showToggle)
|
|
103
|
+
"
|
|
104
|
+
class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-gray-400 dark:text-gray-500"
|
|
105
|
+
>
|
|
106
|
+
<slot name="right">
|
|
107
|
+
<UiIcon v-if="iconRight" :name="iconRight" class="w-4 h-4" />
|
|
108
|
+
</slot>
|
|
109
|
+
</span>
|
|
110
|
+
|
|
111
|
+
<!-- Clear button -->
|
|
112
|
+
<button
|
|
113
|
+
v-if="clearable && modelValue"
|
|
114
|
+
type="button"
|
|
115
|
+
tabindex="-1"
|
|
116
|
+
class="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"
|
|
117
|
+
aria-label="Clear"
|
|
118
|
+
@mousedown.prevent
|
|
119
|
+
@click="emit('update:modelValue', '')"
|
|
120
|
+
>
|
|
121
|
+
<UiIcon name="mdi:close-circle" class="w-4 h-4" />
|
|
122
|
+
</button>
|
|
123
|
+
|
|
124
|
+
<!-- Password visibility toggle button -->
|
|
125
|
+
<button
|
|
126
|
+
v-if="isPassword && showToggle"
|
|
127
|
+
type="button"
|
|
128
|
+
tabindex="-1"
|
|
129
|
+
class="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"
|
|
130
|
+
:aria-label="passwordVisible ? 'Hide password' : 'Show password'"
|
|
131
|
+
@mousedown.prevent
|
|
132
|
+
@click="passwordVisible = !passwordVisible"
|
|
133
|
+
>
|
|
134
|
+
<UiIcon
|
|
135
|
+
:name="passwordVisible ? 'mdi:eye-off-outline' : 'mdi:eye-outline'"
|
|
136
|
+
class="w-4 h-4"
|
|
137
|
+
/>
|
|
138
|
+
</button>
|
|
139
|
+
|
|
140
|
+
<!-- Number stepper: stacked up/down buttons on right -->
|
|
141
|
+
<div
|
|
142
|
+
v-if="isNumber && stepperLayout === 'stacked-right'"
|
|
143
|
+
class="flex flex-col w-6 border border-l-0 border-gray-300 dark:border-gray-600 rounded-r-lg overflow-hidden"
|
|
144
|
+
:class="{ 'opacity-50 pointer-events-none': disabled }"
|
|
145
|
+
>
|
|
146
|
+
<button
|
|
147
|
+
type="button"
|
|
148
|
+
tabindex="-1"
|
|
149
|
+
class="grid place-items-center w-4 flex-1 bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors select-none border-b border-gray-300 dark:border-gray-600"
|
|
150
|
+
aria-label="Increase value"
|
|
151
|
+
@click="stepUp"
|
|
152
|
+
>
|
|
153
|
+
<UiIcon name="mdi:chevron-up" class="block w-3 h-3" />
|
|
154
|
+
</button>
|
|
155
|
+
<button
|
|
156
|
+
type="button"
|
|
157
|
+
tabindex="-1"
|
|
158
|
+
class="grid place-items-center w-4 flex-1 bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors select-none"
|
|
159
|
+
aria-label="Decrease value"
|
|
160
|
+
@click="stepDown"
|
|
161
|
+
>
|
|
162
|
+
<UiIcon name="mdi:chevron-down" class="block w-3 h-3" />
|
|
163
|
+
</button>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<!-- Number stepper: plus button on right (both-sides layout) -->
|
|
167
|
+
<button
|
|
168
|
+
v-if="isNumber && stepperLayout === 'both-sides'"
|
|
169
|
+
type="button"
|
|
170
|
+
tabindex="-1"
|
|
171
|
+
class="flex items-center justify-center w-9 rounded-r-lg border border-l-0 border-gray-300 dark:border-gray-600 bg-gray-50 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors select-none"
|
|
172
|
+
:class="{ 'opacity-50 pointer-events-none': disabled }"
|
|
173
|
+
aria-label="Increase value"
|
|
174
|
+
@click="stepUp"
|
|
175
|
+
>
|
|
176
|
+
<UiIcon name="mdi:plus" class="w-4 h-4" />
|
|
177
|
+
</button>
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
<!-- Validation error message (shown after first blur) -->
|
|
181
|
+
<p v-if="showError && validationError" class="text-xs text-red-600 dark:text-red-400 mt-1">
|
|
182
|
+
{{ validationError }}
|
|
183
|
+
</p>
|
|
184
|
+
</div>
|
|
185
|
+
</template>
|
|
186
|
+
|
|
187
|
+
<script setup>
|
|
188
|
+
/**
|
|
189
|
+
* UiInput — Multi-purpose input component supporting text, number, password, email,
|
|
190
|
+
* phone, and textarea modes in a single unified interface.
|
|
191
|
+
*
|
|
192
|
+
* Features:
|
|
193
|
+
* - Number mode with configurable stepper layouts (both-sides, stacked-left, stacked-right, none)
|
|
194
|
+
* - Password mode with show/hide toggle
|
|
195
|
+
* - Textarea mode with configurable resize, min/max dimensions
|
|
196
|
+
* - Built-in validation for email, phone, and number patterns
|
|
197
|
+
* - Custom regex validation with configurable error messages
|
|
198
|
+
* - Exposes `focus()` method and `el` ref for parent control
|
|
199
|
+
*
|
|
200
|
+
* @example Basic text input
|
|
201
|
+
* <UiInput v-model="name" placeholder="Enter your name" />
|
|
202
|
+
*
|
|
203
|
+
* @example Number input with min/max
|
|
204
|
+
* <UiInput v-model="quantity" type="number" :min="0" :max="100" :step="1" />
|
|
205
|
+
*
|
|
206
|
+
* @example Password with toggle
|
|
207
|
+
* <UiInput v-model="password" type="password" />
|
|
208
|
+
*
|
|
209
|
+
* @example Textarea
|
|
210
|
+
* <UiInput v-model="bio" type="textarea" :rows="5" resize="vertical" />
|
|
211
|
+
*
|
|
212
|
+
* @example Email with validation
|
|
213
|
+
* <UiInput v-model="email" type="email" :validate="true" />
|
|
214
|
+
*
|
|
215
|
+
* @emits {string | number} update:modelValue — Emitted when the input value changes (v-model)
|
|
216
|
+
* @emits {{ valid: boolean, error: string | null }} validation — Emitted when the validation state changes
|
|
217
|
+
*/
|
|
218
|
+
import { ref, computed, watch, useSlots } from 'vue'
|
|
219
|
+
import UiIcon from '../icons/Icon.vue'
|
|
220
|
+
const props = defineProps({
|
|
221
|
+
/**
|
|
222
|
+
* Bound value (v-model).
|
|
223
|
+
* @type {string | number}
|
|
224
|
+
* @default ''
|
|
225
|
+
*/
|
|
226
|
+
modelValue: { type: [String, Number], default: '' },
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Input type determining the mode and behavior.
|
|
230
|
+
* @type {string}
|
|
231
|
+
* @default 'text'
|
|
232
|
+
* @values 'text' | 'number' | 'password' | 'email' | 'phone' | 'textarea'
|
|
233
|
+
*/
|
|
234
|
+
type: { type: String, default: 'text' },
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Placeholder text shown when the input is empty.
|
|
238
|
+
* @type {string}
|
|
239
|
+
* @default ''
|
|
240
|
+
*/
|
|
241
|
+
placeholder: { type: String, default: '' },
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Whether the field is required for form validation.
|
|
245
|
+
* @type {boolean}
|
|
246
|
+
* @default false
|
|
247
|
+
*/
|
|
248
|
+
required: { type: Boolean, default: false },
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Disabled state — dims the input and prevents interaction.
|
|
252
|
+
* @type {boolean}
|
|
253
|
+
* @default false
|
|
254
|
+
*/
|
|
255
|
+
disabled: { type: Boolean, default: false },
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Read-only state — allows focus/selection but prevents editing.
|
|
259
|
+
* @type {boolean}
|
|
260
|
+
* @default false
|
|
261
|
+
*/
|
|
262
|
+
readonly: { type: Boolean, default: false },
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* HTML autocomplete attribute hint for the browser.
|
|
266
|
+
* @type {string}
|
|
267
|
+
* @default undefined
|
|
268
|
+
*/
|
|
269
|
+
autocomplete: { type: String, default: undefined },
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Minimum character length for text validation.
|
|
273
|
+
* @type {number}
|
|
274
|
+
* @default undefined
|
|
275
|
+
*/
|
|
276
|
+
minlength: { type: Number, default: undefined },
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Maximum character length for text validation.
|
|
280
|
+
* @type {number}
|
|
281
|
+
* @default undefined
|
|
282
|
+
*/
|
|
283
|
+
maxlength: { type: Number, default: undefined },
|
|
284
|
+
|
|
285
|
+
// ── Textarea-specific props ──
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Number of visible text rows (textarea mode only).
|
|
289
|
+
* @type {number}
|
|
290
|
+
* @default 3
|
|
291
|
+
*/
|
|
292
|
+
rows: { type: Number, default: 3 },
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Resize behavior for textarea mode.
|
|
296
|
+
* @type {string}
|
|
297
|
+
* @default 'none'
|
|
298
|
+
* @values 'none' | 'vertical' | 'horizontal' | 'both'
|
|
299
|
+
*/
|
|
300
|
+
resize: { type: String, default: 'none' },
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Minimum height CSS value for textarea (e.g. '80px', '5rem').
|
|
304
|
+
* @type {string}
|
|
305
|
+
* @default undefined
|
|
306
|
+
*/
|
|
307
|
+
minHeight: { type: String, default: undefined },
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Maximum height CSS value for textarea (e.g. '300px', '20rem').
|
|
311
|
+
* @type {string}
|
|
312
|
+
* @default undefined
|
|
313
|
+
*/
|
|
314
|
+
maxHeight: { type: String, default: undefined },
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Minimum width CSS value for textarea (e.g. '200px').
|
|
318
|
+
* @type {string}
|
|
319
|
+
* @default undefined
|
|
320
|
+
*/
|
|
321
|
+
minWidth: { type: String, default: undefined },
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Maximum width CSS value for textarea (e.g. '600px').
|
|
325
|
+
* @type {string}
|
|
326
|
+
* @default undefined
|
|
327
|
+
*/
|
|
328
|
+
maxWidth: { type: String, default: undefined },
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* HTML pattern attribute for native form validation.
|
|
332
|
+
* @type {string}
|
|
333
|
+
* @default undefined
|
|
334
|
+
*/
|
|
335
|
+
pattern: { type: String, default: undefined },
|
|
336
|
+
|
|
337
|
+
// ── Password-specific props ──
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Show the password visibility toggle button (password mode only).
|
|
341
|
+
* @type {boolean}
|
|
342
|
+
* @default true
|
|
343
|
+
*/
|
|
344
|
+
showToggle: { type: Boolean, default: true },
|
|
345
|
+
|
|
346
|
+
// ── Number-specific props ──
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Minimum allowed numeric value.
|
|
350
|
+
* @type {number}
|
|
351
|
+
* @default undefined
|
|
352
|
+
*/
|
|
353
|
+
min: { type: Number, default: undefined },
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Maximum allowed numeric value.
|
|
357
|
+
* @type {number}
|
|
358
|
+
* @default undefined
|
|
359
|
+
*/
|
|
360
|
+
max: { type: Number, default: undefined },
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Step increment for number stepper buttons.
|
|
364
|
+
* @type {number}
|
|
365
|
+
* @default 1
|
|
366
|
+
*/
|
|
367
|
+
step: { type: Number, default: 1 },
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Layout of the +/- stepper buttons for number inputs.
|
|
371
|
+
* @type {string}
|
|
372
|
+
* @default 'both-sides'
|
|
373
|
+
* @values 'stacked-left' | 'stacked-right' | 'both-sides' | 'none'
|
|
374
|
+
*/
|
|
375
|
+
stepperLayout: { type: String, default: 'both-sides' },
|
|
376
|
+
|
|
377
|
+
// ── Validation props ──
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Show a clear button when the input has a value.
|
|
381
|
+
* @type {boolean}
|
|
382
|
+
* @default false
|
|
383
|
+
*/
|
|
384
|
+
clearable: { type: Boolean, default: false },
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Icon name to display on the left side of the input.
|
|
388
|
+
* @type {string}
|
|
389
|
+
* @default undefined
|
|
390
|
+
*/
|
|
391
|
+
iconLeft: { type: String, default: undefined },
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Icon name to display on the right side of the input.
|
|
395
|
+
* @type {string}
|
|
396
|
+
* @default undefined
|
|
397
|
+
*/
|
|
398
|
+
iconRight: { type: String, default: undefined },
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Enable built-in validation feedback shown below the input on blur.
|
|
402
|
+
* @type {boolean}
|
|
403
|
+
* @default true
|
|
404
|
+
*/
|
|
405
|
+
validate: { type: Boolean, default: true },
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Custom regex pattern string — overrides built-in type-based patterns.
|
|
409
|
+
* @type {string}
|
|
410
|
+
* @default undefined
|
|
411
|
+
*/
|
|
412
|
+
validationPattern: { type: String, default: undefined },
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Custom error message shown when validation fails.
|
|
416
|
+
* @type {string}
|
|
417
|
+
* @default undefined
|
|
418
|
+
*/
|
|
419
|
+
validationMessage: { type: String, default: undefined },
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
const emit = defineEmits(['update:modelValue', 'validation'])
|
|
423
|
+
|
|
424
|
+
const inputRef = ref(null)
|
|
425
|
+
const passwordVisible = ref(false)
|
|
426
|
+
const touched = ref(false)
|
|
427
|
+
|
|
428
|
+
// --- Computed helpers ---
|
|
429
|
+
|
|
430
|
+
// Detect input mode from the type prop
|
|
431
|
+
const isPassword = computed(() => props.type === 'password')
|
|
432
|
+
const isNumber = computed(() => props.type === 'number')
|
|
433
|
+
const isTextarea = computed(() => props.type === 'textarea')
|
|
434
|
+
|
|
435
|
+
// Map resize prop to Tailwind resize utility class
|
|
436
|
+
const resizeClass = computed(() => {
|
|
437
|
+
const map = { none: 'resize-none', vertical: 'resize-y', horizontal: 'resize-x', both: 'resize' }
|
|
438
|
+
return map[props.resize] || 'resize-none'
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
const textareaStyle = computed(() => {
|
|
442
|
+
const s = {}
|
|
443
|
+
if (props.minHeight) s.minHeight = props.minHeight
|
|
444
|
+
if (props.maxHeight) s.maxHeight = props.maxHeight
|
|
445
|
+
if (props.minWidth) s.minWidth = props.minWidth
|
|
446
|
+
if (props.maxWidth) s.maxWidth = props.maxWidth
|
|
447
|
+
return s
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
// For number type, render as text input so we can filter keystrokes ourselves
|
|
451
|
+
const computedType = computed(() => {
|
|
452
|
+
if (isPassword.value) return passwordVisible.value ? 'text' : 'password'
|
|
453
|
+
if (isNumber.value) return 'text' // we handle number filtering ourselves
|
|
454
|
+
if (props.type === 'phone') return 'tel'
|
|
455
|
+
return props.type
|
|
456
|
+
})
|
|
457
|
+
|
|
458
|
+
// Set appropriate mobile keyboard via inputmode attribute
|
|
459
|
+
const computedInputMode = computed(() => {
|
|
460
|
+
if (isNumber.value) return 'decimal'
|
|
461
|
+
if (props.type === 'phone') return 'tel'
|
|
462
|
+
if (props.type === 'email') return 'email'
|
|
463
|
+
return undefined
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
const hasStepper = computed(() => isNumber.value && props.stepperLayout !== 'none')
|
|
467
|
+
|
|
468
|
+
const slots = useSlots()
|
|
469
|
+
|
|
470
|
+
const hasLeftIcon = computed(() => !!props.iconLeft || !!slots.left)
|
|
471
|
+
const hasRightIcon = computed(() => !!props.iconRight || !!slots.right)
|
|
472
|
+
|
|
473
|
+
const inputClasses = computed(() => {
|
|
474
|
+
const classes = []
|
|
475
|
+
|
|
476
|
+
// Horizontal padding — tighter when steppers are present
|
|
477
|
+
if (hasStepper.value) {
|
|
478
|
+
classes.push('px-1.5')
|
|
479
|
+
} else {
|
|
480
|
+
// Adjust padding for icons/slots
|
|
481
|
+
classes.push(hasLeftIcon.value ? 'pl-9' : 'pl-3')
|
|
482
|
+
classes.push(hasRightIcon.value ? 'pr-9' : 'pr-3')
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// Rounding based on stepper layout
|
|
486
|
+
if (hasStepper.value) {
|
|
487
|
+
if (props.stepperLayout === 'both-sides') classes.push('rounded-none')
|
|
488
|
+
else if (props.stepperLayout === 'stacked-left') classes.push('rounded-l-none', 'rounded-r-lg')
|
|
489
|
+
else if (props.stepperLayout === 'stacked-right') classes.push('rounded-r-none', 'rounded-l-lg')
|
|
490
|
+
} else {
|
|
491
|
+
classes.push('rounded-lg')
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Extra right padding for password toggle
|
|
495
|
+
if (isPassword.value && props.showToggle) classes.push('pr-10')
|
|
496
|
+
|
|
497
|
+
// Extra right padding for clear button
|
|
498
|
+
if (props.clearable) classes.push('pr-8')
|
|
499
|
+
|
|
500
|
+
// Number text alignment
|
|
501
|
+
if (isNumber.value && hasStepper.value) classes.push('text-center')
|
|
502
|
+
|
|
503
|
+
return classes
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
// --- Validation ---
|
|
507
|
+
|
|
508
|
+
// Built-in regex patterns for common input types
|
|
509
|
+
const PATTERNS = {
|
|
510
|
+
email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
511
|
+
phone: /^\+?[\d\s\-().]{7,}$/,
|
|
512
|
+
number: /^-?\d*\.?\d+$/,
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const MESSAGES = {
|
|
516
|
+
email: 'Please enter a valid email address',
|
|
517
|
+
phone: 'Please enter a valid phone number',
|
|
518
|
+
number: 'Please enter a valid number',
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const validationError = computed(() => {
|
|
522
|
+
const val = String(props.modelValue ?? '')
|
|
523
|
+
if (!val) return null
|
|
524
|
+
|
|
525
|
+
// Custom pattern takes priority
|
|
526
|
+
if (props.validationPattern) {
|
|
527
|
+
const re = new RegExp(props.validationPattern)
|
|
528
|
+
if (!re.test(val)) return props.validationMessage || 'Invalid format'
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// Built-in patterns
|
|
532
|
+
const builtIn = PATTERNS[props.type]
|
|
533
|
+
if (builtIn && !builtIn.test(val)) {
|
|
534
|
+
return props.validationMessage || MESSAGES[props.type] || 'Invalid input'
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return null
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
const showError = computed(() => props.validate && touched.value)
|
|
541
|
+
|
|
542
|
+
watch(validationError, (err) => {
|
|
543
|
+
emit('validation', { valid: !err, error: err })
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
// --- Event handlers ---
|
|
547
|
+
|
|
548
|
+
// Regex for validating partial number input (allows intermediate states like "-" or ".")
|
|
549
|
+
const NUMBER_ALLOWED = /^-?\d*\.?\d*$/
|
|
550
|
+
|
|
551
|
+
function onInput(e) {
|
|
552
|
+
const val = e.target.value
|
|
553
|
+
|
|
554
|
+
// For number type, reject non-numeric characters
|
|
555
|
+
if (isNumber.value) {
|
|
556
|
+
if (!NUMBER_ALLOWED.test(val)) {
|
|
557
|
+
// Revert to previous valid value
|
|
558
|
+
e.target.value = String(props.modelValue ?? '')
|
|
559
|
+
return
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
emit(
|
|
564
|
+
'update:modelValue',
|
|
565
|
+
isNumber.value && val !== '' && val !== '-' && val !== '.' && val !== '-.' ? Number(val) : val,
|
|
566
|
+
)
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function onBlur() {
|
|
570
|
+
touched.value = true
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function onKeydown(e) {
|
|
574
|
+
if (!isNumber.value) return
|
|
575
|
+
|
|
576
|
+
// Allow: backspace, delete, tab, escape, enter, arrows, home, end, decimal point, minus
|
|
577
|
+
const allowed = [
|
|
578
|
+
'Backspace',
|
|
579
|
+
'Delete',
|
|
580
|
+
'Tab',
|
|
581
|
+
'Escape',
|
|
582
|
+
'Enter',
|
|
583
|
+
'ArrowLeft',
|
|
584
|
+
'ArrowRight',
|
|
585
|
+
'Home',
|
|
586
|
+
'End',
|
|
587
|
+
]
|
|
588
|
+
if (allowed.includes(e.key)) return
|
|
589
|
+
if (e.key === '.' && !String(props.modelValue).includes('.')) return
|
|
590
|
+
if (e.key === '-' && e.target.selectionStart === 0 && !String(props.modelValue).includes('-'))
|
|
591
|
+
return
|
|
592
|
+
if (e.ctrlKey || e.metaKey) return // allow copy/paste/select-all
|
|
593
|
+
|
|
594
|
+
// Block non-digit keys
|
|
595
|
+
if (!/^\d$/.test(e.key)) {
|
|
596
|
+
e.preventDefault()
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function stepUp() {
|
|
601
|
+
const current = Number(props.modelValue) || 0
|
|
602
|
+
let next = current + (props.step ?? 1)
|
|
603
|
+
if (props.max !== undefined) next = Math.min(next, props.max)
|
|
604
|
+
emit('update:modelValue', next)
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function stepDown() {
|
|
608
|
+
const current = Number(props.modelValue) || 0
|
|
609
|
+
let next = current - (props.step ?? 1)
|
|
610
|
+
if (props.min !== undefined) next = Math.max(next, props.min)
|
|
611
|
+
emit('update:modelValue', next)
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// Expose focus method
|
|
615
|
+
defineExpose({
|
|
616
|
+
focus: () => inputRef.value?.focus(),
|
|
617
|
+
el: inputRef,
|
|
618
|
+
})
|
|
619
|
+
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<kbd
|
|
3
|
+
class="px-3 py-1 bg-gray-100 dark:bg-gray-800 rounded text-sm font-mono text-gray-900 dark:text-gray-400"
|
|
4
|
+
>
|
|
5
|
+
<slot />
|
|
6
|
+
</kbd>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script setup>
|
|
10
|
+
/**
|
|
11
|
+
* UiKbd — Keyboard shortcut badge for displaying key combinations.
|
|
12
|
+
*
|
|
13
|
+
* Renders a styled `<kbd>` element with monospace font and subtle background,
|
|
14
|
+
* matching the app's light/dark theme. Used in help screens and shortcut hints.
|
|
15
|
+
*
|
|
16
|
+
* @example Single key
|
|
17
|
+
* <UiKbd>Enter</UiKbd>
|
|
18
|
+
*
|
|
19
|
+
* @example Key combination
|
|
20
|
+
* <UiKbd>Ctrl+S</UiKbd>
|
|
21
|
+
*
|
|
22
|
+
* @example In a shortcut row
|
|
23
|
+
* <div class="flex justify-between">
|
|
24
|
+
* <span>Save</span>
|
|
25
|
+
* <UiKbd>{{ modLabel }}+S</UiKbd>
|
|
26
|
+
* </div>
|
|
27
|
+
*
|
|
28
|
+
* @slot default — Key text or combination to display
|
|
29
|
+
*/
|
|
30
|
+
</script>
|