@svadmin/ui 0.132.0 → 0.134.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/dist/app.css +505 -83
- package/dist/app.theme.css +505 -83
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/BackTop.svelte +62 -8
- package/dist/components/BackTop.svelte.d.ts +8 -3
- package/dist/components/Carousel.svelte +59 -19
- package/dist/components/Carousel.svelte.d.ts +3 -1
- package/dist/components/Collapse.svelte +5 -2
- package/dist/components/EmptyState.svelte +33 -18
- package/dist/components/EmptyState.svelte.d.ts +3 -1
- package/dist/components/Link.svelte +19 -7
- package/dist/components/Link.svelte.d.ts +5 -3
- package/dist/components/NotificationHost.svelte +2 -2
- package/dist/components/RadioGroup.svelte +11 -1
- package/dist/components/RadioGroup.svelte.d.ts +1 -0
- package/dist/components/RangeSlider.svelte +51 -28
- package/dist/components/RangeSlider.svelte.d.ts +1 -0
- package/dist/components/Slider.svelte +46 -17
- package/dist/components/Slider.svelte.d.ts +1 -0
- package/dist/components/Space.svelte +27 -0
- package/dist/components/Space.svelte.d.ts +1 -0
- package/dist/components/Statistic.svelte +12 -2
- package/dist/components/Statistic.svelte.d.ts +2 -0
- package/dist/components/StepsForm.svelte +4 -2
- package/dist/components/TableToolbar.svelte +132 -0
- package/dist/components/TableToolbar.svelte.d.ts +26 -0
- package/dist/components/Tag.svelte +50 -12
- package/dist/components/Tag.svelte.d.ts +7 -3
- package/dist/components/TagsInput.svelte +77 -15
- package/dist/components/TagsInput.svelte.d.ts +2 -0
- package/dist/components/Toast.svelte +1 -1
- package/dist/components/ui/alert/alert.svelte +42 -1
- package/dist/components/ui/alert/alert.svelte.d.ts +5 -0
- package/dist/components/ui/card/card.svelte +29 -3
- package/dist/components/ui/card/card.svelte.d.ts +5 -2
- package/dist/components/ui/dialog/dialog-content.svelte +1 -1
- package/dist/components/ui/dialog/dialog-content.svelte.d.ts +1 -1
- package/dist/components/ui/input/input.svelte +69 -17
- package/dist/components/ui/input/input.svelte.d.ts +5 -1
- package/dist/components/ui/progress/progress.svelte +3 -2
- package/dist/components/ui/switch/switch.svelte +17 -3
- package/dist/components/ui/switch/switch.svelte.d.ts +2 -0
- package/dist/components/ui/textarea/textarea.svelte +65 -15
- package/dist/components/ui/textarea/textarea.svelte.d.ts +3 -0
- package/dist/components.css +10 -2
- package/dist/icon-registry.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/intent-preload.d.ts +1 -1
- package/dist/intent-preload.js +1 -1
- package/dist/notifications.svelte.d.ts +1 -0
- package/dist/notifications.svelte.js +2 -0
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { X } from '@lucide/svelte';
|
|
2
|
+
import { X, CircleX } from '@lucide/svelte';
|
|
3
3
|
import { cn } from '../utils.js';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
placeholder?: string | undefined;
|
|
9
9
|
separator?: string | undefined;
|
|
10
10
|
maxItems?: number | undefined;
|
|
11
|
+
maxTagCount?: number | undefined;
|
|
12
|
+
allowClear?: boolean | undefined;
|
|
11
13
|
disabled?: boolean | undefined;
|
|
12
14
|
required?: boolean | undefined;
|
|
13
15
|
invalid?: boolean | undefined;
|
|
@@ -23,6 +25,8 @@
|
|
|
23
25
|
placeholder = 'Add a tag',
|
|
24
26
|
separator = ',',
|
|
25
27
|
maxItems,
|
|
28
|
+
maxTagCount,
|
|
29
|
+
allowClear = false,
|
|
26
30
|
disabled = false,
|
|
27
31
|
required = false,
|
|
28
32
|
invalid = false,
|
|
@@ -34,6 +38,8 @@
|
|
|
34
38
|
|
|
35
39
|
let draft = $state('');
|
|
36
40
|
let composing = $state(false);
|
|
41
|
+
const displayedTags = $derived(maxTagCount !== undefined && maxTagCount >= 0 ? value.slice(0, maxTagCount) : value);
|
|
42
|
+
const overflowCount = $derived(maxTagCount !== undefined && maxTagCount >= 0 ? Math.max(0, value.length - maxTagCount) : 0);
|
|
37
43
|
|
|
38
44
|
function normalized(values: readonly string[]): string[] {
|
|
39
45
|
return [...new Set(values.map(item => item.trim()).filter(Boolean))];
|
|
@@ -54,6 +60,11 @@
|
|
|
54
60
|
draft = '';
|
|
55
61
|
}
|
|
56
62
|
|
|
63
|
+
function clearAll(): void {
|
|
64
|
+
if (disabled) return;
|
|
65
|
+
update([]);
|
|
66
|
+
}
|
|
67
|
+
|
|
57
68
|
function remove(index: number): void {
|
|
58
69
|
if (disabled) return;
|
|
59
70
|
update(value.filter((_, itemIndex) => itemIndex !== index));
|
|
@@ -81,7 +92,7 @@
|
|
|
81
92
|
<input type="hidden" {name} value={tag} {disabled} />
|
|
82
93
|
{/each}
|
|
83
94
|
{/if}
|
|
84
|
-
{#each
|
|
95
|
+
{#each displayedTags as tag, index (tag)}
|
|
85
96
|
<span class="svadmin-tags-input__tag">
|
|
86
97
|
<span>{tag}</span>
|
|
87
98
|
<button
|
|
@@ -90,10 +101,15 @@
|
|
|
90
101
|
disabled={disabled}
|
|
91
102
|
onclick={() => remove(index)}
|
|
92
103
|
>
|
|
93
|
-
<X size={
|
|
104
|
+
<X size={12} aria-hidden="true" />
|
|
94
105
|
</button>
|
|
95
106
|
</span>
|
|
96
107
|
{/each}
|
|
108
|
+
{#if overflowCount > 0}
|
|
109
|
+
<span class="svadmin-tags-input__tag svadmin-tags-input__tag--overflow" title={value.slice(maxTagCount).join(", ")}>
|
|
110
|
+
<span>+{overflowCount}</span>
|
|
111
|
+
</span>
|
|
112
|
+
{/if}
|
|
97
113
|
<input
|
|
98
114
|
value={draft}
|
|
99
115
|
{placeholder}
|
|
@@ -107,6 +123,16 @@
|
|
|
107
123
|
oncompositionstart={() => { composing = true; }}
|
|
108
124
|
oncompositionend={(event) => { composing = false; draft = (event.currentTarget as HTMLInputElement).value; }}
|
|
109
125
|
/>
|
|
126
|
+
{#if allowClear && value.length > 0 && !disabled}
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
class="svadmin-tags-input__clear"
|
|
130
|
+
aria-label="Clear all tags"
|
|
131
|
+
onclick={clearAll}
|
|
132
|
+
>
|
|
133
|
+
<CircleX size={12} aria-hidden="true" />
|
|
134
|
+
</button>
|
|
135
|
+
{/if}
|
|
110
136
|
</div>
|
|
111
137
|
|
|
112
138
|
<style>
|
|
@@ -115,11 +141,14 @@
|
|
|
115
141
|
flex-wrap: wrap;
|
|
116
142
|
align-items: center;
|
|
117
143
|
gap: 4px;
|
|
118
|
-
|
|
119
|
-
|
|
144
|
+
box-sizing: border-box;
|
|
145
|
+
min-block-size: var(--svadmin-control-h);
|
|
146
|
+
padding: 1px 4px;
|
|
120
147
|
border: 1px solid var(--border);
|
|
121
|
-
border-radius:
|
|
122
|
-
background: var(--
|
|
148
|
+
border-radius: var(--border-radius-small, 2px);
|
|
149
|
+
background: var(--card);
|
|
150
|
+
color: var(--foreground);
|
|
151
|
+
font-size: var(--svadmin-text-body);
|
|
123
152
|
}
|
|
124
153
|
|
|
125
154
|
.svadmin-tags-input:focus-within {
|
|
@@ -135,12 +164,18 @@
|
|
|
135
164
|
display: inline-flex;
|
|
136
165
|
align-items: center;
|
|
137
166
|
gap: 4px;
|
|
167
|
+
box-sizing: border-box;
|
|
138
168
|
max-inline-size: 100%;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
border
|
|
142
|
-
|
|
169
|
+
height: 24px;
|
|
170
|
+
padding: 0 4px 0 8px;
|
|
171
|
+
border: 1px solid transparent;
|
|
172
|
+
border-radius: var(--border-radius-small, 2px);
|
|
173
|
+
background: var(--svadmin-fill-2, var(--muted));
|
|
143
174
|
color: var(--foreground);
|
|
175
|
+
font-size: var(--svadmin-text-caption);
|
|
176
|
+
font-weight: 500;
|
|
177
|
+
/* 12px 字号下的官方 22px 行高,避免组件样式里写裸像素字号。 */
|
|
178
|
+
line-height: calc(22 / 12);
|
|
144
179
|
}
|
|
145
180
|
|
|
146
181
|
.svadmin-tags-input__tag span {
|
|
@@ -150,10 +185,13 @@
|
|
|
150
185
|
.svadmin-tags-input__tag button {
|
|
151
186
|
display: inline-grid;
|
|
152
187
|
place-items: center;
|
|
153
|
-
|
|
154
|
-
|
|
188
|
+
width: 16px;
|
|
189
|
+
height: 16px;
|
|
190
|
+
min-block-size: 16px;
|
|
191
|
+
min-inline-size: 16px;
|
|
192
|
+
padding: 0;
|
|
155
193
|
border: 0;
|
|
156
|
-
border-radius:
|
|
194
|
+
border-radius: var(--border-radius-small, 2px);
|
|
157
195
|
background: transparent;
|
|
158
196
|
color: var(--muted-foreground);
|
|
159
197
|
cursor: pointer;
|
|
@@ -165,10 +203,34 @@
|
|
|
165
203
|
color: var(--accent-foreground);
|
|
166
204
|
}
|
|
167
205
|
|
|
206
|
+
.svadmin-tags-input__clear {
|
|
207
|
+
display: none;
|
|
208
|
+
place-items: center;
|
|
209
|
+
border: 0;
|
|
210
|
+
background: transparent;
|
|
211
|
+
color: var(--color-text-2, var(--muted-foreground));
|
|
212
|
+
font-size: var(--svadmin-text-caption);
|
|
213
|
+
line-height: 1;
|
|
214
|
+
cursor: pointer;
|
|
215
|
+
padding: 0;
|
|
216
|
+
}
|
|
217
|
+
.svadmin-tags-input:hover .svadmin-tags-input__clear,
|
|
218
|
+
.svadmin-tags-input:focus-within .svadmin-tags-input__clear {
|
|
219
|
+
display: inline-grid;
|
|
220
|
+
}
|
|
221
|
+
.svadmin-tags-input__clear:hover {
|
|
222
|
+
color: var(--foreground);
|
|
223
|
+
}
|
|
224
|
+
.svadmin-tags-input__tag--overflow {
|
|
225
|
+
background: var(--secondary);
|
|
226
|
+
color: var(--secondary-foreground);
|
|
227
|
+
padding: 2px 6px;
|
|
228
|
+
font-weight: 500;
|
|
229
|
+
}
|
|
168
230
|
.svadmin-tags-input input {
|
|
169
231
|
min-inline-size: 8rem;
|
|
170
232
|
flex: 1 1 8rem;
|
|
171
|
-
min-block-size:
|
|
233
|
+
min-block-size: 24px;
|
|
172
234
|
border: 0;
|
|
173
235
|
outline: 0;
|
|
174
236
|
background: transparent;
|
|
@@ -4,6 +4,8 @@ interface Props {
|
|
|
4
4
|
placeholder?: string | undefined;
|
|
5
5
|
separator?: string | undefined;
|
|
6
6
|
maxItems?: number | undefined;
|
|
7
|
+
maxTagCount?: number | undefined;
|
|
8
|
+
allowClear?: boolean | undefined;
|
|
7
9
|
disabled?: boolean | undefined;
|
|
8
10
|
required?: boolean | undefined;
|
|
9
11
|
invalid?: boolean | undefined;
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
const isActiveHost = $derived(host?.isActive() ?? false);
|
|
22
22
|
const theme = $derived(getResolvedTheme() === 'dark' ? 'dark' : 'light');
|
|
23
23
|
// 默认仍是 top-right,抽屉打开时改到 bottom-left,避开底部居中的撤销条。
|
|
24
|
-
// 显式 placement
|
|
24
|
+
// 显式 placement 才用顶部 / 底部居中。
|
|
25
25
|
const toastPosition = $derived<'top-right' | 'bottom-left' | 'top-center' | 'bottom-center'>(
|
|
26
26
|
placement === 'top' ? 'top-center' : placement === 'bottom' ? 'bottom-center' : sheetOpen ? 'bottom-left' : 'top-right',
|
|
27
27
|
);
|
|
@@ -8,12 +8,18 @@
|
|
|
8
8
|
|
|
9
9
|
<script lang="ts">
|
|
10
10
|
import X from "@lucide/svelte/icons/x";
|
|
11
|
+
import { CheckCircle2, CircleAlert, Info, TriangleAlert } from "@lucide/svelte";
|
|
11
12
|
import type { Snippet } from "svelte";
|
|
12
13
|
|
|
13
14
|
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
14
15
|
variant?: AlertVariantValue;
|
|
15
16
|
closable?: boolean;
|
|
16
17
|
closeLabel?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
showIcon?: boolean;
|
|
20
|
+
banner?: boolean;
|
|
21
|
+
action?: Snippet;
|
|
22
|
+
icon?: Snippet;
|
|
17
23
|
onclose?: (event: MouseEvent) => void;
|
|
18
24
|
children?: Snippet;
|
|
19
25
|
};
|
|
@@ -23,11 +29,25 @@
|
|
|
23
29
|
variant = "default",
|
|
24
30
|
closable = false,
|
|
25
31
|
closeLabel = "Dismiss alert",
|
|
32
|
+
title,
|
|
33
|
+
showIcon = false,
|
|
34
|
+
banner = false,
|
|
35
|
+
action,
|
|
36
|
+
icon,
|
|
26
37
|
onclose,
|
|
27
38
|
class: className,
|
|
28
39
|
children,
|
|
29
40
|
...restProps
|
|
30
41
|
}: Props = $props();
|
|
42
|
+
|
|
43
|
+
const statusIcons = {
|
|
44
|
+
default: Info,
|
|
45
|
+
destructive: CircleAlert,
|
|
46
|
+
warning: TriangleAlert,
|
|
47
|
+
success: CheckCircle2,
|
|
48
|
+
} as const;
|
|
49
|
+
|
|
50
|
+
const IconComponent = $derived(statusIcons[variant] ?? Info);
|
|
31
51
|
</script>
|
|
32
52
|
|
|
33
53
|
<div
|
|
@@ -37,10 +57,31 @@
|
|
|
37
57
|
data-feedback="static"
|
|
38
58
|
data-variant={variant}
|
|
39
59
|
data-closable={closable || undefined}
|
|
40
|
-
class={cn(
|
|
60
|
+
class={cn(
|
|
61
|
+
resolveAlertVariants({ variant }),
|
|
62
|
+
banner && "svadmin-alert--banner rounded-none border-x-0 border-t-0 border-b border-border",
|
|
63
|
+
className
|
|
64
|
+
)}
|
|
41
65
|
{...restProps}
|
|
42
66
|
>
|
|
67
|
+
{#if icon}
|
|
68
|
+
{@render icon()}
|
|
69
|
+
{:else if showIcon}
|
|
70
|
+
<IconComponent class="svadmin-alert__icon" aria-hidden="true" />
|
|
71
|
+
{/if}
|
|
72
|
+
|
|
73
|
+
{#if title}
|
|
74
|
+
<div data-slot="alert-title" class="svadmin-alert-title font-semibold">{title}</div>
|
|
75
|
+
{/if}
|
|
76
|
+
|
|
43
77
|
{@render children?.()}
|
|
78
|
+
|
|
79
|
+
{#if action}
|
|
80
|
+
<div class="svadmin-alert__action shrink-0 justify-self-end">
|
|
81
|
+
{@render action()}
|
|
82
|
+
</div>
|
|
83
|
+
{/if}
|
|
84
|
+
|
|
44
85
|
{#if closable}
|
|
45
86
|
<button type="button" class="svadmin-alert__close" aria-label={closeLabel} onclick={(event) => onclose?.(event)}>
|
|
46
87
|
<X size={14} aria-hidden="true" />
|
|
@@ -7,6 +7,11 @@ type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
|
7
7
|
variant?: AlertVariantValue;
|
|
8
8
|
closable?: boolean;
|
|
9
9
|
closeLabel?: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
showIcon?: boolean;
|
|
12
|
+
banner?: boolean;
|
|
13
|
+
action?: Snippet;
|
|
14
|
+
icon?: Snippet;
|
|
10
15
|
onclose?: (event: MouseEvent) => void;
|
|
11
16
|
children?: Snippet;
|
|
12
17
|
};
|
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
3
|
import { cn, type WithElementRef } from "../../../utils.js";
|
|
4
|
+
import { Skeleton } from "../skeleton/index.js";
|
|
5
|
+
|
|
6
|
+
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
7
|
+
size?: "default" | "sm";
|
|
8
|
+
hoverable?: boolean;
|
|
9
|
+
bordered?: boolean;
|
|
10
|
+
loading?: boolean;
|
|
11
|
+
};
|
|
4
12
|
|
|
5
13
|
let {
|
|
6
14
|
ref = $bindable(null),
|
|
7
15
|
class: className,
|
|
8
16
|
children,
|
|
9
17
|
size = "default",
|
|
18
|
+
hoverable = false,
|
|
19
|
+
bordered = true,
|
|
20
|
+
loading = false,
|
|
10
21
|
...restProps
|
|
11
|
-
}:
|
|
22
|
+
}: Props = $props();
|
|
12
23
|
</script>
|
|
13
24
|
|
|
14
25
|
<div
|
|
15
26
|
bind:this={ref}
|
|
16
27
|
data-slot="card"
|
|
17
28
|
data-size={size}
|
|
18
|
-
|
|
29
|
+
data-hoverable={hoverable ? "true" : undefined}
|
|
30
|
+
class={cn(
|
|
31
|
+
"svadmin-card",
|
|
32
|
+
hoverable && "svadmin-card--hoverable",
|
|
33
|
+
!bordered && "border-0 shadow-none",
|
|
34
|
+
className
|
|
35
|
+
)}
|
|
19
36
|
{...restProps}
|
|
20
37
|
>
|
|
21
|
-
{
|
|
38
|
+
{#if loading}
|
|
39
|
+
<div class="space-y-3 p-6" data-slot="card-loading">
|
|
40
|
+
<Skeleton class="h-6 w-1/3" />
|
|
41
|
+
<Skeleton class="h-4 w-full" />
|
|
42
|
+
<Skeleton class="h-4 w-4/5" />
|
|
43
|
+
<Skeleton class="h-16 w-full mt-2" />
|
|
44
|
+
</div>
|
|
45
|
+
{:else}
|
|
46
|
+
{@render children?.()}
|
|
47
|
+
{/if}
|
|
22
48
|
</div>
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { HTMLAttributes } from "svelte/elements";
|
|
2
2
|
import { type WithElementRef } from "../../../utils.js";
|
|
3
|
-
type
|
|
3
|
+
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
4
4
|
size?: "default" | "sm";
|
|
5
|
+
hoverable?: boolean;
|
|
6
|
+
bordered?: boolean;
|
|
7
|
+
loading?: boolean;
|
|
5
8
|
};
|
|
6
|
-
declare const Card: import("svelte").Component
|
|
9
|
+
declare const Card: import("svelte").Component<Props, {}, "ref">;
|
|
7
10
|
type Card = ReturnType<typeof Card>;
|
|
8
11
|
export default Card;
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
showCloseButton?: boolean;
|
|
25
25
|
/** 信息展示可点遮罩关闭。录入表单应传 false。 */
|
|
26
26
|
closeOnOverlayClick?: boolean;
|
|
27
|
-
/**
|
|
27
|
+
/** 建议宽度:400 / 520 / 720。不传则保持现有默认宽度。 */
|
|
28
28
|
size?: 'sm' | 'md' | 'lg';
|
|
29
29
|
/** 加载中时正文区保持最小高度,避免标题和按钮跳动。 */
|
|
30
30
|
loading?: boolean;
|
|
@@ -9,7 +9,7 @@ type $$ComponentProps = WithoutChildrenOrChild<DialogPrimitive.ContentProps> & {
|
|
|
9
9
|
showCloseButton?: boolean;
|
|
10
10
|
/** 信息展示可点遮罩关闭。录入表单应传 false。 */
|
|
11
11
|
closeOnOverlayClick?: boolean;
|
|
12
|
-
/**
|
|
12
|
+
/** 建议宽度:400 / 520 / 720。不传则保持现有默认宽度。 */
|
|
13
13
|
size?: 'sm' | 'md' | 'lg';
|
|
14
14
|
/** 加载中时正文区保持最小高度,避免标题和按钮跳动。 */
|
|
15
15
|
loading?: boolean;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
generics="Type extends HTMLInputTypeAttribute | undefined = undefined"
|
|
4
4
|
>
|
|
5
5
|
import type { HTMLInputAttributes, HTMLInputTypeAttribute } from "svelte/elements";
|
|
6
|
+
import type { Snippet } from "svelte";
|
|
7
|
+
import { CircleX } from "@lucide/svelte";
|
|
6
8
|
import { useTranslation } from "@svadmin/core/i18n";
|
|
7
9
|
import { definedOptions } from "@svadmin/core/options";
|
|
8
10
|
import { cn, type WithElementRef } from "../../../utils.js";
|
|
@@ -22,8 +24,15 @@
|
|
|
22
24
|
onselect?: HTMLInputAttributes["onselect"];
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
type Props = WithElementRef<Omit<HTMLInputAttributes, "type" | "value" | "size" | "onfocus" | "onblur" | "onselect">> &
|
|
26
|
-
{
|
|
27
|
+
type Props = WithElementRef<Omit<HTMLInputAttributes, "type" | "value" | "size" | "onfocus" | "onblur" | "onselect" | "prefix">> &
|
|
28
|
+
{
|
|
29
|
+
size?: InputSize;
|
|
30
|
+
nativeSize?: number;
|
|
31
|
+
status?: InputStatus | undefined;
|
|
32
|
+
allowClear?: boolean;
|
|
33
|
+
prefix?: Snippet;
|
|
34
|
+
suffix?: Snippet;
|
|
35
|
+
} &
|
|
27
36
|
InputHandlers &
|
|
28
37
|
(Type extends "file"
|
|
29
38
|
? { type: "file"; files?: FileList | undefined; value?: never }
|
|
@@ -38,6 +47,9 @@
|
|
|
38
47
|
size: sizeProp,
|
|
39
48
|
nativeSize,
|
|
40
49
|
status,
|
|
50
|
+
allowClear = false,
|
|
51
|
+
prefix,
|
|
52
|
+
suffix,
|
|
41
53
|
class: className,
|
|
42
54
|
"data-slot": dataSlot = "input",
|
|
43
55
|
"aria-invalid": ariaInvalid,
|
|
@@ -107,8 +119,34 @@
|
|
|
107
119
|
textSelected = readSelected(event.currentTarget);
|
|
108
120
|
onselect?.(event);
|
|
109
121
|
}
|
|
122
|
+
|
|
123
|
+
function clearInput() {
|
|
124
|
+
if (disabled) return;
|
|
125
|
+
value = "" as InputValue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const hasWrapper = $derived(!isFileInput && Boolean(allowClear || prefix || suffix));
|
|
110
129
|
</script>
|
|
111
130
|
|
|
131
|
+
{#snippet inputElement()}
|
|
132
|
+
<input
|
|
133
|
+
bind:this={ref}
|
|
134
|
+
data-slot={dataSlot}
|
|
135
|
+
data-size={size}
|
|
136
|
+
data-input-state={inputState}
|
|
137
|
+
aria-invalid={ariaInvalid}
|
|
138
|
+
aria-busy={inputState === "loading" ? "true" : undefined}
|
|
139
|
+
class={cn("svadmin-input", hasWrapper && "border-0 shadow-none bg-transparent px-0 h-full", className)}
|
|
140
|
+
{type}
|
|
141
|
+
lang={isDateInput ? i18n.locale : undefined}
|
|
142
|
+
bind:value
|
|
143
|
+
{...attributes}
|
|
144
|
+
onfocus={handleFocus}
|
|
145
|
+
onblur={handleBlur}
|
|
146
|
+
onselect={handleSelect}
|
|
147
|
+
/>
|
|
148
|
+
{/snippet}
|
|
149
|
+
|
|
112
150
|
{#if isFileInput}
|
|
113
151
|
<div
|
|
114
152
|
class={cn("svadmin-file-input", className)}
|
|
@@ -136,21 +174,35 @@
|
|
|
136
174
|
<span class="svadmin-file-input__name">{selectedFileLabel}</span>
|
|
137
175
|
</span>
|
|
138
176
|
</div>
|
|
139
|
-
{:else}
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
data-slot=
|
|
177
|
+
{:else if hasWrapper}
|
|
178
|
+
<div
|
|
179
|
+
class={cn("svadmin-input-wrapper", className)}
|
|
180
|
+
data-slot="input-wrapper"
|
|
143
181
|
data-size={size}
|
|
144
182
|
data-input-state={inputState}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
{
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
183
|
+
>
|
|
184
|
+
{#if prefix}
|
|
185
|
+
<span class="svadmin-input-prefix" aria-hidden="true">
|
|
186
|
+
{@render prefix()}
|
|
187
|
+
</span>
|
|
188
|
+
{/if}
|
|
189
|
+
{@render inputElement()}
|
|
190
|
+
{#if allowClear && filled && !disabled}
|
|
191
|
+
<button
|
|
192
|
+
type="button"
|
|
193
|
+
class="svadmin-input-clear"
|
|
194
|
+
aria-label="Clear input"
|
|
195
|
+
onclick={clearInput}
|
|
196
|
+
>
|
|
197
|
+
<CircleX size={12} aria-hidden="true" />
|
|
198
|
+
</button>
|
|
199
|
+
{/if}
|
|
200
|
+
{#if suffix}
|
|
201
|
+
<span class="svadmin-input-suffix" aria-hidden="true">
|
|
202
|
+
{@render suffix()}
|
|
203
|
+
</span>
|
|
204
|
+
{/if}
|
|
205
|
+
</div>
|
|
206
|
+
{:else}
|
|
207
|
+
{@render inputElement()}
|
|
156
208
|
{/if}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { HTMLInputAttributes, HTMLInputTypeAttribute } from "svelte/elements";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
2
3
|
declare function $$render<Type extends HTMLInputTypeAttribute | undefined = undefined>(): {
|
|
3
|
-
props: Omit<HTMLInputAttributes, "type" | "value" | "size" | "onfocus" | "onblur" | "onselect"> & {
|
|
4
|
+
props: Omit<HTMLInputAttributes, "type" | "value" | "size" | "prefix" | "onfocus" | "onblur" | "onselect"> & {
|
|
4
5
|
ref?: HTMLElement | null;
|
|
5
6
|
} & {
|
|
6
7
|
size?: "default" | "sm" | "lg" | "compact" | "mini";
|
|
7
8
|
nativeSize?: number;
|
|
8
9
|
status?: ("error" | "success" | "loading") | undefined;
|
|
10
|
+
allowClear?: boolean;
|
|
11
|
+
prefix?: Snippet;
|
|
12
|
+
suffix?: Snippet;
|
|
9
13
|
} & {
|
|
10
14
|
onfocus?: HTMLInputAttributes["onfocus"];
|
|
11
15
|
onblur?: HTMLInputAttributes["onblur"];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { Check, X } from "@lucide/svelte";
|
|
2
3
|
import { cn } from "../../../utils.js";
|
|
3
4
|
|
|
4
5
|
type ProgressStatus = 'normal' | 'success' | 'warning' | 'danger';
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
style:stroke-dashoffset={indeterminate ? circumference * 0.7 : dashOffset}
|
|
60
61
|
/>
|
|
61
62
|
</svg>
|
|
62
|
-
{#if showInfo}<span class="svadmin-progress__info">{indeterminate
|
|
63
|
+
{#if showInfo}<span class="svadmin-progress__info flex items-center justify-center">{#if indeterminate}…{:else if status === "success"}<Check class="size-4 text-success" aria-hidden="true" />{:else if status === "danger"}<X class="size-4 text-destructive" aria-hidden="true" />{:else}{info}{/if}</span>{/if}
|
|
63
64
|
</div>
|
|
64
65
|
{:else}
|
|
65
66
|
<div
|
|
@@ -76,7 +77,7 @@
|
|
|
76
77
|
<div class="svadmin-progress__line-track">
|
|
77
78
|
<div class="svadmin-progress-value" style:transform={indeterminate ? undefined : `translateX(-${100 - percentage}%)`}></div>
|
|
78
79
|
</div>
|
|
79
|
-
<span class="svadmin-progress__info">{indeterminate
|
|
80
|
+
<span class="svadmin-progress__info flex items-center justify-end">{#if indeterminate}…{:else if status === "success"}<Check class="size-3.5 text-success" aria-hidden="true" />{:else if status === "danger"}<X class="size-3.5 text-destructive" aria-hidden="true" />{:else}{info}{/if}</span>
|
|
80
81
|
{:else}
|
|
81
82
|
<div class="svadmin-progress-value" style:transform={indeterminate ? undefined : `translateX(-${100 - percentage}%)`}></div>
|
|
82
83
|
{/if}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { cn, type WithElementRef } from "../../../utils.js";
|
|
3
3
|
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
4
|
+
import { Loader2 } from "@lucide/svelte";
|
|
4
5
|
|
|
5
6
|
type Props = WithElementRef<HTMLButtonAttributes, HTMLButtonElement> & {
|
|
6
7
|
checked?: boolean;
|
|
7
8
|
disabled?: boolean;
|
|
8
9
|
loading?: boolean;
|
|
9
10
|
size?: "default" | "small";
|
|
11
|
+
checkedText?: string;
|
|
12
|
+
uncheckedText?: string;
|
|
10
13
|
onCheckedChange?: (checked: boolean) => void;
|
|
11
14
|
};
|
|
12
15
|
|
|
@@ -16,6 +19,8 @@
|
|
|
16
19
|
disabled = false,
|
|
17
20
|
loading = false,
|
|
18
21
|
size = "default",
|
|
22
|
+
checkedText,
|
|
23
|
+
uncheckedText,
|
|
19
24
|
onCheckedChange,
|
|
20
25
|
class: className,
|
|
21
26
|
...restProps
|
|
@@ -41,11 +46,20 @@
|
|
|
41
46
|
data-size={size}
|
|
42
47
|
data-loading={loading ? "true" : undefined}
|
|
43
48
|
disabled={inactive}
|
|
44
|
-
class={cn("svadmin-switch", className)}
|
|
49
|
+
class={cn("svadmin-switch", (checkedText || uncheckedText) && "svadmin-switch--with-text", className)}
|
|
45
50
|
onclick={toggle}
|
|
46
51
|
{...restProps}
|
|
47
52
|
>
|
|
53
|
+
{#if checkedText || uncheckedText}
|
|
54
|
+
<span class={cn("svadmin-switch-text text-xs font-medium select-none leading-none", checked ? "pl-2 pr-6 text-primary-foreground" : "pl-6 pr-2 text-muted-foreground")}>
|
|
55
|
+
{checked ? (checkedText ?? "") : (uncheckedText ?? "")}
|
|
56
|
+
</span>
|
|
57
|
+
{/if}
|
|
48
58
|
<span
|
|
49
|
-
class="svadmin-switch-thumb"
|
|
50
|
-
|
|
59
|
+
class="svadmin-switch-thumb flex items-center justify-center"
|
|
60
|
+
>
|
|
61
|
+
{#if loading}
|
|
62
|
+
<Loader2 class="size-2.5 animate-spin text-muted-foreground" aria-hidden="true" />
|
|
63
|
+
{/if}
|
|
64
|
+
</span>
|
|
51
65
|
</button>
|
|
@@ -5,6 +5,8 @@ type Props = WithElementRef<HTMLButtonAttributes, HTMLButtonElement> & {
|
|
|
5
5
|
disabled?: boolean;
|
|
6
6
|
loading?: boolean;
|
|
7
7
|
size?: "default" | "small";
|
|
8
|
+
checkedText?: string;
|
|
9
|
+
uncheckedText?: string;
|
|
8
10
|
onCheckedChange?: (checked: boolean) => void;
|
|
9
11
|
};
|
|
10
12
|
declare const Switch: import("svelte").Component<Props, {}, "ref" | "checked">;
|