@svadmin/ui 0.135.0 → 0.136.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 +6 -3
- package/dist/app.theme.css +6 -3
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/Calendar.svelte +121 -26
- package/dist/components/Calendar.svelte.d.ts +1 -0
- package/dist/components/Collapse.svelte +28 -0
- package/dist/components/Collapse.svelte.d.ts +2 -0
- package/dist/components/DatePicker.svelte +96 -13
- package/dist/components/DrawerForm.svelte +4 -1
- package/dist/components/DrawerForm.svelte.d.ts +1 -0
- package/dist/components/Image.svelte +84 -28
- package/dist/components/Image.svelte.d.ts +2 -0
- package/dist/components/InputGroup.svelte +7 -3
- package/dist/components/InputGroup.svelte.d.ts +1 -0
- package/dist/components/Menu.svelte +36 -2
- package/dist/components/Menu.svelte.d.ts +2 -0
- package/dist/components/ModalForm.svelte +4 -1
- package/dist/components/ModalForm.svelte.d.ts +1 -0
- package/dist/components/QRCode.svelte +112 -7
- package/dist/components/QRCode.svelte.d.ts +9 -0
- package/dist/components/component-messages.d.ts +20 -0
- package/dist/components/component-messages.js +5 -0
- package/dist/components/ui/alert/alert.svelte +12 -1
- package/dist/components/ui/alert/alert.svelte.d.ts +2 -0
- package/dist/components/ui/alert/index.d.ts +2 -2
- package/dist/components/ui/badge/badge.svelte +5 -1
- package/dist/components/ui/badge/badge.svelte.d.ts +1 -0
- package/dist/components/ui/card/card.svelte +35 -1
- package/dist/components/ui/card/card.svelte.d.ts +3 -0
- package/dist/components/ui/skeleton/index.d.ts +1 -2
- package/dist/components/ui/skeleton/index.js +1 -2
- package/dist/components/ui/skeleton/skeleton.svelte +18 -6
- package/dist/components/ui/skeleton/skeleton.svelte.d.ts +4 -0
- package/dist/components/ui/tabs/tabs-context.d.svelte.ts +1 -0
- package/dist/components/ui/tabs/tabs-context.svelte.d.ts +4 -0
- package/dist/components/ui/tabs/tabs-list.svelte +14 -2
- package/dist/components/ui/tabs/tabs.svelte +17 -1
- package/dist/components/ui/tabs/tabs.svelte.d.ts +4 -0
- package/dist/components.css +3 -0
- package/dist/index.d.ts +1 -1
- package/package.json +4 -4
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
|
-
import { ImageOff } from '@lucide/svelte';
|
|
3
|
+
import { ImageOff, ZoomIn } from '@lucide/svelte';
|
|
4
4
|
import { cn } from '../utils.js';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
src?: string | undefined;
|
|
8
8
|
alt?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
description?: string;
|
|
9
11
|
width?: string | number;
|
|
10
12
|
height?: string | number;
|
|
11
13
|
fit?: 'cover' | 'contain' | 'fill' | 'none';
|
|
@@ -20,6 +22,8 @@
|
|
|
20
22
|
let {
|
|
21
23
|
src,
|
|
22
24
|
alt = '',
|
|
25
|
+
title,
|
|
26
|
+
description,
|
|
23
27
|
width,
|
|
24
28
|
height,
|
|
25
29
|
fit = 'cover',
|
|
@@ -40,23 +44,36 @@
|
|
|
40
44
|
</script>
|
|
41
45
|
|
|
42
46
|
{#snippet content()}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
<span class="svadmin-image__frame">
|
|
48
|
+
{#if src && !failed}
|
|
49
|
+
<img
|
|
50
|
+
class="svadmin-image__img"
|
|
51
|
+
{src}
|
|
52
|
+
{alt}
|
|
53
|
+
loading="lazy"
|
|
54
|
+
decoding="async"
|
|
55
|
+
style={`object-fit:${fit}`}
|
|
56
|
+
onerror={() => { failed = true; }}
|
|
57
|
+
/>
|
|
58
|
+
{#if preview}
|
|
59
|
+
<span class="svadmin-image__overlay" aria-hidden="true" data-slot="image-overlay">
|
|
60
|
+
<ZoomIn size={16} />
|
|
61
|
+
</span>
|
|
62
|
+
{/if}
|
|
63
|
+
{:else}
|
|
64
|
+
<span class="svadmin-image__fallback" role="img" aria-label={fallback}>
|
|
65
|
+
<ImageOff size={20} aria-hidden="true" />
|
|
66
|
+
{#if fallback}<span>{fallback}</span>{/if}
|
|
67
|
+
</span>
|
|
68
|
+
{/if}
|
|
69
|
+
</span>
|
|
70
|
+
{#if title || description || children}
|
|
71
|
+
<div class="svadmin-image__caption">
|
|
72
|
+
{#if title}<strong class="svadmin-image__title">{title}</strong>{/if}
|
|
73
|
+
{#if description}<p class="svadmin-image__description">{description}</p>{/if}
|
|
74
|
+
{#if children}{@render children()}{/if}
|
|
75
|
+
</div>
|
|
58
76
|
{/if}
|
|
59
|
-
{#if children}<div class="svadmin-image__caption">{@render children()}</div>{/if}
|
|
60
77
|
{/snippet}
|
|
61
78
|
|
|
62
79
|
{#if preview || onclick}
|
|
@@ -78,29 +95,68 @@
|
|
|
78
95
|
|
|
79
96
|
<style>
|
|
80
97
|
.svadmin-image {
|
|
81
|
-
position: relative;
|
|
82
98
|
display: grid;
|
|
83
|
-
place-items: center;
|
|
84
99
|
min-width: 0;
|
|
85
100
|
max-width: 100%;
|
|
86
101
|
margin: 0;
|
|
87
|
-
|
|
88
|
-
background: var(--muted);
|
|
89
|
-
color: var(--muted-foreground);
|
|
102
|
+
color: var(--foreground);
|
|
90
103
|
}
|
|
91
104
|
.svadmin-image__button { display: block; width: 100%; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer; text-align: inherit; }
|
|
92
|
-
.svadmin-
|
|
105
|
+
.svadmin-image__button:focus-visible {
|
|
106
|
+
outline: var(--svadmin-focus-width) solid var(--ring);
|
|
107
|
+
outline-offset: var(--svadmin-focus-offset);
|
|
108
|
+
}
|
|
109
|
+
.svadmin-image.is-rounded .svadmin-image__frame { border-radius: var(--radius); }
|
|
93
110
|
.svadmin-image.is-preview { cursor: zoom-in; }
|
|
111
|
+
.svadmin-image__frame {
|
|
112
|
+
position: relative;
|
|
113
|
+
display: grid;
|
|
114
|
+
place-items: center;
|
|
115
|
+
min-width: 0;
|
|
116
|
+
overflow: hidden;
|
|
117
|
+
background: var(--svadmin-fill-1, var(--muted));
|
|
118
|
+
color: var(--svadmin-text-4, var(--muted-foreground));
|
|
119
|
+
}
|
|
94
120
|
.svadmin-image__img { display: block; width: 100%; height: 100%; max-width: 100%; }
|
|
121
|
+
.svadmin-image__overlay {
|
|
122
|
+
position: absolute;
|
|
123
|
+
inset: 0;
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: center;
|
|
127
|
+
background: var(--svadmin-mask, var(--color-mask-bg));
|
|
128
|
+
color: var(--color-white);
|
|
129
|
+
opacity: 0;
|
|
130
|
+
transition: opacity var(--svadmin-duration-1, 0.1s) var(--svadmin-easing-linear, linear);
|
|
131
|
+
pointer-events: none;
|
|
132
|
+
}
|
|
133
|
+
.svadmin-image__button:hover .svadmin-image__overlay,
|
|
134
|
+
.svadmin-image__button:focus-visible .svadmin-image__overlay {
|
|
135
|
+
opacity: 1;
|
|
136
|
+
}
|
|
95
137
|
.svadmin-image__fallback {
|
|
96
138
|
display: inline-flex;
|
|
97
139
|
flex-direction: column;
|
|
98
140
|
align-items: center;
|
|
99
|
-
gap: var(--svadmin-space-1
|
|
100
|
-
padding:
|
|
101
|
-
color: var(--muted-foreground);
|
|
102
|
-
font-size: var(--svadmin-text-caption
|
|
141
|
+
gap: var(--svadmin-space-1);
|
|
142
|
+
padding: 8px 16px;
|
|
143
|
+
color: var(--svadmin-text-4, var(--muted-foreground));
|
|
144
|
+
font-size: var(--svadmin-text-caption);
|
|
145
|
+
line-height: 1.6667;
|
|
103
146
|
text-align: center;
|
|
104
147
|
}
|
|
105
|
-
.svadmin-image__caption { width: 100%;
|
|
148
|
+
.svadmin-image__caption { width: 100%; margin-top: 4px; }
|
|
149
|
+
.svadmin-image__title {
|
|
150
|
+
display: block;
|
|
151
|
+
color: var(--foreground);
|
|
152
|
+
font-size: var(--svadmin-text-section);
|
|
153
|
+
font-weight: 500;
|
|
154
|
+
line-height: 1.5715;
|
|
155
|
+
}
|
|
156
|
+
.svadmin-image__description {
|
|
157
|
+
margin: 0;
|
|
158
|
+
color: var(--svadmin-text-3, var(--muted-foreground));
|
|
159
|
+
font-size: var(--svadmin-text-body);
|
|
160
|
+
line-height: 1.5715;
|
|
161
|
+
}
|
|
106
162
|
</style>
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
/** Trailing addon rendered after the control (design-system `addAfter` slot). */
|
|
9
9
|
addAfter?: string | Snippet | undefined;
|
|
10
10
|
size?: 'default' | 'compact' | undefined;
|
|
11
|
+
compact?: boolean | undefined;
|
|
11
12
|
invalid?: boolean | undefined;
|
|
12
13
|
disabled?: boolean | undefined;
|
|
13
14
|
class?: string | undefined;
|
|
@@ -18,7 +19,8 @@
|
|
|
18
19
|
let {
|
|
19
20
|
addBefore,
|
|
20
21
|
addAfter,
|
|
21
|
-
size = 'default',
|
|
22
|
+
size: sizeProp = 'default',
|
|
23
|
+
compact = false,
|
|
22
24
|
invalid = false,
|
|
23
25
|
disabled = false,
|
|
24
26
|
class: className = '',
|
|
@@ -26,13 +28,15 @@
|
|
|
26
28
|
children,
|
|
27
29
|
}: InputGroupProps = $props();
|
|
28
30
|
|
|
31
|
+
const size = $derived(compact ? 'compact' : sizeProp);
|
|
29
32
|
const hasBefore = $derived(addBefore !== undefined);
|
|
30
33
|
const hasAfter = $derived(addAfter !== undefined);
|
|
31
34
|
</script>
|
|
32
35
|
|
|
33
36
|
<div
|
|
34
|
-
class={cn('svadmin-input-group', className)}
|
|
37
|
+
class={cn('svadmin-input-group', compact && 'svadmin-input-group--compact', className)}
|
|
35
38
|
data-size={size}
|
|
39
|
+
data-compact={compact ? 'true' : undefined}
|
|
36
40
|
data-invalid={invalid ? 'true' : undefined}
|
|
37
41
|
data-disabled={disabled ? 'true' : undefined}
|
|
38
42
|
data-has-before={hasBefore ? 'true' : undefined}
|
|
@@ -130,4 +134,4 @@
|
|
|
130
134
|
.svadmin-input-group[data-disabled='true'] {
|
|
131
135
|
opacity: 0.6;
|
|
132
136
|
}
|
|
133
|
-
</style>
|
|
137
|
+
</style>
|
|
@@ -5,6 +5,7 @@ export interface InputGroupProps {
|
|
|
5
5
|
/** Trailing addon rendered after the control (design-system `addAfter` slot). */
|
|
6
6
|
addAfter?: string | Snippet | undefined;
|
|
7
7
|
size?: 'default' | 'compact' | undefined;
|
|
8
|
+
compact?: boolean | undefined;
|
|
8
9
|
invalid?: boolean | undefined;
|
|
9
10
|
disabled?: boolean | undefined;
|
|
10
11
|
class?: string | undefined;
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
interface Props {
|
|
16
16
|
items: MenuEntry[];
|
|
17
17
|
mode?: 'vertical' | 'horizontal';
|
|
18
|
+
theme?: 'light' | 'dark';
|
|
19
|
+
accordion?: boolean;
|
|
18
20
|
selected?: string;
|
|
19
21
|
openKeys?: string[];
|
|
20
22
|
collapsed?: boolean;
|
|
@@ -30,6 +32,8 @@
|
|
|
30
32
|
let {
|
|
31
33
|
items,
|
|
32
34
|
mode = 'vertical',
|
|
35
|
+
theme = 'light',
|
|
36
|
+
accordion = false,
|
|
33
37
|
selected = $bindable(),
|
|
34
38
|
openKeys = $bindable([]),
|
|
35
39
|
collapsed = false,
|
|
@@ -47,7 +51,7 @@
|
|
|
47
51
|
function setOpen(item: MenuEntry, open: boolean): void {
|
|
48
52
|
if (item.disabled) return;
|
|
49
53
|
if (!item.children?.length || isOpen(item) === open) return;
|
|
50
|
-
const next = open ? [...openKeys, item.id] : openKeys.filter((key) => key !== item.id);
|
|
54
|
+
const next = open ? (accordion ? [item.id] : [...openKeys, item.id]) : openKeys.filter((key) => key !== item.id);
|
|
51
55
|
openKeys = next;
|
|
52
56
|
onopenchange?.(next);
|
|
53
57
|
}
|
|
@@ -177,7 +181,15 @@
|
|
|
177
181
|
</ul>
|
|
178
182
|
{/snippet}
|
|
179
183
|
|
|
180
|
-
<nav
|
|
184
|
+
<nav
|
|
185
|
+
bind:this={nav}
|
|
186
|
+
class={cn('svadmin-menu', theme === 'dark' && 'svadmin-menu--dark', className)}
|
|
187
|
+
data-mode={mode}
|
|
188
|
+
data-theme={theme}
|
|
189
|
+
data-collapsed={collapsed ? 'true' : 'false'}
|
|
190
|
+
data-accordion={accordion ? 'true' : undefined}
|
|
191
|
+
aria-label={label}
|
|
192
|
+
>
|
|
181
193
|
{@render renderItems(items, 0)}
|
|
182
194
|
</nav>
|
|
183
195
|
|
|
@@ -250,5 +262,27 @@
|
|
|
250
262
|
background: var(--card);
|
|
251
263
|
box-shadow: var(--shadow-lg, 0 12px 30px color-mix(in srgb, var(--foreground) 16%, transparent));
|
|
252
264
|
}
|
|
265
|
+
|
|
266
|
+
/* Dark theme */
|
|
267
|
+
.svadmin-menu[data-theme='dark'] {
|
|
268
|
+
background: var(--sidebar, var(--card));
|
|
269
|
+
color: var(--sidebar-foreground, var(--foreground));
|
|
270
|
+
}
|
|
271
|
+
.svadmin-menu[data-theme='dark'] .svadmin-menu__link {
|
|
272
|
+
color: color-mix(in srgb, var(--sidebar-foreground, var(--foreground)) 75%, transparent);
|
|
273
|
+
}
|
|
274
|
+
.svadmin-menu[data-theme='dark'] .svadmin-menu__link:hover {
|
|
275
|
+
background: var(--sidebar-accent, var(--muted));
|
|
276
|
+
color: var(--sidebar-foreground, var(--foreground));
|
|
277
|
+
}
|
|
278
|
+
.svadmin-menu[data-theme='dark'] .svadmin-menu__link[data-selected='true'] {
|
|
279
|
+
background: var(--sidebar-accent, var(--primary));
|
|
280
|
+
color: var(--primary);
|
|
281
|
+
}
|
|
282
|
+
.svadmin-menu[data-theme='dark'][data-collapsed='true'] .svadmin-menu__list[data-depth]:not([data-depth='0']) {
|
|
283
|
+
background: var(--sidebar, var(--card));
|
|
284
|
+
border-color: var(--border);
|
|
285
|
+
}
|
|
286
|
+
|
|
253
287
|
@media (prefers-reduced-motion: reduce) { .svadmin-menu__chevron { transition: none; } }
|
|
254
288
|
</style>
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
triggerVariant?: 'default' | 'outline' | 'secondary' | 'ghost' | 'destructive';
|
|
16
16
|
triggerSize?: 'default' | 'sm' | 'lg' | 'icon';
|
|
17
17
|
submitText?: string;
|
|
18
|
+
okText?: string;
|
|
18
19
|
cancelText?: string;
|
|
19
20
|
widthClass?: string;
|
|
20
21
|
isSubmitting?: boolean;
|
|
@@ -34,6 +35,7 @@
|
|
|
34
35
|
triggerVariant = 'default',
|
|
35
36
|
triggerSize = 'sm',
|
|
36
37
|
submitText = 'Confirm',
|
|
38
|
+
okText,
|
|
37
39
|
cancelText = 'Cancel',
|
|
38
40
|
widthClass = '',
|
|
39
41
|
isSubmitting = false,
|
|
@@ -54,6 +56,7 @@
|
|
|
54
56
|
let formElement: HTMLFormElement | undefined;
|
|
55
57
|
let destroyed = false;
|
|
56
58
|
const busy = $derived(loading || isSubmitting);
|
|
59
|
+
const effectiveSubmitText = $derived(okText ?? submitText);
|
|
57
60
|
|
|
58
61
|
let lastOpen = open;
|
|
59
62
|
let lastOnsubmit: Props['onsubmit'];
|
|
@@ -191,7 +194,7 @@
|
|
|
191
194
|
{#if busy}
|
|
192
195
|
<Loader2 class="h-4 w-4 animate-spin" />
|
|
193
196
|
{/if}
|
|
194
|
-
{
|
|
197
|
+
{effectiveSubmitText}
|
|
195
198
|
</Button>
|
|
196
199
|
</Dialog.Footer>
|
|
197
200
|
</form>
|
|
@@ -7,6 +7,7 @@ interface Props {
|
|
|
7
7
|
triggerVariant?: 'default' | 'outline' | 'secondary' | 'ghost' | 'destructive';
|
|
8
8
|
triggerSize?: 'default' | 'sm' | 'lg' | 'icon';
|
|
9
9
|
submitText?: string;
|
|
10
|
+
okText?: string;
|
|
10
11
|
cancelText?: string;
|
|
11
12
|
widthClass?: string;
|
|
12
13
|
isSubmitting?: boolean;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import QRCodeLib from 'qrcode';
|
|
3
|
+
import { Loader2, RefreshCw, CheckCircle2 } from '@lucide/svelte';
|
|
4
|
+
import { useTranslation } from '@svadmin/core/i18n';
|
|
3
5
|
import { cn } from '../utils.js';
|
|
6
|
+
import { hasComponentConfig, useComponentConfig } from './ConfigProvider.svelte';
|
|
7
|
+
import { componentText, resolveComponentLocale } from './component-messages.js';
|
|
8
|
+
|
|
9
|
+
export type QRCodeStatus = 'normal' | 'loading' | 'expired' | 'scanned';
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* Renders a QR code from the Svelte ecosystem `qrcode` package as a crisp
|
|
@@ -18,6 +24,14 @@
|
|
|
18
24
|
color?: string;
|
|
19
25
|
/** Background color; defaults to the semantic background token. */
|
|
20
26
|
background?: string;
|
|
27
|
+
/** Current status of the QR code */
|
|
28
|
+
status?: QRCodeStatus;
|
|
29
|
+
/** Custom status text displayed on overlay */
|
|
30
|
+
statusText?: string;
|
|
31
|
+
/** Callback when user clicks the refresh button in expired status */
|
|
32
|
+
onrefresh?: () => void;
|
|
33
|
+
/** Overrides ConfigProvider and i18n for the status copy. */
|
|
34
|
+
locale?: string;
|
|
21
35
|
ariaLabel?: string;
|
|
22
36
|
class?: string;
|
|
23
37
|
}
|
|
@@ -29,10 +43,30 @@
|
|
|
29
43
|
errorCorrectionLevel = 'M',
|
|
30
44
|
color = 'var(--foreground, black)',
|
|
31
45
|
background = 'var(--background, white)',
|
|
46
|
+
status = 'normal',
|
|
47
|
+
statusText,
|
|
48
|
+
onrefresh,
|
|
49
|
+
locale,
|
|
32
50
|
ariaLabel = 'QR code',
|
|
33
51
|
class: className = '',
|
|
34
52
|
}: Props = $props();
|
|
35
53
|
|
|
54
|
+
const config = useComponentConfig();
|
|
55
|
+
const i18n = useTranslation();
|
|
56
|
+
const provided = hasComponentConfig();
|
|
57
|
+
const activeLocale = $derived(resolveComponentLocale({
|
|
58
|
+
explicit: locale,
|
|
59
|
+
configLocale: provided ? config.locale : undefined,
|
|
60
|
+
i18nLocale: i18n.locale,
|
|
61
|
+
}));
|
|
62
|
+
const copy = $derived({
|
|
63
|
+
expired: componentText(i18n, activeLocale, 'qrCode.expired'),
|
|
64
|
+
refresh: componentText(i18n, activeLocale, 'qrCode.refresh'),
|
|
65
|
+
refreshLabel: componentText(i18n, activeLocale, 'qrCode.refreshLabel'),
|
|
66
|
+
scanned: componentText(i18n, activeLocale, 'qrCode.scanned'),
|
|
67
|
+
empty: componentText(i18n, activeLocale, 'qrCode.empty'),
|
|
68
|
+
});
|
|
69
|
+
|
|
36
70
|
const matrix = $derived.by(() => {
|
|
37
71
|
if (!value) return null;
|
|
38
72
|
try {
|
|
@@ -53,7 +87,7 @@
|
|
|
53
87
|
});
|
|
54
88
|
</script>
|
|
55
89
|
|
|
56
|
-
<figure class={cn('svadmin-qr-code', className)} data-slot="qr-code">
|
|
90
|
+
<figure class={cn('svadmin-qr-code relative', className)} data-slot="qr-code" data-status={status}>
|
|
57
91
|
{#if matrix}
|
|
58
92
|
<svg
|
|
59
93
|
class="svadmin-qr-code__svg"
|
|
@@ -67,22 +101,93 @@
|
|
|
67
101
|
<rect width={matrix.total} height={matrix.total} fill={background} />
|
|
68
102
|
<path d={matrix.path} fill={color} />
|
|
69
103
|
</svg>
|
|
104
|
+
{#if status !== 'normal'}
|
|
105
|
+
<div
|
|
106
|
+
class="svadmin-qr-code__mask"
|
|
107
|
+
data-slot="qr-code-mask"
|
|
108
|
+
data-status={status}
|
|
109
|
+
>
|
|
110
|
+
{#if status === 'loading'}
|
|
111
|
+
<Loader2 class="animate-spin text-primary size-7" />
|
|
112
|
+
{#if statusText}<span class="svadmin-qr-code__status-text">{statusText}</span>{/if}
|
|
113
|
+
{:else if status === 'expired'}
|
|
114
|
+
<p class="svadmin-qr-code__status-text">{statusText ?? copy.expired}</p>
|
|
115
|
+
<button
|
|
116
|
+
type="button"
|
|
117
|
+
class="svadmin-qr-code__refresh-btn"
|
|
118
|
+
onclick={onrefresh}
|
|
119
|
+
aria-label={copy.refreshLabel}
|
|
120
|
+
>
|
|
121
|
+
<RefreshCw size={12} />
|
|
122
|
+
<span>{copy.refresh}</span>
|
|
123
|
+
</button>
|
|
124
|
+
{:else if status === 'scanned'}
|
|
125
|
+
<CheckCircle2 class="text-success size-7" />
|
|
126
|
+
<p class="svadmin-qr-code__status-text">{statusText ?? copy.scanned}</p>
|
|
127
|
+
{/if}
|
|
128
|
+
</div>
|
|
129
|
+
{/if}
|
|
70
130
|
{:else}
|
|
71
|
-
<p class="svadmin-qr-code__empty" role="status">
|
|
131
|
+
<p class="svadmin-qr-code__empty" role="status">{copy.empty}</p>
|
|
72
132
|
{/if}
|
|
73
133
|
</figure>
|
|
74
134
|
|
|
75
135
|
<style>
|
|
76
136
|
.svadmin-qr-code {
|
|
137
|
+
position: relative;
|
|
77
138
|
display: inline-flex;
|
|
78
139
|
margin: 0;
|
|
79
140
|
border: 1px solid var(--border, currentColor);
|
|
80
|
-
border-radius:
|
|
81
|
-
padding:
|
|
141
|
+
border-radius: var(--radius);
|
|
142
|
+
padding: var(--svadmin-space-2);
|
|
82
143
|
background: var(--card, var(--background, transparent));
|
|
83
144
|
color: var(--card-foreground, var(--foreground, currentColor));
|
|
84
145
|
}
|
|
85
146
|
|
|
86
|
-
.svadmin-qr-code__svg { display: block; border-radius:
|
|
87
|
-
.svadmin-qr-code__empty {
|
|
88
|
-
|
|
147
|
+
.svadmin-qr-code__svg { display: block; border-radius: var(--border-radius-small, 2px); }
|
|
148
|
+
.svadmin-qr-code__empty {
|
|
149
|
+
margin: 0;
|
|
150
|
+
padding: var(--svadmin-space-4);
|
|
151
|
+
color: var(--muted-foreground, currentColor);
|
|
152
|
+
font-size: var(--svadmin-text-body);
|
|
153
|
+
line-height: 1.5715;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.svadmin-qr-code__mask {
|
|
157
|
+
position: absolute;
|
|
158
|
+
inset: 0.5rem;
|
|
159
|
+
display: flex;
|
|
160
|
+
flex-direction: column;
|
|
161
|
+
align-items: center;
|
|
162
|
+
justify-content: center;
|
|
163
|
+
gap: 0.5rem;
|
|
164
|
+
background: color-mix(in srgb, var(--card, white) 92%, transparent);
|
|
165
|
+
border-radius: var(--border-radius-small, 2px);
|
|
166
|
+
text-align: center;
|
|
167
|
+
padding: var(--svadmin-space-2);
|
|
168
|
+
}
|
|
169
|
+
.svadmin-qr-code__status-text {
|
|
170
|
+
margin: 0;
|
|
171
|
+
color: var(--foreground);
|
|
172
|
+
font-size: var(--svadmin-text-caption);
|
|
173
|
+
line-height: 1.6667;
|
|
174
|
+
}
|
|
175
|
+
.svadmin-qr-code__refresh-btn {
|
|
176
|
+
display: inline-flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
gap: var(--svadmin-space-1);
|
|
179
|
+
padding: 1px 4px;
|
|
180
|
+
border: 0;
|
|
181
|
+
border-radius: var(--border-radius-small, 2px);
|
|
182
|
+
background: transparent;
|
|
183
|
+
color: var(--primary);
|
|
184
|
+
font-size: var(--svadmin-text-caption);
|
|
185
|
+
line-height: 1.6667;
|
|
186
|
+
cursor: pointer;
|
|
187
|
+
}
|
|
188
|
+
.svadmin-qr-code__refresh-btn:hover { background: var(--svadmin-fill-2, var(--muted)); }
|
|
189
|
+
.svadmin-qr-code__refresh-btn:focus-visible {
|
|
190
|
+
outline: var(--svadmin-focus-width) solid var(--ring);
|
|
191
|
+
outline-offset: var(--svadmin-focus-offset);
|
|
192
|
+
}
|
|
193
|
+
</style>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type QRCodeStatus = 'normal' | 'loading' | 'expired' | 'scanned';
|
|
1
2
|
/**
|
|
2
3
|
* Renders a QR code from the Svelte ecosystem `qrcode` package as a crisp
|
|
3
4
|
* SVG. No canvas is required, so it is safe under SSR and test DOMs.
|
|
@@ -14,6 +15,14 @@ interface Props {
|
|
|
14
15
|
color?: string;
|
|
15
16
|
/** Background color; defaults to the semantic background token. */
|
|
16
17
|
background?: string;
|
|
18
|
+
/** Current status of the QR code */
|
|
19
|
+
status?: QRCodeStatus;
|
|
20
|
+
/** Custom status text displayed on overlay */
|
|
21
|
+
statusText?: string;
|
|
22
|
+
/** Callback when user clicks the refresh button in expired status */
|
|
23
|
+
onrefresh?: () => void;
|
|
24
|
+
/** Overrides ConfigProvider and i18n for the status copy. */
|
|
25
|
+
locale?: string;
|
|
17
26
|
ariaLabel?: string;
|
|
18
27
|
class?: string;
|
|
19
28
|
}
|
|
@@ -42,6 +42,26 @@ export declare const componentMessageCatalog: {
|
|
|
42
42
|
readonly en: "Calendar dates";
|
|
43
43
|
readonly zh: "日历日期";
|
|
44
44
|
};
|
|
45
|
+
readonly 'qrCode.expired': {
|
|
46
|
+
readonly en: "QR code expired";
|
|
47
|
+
readonly zh: "二维码已失效";
|
|
48
|
+
};
|
|
49
|
+
readonly 'qrCode.refresh': {
|
|
50
|
+
readonly en: "Refresh";
|
|
51
|
+
readonly zh: "点击刷新";
|
|
52
|
+
};
|
|
53
|
+
readonly 'qrCode.refreshLabel': {
|
|
54
|
+
readonly en: "Refresh QR code";
|
|
55
|
+
readonly zh: "刷新二维码";
|
|
56
|
+
};
|
|
57
|
+
readonly 'qrCode.scanned': {
|
|
58
|
+
readonly en: "Scanned";
|
|
59
|
+
readonly zh: "已扫描";
|
|
60
|
+
};
|
|
61
|
+
readonly 'qrCode.empty': {
|
|
62
|
+
readonly en: "No QR content.";
|
|
63
|
+
readonly zh: "没有二维码内容。";
|
|
64
|
+
};
|
|
45
65
|
};
|
|
46
66
|
export type ComponentMessageKey = keyof typeof componentMessageCatalog;
|
|
47
67
|
export interface ComponentMessageSource {
|
|
@@ -15,6 +15,11 @@ export const componentMessageCatalog = {
|
|
|
15
15
|
'datePicker.previousYear': { en: 'Previous year', zh: '上一年' },
|
|
16
16
|
'datePicker.nextYear': { en: 'Next year', zh: '下一年' },
|
|
17
17
|
'datePicker.calendarDates': { en: 'Calendar dates', zh: '日历日期' },
|
|
18
|
+
'qrCode.expired': { en: 'QR code expired', zh: '二维码已失效' },
|
|
19
|
+
'qrCode.refresh': { en: 'Refresh', zh: '点击刷新' },
|
|
20
|
+
'qrCode.refreshLabel': { en: 'Refresh QR code', zh: '刷新二维码' },
|
|
21
|
+
'qrCode.scanned': { en: 'Scanned', zh: '已扫描' },
|
|
22
|
+
'qrCode.empty': { en: 'No QR content.', zh: '没有二维码内容。' },
|
|
18
23
|
};
|
|
19
24
|
export function resolveComponentLocale(input) {
|
|
20
25
|
const explicit = input.explicit?.trim();
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { alertVariants as resolveAlertVariants, type AlertVariant as AlertVariantValue } from "./alert-variants.js";
|
|
5
5
|
|
|
6
6
|
export { alertVariants, type AlertVariant } from "./alert-variants.js";
|
|
7
|
+
export type AlertType = "info" | "success" | "warning" | "error" | AlertVariantValue;
|
|
7
8
|
</script>
|
|
8
9
|
|
|
9
10
|
<script lang="ts">
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
|
|
14
15
|
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
15
16
|
variant?: AlertVariantValue;
|
|
17
|
+
type?: AlertType;
|
|
16
18
|
closable?: boolean;
|
|
17
19
|
closeLabel?: string;
|
|
18
20
|
title?: string;
|
|
@@ -26,7 +28,8 @@
|
|
|
26
28
|
|
|
27
29
|
let {
|
|
28
30
|
ref = $bindable(null),
|
|
29
|
-
variant
|
|
31
|
+
variant: variantProp,
|
|
32
|
+
type: typeProp,
|
|
30
33
|
closable = false,
|
|
31
34
|
closeLabel = "Dismiss alert",
|
|
32
35
|
title,
|
|
@@ -40,6 +43,14 @@
|
|
|
40
43
|
...restProps
|
|
41
44
|
}: Props = $props();
|
|
42
45
|
|
|
46
|
+
const variant = $derived.by<AlertVariantValue>(() => {
|
|
47
|
+
if (variantProp) return variantProp;
|
|
48
|
+
if (typeProp === "error") return "destructive";
|
|
49
|
+
if (typeProp === "info") return "default";
|
|
50
|
+
if (typeProp === "success" || typeProp === "warning") return typeProp;
|
|
51
|
+
return (typeProp as AlertVariantValue) ?? "default";
|
|
52
|
+
});
|
|
53
|
+
|
|
43
54
|
const statusIcons = {
|
|
44
55
|
default: Info,
|
|
45
56
|
destructive: CircleAlert,
|
|
@@ -2,9 +2,11 @@ import { type WithElementRef } from "../../../utils.js";
|
|
|
2
2
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
3
|
import { type AlertVariant as AlertVariantValue } from "./alert-variants.js";
|
|
4
4
|
export { alertVariants, type AlertVariant } from "./alert-variants.js";
|
|
5
|
+
export type AlertType = "info" | "success" | "warning" | "error" | AlertVariantValue;
|
|
5
6
|
import type { Snippet } from "svelte";
|
|
6
7
|
type Props = WithElementRef<HTMLAttributes<HTMLDivElement>> & {
|
|
7
8
|
variant?: AlertVariantValue;
|
|
9
|
+
type?: AlertType;
|
|
8
10
|
closable?: boolean;
|
|
9
11
|
closeLabel?: string;
|
|
10
12
|
title?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Alert, { type AlertVariant, alertVariants } from "./alert.svelte";
|
|
1
|
+
import Alert, { type AlertVariant, type AlertType, alertVariants } from "./alert.svelte";
|
|
2
2
|
import AlertTitle from "./alert-title.svelte";
|
|
3
3
|
import AlertDescription from "./alert-description.svelte";
|
|
4
|
-
export { Alert, AlertTitle, AlertDescription, Alert as Root, AlertTitle as Title, AlertDescription as Description, alertVariants, type AlertVariant, };
|
|
4
|
+
export { Alert, AlertTitle, AlertDescription, Alert as Root, AlertTitle as Title, AlertDescription as Description, alertVariants, type AlertVariant, type AlertType, };
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
size: sizeProp,
|
|
19
19
|
count,
|
|
20
20
|
overflowCount = 99,
|
|
21
|
+
maxCount,
|
|
21
22
|
dot = false,
|
|
22
23
|
status,
|
|
23
24
|
text,
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
size?: "default" | "compact";
|
|
32
33
|
count?: number | string | undefined;
|
|
33
34
|
overflowCount?: number | undefined;
|
|
35
|
+
maxCount?: number | undefined;
|
|
34
36
|
dot?: boolean | undefined;
|
|
35
37
|
status?: BadgeStatus | undefined;
|
|
36
38
|
text?: string | undefined;
|
|
@@ -44,11 +46,13 @@
|
|
|
44
46
|
|
|
45
47
|
const isStatusMode = $derived(count !== undefined || dot || status !== undefined);
|
|
46
48
|
|
|
49
|
+
const effectiveOverflowCount = $derived(maxCount ?? overflowCount);
|
|
50
|
+
|
|
47
51
|
const displayCount = $derived.by(() => {
|
|
48
52
|
if (count === undefined) return null;
|
|
49
53
|
if (typeof count === 'number') {
|
|
50
54
|
if (count === 0 && !showZero) return null;
|
|
51
|
-
if (count >
|
|
55
|
+
if (count > effectiveOverflowCount) return `${effectiveOverflowCount}+`;
|
|
52
56
|
return String(count);
|
|
53
57
|
}
|
|
54
58
|
return count;
|
|
@@ -8,6 +8,7 @@ type $$ComponentProps = WithElementRef<HTMLAnchorAttributes> & {
|
|
|
8
8
|
size?: "default" | "compact";
|
|
9
9
|
count?: number | string | undefined;
|
|
10
10
|
overflowCount?: number | undefined;
|
|
11
|
+
maxCount?: number | undefined;
|
|
11
12
|
dot?: boolean | undefined;
|
|
12
13
|
status?: BadgeStatus | undefined;
|
|
13
14
|
text?: string | undefined;
|