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