uisv 0.0.13 → 0.0.14
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/dist/components/button.svelte +409 -0
- package/dist/components/{button/index.d.ts → button.svelte.d.ts} +4 -3
- package/dist/components/index.d.ts +6 -3
- package/dist/components/index.js +6 -3
- package/dist/components/input-time.svelte +234 -0
- package/dist/components/input-time.svelte.d.ts +54 -0
- package/dist/components/input.svelte +285 -0
- package/dist/components/{input/index.d.ts → input.svelte.d.ts} +5 -4
- package/dist/components/tabs.svelte +1 -2
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +14 -39
- package/package.json +35 -38
- package/dist/components/button/button.svelte +0 -105
- package/dist/components/button/button.svelte.d.ts +0 -4
- package/dist/components/button/index.js +0 -4
- package/dist/components/button/style.d.ts +0 -148
- package/dist/components/button/style.js +0 -248
- package/dist/components/input/index.js +0 -2
- package/dist/components/input/input.svelte +0 -103
- package/dist/components/input/input.svelte.d.ts +0 -4
- package/dist/components/input/style.d.ts +0 -316
- package/dist/components/input/style.js +0 -128
- package/dist/components/input-time/index.d.ts +0 -375
- package/dist/components/input-time/index.js +0 -144
- package/dist/components/input-time/input-time.svelte +0 -39
- package/dist/components/input-time/input-time.svelte.d.ts +0 -4
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { type Component, type Snippet } from 'svelte';
|
|
3
|
+
import { type PropColor } from '../index.js';
|
|
4
|
+
import type { ClassNameValue } from 'tailwind-merge';
|
|
5
|
+
// import { FORM_LOADING_CONTEXT_KEY } from '../utils/keys.js';
|
|
6
|
+
import { isSnippet } from '../index.js';
|
|
7
|
+
import { tv } from 'tailwind-variants';
|
|
8
|
+
|
|
9
|
+
export type ButtonProps = {
|
|
10
|
+
/** The underlying DOM element being rendered. You can bind to this to get a reference to the element. */
|
|
11
|
+
ref?: HTMLButtonElement | HTMLAnchorElement;
|
|
12
|
+
/** Where to display the linked URL, as the name for a browsing context. */
|
|
13
|
+
target?: null | '_blank' | '_parent' | '_self' | '_top' | (string & {});
|
|
14
|
+
/** Force the link to be active independent of the current route. */
|
|
15
|
+
// active?: boolean;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** The type of the button when not a link. */
|
|
18
|
+
type?: 'submit' | 'reset' | 'button' | null | undefined;
|
|
19
|
+
/** When true, the icon will be displayed on the right side. */
|
|
20
|
+
loadingicon?: string | Snippet | Component;
|
|
21
|
+
/** When true, the loading icon will be displayed. */
|
|
22
|
+
loading?: boolean;
|
|
23
|
+
/** The position of the icon, including the loading icon */
|
|
24
|
+
iconposition?: 'left' | 'right';
|
|
25
|
+
/** Icon when `loading` is `false` */
|
|
26
|
+
icon?: string | Snippet | Component;
|
|
27
|
+
/** Route Location the link should navigate to when clicked on. */
|
|
28
|
+
href?: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
/**
|
|
31
|
+
* @defaultValue 'primary'
|
|
32
|
+
*/
|
|
33
|
+
color?: PropColor;
|
|
34
|
+
// activecolor?: PropColor;
|
|
35
|
+
/**
|
|
36
|
+
* @defaultValue 'solid'
|
|
37
|
+
*/
|
|
38
|
+
variant?: 'link' | 'solid' | 'outline' | 'soft' | 'subtle' | 'ghost';
|
|
39
|
+
// activevariant?: ButtonVariant;
|
|
40
|
+
/**
|
|
41
|
+
* @defaultValue 'md'
|
|
42
|
+
*/
|
|
43
|
+
size?: 'md' | 'xs' | 'sm' | 'lg' | 'xl';
|
|
44
|
+
/** Render the button full width. */
|
|
45
|
+
block?: boolean;
|
|
46
|
+
/** Set loading state automatically based on the `@click` promise state */
|
|
47
|
+
loadingauto?: boolean;
|
|
48
|
+
onclick?: (event: MouseEvent) => void | Promise<void>;
|
|
49
|
+
ui?: {
|
|
50
|
+
base?: ClassNameValue;
|
|
51
|
+
icon?: ClassNameValue;
|
|
52
|
+
};
|
|
53
|
+
children?: Snippet;
|
|
54
|
+
};
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<script lang="ts">
|
|
58
|
+
// let form_loading = getContext<{ value: boolean } | undefined>(FORM_LOADING_CONTEXT_KEY);
|
|
59
|
+
let {
|
|
60
|
+
ref = $bindable(),
|
|
61
|
+
size = 'md',
|
|
62
|
+
variant = 'solid',
|
|
63
|
+
color = 'primary',
|
|
64
|
+
iconposition = 'left',
|
|
65
|
+
children,
|
|
66
|
+
// active,
|
|
67
|
+
// activecolor,
|
|
68
|
+
// activevariant,
|
|
69
|
+
block,
|
|
70
|
+
label,
|
|
71
|
+
loadingauto,
|
|
72
|
+
onclick,
|
|
73
|
+
ui = {},
|
|
74
|
+
disabled,
|
|
75
|
+
href,
|
|
76
|
+
icon,
|
|
77
|
+
loading,
|
|
78
|
+
loadingicon,
|
|
79
|
+
target,
|
|
80
|
+
type,
|
|
81
|
+
}: ButtonProps = $props();
|
|
82
|
+
|
|
83
|
+
let internal_loading = $state(false);
|
|
84
|
+
const is_loading = $derived.by(() => {
|
|
85
|
+
if (loading) return true;
|
|
86
|
+
if (loadingauto) return internal_loading;
|
|
87
|
+
return false;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const variants = $derived(
|
|
91
|
+
tv({
|
|
92
|
+
slots: {
|
|
93
|
+
icon: '',
|
|
94
|
+
base: 'transition flex-inline items-center font-sans',
|
|
95
|
+
},
|
|
96
|
+
variants: {
|
|
97
|
+
color: {
|
|
98
|
+
primary: '',
|
|
99
|
+
surface: '',
|
|
100
|
+
error: '',
|
|
101
|
+
success: '',
|
|
102
|
+
info: '',
|
|
103
|
+
warning: '',
|
|
104
|
+
},
|
|
105
|
+
variant: {
|
|
106
|
+
link: '',
|
|
107
|
+
solid: 'text-inverted',
|
|
108
|
+
outline: 'border',
|
|
109
|
+
soft: '',
|
|
110
|
+
subtle: 'border',
|
|
111
|
+
ghost: '',
|
|
112
|
+
},
|
|
113
|
+
size: {
|
|
114
|
+
xs: {
|
|
115
|
+
base: 'font-medium text-xs px-2 h-6 rounded gap-1',
|
|
116
|
+
icon: 'size-4',
|
|
117
|
+
},
|
|
118
|
+
sm: { base: 'font-medium text-xs px-2 h-7 rounded gap-1', icon: 'size-4' },
|
|
119
|
+
md: { base: 'font-medium text-sm rounded-md px-2 h-8 gap-2', icon: 'size-5' },
|
|
120
|
+
lg: { base: 'font-medium text-sm px-3 h-9 rounded-md gap-2', icon: 'size-6' },
|
|
121
|
+
xl: { base: 'font-medium px-3 h-10 rounded-md gap-2', icon: 'size-6' },
|
|
122
|
+
},
|
|
123
|
+
block: {
|
|
124
|
+
true: 'w-full',
|
|
125
|
+
},
|
|
126
|
+
disabled: {
|
|
127
|
+
true: 'cursor-not-allowed',
|
|
128
|
+
false: 'cursor-default',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
compoundVariants: [
|
|
132
|
+
{
|
|
133
|
+
color: 'primary',
|
|
134
|
+
variant: 'solid',
|
|
135
|
+
class: 'bg-primary-500 hover:(bg-primary-400)',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
color: 'surface',
|
|
139
|
+
variant: 'solid',
|
|
140
|
+
class: 'bg-surface-inverted text-inverted hover:(bg-toned)',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
color: 'info',
|
|
144
|
+
variant: 'solid',
|
|
145
|
+
class: 'bg-info-500 hover:(bg-info-400)',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
color: 'success',
|
|
149
|
+
variant: 'solid',
|
|
150
|
+
class: 'bg-success-500 hover:(bg-success-400)',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
color: 'error',
|
|
154
|
+
variant: 'solid',
|
|
155
|
+
class: 'bg-error-500 hover:(bg-error-400)',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
color: 'warning',
|
|
159
|
+
variant: 'solid',
|
|
160
|
+
class: 'bg-warning-500 hover:(bg-warning-400)',
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
{
|
|
164
|
+
color: 'primary',
|
|
165
|
+
variant: 'outline',
|
|
166
|
+
class: {
|
|
167
|
+
base: [
|
|
168
|
+
'border-primary/50 text-primary-500 hover:(bg-primary-50)',
|
|
169
|
+
'dark:hover:bg-primary-950',
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
color: 'surface',
|
|
175
|
+
variant: 'outline',
|
|
176
|
+
class: {
|
|
177
|
+
base: [
|
|
178
|
+
'border-surface-accented text-surface-inverted hover:bg-surface/10',
|
|
179
|
+
'dark:hover:bg-surface-800',
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
color: 'info',
|
|
185
|
+
variant: 'outline',
|
|
186
|
+
class: {
|
|
187
|
+
base: ['border-info/50 text-blue-500 hover:bg-info/10', 'dark:hover:bg-info-950'],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
color: 'success',
|
|
192
|
+
variant: 'outline',
|
|
193
|
+
class: {
|
|
194
|
+
base: [
|
|
195
|
+
'border-success/50 text-success-500 hover:bg-success/10',
|
|
196
|
+
'dark:hover:bg-success-950',
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
color: 'error',
|
|
202
|
+
variant: 'outline',
|
|
203
|
+
class: {
|
|
204
|
+
base: ['border-red/50 text-red-500 hover:bg-red/10', 'dark:hover:bg-red-950'],
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
color: 'warning',
|
|
209
|
+
variant: 'outline',
|
|
210
|
+
class: {
|
|
211
|
+
base: [
|
|
212
|
+
'border-warning/50 text-warning-500 hover:(bg-warning/10)',
|
|
213
|
+
'dark:hover:bg-warning-950',
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
{
|
|
219
|
+
color: 'primary',
|
|
220
|
+
variant: 'soft',
|
|
221
|
+
class: 'bg-primary-50 text-primary-500 hover:(bg-primary-100)',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
color: 'surface',
|
|
225
|
+
variant: 'soft',
|
|
226
|
+
class: 'bg-surface-100 text-surface-800 hover:(bg-surface-200)',
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
color: 'info',
|
|
230
|
+
variant: 'soft',
|
|
231
|
+
class: 'bg-blue-100 text-blue-500 hover:(bg-blue-50)',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
color: 'success',
|
|
235
|
+
variant: 'soft',
|
|
236
|
+
class: 'bg-green-100 text-green-500 hover:(bg-green-50)',
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
color: 'error',
|
|
240
|
+
variant: 'soft',
|
|
241
|
+
class: 'bg-red-100 text-red-500 hover:(bg-red-50)',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
color: 'warning',
|
|
245
|
+
variant: 'soft',
|
|
246
|
+
class: 'bg-yellow-100 text-yellow-500 hover:(bg-yellow-50)',
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
{
|
|
250
|
+
color: 'primary',
|
|
251
|
+
variant: 'subtle',
|
|
252
|
+
class: 'bg-primary-50 text-primary-500 border-primary-200 hover:(bg-primary-100)',
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
color: 'surface',
|
|
256
|
+
variant: 'subtle',
|
|
257
|
+
class: 'bg-surface-50 text-surface-800 border-surface-300 hover:(bg-surface-100)',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
color: 'info',
|
|
261
|
+
variant: 'subtle',
|
|
262
|
+
class: 'bg-blue-50 text-blue-600 border-blue-200 hover:(bg-blue-100)',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
color: 'success',
|
|
266
|
+
variant: 'subtle',
|
|
267
|
+
class: 'bg-green-100 text-green-600 border-green-300 hover:(bg-green-100)',
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
color: 'error',
|
|
271
|
+
variant: 'subtle',
|
|
272
|
+
class: 'bg-red-50 text-red-600 border-red-200 hover:(bg-red-100)',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
color: 'warning',
|
|
276
|
+
variant: 'subtle',
|
|
277
|
+
class: 'bg-yellow-50 text-yellow-600 border-yellow-300 hover:(bg-yellow-100)',
|
|
278
|
+
},
|
|
279
|
+
|
|
280
|
+
{
|
|
281
|
+
color: 'primary',
|
|
282
|
+
variant: 'ghost',
|
|
283
|
+
class: 'text-primary-500 hover:(bg-primary-100)',
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
color: 'surface',
|
|
287
|
+
variant: 'ghost',
|
|
288
|
+
class: 'text-surface-inverted hover:(bg-surface-elevated text-surface-inverted)',
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
color: 'info',
|
|
292
|
+
variant: 'ghost',
|
|
293
|
+
class: 'text-blue-600 hover:(bg-blue-100)',
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
color: 'success',
|
|
297
|
+
variant: 'ghost',
|
|
298
|
+
class: 'text-green-600 hover:(bg-green-100)',
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
color: 'error',
|
|
302
|
+
variant: 'ghost',
|
|
303
|
+
class: 'text-red-600 hover:(bg-red-100)',
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
color: 'warning',
|
|
307
|
+
variant: 'ghost',
|
|
308
|
+
class: 'text-yellow-600 hover:(bg-yellow-100)',
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
{
|
|
312
|
+
color: 'primary',
|
|
313
|
+
variant: 'link',
|
|
314
|
+
class: 'text-primary-500 hover:(text-primary-400)',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
color: 'surface',
|
|
318
|
+
variant: 'link',
|
|
319
|
+
class: 'text-muted hover:(text-surface-inverted)',
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
color: 'info',
|
|
323
|
+
variant: 'link',
|
|
324
|
+
class: 'text-blue-500 hover:(text-blue-400)',
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
color: 'success',
|
|
328
|
+
variant: 'link',
|
|
329
|
+
class: 'text-green-500 hover:(text-green-400)',
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
color: 'error',
|
|
333
|
+
variant: 'link',
|
|
334
|
+
class: 'text-red-500 hover:(text-red-400)',
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
color: 'warning',
|
|
338
|
+
variant: 'link',
|
|
339
|
+
class: 'text-yellow-500 hover:(text-yellow-400)',
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
})({ variant, color, size, block, disabled: disabled || is_loading }),
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
const only_icon = $derived(!(children || label) && !!icon);
|
|
346
|
+
|
|
347
|
+
async function onClickWrapper(event: MouseEvent) {
|
|
348
|
+
if (!onclick) return;
|
|
349
|
+
internal_loading = true;
|
|
350
|
+
|
|
351
|
+
await onclick(event);
|
|
352
|
+
|
|
353
|
+
internal_loading = false;
|
|
354
|
+
}
|
|
355
|
+
</script>
|
|
356
|
+
|
|
357
|
+
{#if href}
|
|
358
|
+
<a
|
|
359
|
+
{href}
|
|
360
|
+
{target}
|
|
361
|
+
class={variants.base({
|
|
362
|
+
class: [only_icon ? 'px-0 aspect-square justify-center' : '', 'cursor-pointer', ui.base],
|
|
363
|
+
})}
|
|
364
|
+
onclick={onClickWrapper}
|
|
365
|
+
>
|
|
366
|
+
{@render Content()}
|
|
367
|
+
</a>
|
|
368
|
+
{:else}
|
|
369
|
+
<button
|
|
370
|
+
{type}
|
|
371
|
+
disabled={disabled || is_loading}
|
|
372
|
+
class={variants.base({
|
|
373
|
+
class: [only_icon ? 'px-0 aspect-square justify-center' : '', ui.base],
|
|
374
|
+
})}
|
|
375
|
+
onclick={onClickWrapper}
|
|
376
|
+
>
|
|
377
|
+
{@render Content()}
|
|
378
|
+
</button>
|
|
379
|
+
{/if}
|
|
380
|
+
|
|
381
|
+
{#snippet Content()}
|
|
382
|
+
{#if iconposition === 'left'}
|
|
383
|
+
{@render Icon()}
|
|
384
|
+
{/if}
|
|
385
|
+
|
|
386
|
+
{#if label}
|
|
387
|
+
{label}
|
|
388
|
+
{:else}
|
|
389
|
+
{@render children?.()}
|
|
390
|
+
{/if}
|
|
391
|
+
|
|
392
|
+
{#if iconposition !== 'left'}
|
|
393
|
+
{@render Icon()}
|
|
394
|
+
{/if}
|
|
395
|
+
{/snippet}
|
|
396
|
+
|
|
397
|
+
{#snippet Icon()}
|
|
398
|
+
{@const IconCom = is_loading ? loadingicon || '-ph-lucide-loader-circle' : icon}
|
|
399
|
+
|
|
400
|
+
{#if IconCom}
|
|
401
|
+
{#if typeof IconCom === 'string'}
|
|
402
|
+
<div class={variants.icon({ class: [is_loading && 'animate-spin', IconCom, ui.icon] })}></div>
|
|
403
|
+
{:else if isSnippet(IconCom)}
|
|
404
|
+
{@render IconCom()}
|
|
405
|
+
{:else}
|
|
406
|
+
<IconCom />
|
|
407
|
+
{/if}
|
|
408
|
+
{/if}
|
|
409
|
+
{/snippet}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { type Component, type Snippet } from 'svelte';
|
|
2
|
-
import { type PropColor } from '
|
|
2
|
+
import { type PropColor } from '../index.js';
|
|
3
3
|
import type { ClassNameValue } from 'tailwind-merge';
|
|
4
|
-
export * from './style.js';
|
|
5
|
-
export { default as Button } from './button.svelte';
|
|
6
4
|
export type ButtonProps = {
|
|
7
5
|
/** The underlying DOM element being rendered. You can bind to this to get a reference to the element. */
|
|
8
6
|
ref?: HTMLButtonElement | HTMLAnchorElement;
|
|
@@ -46,3 +44,6 @@ export type ButtonProps = {
|
|
|
46
44
|
};
|
|
47
45
|
children?: Snippet;
|
|
48
46
|
};
|
|
47
|
+
declare const Button: Component<ButtonProps, {}, "ref">;
|
|
48
|
+
type Button = ReturnType<typeof Button>;
|
|
49
|
+
export default Button;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export * from './button
|
|
2
|
-
export
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './button.svelte';
|
|
2
|
+
export { default as Button } from './button.svelte';
|
|
3
|
+
export * from './badge.svelte';
|
|
4
|
+
export { default as Input } from './input.svelte';
|
|
5
|
+
export * from './badge.svelte';
|
|
6
|
+
export { default as InputTime } from './input-time.svelte';
|
|
4
7
|
export * from './badge.svelte';
|
|
5
8
|
export { default as Badge } from './badge.svelte';
|
|
6
9
|
export * from './alert.svelte';
|
package/dist/components/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export * from './button
|
|
2
|
-
export
|
|
3
|
-
export * from './
|
|
1
|
+
export * from './button.svelte';
|
|
2
|
+
export { default as Button } from './button.svelte';
|
|
3
|
+
export * from './badge.svelte';
|
|
4
|
+
export { default as Input } from './input.svelte';
|
|
5
|
+
export * from './badge.svelte';
|
|
6
|
+
export { default as InputTime } from './input-time.svelte';
|
|
4
7
|
export * from './badge.svelte';
|
|
5
8
|
export { default as Badge } from './badge.svelte';
|
|
6
9
|
export * from './alert.svelte';
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import { type PropColor } from '../index.js';
|
|
3
|
+
import type { Component, Snippet } from 'svelte';
|
|
4
|
+
import type { ClassNameValue } from 'tailwind-merge';
|
|
5
|
+
import { tv } from 'tailwind-variants';
|
|
6
|
+
import { Time } from '@internationalized/date';
|
|
7
|
+
|
|
8
|
+
export { Time };
|
|
9
|
+
export { default as InputTime } from './input-time.svelte';
|
|
10
|
+
|
|
11
|
+
export type InputTimeProps = {
|
|
12
|
+
id?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
hourcycle?: 12 | 24;
|
|
15
|
+
max?: Time;
|
|
16
|
+
min?: Time;
|
|
17
|
+
/**
|
|
18
|
+
* The placeholder text when the input is empty.
|
|
19
|
+
*/
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
/**
|
|
22
|
+
* @default primary
|
|
23
|
+
*/
|
|
24
|
+
color?: PropColor;
|
|
25
|
+
/**
|
|
26
|
+
* @default outline
|
|
27
|
+
*/
|
|
28
|
+
variant?: 'outline' | 'soft' | 'subtle' | 'ghost' | 'none';
|
|
29
|
+
/**
|
|
30
|
+
* @default md
|
|
31
|
+
*/
|
|
32
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
33
|
+
/**
|
|
34
|
+
* @default off
|
|
35
|
+
*/
|
|
36
|
+
autocomplete?: 'on' | 'off';
|
|
37
|
+
/**
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
autofocus?: boolean | number;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Highlight the ring color like a focus state.
|
|
44
|
+
*/
|
|
45
|
+
highlight?: boolean;
|
|
46
|
+
value?: Time;
|
|
47
|
+
icon?: string | Snippet | Component;
|
|
48
|
+
ui?: {
|
|
49
|
+
root?: ClassNameValue;
|
|
50
|
+
leading?: ClassNameValue;
|
|
51
|
+
icon?: ClassNameValue;
|
|
52
|
+
trailing?: ClassNameValue;
|
|
53
|
+
segment?: ClassNameValue;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<script lang="ts">
|
|
59
|
+
import { TimeField } from 'bits-ui';
|
|
60
|
+
|
|
61
|
+
let {
|
|
62
|
+
hourcycle = 12,
|
|
63
|
+
value = $bindable(),
|
|
64
|
+
color = 'primary',
|
|
65
|
+
variant = 'outline',
|
|
66
|
+
size = 'md',
|
|
67
|
+
icon,
|
|
68
|
+
disabled,
|
|
69
|
+
highlight,
|
|
70
|
+
ui = {},
|
|
71
|
+
...rest
|
|
72
|
+
}: InputTimeProps = $props();
|
|
73
|
+
|
|
74
|
+
const variants = $derived(
|
|
75
|
+
tv({
|
|
76
|
+
slots: {
|
|
77
|
+
root: 'inline-flex items-center rounded transition-all ring ring-inset ring-transparent',
|
|
78
|
+
leading: 'text-muted',
|
|
79
|
+
trailing: 'text-muted',
|
|
80
|
+
icon: '',
|
|
81
|
+
segment: [
|
|
82
|
+
'rounded text-center outline-hidden transition-all focus:bg-surface-accented shrink',
|
|
83
|
+
'aria-[valuetext="Empty"]:text-dimmed data-[segment="literal"]:(text-muted px-1) data-invalid:text-error data-disabled:(cursor-not-allowed opacity-75)',
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
variants: {
|
|
87
|
+
fieldGroup: {
|
|
88
|
+
horizontal: {
|
|
89
|
+
root: '',
|
|
90
|
+
},
|
|
91
|
+
vertical: {
|
|
92
|
+
root: '',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
size: {
|
|
96
|
+
xs: {
|
|
97
|
+
root: 'px-2 h-6 text-xs',
|
|
98
|
+
leading: 'ps-2',
|
|
99
|
+
trailing: 'pe-2',
|
|
100
|
+
icon: 'size-4',
|
|
101
|
+
segment: 'px-1',
|
|
102
|
+
},
|
|
103
|
+
sm: {
|
|
104
|
+
root: 'px-2.5 h-7 text-xs',
|
|
105
|
+
leading: 'ps-2.5',
|
|
106
|
+
trailing: 'pe-2.5',
|
|
107
|
+
icon: 'size-4',
|
|
108
|
+
segment: 'px-1',
|
|
109
|
+
},
|
|
110
|
+
md: {
|
|
111
|
+
root: 'px-2.5 h-8 text-sm',
|
|
112
|
+
leading: 'ps-2.5',
|
|
113
|
+
trailing: 'pe-2.5',
|
|
114
|
+
icon: 'size-5',
|
|
115
|
+
segment: 'px-2',
|
|
116
|
+
},
|
|
117
|
+
lg: {
|
|
118
|
+
root: 'px-3 h-9 text-sm',
|
|
119
|
+
leading: 'ps-3',
|
|
120
|
+
trailing: 'pe-3',
|
|
121
|
+
icon: 'size-5',
|
|
122
|
+
segment: 'px-3',
|
|
123
|
+
},
|
|
124
|
+
xl: {
|
|
125
|
+
root: 'px-3 h-10 text-base',
|
|
126
|
+
leading: 'ps-3',
|
|
127
|
+
trailing: 'pe-3',
|
|
128
|
+
icon: 'size-6',
|
|
129
|
+
segment: 'px-3',
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
variant: {
|
|
133
|
+
outline: { root: 'ring ring-surface-accented' },
|
|
134
|
+
soft: {
|
|
135
|
+
root: 'bg-surface-muted hover:bg-surface-elevated focus-within:bg-surface-elevated',
|
|
136
|
+
},
|
|
137
|
+
subtle: { root: 'ring ring-accented' },
|
|
138
|
+
ghost: { root: 'hover:bg-surface-elevated focus-within:bg-surface-elevated' },
|
|
139
|
+
none: { root: '' },
|
|
140
|
+
},
|
|
141
|
+
color: {
|
|
142
|
+
primary: { root: '' },
|
|
143
|
+
surface: { root: '' },
|
|
144
|
+
info: { root: '' },
|
|
145
|
+
success: { root: '' },
|
|
146
|
+
warning: { root: '' },
|
|
147
|
+
error: { root: '' },
|
|
148
|
+
},
|
|
149
|
+
leading: {
|
|
150
|
+
false: { leading: 'hidden' },
|
|
151
|
+
},
|
|
152
|
+
trailing: {
|
|
153
|
+
false: { trailing: 'hidden' },
|
|
154
|
+
},
|
|
155
|
+
loading: {
|
|
156
|
+
true: '',
|
|
157
|
+
},
|
|
158
|
+
highlight: {
|
|
159
|
+
true: '',
|
|
160
|
+
},
|
|
161
|
+
type: {
|
|
162
|
+
file: 'file:me-1.5 file:font-medium file:text-muted file:outline-none',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
compoundVariants: [
|
|
166
|
+
{
|
|
167
|
+
color: 'primary',
|
|
168
|
+
variant: ['outline', 'subtle'],
|
|
169
|
+
highlight: true,
|
|
170
|
+
class: {
|
|
171
|
+
root: 'ring-primary-500 ring-2',
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
color: 'surface',
|
|
176
|
+
variant: ['outline', 'subtle'],
|
|
177
|
+
highlight: true,
|
|
178
|
+
class: {
|
|
179
|
+
root: 'ring-surface-800 ring-2',
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
color: 'info',
|
|
184
|
+
variant: ['outline', 'subtle'],
|
|
185
|
+
highlight: true,
|
|
186
|
+
class: {
|
|
187
|
+
root: 'ring-info-500 ring-2',
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
color: 'success',
|
|
192
|
+
variant: ['outline', 'subtle'],
|
|
193
|
+
highlight: true,
|
|
194
|
+
class: {
|
|
195
|
+
root: 'ring-success-500 ring-2',
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
color: 'warning',
|
|
200
|
+
variant: ['outline', 'subtle'],
|
|
201
|
+
highlight: true,
|
|
202
|
+
class: {
|
|
203
|
+
root: 'ring-warning-500 ring-2',
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
color: 'error',
|
|
208
|
+
variant: ['outline', 'subtle'],
|
|
209
|
+
highlight: true,
|
|
210
|
+
class: {
|
|
211
|
+
root: 'ring-error-500 ring-2',
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
})({
|
|
216
|
+
size,
|
|
217
|
+
color,
|
|
218
|
+
variant,
|
|
219
|
+
highlight,
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
222
|
+
</script>
|
|
223
|
+
|
|
224
|
+
<TimeField.Root bind:value hourCycle={hourcycle}>
|
|
225
|
+
<TimeField.Input name="hello" class={variants.root({ class: ui.root })}>
|
|
226
|
+
{#snippet children({ segments })}
|
|
227
|
+
{#each segments as { part, value }, i (part + i)}
|
|
228
|
+
<TimeField.Segment {part} class={variants.segment({ class: ui.segment })}>
|
|
229
|
+
{value}
|
|
230
|
+
</TimeField.Segment>
|
|
231
|
+
{/each}
|
|
232
|
+
{/snippet}
|
|
233
|
+
</TimeField.Input>
|
|
234
|
+
</TimeField.Root>
|