@aspect-ops/exon-ui 0.0.3 → 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/README.md +793 -43
- package/dist/components/Accordion/Accordion.svelte +79 -0
- package/dist/components/Accordion/Accordion.svelte.d.ts +10 -0
- package/dist/components/Accordion/AccordionItem.svelte +198 -0
- package/dist/components/Accordion/AccordionItem.svelte.d.ts +10 -0
- package/dist/components/Accordion/index.d.ts +2 -0
- package/dist/components/Accordion/index.js +2 -0
- package/dist/components/Carousel/Carousel.svelte +454 -0
- package/dist/components/Carousel/Carousel.svelte.d.ts +14 -0
- package/dist/components/Carousel/CarouselSlide.svelte +22 -0
- package/dist/components/Carousel/CarouselSlide.svelte.d.ts +7 -0
- package/dist/components/Carousel/index.d.ts +2 -0
- package/dist/components/Carousel/index.js +2 -0
- package/dist/components/Chip/Chip.svelte +461 -0
- package/dist/components/Chip/Chip.svelte.d.ts +17 -0
- package/dist/components/Chip/ChipGroup.svelte +76 -0
- package/dist/components/Chip/ChipGroup.svelte.d.ts +9 -0
- package/dist/components/Chip/index.d.ts +2 -0
- package/dist/components/Chip/index.js +2 -0
- package/dist/components/DatePicker/DatePicker.svelte +746 -0
- package/dist/components/DatePicker/DatePicker.svelte.d.ts +19 -0
- package/dist/components/DatePicker/index.d.ts +1 -0
- package/dist/components/DatePicker/index.js +1 -0
- package/dist/components/FileUpload/FileUpload.svelte +484 -0
- package/dist/components/FileUpload/FileUpload.svelte.d.ts +16 -0
- package/dist/components/FileUpload/index.d.ts +1 -0
- package/dist/components/FileUpload/index.js +1 -0
- package/dist/components/Image/Image.svelte +223 -0
- package/dist/components/Image/Image.svelte.d.ts +19 -0
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/components/Image/index.js +1 -0
- package/dist/components/OTPInput/OTPInput.svelte +312 -0
- package/dist/components/OTPInput/OTPInput.svelte.d.ts +57 -0
- package/dist/components/OTPInput/index.d.ts +1 -0
- package/dist/components/OTPInput/index.js +1 -0
- package/dist/components/Rating/Rating.svelte +316 -0
- package/dist/components/Rating/Rating.svelte.d.ts +16 -0
- package/dist/components/Rating/index.d.ts +1 -0
- package/dist/components/Rating/index.js +1 -0
- package/dist/components/SearchInput/SearchInput.svelte +480 -0
- package/dist/components/SearchInput/SearchInput.svelte.d.ts +22 -0
- package/dist/components/SearchInput/index.d.ts +1 -0
- package/dist/components/SearchInput/index.js +1 -0
- package/dist/components/Slider/Slider.svelte +324 -0
- package/dist/components/Slider/Slider.svelte.d.ts +14 -0
- package/dist/components/Slider/index.d.ts +1 -0
- package/dist/components/Slider/index.js +1 -0
- package/dist/components/Stepper/Stepper.svelte +100 -0
- package/dist/components/Stepper/Stepper.svelte.d.ts +11 -0
- package/dist/components/Stepper/StepperStep.svelte +391 -0
- package/dist/components/Stepper/StepperStep.svelte.d.ts +13 -0
- package/dist/components/Stepper/index.d.ts +2 -0
- package/dist/components/Stepper/index.js +2 -0
- package/dist/components/TimePicker/TimePicker.svelte +803 -0
- package/dist/components/TimePicker/TimePicker.svelte.d.ts +17 -0
- package/dist/components/TimePicker/index.d.ts +1 -0
- package/dist/components/TimePicker/index.js +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +9 -0
- package/dist/types/data-display.d.ts +68 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/input.d.ts +67 -0
- package/dist/types/input.js +2 -0
- package/dist/types/navigation.d.ts +15 -0
- package/package.json +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
interface Props {
|
|
3
|
+
src: string;
|
|
4
|
+
alt: string;
|
|
5
|
+
width?: number | string;
|
|
6
|
+
height?: number | string;
|
|
7
|
+
loading?: 'lazy' | 'eager';
|
|
8
|
+
objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
9
|
+
objectPosition?: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
fallback?: string;
|
|
12
|
+
rounded?: boolean | 'sm' | 'md' | 'lg' | 'full';
|
|
13
|
+
aspectRatio?: string;
|
|
14
|
+
class?: string;
|
|
15
|
+
onload?: () => void;
|
|
16
|
+
onerror?: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
src,
|
|
21
|
+
alt,
|
|
22
|
+
width,
|
|
23
|
+
height,
|
|
24
|
+
loading = 'lazy',
|
|
25
|
+
objectFit = 'cover',
|
|
26
|
+
objectPosition = 'center',
|
|
27
|
+
placeholder,
|
|
28
|
+
fallback,
|
|
29
|
+
rounded = false,
|
|
30
|
+
aspectRatio,
|
|
31
|
+
class: className = '',
|
|
32
|
+
onload,
|
|
33
|
+
onerror
|
|
34
|
+
}: Props = $props();
|
|
35
|
+
|
|
36
|
+
let status = $state<'loading' | 'loaded' | 'error'>('loading');
|
|
37
|
+
|
|
38
|
+
const currentSrc = $derived(status === 'error' && fallback ? fallback : src);
|
|
39
|
+
|
|
40
|
+
const roundedClass = $derived(() => {
|
|
41
|
+
if (rounded === false) return '';
|
|
42
|
+
if (rounded === true) return 'image-container--rounded-md';
|
|
43
|
+
return `image-container--rounded-${rounded}`;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const containerStyle = $derived(() => {
|
|
47
|
+
const styles: string[] = [];
|
|
48
|
+
if (aspectRatio) {
|
|
49
|
+
styles.push(`aspect-ratio: ${aspectRatio}`);
|
|
50
|
+
}
|
|
51
|
+
if (width) {
|
|
52
|
+
styles.push(`width: ${typeof width === 'number' ? `${width}px` : width}`);
|
|
53
|
+
}
|
|
54
|
+
if (height && !aspectRatio) {
|
|
55
|
+
styles.push(`height: ${typeof height === 'number' ? `${height}px` : height}`);
|
|
56
|
+
}
|
|
57
|
+
return styles.join('; ');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const imageStyle = $derived(() => {
|
|
61
|
+
const styles: string[] = [];
|
|
62
|
+
styles.push(`object-fit: ${objectFit}`);
|
|
63
|
+
styles.push(`object-position: ${objectPosition}`);
|
|
64
|
+
return styles.join('; ');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function handleLoad() {
|
|
68
|
+
status = 'loaded';
|
|
69
|
+
onload?.();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function handleError() {
|
|
73
|
+
status = 'error';
|
|
74
|
+
onerror?.();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Reset status when src changes
|
|
78
|
+
$effect(() => {
|
|
79
|
+
src;
|
|
80
|
+
status = 'loading';
|
|
81
|
+
});
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<div
|
|
85
|
+
class="image-container {roundedClass()} {className}"
|
|
86
|
+
style={containerStyle()}
|
|
87
|
+
role="img"
|
|
88
|
+
aria-label={alt}
|
|
89
|
+
>
|
|
90
|
+
{#if status === 'loading' && placeholder}
|
|
91
|
+
<div
|
|
92
|
+
class="image-placeholder"
|
|
93
|
+
style={typeof placeholder === 'string' && placeholder.startsWith('#')
|
|
94
|
+
? `background-color: ${placeholder}`
|
|
95
|
+
: `background-image: url(${placeholder})`}
|
|
96
|
+
></div>
|
|
97
|
+
{/if}
|
|
98
|
+
|
|
99
|
+
<img
|
|
100
|
+
class="image image--{status}"
|
|
101
|
+
src={currentSrc}
|
|
102
|
+
{alt}
|
|
103
|
+
{loading}
|
|
104
|
+
style={imageStyle()}
|
|
105
|
+
onload={handleLoad}
|
|
106
|
+
onerror={handleError}
|
|
107
|
+
/>
|
|
108
|
+
|
|
109
|
+
{#if status === 'error' && !fallback}
|
|
110
|
+
<div class="image-error">
|
|
111
|
+
<svg
|
|
112
|
+
class="image-error__icon"
|
|
113
|
+
viewBox="0 0 24 24"
|
|
114
|
+
fill="none"
|
|
115
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
116
|
+
aria-hidden="true"
|
|
117
|
+
>
|
|
118
|
+
<path
|
|
119
|
+
d="M21 19V5C21 3.9 20.1 3 19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19ZM8.5 13.5L11 16.51L14.5 12L19 18H5L8.5 13.5Z"
|
|
120
|
+
fill="currentColor"
|
|
121
|
+
/>
|
|
122
|
+
<line
|
|
123
|
+
x1="4"
|
|
124
|
+
y1="4"
|
|
125
|
+
x2="20"
|
|
126
|
+
y2="20"
|
|
127
|
+
stroke="currentColor"
|
|
128
|
+
stroke-width="2"
|
|
129
|
+
stroke-linecap="round"
|
|
130
|
+
/>
|
|
131
|
+
</svg>
|
|
132
|
+
<span class="image-error__text">{alt}</span>
|
|
133
|
+
</div>
|
|
134
|
+
{/if}
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
<style>
|
|
138
|
+
.image-container {
|
|
139
|
+
position: relative;
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
display: inline-block;
|
|
142
|
+
background: var(--color-bg-muted, #f3f4f6);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.image {
|
|
146
|
+
width: 100%;
|
|
147
|
+
height: 100%;
|
|
148
|
+
display: block;
|
|
149
|
+
transition: opacity var(--transition-base, 0.2s ease);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.image--loading {
|
|
153
|
+
opacity: 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.image--loaded {
|
|
157
|
+
opacity: 1;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.image--error {
|
|
161
|
+
opacity: 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* Rounded variants */
|
|
165
|
+
.image-container--rounded-sm {
|
|
166
|
+
border-radius: var(--radius-sm, 0.25rem);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.image-container--rounded-md {
|
|
170
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.image-container--rounded-lg {
|
|
174
|
+
border-radius: var(--radius-lg, 0.5rem);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.image-container--rounded-full {
|
|
178
|
+
border-radius: var(--radius-full, 9999px);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* Placeholder */
|
|
182
|
+
.image-placeholder {
|
|
183
|
+
position: absolute;
|
|
184
|
+
inset: 0;
|
|
185
|
+
background-size: cover;
|
|
186
|
+
background-position: center;
|
|
187
|
+
background-repeat: no-repeat;
|
|
188
|
+
z-index: 1;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* Error state */
|
|
192
|
+
.image-error {
|
|
193
|
+
position: absolute;
|
|
194
|
+
inset: 0;
|
|
195
|
+
display: flex;
|
|
196
|
+
flex-direction: column;
|
|
197
|
+
align-items: center;
|
|
198
|
+
justify-content: center;
|
|
199
|
+
background: var(--color-bg-muted, #f3f4f6);
|
|
200
|
+
color: var(--color-text-muted, #6b7280);
|
|
201
|
+
padding: 1rem;
|
|
202
|
+
text-align: center;
|
|
203
|
+
z-index: 2;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.image-error__icon {
|
|
207
|
+
width: 3rem;
|
|
208
|
+
height: 3rem;
|
|
209
|
+
margin-bottom: 0.5rem;
|
|
210
|
+
opacity: 0.5;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.image-error__text {
|
|
214
|
+
font-size: 0.875rem;
|
|
215
|
+
max-width: 100%;
|
|
216
|
+
overflow: hidden;
|
|
217
|
+
text-overflow: ellipsis;
|
|
218
|
+
display: -webkit-box;
|
|
219
|
+
line-clamp: 2;
|
|
220
|
+
-webkit-line-clamp: 2;
|
|
221
|
+
-webkit-box-orient: vertical;
|
|
222
|
+
}
|
|
223
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
src: string;
|
|
3
|
+
alt: string;
|
|
4
|
+
width?: number | string;
|
|
5
|
+
height?: number | string;
|
|
6
|
+
loading?: 'lazy' | 'eager';
|
|
7
|
+
objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
8
|
+
objectPosition?: string;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
fallback?: string;
|
|
11
|
+
rounded?: boolean | 'sm' | 'md' | 'lg' | 'full';
|
|
12
|
+
aspectRatio?: string;
|
|
13
|
+
class?: string;
|
|
14
|
+
onload?: () => void;
|
|
15
|
+
onerror?: () => void;
|
|
16
|
+
}
|
|
17
|
+
declare const Image: import("svelte").Component<Props, {}, "">;
|
|
18
|
+
type Image = ReturnType<typeof Image>;
|
|
19
|
+
export default Image;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Image } from './Image.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Image } from './Image.svelte';
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount } from 'svelte';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
/**
|
|
6
|
+
* The OTP value (bindable)
|
|
7
|
+
* @default ''
|
|
8
|
+
*/
|
|
9
|
+
value?: string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Number of OTP digits
|
|
13
|
+
* @default 6
|
|
14
|
+
*/
|
|
15
|
+
length?: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Input type validation
|
|
19
|
+
* @default 'numeric'
|
|
20
|
+
*/
|
|
21
|
+
type?: 'numeric' | 'alphanumeric';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Show dots instead of characters
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
masked?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Disabled state
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Error state
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
error?: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Component size
|
|
43
|
+
* @default 'md'
|
|
44
|
+
*/
|
|
45
|
+
size?: 'sm' | 'md' | 'lg';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Auto-focus first input on mount
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
autoFocus?: boolean;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Additional CSS classes
|
|
55
|
+
*/
|
|
56
|
+
class?: string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Callback when all digits are entered
|
|
60
|
+
*/
|
|
61
|
+
oncomplete?: (value: string) => void;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Callback on value change
|
|
65
|
+
*/
|
|
66
|
+
onchange?: (value: string) => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let {
|
|
70
|
+
value = $bindable(''),
|
|
71
|
+
length = 6,
|
|
72
|
+
type = 'numeric',
|
|
73
|
+
masked = false,
|
|
74
|
+
disabled = false,
|
|
75
|
+
error = false,
|
|
76
|
+
size = 'md',
|
|
77
|
+
autoFocus = false,
|
|
78
|
+
class: className = '',
|
|
79
|
+
oncomplete,
|
|
80
|
+
onchange
|
|
81
|
+
}: Props = $props();
|
|
82
|
+
|
|
83
|
+
// Track individual input elements
|
|
84
|
+
let inputs: (HTMLInputElement | null)[] = $state([]);
|
|
85
|
+
|
|
86
|
+
// Split value into individual characters
|
|
87
|
+
let chars = $derived(value.padEnd(length, ' ').slice(0, length).split(''));
|
|
88
|
+
|
|
89
|
+
onMount(() => {
|
|
90
|
+
if (autoFocus && inputs[0]) {
|
|
91
|
+
inputs[0].focus();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function handleInput(index: number, e: Event) {
|
|
96
|
+
const input = e.target as HTMLInputElement;
|
|
97
|
+
const char = input.value.slice(-1); // Get last character entered
|
|
98
|
+
|
|
99
|
+
// Validate based on type
|
|
100
|
+
if (type === 'numeric' && char && !/^\d$/.test(char)) {
|
|
101
|
+
input.value = '';
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (type === 'alphanumeric' && char && !/^[a-zA-Z0-9]$/.test(char)) {
|
|
106
|
+
input.value = '';
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Update value
|
|
111
|
+
const newChars = chars.map((c, i) => (i === index ? char : c));
|
|
112
|
+
const newValue = newChars.join('').trim();
|
|
113
|
+
value = newValue;
|
|
114
|
+
|
|
115
|
+
// Call onchange callback
|
|
116
|
+
onchange?.(newValue);
|
|
117
|
+
|
|
118
|
+
// Move to next input if character was entered
|
|
119
|
+
if (char && index < length - 1) {
|
|
120
|
+
inputs[index + 1]?.focus();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Check completion
|
|
124
|
+
if (newValue.length === length) {
|
|
125
|
+
oncomplete?.(newValue);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function handleKeydown(index: number, e: KeyboardEvent) {
|
|
130
|
+
const input = e.target as HTMLInputElement;
|
|
131
|
+
|
|
132
|
+
switch (e.key) {
|
|
133
|
+
case 'Backspace':
|
|
134
|
+
// If input is empty, move to previous input
|
|
135
|
+
if (!input.value && index > 0) {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
inputs[index - 1]?.focus();
|
|
138
|
+
// Clear previous input
|
|
139
|
+
const newChars = chars.map((c, i) => (i === index - 1 ? '' : c));
|
|
140
|
+
value = newChars.join('').trim();
|
|
141
|
+
onchange?.(value);
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
case 'ArrowLeft':
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
if (index > 0) {
|
|
148
|
+
inputs[index - 1]?.focus();
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
|
|
152
|
+
case 'ArrowRight':
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
if (index < length - 1) {
|
|
155
|
+
inputs[index + 1]?.focus();
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
|
|
159
|
+
case 'ArrowUp':
|
|
160
|
+
case 'ArrowDown':
|
|
161
|
+
// Prevent default to avoid number spinner in numeric inputs
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function handlePaste(e: ClipboardEvent) {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
const pastedData = e.clipboardData?.getData('text') || '';
|
|
170
|
+
|
|
171
|
+
// Filter based on type
|
|
172
|
+
let filteredData = pastedData;
|
|
173
|
+
if (type === 'numeric') {
|
|
174
|
+
filteredData = pastedData.replace(/\D/g, '');
|
|
175
|
+
} else if (type === 'alphanumeric') {
|
|
176
|
+
filteredData = pastedData.replace(/[^a-zA-Z0-9]/g, '');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Trim to length and update value
|
|
180
|
+
const newValue = filteredData.slice(0, length);
|
|
181
|
+
value = newValue;
|
|
182
|
+
onchange?.(newValue);
|
|
183
|
+
|
|
184
|
+
// Focus the next empty input or the last input
|
|
185
|
+
const nextEmptyIndex = newValue.length < length ? newValue.length : length - 1;
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
inputs[nextEmptyIndex]?.focus();
|
|
188
|
+
}, 0);
|
|
189
|
+
|
|
190
|
+
// Check completion
|
|
191
|
+
if (newValue.length === length) {
|
|
192
|
+
oncomplete?.(newValue);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function handleFocus(index: number, e: FocusEvent) {
|
|
197
|
+
const input = e.target as HTMLInputElement;
|
|
198
|
+
// Select content on focus for easy replacement
|
|
199
|
+
input.select();
|
|
200
|
+
}
|
|
201
|
+
</script>
|
|
202
|
+
|
|
203
|
+
<div
|
|
204
|
+
class="otp-input otp-input--{size} {error ? 'otp-input--error' : ''} {disabled
|
|
205
|
+
? 'otp-input--disabled'
|
|
206
|
+
: ''} {className}"
|
|
207
|
+
role="group"
|
|
208
|
+
aria-label="One-time password input"
|
|
209
|
+
>
|
|
210
|
+
{#each Array(length) as _, index (index)}
|
|
211
|
+
<input
|
|
212
|
+
bind:this={inputs[index]}
|
|
213
|
+
class="otp-input__field"
|
|
214
|
+
type={masked ? 'password' : 'text'}
|
|
215
|
+
inputmode={type === 'numeric' ? 'numeric' : 'text'}
|
|
216
|
+
autocomplete="one-time-code"
|
|
217
|
+
maxlength="1"
|
|
218
|
+
value={chars[index]?.trim() || ''}
|
|
219
|
+
aria-label="Digit {index + 1} of {length}"
|
|
220
|
+
aria-invalid={error}
|
|
221
|
+
{disabled}
|
|
222
|
+
oninput={(e) => handleInput(index, e)}
|
|
223
|
+
onkeydown={(e) => handleKeydown(index, e)}
|
|
224
|
+
onpaste={(e) => handlePaste(e)}
|
|
225
|
+
onfocus={(e) => handleFocus(index, e)}
|
|
226
|
+
/>
|
|
227
|
+
{/each}
|
|
228
|
+
</div>
|
|
229
|
+
|
|
230
|
+
<style>
|
|
231
|
+
.otp-input {
|
|
232
|
+
display: flex;
|
|
233
|
+
gap: var(--space-sm, 0.5rem);
|
|
234
|
+
align-items: center;
|
|
235
|
+
width: 100%;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.otp-input--disabled {
|
|
239
|
+
opacity: 0.5;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.otp-input__field {
|
|
243
|
+
flex: 1;
|
|
244
|
+
min-width: 0;
|
|
245
|
+
min-height: var(--touch-target-min, 44px);
|
|
246
|
+
max-width: 3rem;
|
|
247
|
+
padding: var(--space-sm, 0.5rem);
|
|
248
|
+
border: 1px solid var(--color-border, #e5e7eb);
|
|
249
|
+
border-radius: var(--radius-md, 0.375rem);
|
|
250
|
+
background: var(--color-bg, #ffffff);
|
|
251
|
+
color: var(--color-text, #1f2937);
|
|
252
|
+
font-family: inherit;
|
|
253
|
+
font-size: var(--text-lg, 1.125rem);
|
|
254
|
+
font-weight: var(--font-semibold, 600);
|
|
255
|
+
text-align: center;
|
|
256
|
+
line-height: 1;
|
|
257
|
+
transition:
|
|
258
|
+
border-color var(--transition-fast, 150ms ease),
|
|
259
|
+
box-shadow var(--transition-fast, 150ms ease);
|
|
260
|
+
-webkit-tap-highlight-color: transparent;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.otp-input__field:focus {
|
|
264
|
+
outline: none;
|
|
265
|
+
border-color: var(--color-primary, #3b82f6);
|
|
266
|
+
box-shadow: 0 0 0 3px var(--color-primary-alpha, rgba(59, 130, 246, 0.1));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.otp-input__field:disabled {
|
|
270
|
+
background: var(--color-bg-muted, #f3f4f6);
|
|
271
|
+
cursor: not-allowed;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/* Size variants */
|
|
275
|
+
.otp-input--sm .otp-input__field {
|
|
276
|
+
min-height: var(--touch-target-min, 44px);
|
|
277
|
+
max-width: 2.5rem;
|
|
278
|
+
padding: var(--space-xs, 0.25rem);
|
|
279
|
+
font-size: var(--text-base, 1rem);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.otp-input--md .otp-input__field {
|
|
283
|
+
min-height: var(--touch-target-min, 44px);
|
|
284
|
+
max-width: 3rem;
|
|
285
|
+
padding: var(--space-sm, 0.5rem);
|
|
286
|
+
font-size: var(--text-lg, 1.125rem);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.otp-input--lg .otp-input__field {
|
|
290
|
+
min-height: 3.25rem;
|
|
291
|
+
max-width: 3.5rem;
|
|
292
|
+
padding: var(--space-md, 1rem);
|
|
293
|
+
font-size: var(--text-xl, 1.25rem);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* Error state */
|
|
297
|
+
.otp-input--error .otp-input__field {
|
|
298
|
+
border-color: var(--color-error, #ef4444);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.otp-input--error .otp-input__field:focus {
|
|
302
|
+
border-color: var(--color-error, #ef4444);
|
|
303
|
+
box-shadow: 0 0 0 3px var(--color-error-alpha, rgba(239, 68, 68, 0.1));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/* Remove number spinner for numeric inputs */
|
|
307
|
+
.otp-input__field::-webkit-outer-spin-button,
|
|
308
|
+
.otp-input__field::-webkit-inner-spin-button {
|
|
309
|
+
-webkit-appearance: none;
|
|
310
|
+
margin: 0;
|
|
311
|
+
}
|
|
312
|
+
</style>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
/**
|
|
3
|
+
* The OTP value (bindable)
|
|
4
|
+
* @default ''
|
|
5
|
+
*/
|
|
6
|
+
value?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Number of OTP digits
|
|
9
|
+
* @default 6
|
|
10
|
+
*/
|
|
11
|
+
length?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Input type validation
|
|
14
|
+
* @default 'numeric'
|
|
15
|
+
*/
|
|
16
|
+
type?: 'numeric' | 'alphanumeric';
|
|
17
|
+
/**
|
|
18
|
+
* Show dots instead of characters
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
masked?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Disabled state
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Error state
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
error?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Component size
|
|
34
|
+
* @default 'md'
|
|
35
|
+
*/
|
|
36
|
+
size?: 'sm' | 'md' | 'lg';
|
|
37
|
+
/**
|
|
38
|
+
* Auto-focus first input on mount
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
autoFocus?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Additional CSS classes
|
|
44
|
+
*/
|
|
45
|
+
class?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Callback when all digits are entered
|
|
48
|
+
*/
|
|
49
|
+
oncomplete?: (value: string) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Callback on value change
|
|
52
|
+
*/
|
|
53
|
+
onchange?: (value: string) => void;
|
|
54
|
+
}
|
|
55
|
+
declare const OTPInput: import("svelte").Component<Props, {}, "value">;
|
|
56
|
+
type OTPInput = ReturnType<typeof OTPInput>;
|
|
57
|
+
export default OTPInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as OTPInput } from './OTPInput.svelte';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as OTPInput } from './OTPInput.svelte';
|