@getmicdrop/svelte-components 5.6.0 → 5.6.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 (77) hide show
  1. package/dist/components/Layout/__tests__/AppShell.test.d.ts +2 -0
  2. package/dist/components/Layout/__tests__/AppShell.test.d.ts.map +1 -0
  3. package/dist/components/Layout/__tests__/AppShell.test.js +95 -0
  4. package/dist/components/Layout/__tests__/ContentSection.test.d.ts +2 -0
  5. package/dist/components/Layout/__tests__/ContentSection.test.d.ts.map +1 -0
  6. package/dist/components/Layout/__tests__/ContentSection.test.js +112 -0
  7. package/dist/components/Layout/__tests__/PageContainer.test.d.ts +2 -0
  8. package/dist/components/Layout/__tests__/PageContainer.test.d.ts.map +1 -0
  9. package/dist/components/Layout/__tests__/PageContainer.test.js +133 -0
  10. package/dist/components/Layout/__tests__/Responsive.test.d.ts +2 -0
  11. package/dist/components/Layout/__tests__/Responsive.test.d.ts.map +1 -0
  12. package/dist/components/Layout/__tests__/Responsive.test.js +123 -0
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +41 -40
  15. package/dist/patterns/navigation/BottomNav.svelte +18 -8
  16. package/dist/patterns/navigation/BottomNav.svelte.d.ts.map +1 -1
  17. package/dist/primitives/Accordion/AccordionItemWrapper.test.svelte +107 -107
  18. package/dist/primitives/Accordion/AccordionItemWrapper.test.svelte.d.ts +2 -2
  19. package/dist/primitives/Accordion/AccordionItemWrapper.test.svelte.d.ts.map +1 -1
  20. package/dist/primitives/Checkbox/Checkbox.svelte +3 -3
  21. package/dist/primitives/Dropdown/DropdownDivider.svelte +9 -0
  22. package/dist/primitives/Dropdown/DropdownDivider.svelte.d.ts +7 -0
  23. package/dist/primitives/Dropdown/DropdownDivider.svelte.d.ts.map +1 -0
  24. package/dist/primitives/Helper/Helper.svelte +33 -0
  25. package/dist/primitives/Helper/Helper.svelte.d.ts +18 -0
  26. package/dist/primitives/Helper/Helper.svelte.d.ts.map +1 -0
  27. package/dist/primitives/Input/Input.svelte +416 -417
  28. package/dist/primitives/Input/Input.svelte.d.ts +2 -4
  29. package/dist/primitives/Input/Input.svelte.d.ts.map +1 -1
  30. package/dist/primitives/Modal/Modal.svelte +157 -158
  31. package/dist/primitives/Modal/Modal.svelte.d.ts +6 -8
  32. package/dist/primitives/Modal/Modal.svelte.d.ts.map +1 -1
  33. package/dist/primitives/NumberInput/NumberInput.svelte +105 -106
  34. package/dist/primitives/NumberInput/NumberInput.svelte.d.ts +0 -2
  35. package/dist/primitives/NumberInput/NumberInput.svelte.d.ts.map +1 -1
  36. package/dist/primitives/Toggle.svelte +70 -71
  37. package/dist/primitives/Toggle.svelte.d.ts +2 -4
  38. package/dist/primitives/Toggle.svelte.d.ts.map +1 -1
  39. package/dist/primitives/Tooltip/Tooltip.svelte +83 -0
  40. package/dist/primitives/Tooltip/Tooltip.svelte.d.ts +15 -0
  41. package/dist/primitives/Tooltip/Tooltip.svelte.d.ts.map +1 -0
  42. package/dist/primitives/index.d.ts +3 -0
  43. package/dist/primitives/index.js +7 -0
  44. package/dist/recipes/ImageUploader/ImageUploader.spec.js +6 -5
  45. package/dist/recipes/inputs/MultiSelect.svelte +277 -256
  46. package/dist/recipes/inputs/MultiSelect.svelte.d.ts +54 -21
  47. package/dist/recipes/inputs/MultiSelect.svelte.d.ts.map +1 -1
  48. package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.spec.js +9 -4
  49. package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.svelte +332 -327
  50. package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.svelte.d.ts +12 -1
  51. package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.svelte.d.ts.map +1 -1
  52. package/dist/stores/auth.js +8 -0
  53. package/dist/stores/auth.svelte.d.ts +39 -0
  54. package/dist/stores/auth.svelte.d.ts.map +1 -0
  55. package/dist/stores/auth.svelte.js +60 -0
  56. package/dist/stores/formDataStore.d.ts.map +1 -1
  57. package/dist/stores/formDataStore.js +8 -0
  58. package/dist/stores/formDataStore.svelte.d.ts +47 -0
  59. package/dist/stores/formDataStore.svelte.d.ts.map +1 -0
  60. package/dist/stores/formDataStore.svelte.js +84 -0
  61. package/dist/stores/formSave.d.ts.map +1 -1
  62. package/dist/stores/formSave.js +8 -0
  63. package/dist/stores/formSave.svelte.d.ts +33 -0
  64. package/dist/stores/formSave.svelte.d.ts.map +1 -0
  65. package/dist/stores/formSave.svelte.js +113 -0
  66. package/dist/stores/navigation.d.ts.map +1 -1
  67. package/dist/stores/navigation.js +8 -0
  68. package/dist/stores/navigation.svelte.d.ts +35 -0
  69. package/dist/stores/navigation.svelte.d.ts.map +1 -0
  70. package/dist/stores/navigation.svelte.js +69 -0
  71. package/dist/telemetry.server.spec.js +11 -8
  72. package/dist/telemetry.spec.js +75 -50
  73. package/dist/utils/imageValidation.spec.js +62 -59
  74. package/dist/utils/logger.d.ts +19 -0
  75. package/dist/utils/logger.d.ts.map +1 -0
  76. package/dist/utils/logger.js +47 -0
  77. package/package.json +296 -292
@@ -1,418 +1,417 @@
1
- <script>
2
- /**
3
- * Input Component - Flowbite Native
4
- * Migrated to Svelte 5 runes
5
- *
6
- * NOTE: This component does NOT perform any validation.
7
- * All validation should be handled externally (e.g., via Zod schemas).
8
- * Use the `errorText` prop to display validation errors.
9
- * Use the `color` prop ('red' | 'base') to style the border.
10
- */
11
- import { safeSlide } from "../../utils/transitions.js";
12
- import { cubicOut } from "svelte/easing";
13
- import { onDestroy } from "svelte";
14
- import { EyeOutline, EyeSlashOutline, CloseCircleOutline, ExclamationCircleOutline } from "../Icons";
15
- import { typography } from "../../tokens/typography";
16
- import { formInputSizes } from "../../tokens/sizing";
17
- import { formatCreditCardNumber, formatPhoneNumber } from "../../utils/formatters";
18
-
19
- /** @type {{
20
- required?: boolean,
21
- disabled?: boolean,
22
- optional?: boolean,
23
- icon?: string | null,
24
- buttonIcon?: string | null,
25
- buttonText?: string | null,
26
- maxlength?: number | null,
27
- minlength?: number | null,
28
- type?: string,
29
- placeholder?: string,
30
- label?: string,
31
- id?: string,
32
- name?: string,
33
- className?: string,
34
- size?: 'sm' | 'md' | 'lg',
35
- textareaSize?: string,
36
- errorText?: string,
37
- color?: 'base' | 'red',
38
- helperText?: string,
39
- helperIcon?: string,
40
- hintText?: string,
41
- hintIcon?: string,
42
- contentFloat?: string,
43
- readonly?: boolean,
44
- controlled?: boolean,
45
- onButtonClick?: ((value: string) => void) | null,
46
- value?: string | number | null,
47
- autocomplete?: string | null,
48
- autofocus?: boolean,
49
- showPasswordToggle?: boolean,
50
- animateFocus?: boolean,
51
- statusText?: string,
52
- statusType?: string,
53
- buttonDisabled?: boolean,
54
- inputmode?: string | null,
55
- instantSearch?: boolean,
56
- debounceMs?: number,
57
- minSearchChars?: number,
58
- showClearButton?: boolean,
59
- onsearch?: (detail: { query: string }) => void,
60
- onfocus?: () => void,
61
- onblur?: () => void,
62
- oninputchange?: (value: string) => void,
63
- leftIcon?: any,
64
- [key: string]: any
65
- }} */
66
- let {
67
- required = false,
68
- disabled = false,
69
- optional = false,
70
- icon = null,
71
- buttonIcon = null,
72
- buttonText = null,
73
- maxlength = null,
74
- minlength = null,
75
- type = "text",
76
- placeholder = "",
77
- label = "",
78
- id = "",
79
- name = "",
80
- className = "",
81
- size = "md",
82
- textareaSize = "",
83
- errorText = "",
84
- color = "base",
85
- helperText = "",
86
- helperIcon = "",
87
- hintText = "",
88
- hintIcon = "",
89
- contentFloat = "left",
90
- readonly = false,
91
- controlled = false,
92
- onButtonClick = null,
93
- value = $bindable(""),
94
- autocomplete = null,
95
- autofocus = false,
96
- showPasswordToggle = true,
97
- animateFocus = true,
98
- statusText = "",
99
- statusType = "",
100
- buttonDisabled = false,
101
- inputmode = null,
102
- instantSearch = false,
103
- debounceMs = 250,
104
- minSearchChars = 2,
105
- showClearButton = false,
106
- onsearch,
107
- onfocus,
108
- onblur,
109
- oninputchange,
110
- leftIcon,
111
- ...restProps
112
- } = $props();
113
-
114
- let inputValue = $state(value);
115
- let inputElement = $state(null);
116
- let debounceTimer;
117
-
118
- let computedInputmode = $derived(inputmode || getInputmodeFromType(type));
119
-
120
- function getInputmodeFromType(inputType) {
121
- switch (inputType) {
122
- case 'phoneNumber':
123
- case 'creditCardNumber':
124
- return 'tel';
125
- case 'email':
126
- return 'email';
127
- default:
128
- return null;
129
- }
130
- }
131
-
132
- $effect(() => {
133
- if (value !== inputValue) {
134
- inputValue = value;
135
- }
136
- });
137
-
138
- function checkForAutofill() {
139
- if (inputElement && inputElement.value !== inputValue) {
140
- inputValue = inputElement.value;
141
- value = inputValue;
142
- }
143
- }
144
-
145
- let isPasswordVisible = $state(false);
146
-
147
- // Error state derived from color prop or errorText
148
- let hasError = $derived(color === 'red' || Boolean(errorText));
149
-
150
- let inputType = $derived(showPasswordToggle && isPasswordVisible ? "text" : type);
151
- let shouldAnimate = $derived(animateFocus && !disabled && !readonly);
152
-
153
- let sizeClass = $derived(formInputSizes[size] || formInputSizes.md);
154
-
155
- const togglePasswordVisibility = () => {
156
- isPasswordVisible = !isPasswordVisible;
157
- };
158
-
159
- const handleInput = (event) => {
160
- inputValue = event.target.value;
161
-
162
- // Format special input types
163
- if (type === "creditCardNumber") {
164
- const rawInput = inputValue.replace(/\D/g, "");
165
- inputValue = formatCreditCardNumber(rawInput);
166
- event.target.value = inputValue;
167
- }
168
-
169
- if (type === "phoneNumber") {
170
- const rawInput = inputValue.replace(/\D/g, "");
171
- inputValue = formatPhoneNumber(rawInput);
172
- event.target.value = inputValue;
173
- }
174
-
175
- if (type === "username") {
176
- let sanitized = inputValue.trim();
177
- const urlPattern = /(?:https?:\/\/)?(?:www\.)?(?:instagram\.com|twitter\.com|x\.com|facebook\.com|fb\.com|tiktok\.com|linkedin\.com)\/(?:@)?([A-Za-z0-9._]+)\/?/i;
178
- const urlMatch = sanitized.match(urlPattern);
179
- if (urlMatch) {
180
- sanitized = urlMatch[1];
181
- }
182
- sanitized = sanitized.replace(/^@+/, "");
183
- sanitized = sanitized.replace(/[^A-Za-z0-9._]/g, "");
184
- inputValue = sanitized;
185
- event.target.value = inputValue;
186
- }
187
-
188
- value = inputValue;
189
-
190
- // Call oninputchange callback if provided
191
- oninputchange?.(inputValue);
192
-
193
- // Handle instant search
194
- if (instantSearch) {
195
- const inputValueStr = inputValue ?? '';
196
- clearTimeout(debounceTimer);
197
- if (inputValueStr.length === 0) {
198
- onsearch?.({ query: '' });
199
- return;
200
- }
201
- if (inputValueStr.length >= minSearchChars) {
202
- debounceTimer = setTimeout(() => {
203
- onsearch?.({ query: inputValue });
204
- }, debounceMs);
205
- }
206
- }
207
- };
208
-
209
- function clearInput() {
210
- inputValue = '';
211
- value = '';
212
- clearTimeout(debounceTimer);
213
- if (instantSearch) {
214
- onsearch?.({ query: '' });
215
- }
216
- if (inputElement) {
217
- inputElement.focus();
218
- }
219
- }
220
-
221
- function handleSearchKeyDown(event) {
222
- if (instantSearch) {
223
- if (event.key === 'Enter') {
224
- clearTimeout(debounceTimer);
225
- onsearch?.({ query: inputValue });
226
- }
227
- if (event.key === 'Escape') {
228
- clearInput();
229
- }
230
- }
231
- }
232
-
233
- onDestroy(() => {
234
- clearTimeout(debounceTimer);
235
- });
236
-
237
- const handleBlur = () => {
238
- onblur?.();
239
- };
240
-
241
- const handleFocus = () => {
242
- onfocus?.();
243
- };
244
-
245
- const getContentFloatClass = () => {
246
- switch (contentFloat) {
247
- case "center": return "text-center";
248
- case "right": return "text-right";
249
- default: return "text-left";
250
- }
251
- };
252
-
253
- const getTextareaSizeClass = () => {
254
- switch (textareaSize) {
255
- case "sm": return "h-24";
256
- case "md": return "h-36";
257
- case "lg": return "h-44";
258
- default: return "";
259
- }
260
- };
261
-
262
- const handleButtonClick = () => {
263
- if (typeof onButtonClick === "function") {
264
- onButtonClick(inputValue);
265
- }
266
- };
267
- </script>
268
-
269
- <div class="flex flex-col gap-2 {className}" {...restProps}>
270
- {#if label}
271
- <div class="flex justify-start items-center gap-1">
272
- <label for={id} class={`${typography.label} leading-tight sm:leading-none`}>
273
- {label}{#if required}<span class="text-red-500 font-medium text-sm ml-0.5">*</span>{/if}
274
- </label>
275
- {#if statusText}
276
- <span class="text-sm font-medium {statusType === 'success' ? 'text-green-600' : statusType === 'error' ? 'text-red-500' : ''}">({statusText})</span>
277
- {/if}
278
- {#if optional}
279
- <span class={typography.smMuted}>(optional)</span>
280
- {/if}
281
- </div>
282
- {/if}
283
- <div class="relative w-full">
284
- {#if type === "textarea"}
285
- <textarea
286
- {id}
287
- {name}
288
- {placeholder}
289
- value={inputValue}
290
- oninput={handleInput}
291
- onblur={handleBlur}
292
- onfocus={handleFocus}
293
- {maxlength}
294
- {minlength}
295
- class="{typography.sm} w-full px-3 py-2 bg-gray-50 dark:bg-gray-800 border rounded-lg font-medium placeholder-gray-500 dark:placeholder-gray-400 transition-all focus:outline-none focus:ring-4 focus:ring-blue-300 dark:focus:ring-blue-800 resize-y {hasError ? 'border-red-500' : 'border-gray-300 dark:border-gray-600 hover:border-blue-500 focus:border-blue-500'} {getContentFloatClass()} {getTextareaSizeClass()} {shouldAnimate ? 'focus:scale-[1.01]' : ''}"
296
- required={false}
297
- {disabled}
298
- {readonly}
299
- rows="4"
300
- aria-required={required}
301
- ></textarea>
302
- {:else if type === "password" && showPasswordToggle}
303
- <div class="flex items-center w-full bg-gray-50 dark:bg-gray-800 border rounded-lg transition-all outline-none focus-within:ring-4 focus-within:ring-blue-300 dark:focus-within:ring-blue-800 {hasError ? 'border-red-500' : 'border-gray-300 dark:border-gray-600 hover:border-blue-500 focus-within:border-blue-500'} {shouldAnimate ? 'focus-within:scale-[1.01]' : ''}">
304
- <!-- svelte-ignore a11y_autofocus -->
305
- <input
306
- bind:this={inputElement}
307
- {id}
308
- type={inputType}
309
- {name}
310
- {placeholder}
311
- value={inputValue}
312
- oninput={handleInput}
313
- onchange={checkForAutofill}
314
- onblur={handleBlur}
315
- onfocus={handleFocus}
316
- {maxlength}
317
- {minlength}
318
- class="{typography.sm} flex-1 w-full {sizeClass} bg-transparent border-none font-medium placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-0 {getContentFloatClass()}"
319
- required={false}
320
- {disabled}
321
- {readonly}
322
- aria-required={required}
323
- {autocomplete}
324
- {autofocus}
325
- inputmode={computedInputmode}
326
- />
327
- <button
328
- type="button"
329
- onclick={togglePasswordVisibility}
330
- class="flex items-center justify-center px-3 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 focus:outline-none"
331
- tabindex="-1"
332
- aria-label={isPasswordVisible ? "Hide password" : "Show password"}
333
- >
334
- {#if isPasswordVisible}
335
- <EyeSlashOutline class="w-5 h-5" />
336
- {:else}
337
- <EyeOutline class="w-5 h-5" />
338
- {/if}
339
- </button>
340
- </div>
341
- {:else}
342
- <div class="relative flex items-center w-full">
343
- {#if leftIcon}
344
- <div class="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 z-10 pointer-events-none">
345
- {@render leftIcon()}
346
- </div>
347
- {/if}
348
- <!-- svelte-ignore a11y_autofocus -->
349
- <input
350
- bind:this={inputElement}
351
- {id}
352
- type={inputType}
353
- {name}
354
- {placeholder}
355
- value={inputValue}
356
- oninput={handleInput}
357
- onchange={checkForAutofill}
358
- onblur={handleBlur}
359
- onfocus={handleFocus}
360
- onkeydown={handleSearchKeyDown}
361
- {maxlength}
362
- {minlength}
363
- class="{typography.body} w-full {sizeClass} bg-gray-50 dark:bg-gray-800 border rounded-lg font-medium placeholder-gray-500 dark:placeholder-gray-400 transition-all focus:outline-none focus:ring-4 focus:ring-blue-300 dark:focus:ring-blue-800 {hasError ? 'border-red-500' : 'border-gray-300 dark:border-gray-600 hover:border-blue-500 focus:border-blue-500'} {icon || (showClearButton && inputValue) ? 'pr-10' : ''} {leftIcon ? 'pl-10' : ''} {getContentFloatClass()} {shouldAnimate ? 'focus:scale-[1.01]' : ''} {disabled ? 'opacity-50 cursor-not-allowed' : ''}"
364
- required={false}
365
- {disabled}
366
- {readonly}
367
- aria-required={required}
368
- {autocomplete}
369
- {autofocus}
370
- inputmode={computedInputmode}
371
- />
372
- {#if showClearButton && inputValue}
373
- <button
374
- type="button"
375
- onclick={clearInput}
376
- class="absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200"
377
- aria-label="Clear input"
378
- tabindex="-1"
379
- >
380
- <CloseCircleOutline class="w-4 h-4" />
381
- </button>
382
- {:else if controlled && (buttonIcon || buttonText)}
383
- <button
384
- type="button"
385
- onclick={handleButtonClick}
386
- disabled={buttonDisabled}
387
- class="absolute inset-y-0 right-0 gap-1 flex items-center justify-center px-4 text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300 disabled:opacity-50 disabled:cursor-not-allowed {helperText || hintText || errorText ? 'mb-7' : ''}"
388
- >
389
- {#if buttonIcon}
390
- <img src={buttonIcon} alt="Button Icon" class="w-5 h-5" />
391
- {/if}
392
- {#if buttonText}
393
- <span class="text-sm font-medium">{buttonText}</span>
394
- {/if}
395
- </button>
396
- {/if}
397
- {#if icon && type !== "textarea" && !(showClearButton && inputValue)}
398
- <img src={icon} alt="Input icon" class="absolute inset-y-0 right-0 w-5 h-5 mr-3 top-1/2 transform -translate-y-1/2" />
399
- {/if}
400
- </div>
401
- {/if}
402
-
403
- {#if errorText}
404
- <div transition:safeSlide={{ duration: 300, easing: cubicOut }} class="flex items-start gap-1.5 mt-2" role="alert" aria-live="assertive">
405
- <ExclamationCircleOutline class="w-4 h-4 shrink-0 text-red-500 mt-0.5" />
406
- <p class={typography.error}>{errorText}</p>
407
- </div>
408
- {:else if helperText || hintText}
409
- <div class={`mt-2 flex items-center ${typography.xsMuted} opacity-65`}>
410
- {#if helperIcon || hintIcon}
411
- <img src={helperIcon || hintIcon} alt="Helper icon" class="w-4 h-4 mr-2" />
412
- {/if}
1
+ <script>
2
+ /**
3
+ * Input Component - Flowbite Native
4
+ * Migrated to Svelte 5 runes
5
+ *
6
+ * NOTE: This component does NOT perform any validation.
7
+ * All validation should be handled externally (e.g., via Zod schemas).
8
+ * Use the `errorText` prop to display validation errors.
9
+ * Use the `color` prop ('red' | 'base') to style the border.
10
+ */
11
+ import { safeSlide } from "../../utils/transitions.js";
12
+ import { cubicOut } from "svelte/easing";
13
+ import { onDestroy } from "svelte";
14
+ import { EyeOutline, EyeSlashOutline, CloseCircleOutline, ExclamationCircleOutline } from "../Icons";
15
+ import { typography } from "../../tokens/typography";
16
+ import { formInputSizes } from "../../tokens/sizing";
17
+ import { formatCreditCardNumber, formatPhoneNumber } from "../../utils/formatters";
18
+
19
+ /** @type {{
20
+ required?: boolean,
21
+ disabled?: boolean,
22
+ optional?: boolean,
23
+ icon?: string | null,
24
+ buttonIcon?: string | null,
25
+ buttonText?: string | null,
26
+ maxlength?: number | null,
27
+ minlength?: number | null,
28
+ type?: string,
29
+ placeholder?: string,
30
+ label?: string,
31
+ id?: string,
32
+ name?: string,
33
+ className?: string,
34
+ size?: 'sm' | 'md' | 'lg',
35
+ textareaSize?: string,
36
+ errorText?: string,
37
+ color?: 'base' | 'red',
38
+ helperText?: string,
39
+ helperIcon?: string,
40
+ hintText?: string,
41
+ hintIcon?: string,
42
+ contentFloat?: string,
43
+ readonly?: boolean,
44
+ controlled?: boolean,
45
+ onButtonClick?: ((value: string) => void) | null,
46
+ value?: string | number | null,
47
+ autocomplete?: string | null,
48
+ autofocus?: boolean,
49
+ showPasswordToggle?: boolean,
50
+ animateFocus?: boolean,
51
+ statusText?: string,
52
+ statusType?: string,
53
+ buttonDisabled?: boolean,
54
+ inputmode?: string | null,
55
+ instantSearch?: boolean,
56
+ debounceMs?: number,
57
+ minSearchChars?: number,
58
+ showClearButton?: boolean,
59
+ onsearch?: (detail: { query: string }) => void,
60
+ onfocus?: () => void,
61
+ onblur?: () => void,
62
+ oninputchange?: (value: string) => void,
63
+ leftIcon?: import('svelte').Snippet
64
+ }} */
65
+ let {
66
+ required = false,
67
+ disabled = false,
68
+ optional = false,
69
+ icon = null,
70
+ buttonIcon = null,
71
+ buttonText = null,
72
+ maxlength = null,
73
+ minlength = null,
74
+ type = "text",
75
+ placeholder = "",
76
+ label = "",
77
+ id = "",
78
+ name = "",
79
+ className = "",
80
+ size = "md",
81
+ textareaSize = "",
82
+ errorText = "",
83
+ color = "base",
84
+ helperText = "",
85
+ helperIcon = "",
86
+ hintText = "",
87
+ hintIcon = "",
88
+ contentFloat = "left",
89
+ readonly = false,
90
+ controlled = false,
91
+ onButtonClick = null,
92
+ value = $bindable(""),
93
+ autocomplete = null,
94
+ autofocus = false,
95
+ showPasswordToggle = true,
96
+ animateFocus = true,
97
+ statusText = "",
98
+ statusType = "",
99
+ buttonDisabled = false,
100
+ inputmode = null,
101
+ instantSearch = false,
102
+ debounceMs = 250,
103
+ minSearchChars = 2,
104
+ showClearButton = false,
105
+ onsearch,
106
+ onfocus,
107
+ onblur,
108
+ oninputchange,
109
+ leftIcon,
110
+ ...restProps
111
+ } = $props();
112
+
113
+ let inputValue = $state(value);
114
+ let inputElement = $state(null);
115
+ let debounceTimer;
116
+
117
+ let computedInputmode = $derived(inputmode || getInputmodeFromType(type));
118
+
119
+ function getInputmodeFromType(inputType) {
120
+ switch (inputType) {
121
+ case 'phoneNumber':
122
+ case 'creditCardNumber':
123
+ return 'tel';
124
+ case 'email':
125
+ return 'email';
126
+ default:
127
+ return null;
128
+ }
129
+ }
130
+
131
+ $effect(() => {
132
+ if (value !== inputValue) {
133
+ inputValue = value;
134
+ }
135
+ });
136
+
137
+ function checkForAutofill() {
138
+ if (inputElement && inputElement.value !== inputValue) {
139
+ inputValue = inputElement.value;
140
+ value = inputValue;
141
+ }
142
+ }
143
+
144
+ let isPasswordVisible = $state(false);
145
+
146
+ // Error state derived from color prop or errorText
147
+ let hasError = $derived(color === 'red' || Boolean(errorText));
148
+
149
+ let inputType = $derived(showPasswordToggle && isPasswordVisible ? "text" : type);
150
+ let shouldAnimate = $derived(animateFocus && !disabled && !readonly);
151
+
152
+ let sizeClass = $derived(formInputSizes[size] || formInputSizes.md);
153
+
154
+ const togglePasswordVisibility = () => {
155
+ isPasswordVisible = !isPasswordVisible;
156
+ };
157
+
158
+ const handleInput = (event) => {
159
+ inputValue = event.target.value;
160
+
161
+ // Format special input types
162
+ if (type === "creditCardNumber") {
163
+ const rawInput = inputValue.replace(/\D/g, "");
164
+ inputValue = formatCreditCardNumber(rawInput);
165
+ event.target.value = inputValue;
166
+ }
167
+
168
+ if (type === "phoneNumber") {
169
+ const rawInput = inputValue.replace(/\D/g, "");
170
+ inputValue = formatPhoneNumber(rawInput);
171
+ event.target.value = inputValue;
172
+ }
173
+
174
+ if (type === "username") {
175
+ let sanitized = inputValue.trim();
176
+ const urlPattern = /(?:https?:\/\/)?(?:www\.)?(?:instagram\.com|twitter\.com|x\.com|facebook\.com|fb\.com|tiktok\.com|linkedin\.com)\/(?:@)?([A-Za-z0-9._]+)\/?/i;
177
+ const urlMatch = sanitized.match(urlPattern);
178
+ if (urlMatch) {
179
+ sanitized = urlMatch[1];
180
+ }
181
+ sanitized = sanitized.replace(/^@+/, "");
182
+ sanitized = sanitized.replace(/[^A-Za-z0-9._]/g, "");
183
+ inputValue = sanitized;
184
+ event.target.value = inputValue;
185
+ }
186
+
187
+ value = inputValue;
188
+
189
+ // Call oninputchange callback if provided
190
+ oninputchange?.(inputValue);
191
+
192
+ // Handle instant search
193
+ if (instantSearch) {
194
+ const inputValueStr = inputValue ?? '';
195
+ clearTimeout(debounceTimer);
196
+ if (inputValueStr.length === 0) {
197
+ onsearch?.({ query: '' });
198
+ return;
199
+ }
200
+ if (inputValueStr.length >= minSearchChars) {
201
+ debounceTimer = setTimeout(() => {
202
+ onsearch?.({ query: inputValue });
203
+ }, debounceMs);
204
+ }
205
+ }
206
+ };
207
+
208
+ function clearInput() {
209
+ inputValue = '';
210
+ value = '';
211
+ clearTimeout(debounceTimer);
212
+ if (instantSearch) {
213
+ onsearch?.({ query: '' });
214
+ }
215
+ if (inputElement) {
216
+ inputElement.focus();
217
+ }
218
+ }
219
+
220
+ function handleSearchKeyDown(event) {
221
+ if (instantSearch) {
222
+ if (event.key === 'Enter') {
223
+ clearTimeout(debounceTimer);
224
+ onsearch?.({ query: inputValue });
225
+ }
226
+ if (event.key === 'Escape') {
227
+ clearInput();
228
+ }
229
+ }
230
+ }
231
+
232
+ onDestroy(() => {
233
+ clearTimeout(debounceTimer);
234
+ });
235
+
236
+ const handleBlur = () => {
237
+ onblur?.();
238
+ };
239
+
240
+ const handleFocus = () => {
241
+ onfocus?.();
242
+ };
243
+
244
+ const getContentFloatClass = () => {
245
+ switch (contentFloat) {
246
+ case "center": return "text-center";
247
+ case "right": return "text-right";
248
+ default: return "text-left";
249
+ }
250
+ };
251
+
252
+ const getTextareaSizeClass = () => {
253
+ switch (textareaSize) {
254
+ case "sm": return "h-24";
255
+ case "md": return "h-36";
256
+ case "lg": return "h-44";
257
+ default: return "";
258
+ }
259
+ };
260
+
261
+ const handleButtonClick = () => {
262
+ if (typeof onButtonClick === "function") {
263
+ onButtonClick(inputValue);
264
+ }
265
+ };
266
+ </script>
267
+
268
+ <div class="flex flex-col gap-2 {className}" {...restProps}>
269
+ {#if label}
270
+ <div class="flex justify-start items-center gap-1">
271
+ <label for={id} class={`${typography.label} leading-tight sm:leading-none`}>
272
+ {label}{#if required}<span class="text-red-500 font-medium text-sm ml-0.5">*</span>{/if}
273
+ </label>
274
+ {#if statusText}
275
+ <span class="text-sm font-medium {statusType === 'success' ? 'text-green-600' : statusType === 'error' ? 'text-red-500' : ''}">({statusText})</span>
276
+ {/if}
277
+ {#if optional}
278
+ <span class={typography.smMuted}>(optional)</span>
279
+ {/if}
280
+ </div>
281
+ {/if}
282
+ <div class="relative w-full">
283
+ {#if type === "textarea"}
284
+ <textarea
285
+ {id}
286
+ {name}
287
+ {placeholder}
288
+ value={inputValue}
289
+ oninput={handleInput}
290
+ onblur={handleBlur}
291
+ onfocus={handleFocus}
292
+ {maxlength}
293
+ {minlength}
294
+ class="{typography.sm} w-full px-3 py-2 bg-gray-50 dark:bg-gray-800 border rounded-lg font-medium placeholder-gray-500 dark:placeholder-gray-400 transition-all focus:outline-none focus:ring-4 focus:ring-blue-300 dark:focus:ring-blue-800 resize-y {hasError ? 'border-red-500' : 'border-gray-300 dark:border-gray-600 hover:border-blue-500 focus:border-blue-500'} {getContentFloatClass()} {getTextareaSizeClass()} {shouldAnimate ? 'focus:scale-[1.01]' : ''}"
295
+ required={false}
296
+ {disabled}
297
+ {readonly}
298
+ rows="4"
299
+ aria-required={required}
300
+ ></textarea>
301
+ {:else if type === "password" && showPasswordToggle}
302
+ <div class="flex items-center w-full bg-gray-50 dark:bg-gray-800 border rounded-lg transition-all outline-none focus-within:ring-4 focus-within:ring-blue-300 dark:focus-within:ring-blue-800 {hasError ? 'border-red-500' : 'border-gray-300 dark:border-gray-600 hover:border-blue-500 focus-within:border-blue-500'} {shouldAnimate ? 'focus-within:scale-[1.01]' : ''}">
303
+ <!-- svelte-ignore a11y_autofocus -->
304
+ <input
305
+ bind:this={inputElement}
306
+ {id}
307
+ type={inputType}
308
+ {name}
309
+ {placeholder}
310
+ value={inputValue}
311
+ oninput={handleInput}
312
+ onchange={checkForAutofill}
313
+ onblur={handleBlur}
314
+ onfocus={handleFocus}
315
+ {maxlength}
316
+ {minlength}
317
+ class="{typography.sm} flex-1 w-full {sizeClass} bg-transparent border-none font-medium placeholder-gray-500 dark:placeholder-gray-400 focus:outline-none focus:ring-0 {getContentFloatClass()}"
318
+ required={false}
319
+ {disabled}
320
+ {readonly}
321
+ aria-required={required}
322
+ {autocomplete}
323
+ {autofocus}
324
+ inputmode={computedInputmode}
325
+ />
326
+ <button
327
+ type="button"
328
+ onclick={togglePasswordVisibility}
329
+ class="flex items-center justify-center px-3 text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 focus:outline-none"
330
+ tabindex="-1"
331
+ aria-label={isPasswordVisible ? "Hide password" : "Show password"}
332
+ >
333
+ {#if isPasswordVisible}
334
+ <EyeSlashOutline class="w-5 h-5" />
335
+ {:else}
336
+ <EyeOutline class="w-5 h-5" />
337
+ {/if}
338
+ </button>
339
+ </div>
340
+ {:else}
341
+ <div class="relative flex items-center w-full">
342
+ {#if leftIcon}
343
+ <div class="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 z-10 pointer-events-none">
344
+ {@render leftIcon()}
345
+ </div>
346
+ {/if}
347
+ <!-- svelte-ignore a11y_autofocus -->
348
+ <input
349
+ bind:this={inputElement}
350
+ {id}
351
+ type={inputType}
352
+ {name}
353
+ {placeholder}
354
+ value={inputValue}
355
+ oninput={handleInput}
356
+ onchange={checkForAutofill}
357
+ onblur={handleBlur}
358
+ onfocus={handleFocus}
359
+ onkeydown={handleSearchKeyDown}
360
+ {maxlength}
361
+ {minlength}
362
+ class="{typography.body} w-full {sizeClass} bg-gray-50 dark:bg-gray-800 border rounded-lg font-medium placeholder-gray-500 dark:placeholder-gray-400 transition-all focus:outline-none focus:ring-4 focus:ring-blue-300 dark:focus:ring-blue-800 {hasError ? 'border-red-500' : 'border-gray-300 dark:border-gray-600 hover:border-blue-500 focus:border-blue-500'} {icon || (showClearButton && inputValue) ? 'pr-10' : ''} {leftIcon ? 'pl-10' : ''} {getContentFloatClass()} {shouldAnimate ? 'focus:scale-[1.01]' : ''} {disabled ? 'opacity-50 cursor-not-allowed' : ''}"
363
+ required={false}
364
+ {disabled}
365
+ {readonly}
366
+ aria-required={required}
367
+ {autocomplete}
368
+ {autofocus}
369
+ inputmode={computedInputmode}
370
+ />
371
+ {#if showClearButton && inputValue}
372
+ <button
373
+ type="button"
374
+ onclick={clearInput}
375
+ class="absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center p-1 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200"
376
+ aria-label="Clear input"
377
+ tabindex="-1"
378
+ >
379
+ <CloseCircleOutline class="w-4 h-4" />
380
+ </button>
381
+ {:else if controlled && (buttonIcon || buttonText)}
382
+ <button
383
+ type="button"
384
+ onclick={handleButtonClick}
385
+ disabled={buttonDisabled}
386
+ class="absolute inset-y-0 right-0 gap-1 flex items-center justify-center px-4 text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300 disabled:opacity-50 disabled:cursor-not-allowed {helperText || hintText || errorText ? 'mb-7' : ''}"
387
+ >
388
+ {#if buttonIcon}
389
+ <img src={buttonIcon} alt="Button Icon" class="w-5 h-5" />
390
+ {/if}
391
+ {#if buttonText}
392
+ <span class="text-sm font-medium">{buttonText}</span>
393
+ {/if}
394
+ </button>
395
+ {/if}
396
+ {#if icon && type !== "textarea" && !(showClearButton && inputValue)}
397
+ <img src={icon} alt="Input icon" class="absolute inset-y-0 right-0 w-5 h-5 mr-3 top-1/2 transform -translate-y-1/2" />
398
+ {/if}
399
+ </div>
400
+ {/if}
401
+
402
+ {#if errorText}
403
+ <div transition:safeSlide={{ duration: 300, easing: cubicOut }} class="flex items-start gap-1.5 mt-2" role="alert" aria-live="assertive">
404
+ <ExclamationCircleOutline class="w-4 h-4 shrink-0 text-red-500 mt-0.5" />
405
+ <p class={typography.error}>{errorText}</p>
406
+ </div>
407
+ {:else if helperText || hintText}
408
+ <div class={`mt-2 flex items-center ${typography.xsMuted} opacity-65`}>
409
+ {#if helperIcon || hintIcon}
410
+ <img src={helperIcon || hintIcon} alt="Helper icon" class="w-4 h-4 mr-2" />
411
+ {/if}
413
412
  <!-- eslint-disable-next-line svelte/no-at-html-tags -->
414
- <span>{@html helperText || hintText}</span>
415
- </div>
416
- {/if}
417
- </div>
418
- </div>
413
+ <span>{@html helperText || hintText}</span>
414
+ </div>
415
+ {/if}
416
+ </div>
417
+ </div>