@svadmin/ui 0.136.0 → 0.137.1
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 +107 -2
- package/dist/app.theme.css +107 -2
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/Affix.svelte +17 -2
- package/dist/components/Affix.svelte.d.ts +2 -0
- package/dist/components/Anchor.svelte +33 -8
- package/dist/components/Anchor.svelte.d.ts +6 -2
- package/dist/components/AutoComplete.svelte +27 -3
- package/dist/components/AutoComplete.svelte.d.ts +3 -0
- package/dist/components/BackTop.svelte +18 -7
- package/dist/components/BackTop.svelte.d.ts +4 -0
- package/dist/components/Barcode.svelte +9 -2
- package/dist/components/Barcode.svelte.d.ts +2 -0
- package/dist/components/Breadcrumbs.svelte +21 -8
- package/dist/components/Breadcrumbs.svelte.d.ts +6 -2
- package/dist/components/Calendar.svelte +26 -4
- package/dist/components/Calendar.svelte.d.ts +4 -1
- package/dist/components/Carousel.svelte +30 -4
- package/dist/components/Carousel.svelte.d.ts +4 -0
- package/dist/components/Cascader.svelte +79 -17
- package/dist/components/Cascader.svelte.d.ts +9 -2
- package/dist/components/CheckCard.svelte +14 -4
- package/dist/components/CheckCard.svelte.d.ts +4 -2
- package/dist/components/Col.svelte +14 -10
- package/dist/components/Col.svelte.d.ts +2 -0
- package/dist/components/Collapse.svelte +67 -9
- package/dist/components/Collapse.svelte.d.ts +12 -4
- package/dist/components/ColorPicker.svelte +76 -14
- package/dist/components/ColorPicker.svelte.d.ts +6 -0
- package/dist/components/ConfigProvider.svelte +1 -0
- package/dist/components/ConfigProvider.svelte.d.ts +1 -0
- package/dist/components/ConfirmDialog.svelte +33 -8
- package/dist/components/ConfirmDialog.svelte.d.ts +5 -0
- package/dist/components/Countdown.svelte +49 -15
- package/dist/components/Countdown.svelte.d.ts +6 -2
- package/dist/components/DatePicker.svelte +36 -8
- package/dist/components/DatePicker.svelte.d.ts +8 -0
- package/dist/components/DateRangeInput.svelte +67 -4
- package/dist/components/DateRangeInput.svelte.d.ts +7 -0
- package/dist/components/DateTimeInput.svelte +19 -1
- package/dist/components/DateTimeInput.svelte.d.ts +4 -0
- package/dist/components/Divider.svelte +27 -4
- package/dist/components/Divider.svelte.d.ts +6 -0
- package/dist/components/DrawerForm.svelte +131 -43
- package/dist/components/DrawerForm.svelte.d.ts +14 -1
- package/dist/components/EditableTabs.svelte +1 -1
- package/dist/components/EllipsisText.svelte +31 -8
- package/dist/components/EllipsisText.svelte.d.ts +8 -0
- package/dist/components/EmptyState.svelte +25 -5
- package/dist/components/EmptyState.svelte.d.ts +6 -1
- package/dist/components/FileUpload.svelte +15 -5
- package/dist/components/FileUpload.svelte.d.ts +3 -0
- package/dist/components/FloatButton.svelte +4 -1
- package/dist/components/FloatButton.svelte.d.ts +1 -0
- package/dist/components/HighlightText.svelte +15 -3
- package/dist/components/HighlightText.svelte.d.ts +6 -0
- package/dist/components/Image.svelte +10 -4
- package/dist/components/Image.svelte.d.ts +1 -0
- package/dist/components/LightFilter.svelte +37 -17
- package/dist/components/LightFilter.svelte.d.ts +8 -2
- package/dist/components/Link.svelte +19 -8
- package/dist/components/Link.svelte.d.ts +3 -2
- package/dist/components/ListPagination.svelte +165 -27
- package/dist/components/ListPagination.svelte.d.ts +10 -3
- package/dist/components/MentionsInput.svelte +33 -3
- package/dist/components/MentionsInput.svelte.d.ts +5 -0
- package/dist/components/ModalForm.svelte +116 -48
- package/dist/components/ModalForm.svelte.d.ts +14 -1
- package/dist/components/OtpInput.svelte +40 -12
- package/dist/components/OtpInput.svelte.d.ts +4 -1
- package/dist/components/PageContainer.svelte +74 -22
- package/dist/components/PageContainer.svelte.d.ts +20 -4
- package/dist/components/PageHeader.svelte +47 -8
- package/dist/components/PageHeader.svelte.d.ts +7 -2
- package/dist/components/PasswordInput.svelte +42 -11
- package/dist/components/PasswordInput.svelte.d.ts +10 -3
- package/dist/components/Popconfirm.svelte +96 -17
- package/dist/components/Popconfirm.svelte.d.ts +13 -1
- package/dist/components/PresenceAvatarGroup.svelte +12 -4
- package/dist/components/PresenceAvatarGroup.svelte.d.ts +1 -1
- package/dist/components/ProCard.svelte +17 -0
- package/dist/components/ProCard.svelte.d.ts +6 -0
- package/dist/components/ProDescriptions.svelte +28 -12
- package/dist/components/ProDescriptions.svelte.d.ts +7 -3
- package/dist/components/ProSkeleton.svelte +17 -2
- package/dist/components/ProSkeleton.svelte.d.ts +7 -0
- package/dist/components/QRCode.svelte +51 -14
- package/dist/components/QRCode.svelte.d.ts +10 -0
- package/dist/components/QueryFilter.svelte +48 -9
- package/dist/components/QueryFilter.svelte.d.ts +16 -0
- package/dist/components/RadioGroup.svelte +86 -8
- package/dist/components/RadioGroup.svelte.d.ts +2 -0
- package/dist/components/RangeSlider.svelte +34 -7
- package/dist/components/RangeSlider.svelte.d.ts +4 -0
- package/dist/components/Rate.svelte +178 -15
- package/dist/components/Rate.svelte.d.ts +16 -0
- package/dist/components/ResizeBox.svelte +39 -9
- package/dist/components/ResizeBox.svelte.d.ts +3 -0
- package/dist/components/Result.svelte +34 -5
- package/dist/components/Result.svelte.d.ts +4 -2
- package/dist/components/Ribbon.svelte +8 -4
- package/dist/components/Ribbon.svelte.d.ts +1 -1
- package/dist/components/Row.svelte +21 -5
- package/dist/components/Row.svelte.d.ts +2 -2
- package/dist/components/RowActions.svelte +4 -0
- package/dist/components/SegmentedControl.svelte +70 -8
- package/dist/components/SegmentedControl.svelte.d.ts +6 -1
- package/dist/components/Slider.svelte +35 -8
- package/dist/components/Slider.svelte.d.ts +4 -0
- package/dist/components/Space.svelte +34 -7
- package/dist/components/Space.svelte.d.ts +3 -3
- package/dist/components/Spin.svelte +142 -9
- package/dist/components/Spin.svelte.d.ts +7 -2
- package/dist/components/Statistic.svelte +29 -6
- package/dist/components/Statistic.svelte.d.ts +5 -1
- package/dist/components/StatisticCard.svelte +20 -4
- package/dist/components/StatisticCard.svelte.d.ts +5 -1
- package/dist/components/Steps.svelte +28 -7
- package/dist/components/Steps.svelte.d.ts +8 -2
- package/dist/components/Tag.svelte +63 -6
- package/dist/components/Tag.svelte.d.ts +12 -3
- package/dist/components/TagsInput.svelte +42 -21
- package/dist/components/TagsInput.svelte.d.ts +4 -0
- package/dist/components/Timeline.svelte +54 -3
- package/dist/components/Timeline.svelte.d.ts +13 -1
- package/dist/components/TooltipButton.svelte +7 -3
- package/dist/components/TooltipButton.svelte.d.ts +4 -1
- package/dist/components/Tour.svelte +56 -6
- package/dist/components/Tour.svelte.d.ts +7 -0
- package/dist/components/Transfer.svelte +77 -20
- package/dist/components/Transfer.svelte.d.ts +11 -2
- package/dist/components/Tree.svelte +109 -26
- package/dist/components/Tree.svelte.d.ts +15 -2
- package/dist/components/TreeSelect.svelte +168 -97
- package/dist/components/TreeSelect.svelte.d.ts +11 -2
- package/dist/components/Typography.svelte +18 -2
- package/dist/components/Typography.svelte.d.ts +4 -1
- package/dist/components/TypographyText.svelte +10 -3
- package/dist/components/TypographyText.svelte.d.ts +3 -1
- package/dist/components/Watermark.svelte +15 -2
- package/dist/components/Watermark.svelte.d.ts +3 -0
- package/dist/components/content/DescriptionList.svelte +21 -8
- package/dist/components/content/DescriptionList.svelte.d.ts +3 -0
- package/dist/components/content/FilterToolbar.svelte +1 -0
- package/dist/components/ui/alert/alert.svelte +51 -7
- package/dist/components/ui/alert/alert.svelte.d.ts +8 -2
- package/dist/components/ui/avatar/avatar-variants.d.ts +1 -1
- package/dist/components/ui/avatar/avatar-variants.js +19 -7
- package/dist/components/ui/avatar/avatar.svelte +50 -3
- package/dist/components/ui/avatar/avatar.svelte.d.ts +5 -0
- package/dist/components/ui/badge/badge.svelte +27 -12
- package/dist/components/ui/badge/badge.svelte.d.ts +5 -2
- package/dist/components/ui/breadcrumb/breadcrumb-separator.svelte +4 -2
- package/dist/components/ui/breadcrumb/breadcrumb-separator.svelte.d.ts +1 -1
- package/dist/components/ui/button/button.svelte +100 -11
- package/dist/components/ui/button/button.svelte.d.ts +15 -2
- package/dist/components/ui/card/card.svelte +40 -4
- package/dist/components/ui/card/card.svelte.d.ts +5 -1
- package/dist/components/ui/checkbox/checkbox.svelte +71 -23
- package/dist/components/ui/checkbox/checkbox.svelte.d.ts +8 -1
- package/dist/components/ui/input/input.svelte +7 -4
- package/dist/components/ui/input/input.svelte.d.ts +2 -2
- package/dist/components/ui/progress/progress.svelte +122 -22
- package/dist/components/ui/progress/progress.svelte.d.ts +9 -1
- package/dist/components/ui/skeleton/index.d.ts +1 -1
- package/dist/components/ui/skeleton/skeleton.svelte +124 -6
- package/dist/components/ui/skeleton/skeleton.svelte.d.ts +19 -3
- package/dist/components/ui/switch/switch.svelte +44 -6
- package/dist/components/ui/switch/switch.svelte.d.ts +10 -3
- package/dist/components/ui/tabs/tabs-content.svelte +6 -1
- package/dist/components/ui/tabs/tabs-content.svelte.d.ts +1 -0
- package/dist/components/ui/tabs/tabs-context.svelte.d.ts +4 -1
- package/dist/components/ui/tabs/tabs-list.svelte +12 -3
- package/dist/components/ui/tabs/tabs-list.svelte.d.ts +4 -2
- package/dist/components/ui/tabs/tabs-trigger.svelte +11 -1
- package/dist/components/ui/tabs/tabs-trigger.svelte.d.ts +3 -0
- package/dist/components/ui/tabs/tabs.svelte +49 -5
- package/dist/components/ui/tabs/tabs.svelte.d.ts +10 -2
- package/dist/components/ui/textarea/textarea.svelte +17 -2
- package/dist/components/ui/textarea/textarea.svelte.d.ts +3 -1
- package/dist/components/ui/tooltip/tooltip-content.svelte +4 -1
- package/dist/components/ui/tooltip/tooltip-content.svelte.d.ts +1 -0
- package/dist/components/ui/tooltip/tooltip.svelte +14 -1
- package/dist/components.css +7 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/notifications.svelte.d.ts +6 -1
- package/dist/notifications.svelte.js +20 -4
- package/dist/page-chrome.css +5 -0
- package/package.json +1 -1
- package/dist/components/ui/tooltip/tooltip.svelte.d.ts +0 -25
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { cn } from '../utils.js';
|
|
3
3
|
|
|
4
|
+
export type ColorPickerSize = 'mini' | 'small' | 'default' | 'large';
|
|
5
|
+
|
|
4
6
|
interface Props {
|
|
5
7
|
value?: string | undefined;
|
|
8
|
+
defaultValue?: string | undefined;
|
|
6
9
|
name?: string | undefined;
|
|
7
10
|
id?: string | undefined;
|
|
11
|
+
size?: ColorPickerSize | undefined;
|
|
12
|
+
showText?: boolean | undefined;
|
|
13
|
+
presetColors?: string[] | undefined;
|
|
14
|
+
historyColors?: string[] | undefined;
|
|
8
15
|
disabled?: boolean | undefined;
|
|
9
16
|
required?: boolean | undefined;
|
|
10
17
|
invalid?: boolean | undefined;
|
|
@@ -16,8 +23,13 @@
|
|
|
16
23
|
|
|
17
24
|
let {
|
|
18
25
|
value = $bindable(''),
|
|
26
|
+
defaultValue,
|
|
19
27
|
name,
|
|
20
28
|
id,
|
|
29
|
+
size = 'default',
|
|
30
|
+
showText = false,
|
|
31
|
+
presetColors,
|
|
32
|
+
historyColors,
|
|
21
33
|
disabled = false,
|
|
22
34
|
required = false,
|
|
23
35
|
invalid = false,
|
|
@@ -27,6 +39,18 @@
|
|
|
27
39
|
onchange,
|
|
28
40
|
}: Props = $props();
|
|
29
41
|
|
|
42
|
+
let initialized = false;
|
|
43
|
+
$effect.pre(() => {
|
|
44
|
+
if (!initialized) {
|
|
45
|
+
initialized = true;
|
|
46
|
+
if (defaultValue !== undefined && !value) {
|
|
47
|
+
value = defaultValue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const swatches = $derived(presetColors ?? historyColors);
|
|
53
|
+
|
|
30
54
|
function handleInput(event: Event): void {
|
|
31
55
|
const input = event.currentTarget;
|
|
32
56
|
if (!(input instanceof HTMLInputElement) || disabled) return;
|
|
@@ -35,19 +59,42 @@
|
|
|
35
59
|
}
|
|
36
60
|
</script>
|
|
37
61
|
|
|
38
|
-
<
|
|
39
|
-
class=
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
<div class={cn('svadmin-color-picker-root inline-flex flex-col gap-1.5', className)}>
|
|
63
|
+
<div class="inline-flex items-center gap-2">
|
|
64
|
+
<input
|
|
65
|
+
class="svadmin-color-picker"
|
|
66
|
+
data-size={size}
|
|
67
|
+
{id}
|
|
68
|
+
{name}
|
|
69
|
+
type="color"
|
|
70
|
+
value={value}
|
|
71
|
+
{disabled}
|
|
72
|
+
{required}
|
|
73
|
+
aria-label={ariaLabel}
|
|
74
|
+
aria-invalid={invalid || undefined}
|
|
75
|
+
aria-describedby={describedby}
|
|
76
|
+
oninput={handleInput}
|
|
77
|
+
/>
|
|
78
|
+
{#if showText}
|
|
79
|
+
<span class="svadmin-color-picker__text font-mono text-xs text-foreground uppercase">{value || '—'}</span>
|
|
80
|
+
{/if}
|
|
81
|
+
</div>
|
|
82
|
+
{#if swatches && swatches.length > 0}
|
|
83
|
+
<div class="svadmin-color-picker__presets flex flex-wrap gap-1" data-slot="color-picker-presets">
|
|
84
|
+
{#each swatches as swatchColor (swatchColor)}
|
|
85
|
+
<button
|
|
86
|
+
type="button"
|
|
87
|
+
class="h-5 w-5 rounded-xs border border-border cursor-pointer transition-transform hover:scale-110"
|
|
88
|
+
style={`background-color: ${swatchColor};`}
|
|
89
|
+
disabled={disabled}
|
|
90
|
+
title={swatchColor}
|
|
91
|
+
aria-label={swatchColor}
|
|
92
|
+
onclick={() => { if (!disabled) { value = swatchColor; onchange?.(swatchColor); } }}
|
|
93
|
+
></button>
|
|
94
|
+
{/each}
|
|
95
|
+
</div>
|
|
96
|
+
{/if}
|
|
97
|
+
</div>
|
|
51
98
|
|
|
52
99
|
<style>
|
|
53
100
|
.svadmin-color-picker {
|
|
@@ -56,11 +103,26 @@
|
|
|
56
103
|
block-size: 32px;
|
|
57
104
|
padding: 2px;
|
|
58
105
|
border: 1px solid var(--border);
|
|
59
|
-
border-radius: 6px;
|
|
106
|
+
border-radius: var(--radius-sm, 6px);
|
|
60
107
|
background: var(--background);
|
|
61
108
|
cursor: pointer;
|
|
62
109
|
}
|
|
63
110
|
|
|
111
|
+
.svadmin-color-picker[data-size='mini'] {
|
|
112
|
+
inline-size: 28px;
|
|
113
|
+
block-size: 22px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.svadmin-color-picker[data-size='small'] {
|
|
117
|
+
inline-size: 32px;
|
|
118
|
+
block-size: 26px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.svadmin-color-picker[data-size='large'] {
|
|
122
|
+
inline-size: 48px;
|
|
123
|
+
block-size: 38px;
|
|
124
|
+
}
|
|
125
|
+
|
|
64
126
|
.svadmin-color-picker:focus-visible {
|
|
65
127
|
outline: var(--svadmin-focus-width) solid var(--ring);
|
|
66
128
|
outline-offset: var(--svadmin-focus-offset);
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
export type ColorPickerSize = 'mini' | 'small' | 'default' | 'large';
|
|
1
2
|
interface Props {
|
|
2
3
|
value?: string | undefined;
|
|
4
|
+
defaultValue?: string | undefined;
|
|
3
5
|
name?: string | undefined;
|
|
4
6
|
id?: string | undefined;
|
|
7
|
+
size?: ColorPickerSize | undefined;
|
|
8
|
+
showText?: boolean | undefined;
|
|
9
|
+
presetColors?: string[] | undefined;
|
|
10
|
+
historyColors?: string[] | undefined;
|
|
5
11
|
disabled?: boolean | undefined;
|
|
6
12
|
required?: boolean | undefined;
|
|
7
13
|
invalid?: boolean | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
2
3
|
import * as AlertDialog from './ui/alert-dialog/index.js';
|
|
3
4
|
import { Button } from './ui/button/index.js';
|
|
4
5
|
import { Loader2 } from '@lucide/svelte';
|
|
@@ -10,17 +11,33 @@
|
|
|
10
11
|
open?: boolean;
|
|
11
12
|
title?: string;
|
|
12
13
|
message?: string;
|
|
14
|
+
content?: string | Snippet;
|
|
13
15
|
confirmText?: string;
|
|
16
|
+
okText?: string;
|
|
14
17
|
cancelText?: string;
|
|
15
18
|
variant?: 'danger' | 'warning' | 'info';
|
|
16
19
|
confirming?: boolean;
|
|
20
|
+
loading?: boolean;
|
|
21
|
+
confirmLoading?: boolean;
|
|
17
22
|
onconfirm: () => void;
|
|
18
23
|
oncancel: () => void;
|
|
19
24
|
};
|
|
20
25
|
|
|
21
|
-
let {
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
let {
|
|
27
|
+
open = $bindable(false),
|
|
28
|
+
title,
|
|
29
|
+
message = '',
|
|
30
|
+
content,
|
|
31
|
+
confirmText,
|
|
32
|
+
okText,
|
|
33
|
+
cancelText,
|
|
34
|
+
variant = 'danger',
|
|
35
|
+
confirming = false,
|
|
36
|
+
loading,
|
|
37
|
+
confirmLoading,
|
|
38
|
+
onconfirm,
|
|
39
|
+
oncancel,
|
|
40
|
+
}: Props = $props();
|
|
24
41
|
|
|
25
42
|
const variantMap = {
|
|
26
43
|
danger: 'destructive' as const,
|
|
@@ -29,8 +46,10 @@
|
|
|
29
46
|
};
|
|
30
47
|
|
|
31
48
|
const resolvedTitle = $derived(title ?? i18n.t('common.confirmAction'));
|
|
32
|
-
const resolvedConfirmText = $derived(confirmText ?? i18n.t('common.confirm'));
|
|
49
|
+
const resolvedConfirmText = $derived(okText ?? confirmText ?? i18n.t('common.confirm'));
|
|
33
50
|
const resolvedCancelText = $derived(cancelText ?? i18n.t('common.cancel'));
|
|
51
|
+
const resolvedContent = $derived(content ?? message);
|
|
52
|
+
const resolvedLoading = $derived(loading ?? confirmLoading ?? confirming);
|
|
34
53
|
|
|
35
54
|
let confirmed = $state(false);
|
|
36
55
|
|
|
@@ -51,20 +70,26 @@
|
|
|
51
70
|
<AlertDialog.Content>
|
|
52
71
|
<AlertDialog.Header>
|
|
53
72
|
<AlertDialog.Title>{resolvedTitle}</AlertDialog.Title>
|
|
54
|
-
<AlertDialog.Description>
|
|
73
|
+
<AlertDialog.Description>
|
|
74
|
+
{#if typeof resolvedContent === 'string'}
|
|
75
|
+
{resolvedContent}
|
|
76
|
+
{:else if resolvedContent}
|
|
77
|
+
{@render resolvedContent()}
|
|
78
|
+
{/if}
|
|
79
|
+
</AlertDialog.Description>
|
|
55
80
|
</AlertDialog.Header>
|
|
56
81
|
<AlertDialog.Footer>
|
|
57
82
|
<AlertDialog.Cancel>
|
|
58
83
|
{#snippet child({ props })}
|
|
59
|
-
<Button variant="outline" {...props} disabled={
|
|
84
|
+
<Button variant="outline" {...props} disabled={resolvedLoading}>
|
|
60
85
|
{resolvedCancelText}
|
|
61
86
|
</Button>
|
|
62
87
|
{/snippet}
|
|
63
88
|
</AlertDialog.Cancel>
|
|
64
89
|
<AlertDialog.Action>
|
|
65
90
|
{#snippet child({ props })}
|
|
66
|
-
<Button {...props} variant={variantMap[variant as keyof typeof variantMap]} data-status={variant === 'warning' ? 'warning' : undefined} disabled={
|
|
67
|
-
{#if
|
|
91
|
+
<Button {...props} variant={variantMap[variant as keyof typeof variantMap]} data-status={variant === 'warning' ? 'warning' : undefined} disabled={resolvedLoading} onclick={handleConfirm}>
|
|
92
|
+
{#if resolvedLoading}
|
|
68
93
|
<Loader2 class="mr-2 h-4 w-4 animate-spin" aria-hidden="true" />
|
|
69
94
|
{/if}
|
|
70
95
|
{resolvedConfirmText}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
type Props = {
|
|
2
3
|
open?: boolean;
|
|
3
4
|
title?: string;
|
|
4
5
|
message?: string;
|
|
6
|
+
content?: string | Snippet;
|
|
5
7
|
confirmText?: string;
|
|
8
|
+
okText?: string;
|
|
6
9
|
cancelText?: string;
|
|
7
10
|
variant?: 'danger' | 'warning' | 'info';
|
|
8
11
|
confirming?: boolean;
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
confirmLoading?: boolean;
|
|
9
14
|
onconfirm: () => void;
|
|
10
15
|
oncancel: () => void;
|
|
11
16
|
};
|
|
@@ -1,46 +1,76 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
2
3
|
import { cn } from '../utils.js';
|
|
3
4
|
|
|
4
5
|
interface Props {
|
|
5
6
|
target?: Date | string | number;
|
|
7
|
+
value?: Date | string | number;
|
|
6
8
|
duration?: number;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
now?: number;
|
|
10
|
+
start?: boolean;
|
|
11
|
+
title?: string | Snippet;
|
|
12
|
+
format?: string;
|
|
9
13
|
onfinish?: () => void;
|
|
10
14
|
class?: string;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
let {
|
|
17
|
+
let {
|
|
18
|
+
target,
|
|
19
|
+
value,
|
|
20
|
+
duration,
|
|
21
|
+
now: initialNow,
|
|
22
|
+
start = true,
|
|
23
|
+
title,
|
|
24
|
+
format = 'full',
|
|
25
|
+
onfinish,
|
|
26
|
+
class: className = '',
|
|
27
|
+
}: Props = $props();
|
|
28
|
+
|
|
29
|
+
const effectiveTarget = $derived(value ?? target);
|
|
14
30
|
let remaining = $state(0);
|
|
15
31
|
let finished = $state(false);
|
|
16
32
|
|
|
17
33
|
function resolveRemaining(): number {
|
|
18
34
|
if (duration !== undefined) return Math.max(0, duration * 1000);
|
|
19
|
-
if (!
|
|
20
|
-
const end =
|
|
21
|
-
|
|
35
|
+
if (!effectiveTarget) return 0;
|
|
36
|
+
const end = effectiveTarget instanceof Date ? effectiveTarget.getTime() : new Date(effectiveTarget).getTime();
|
|
37
|
+
const current = initialNow !== undefined ? initialNow : Date.now();
|
|
38
|
+
return Number.isNaN(end) ? 0 : Math.max(0, end - current);
|
|
22
39
|
}
|
|
23
40
|
|
|
24
|
-
function formatTime(
|
|
25
|
-
const total = Math.max(0, Math.floor(
|
|
41
|
+
function formatTime(val: number): string {
|
|
42
|
+
const total = Math.max(0, Math.floor(val / 1000));
|
|
26
43
|
const days = Math.floor(total / 86400);
|
|
27
44
|
const hours = Math.floor((total % 86400) / 3600);
|
|
28
45
|
const minutes = Math.floor((total % 3600) / 60);
|
|
29
46
|
const seconds = total % 60;
|
|
30
47
|
const clock = [hours, minutes, seconds].map((part) => String(part).padStart(2, '0')).join(':');
|
|
31
|
-
|
|
48
|
+
|
|
49
|
+
if (format === 'clock') return clock;
|
|
50
|
+
if (format === 'full') return days > 0 ? `${days}d ${clock}` : clock;
|
|
51
|
+
|
|
52
|
+
let res = format;
|
|
53
|
+
res = res.replace(/DD/g, String(days).padStart(2, '0'));
|
|
54
|
+
res = res.replace(/\bD\b/g, String(days));
|
|
55
|
+
res = res.replace(/HH/g, String(hours).padStart(2, '0'));
|
|
56
|
+
res = res.replace(/\bH\b/g, String(hours));
|
|
57
|
+
res = res.replace(/mm/g, String(minutes).padStart(2, '0'));
|
|
58
|
+
res = res.replace(/\bm\b/g, String(minutes));
|
|
59
|
+
res = res.replace(/ss/g, String(seconds).padStart(2, '0'));
|
|
60
|
+
res = res.replace(/\bs\b/g, String(seconds));
|
|
61
|
+
return res;
|
|
32
62
|
}
|
|
33
63
|
|
|
34
64
|
$effect(() => {
|
|
35
65
|
const next = resolveRemaining();
|
|
36
66
|
remaining = next;
|
|
37
67
|
finished = next <= 0;
|
|
38
|
-
if (next <= 0) return;
|
|
68
|
+
if (next <= 0 || !start) return;
|
|
39
69
|
const deadline = Date.now() + next;
|
|
40
70
|
const timer = setInterval(() => {
|
|
41
|
-
const
|
|
42
|
-
remaining =
|
|
43
|
-
if (
|
|
71
|
+
const currentVal = Math.max(0, deadline - Date.now());
|
|
72
|
+
remaining = currentVal;
|
|
73
|
+
if (currentVal === 0) {
|
|
44
74
|
finished = true;
|
|
45
75
|
clearInterval(timer);
|
|
46
76
|
onfinish?.();
|
|
@@ -51,7 +81,11 @@
|
|
|
51
81
|
</script>
|
|
52
82
|
|
|
53
83
|
<div class={cn('svadmin-countdown', className)} data-finished={finished ? 'true' : 'false'}>
|
|
54
|
-
{#if title}
|
|
84
|
+
{#if title}
|
|
85
|
+
<div class="svadmin-countdown__title">
|
|
86
|
+
{#if typeof title === 'string'}{title}{:else}{@render title()}{/if}
|
|
87
|
+
</div>
|
|
88
|
+
{/if}
|
|
55
89
|
<time class="svadmin-countdown__value" aria-live="off">{formatTime(remaining)}</time>
|
|
56
90
|
<span class="svadmin-countdown__sr" aria-live="polite">{finished ? 'Countdown finished' : formatTime(remaining)}</span>
|
|
57
91
|
</div>
|
|
@@ -62,4 +96,4 @@
|
|
|
62
96
|
.svadmin-countdown__value { color: var(--foreground); font-size: var(--svadmin-text-heading); font-weight: 650; font-variant-numeric: tabular-nums; line-height: var(--svadmin-leading-tight); }
|
|
63
97
|
.svadmin-countdown[data-finished='true'] .svadmin-countdown__value { color: var(--muted-foreground); }
|
|
64
98
|
.svadmin-countdown__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
|
|
65
|
-
</style>
|
|
99
|
+
</style>
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
interface Props {
|
|
2
3
|
target?: Date | string | number;
|
|
4
|
+
value?: Date | string | number;
|
|
3
5
|
duration?: number;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
now?: number;
|
|
7
|
+
start?: boolean;
|
|
8
|
+
title?: string | Snippet;
|
|
9
|
+
format?: string;
|
|
6
10
|
onfinish?: () => void;
|
|
7
11
|
class?: string;
|
|
8
12
|
}
|
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
placeholder?: string;
|
|
25
25
|
/** 覆盖 ConfigProvider 与 i18n 的面板语言。不传则保持原有默认路径。 */
|
|
26
26
|
locale?: string;
|
|
27
|
+
/** Whether clear button is enabled (defaults to true) */
|
|
28
|
+
allowClear?: boolean;
|
|
29
|
+
/** Size tier */
|
|
30
|
+
size?: 'mini' | 'small' | 'default' | 'large';
|
|
31
|
+
/** Status validation styling */
|
|
32
|
+
status?: 'error' | 'warning' | 'normal';
|
|
33
|
+
defaultValue?: string | null;
|
|
34
|
+
onChange?: (value: string | null) => void;
|
|
27
35
|
onchange?: (value: string | null) => void;
|
|
28
36
|
}
|
|
29
37
|
|
|
@@ -31,13 +39,18 @@
|
|
|
31
39
|
|
|
32
40
|
let {
|
|
33
41
|
value = $bindable(null),
|
|
42
|
+
defaultValue,
|
|
34
43
|
panel = false,
|
|
35
44
|
picker = 'date',
|
|
36
45
|
presets = [],
|
|
37
46
|
placeholder,
|
|
38
47
|
locale: localeProp,
|
|
48
|
+
allowClear = true,
|
|
49
|
+
size = 'default',
|
|
50
|
+
status = 'normal',
|
|
39
51
|
disabled = false,
|
|
40
52
|
class: className,
|
|
53
|
+
onChange,
|
|
41
54
|
onchange,
|
|
42
55
|
...nativeProps
|
|
43
56
|
}: Props = $props();
|
|
@@ -59,6 +72,19 @@
|
|
|
59
72
|
});
|
|
60
73
|
const resolvedPlaceholder = $derived(placeholder ?? copy.selectDate);
|
|
61
74
|
const weekdays = $derived(weekdayLabels(activeLocale));
|
|
75
|
+
const emitChange = (val: string | null): void => {
|
|
76
|
+
onchange?.(val);
|
|
77
|
+
onChange?.(val);
|
|
78
|
+
};
|
|
79
|
+
let initialized = false;
|
|
80
|
+
$effect.pre(() => {
|
|
81
|
+
if (!initialized) {
|
|
82
|
+
initialized = true;
|
|
83
|
+
if (value === null && defaultValue !== undefined) {
|
|
84
|
+
value = defaultValue;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
62
88
|
let open = $state(false);
|
|
63
89
|
let viewMode = $state<'day' | 'month' | 'year'>(untrack(() => picker === 'year' ? 'year' : picker === 'month' ? 'month' : 'day'));
|
|
64
90
|
let viewDate = $state(initialView(value));
|
|
@@ -142,7 +168,7 @@
|
|
|
142
168
|
function chooseDay(iso: string, isDisabled: boolean): void {
|
|
143
169
|
if (isDisabled) return;
|
|
144
170
|
value = iso;
|
|
145
|
-
|
|
171
|
+
emitChange(iso);
|
|
146
172
|
open = false;
|
|
147
173
|
}
|
|
148
174
|
|
|
@@ -150,7 +176,7 @@
|
|
|
150
176
|
const next = new Date(viewDate.getFullYear(), month, 1);
|
|
151
177
|
if (picker === 'month') {
|
|
152
178
|
value = toMonth(next);
|
|
153
|
-
|
|
179
|
+
emitChange(value);
|
|
154
180
|
open = false;
|
|
155
181
|
return;
|
|
156
182
|
}
|
|
@@ -163,7 +189,7 @@
|
|
|
163
189
|
next.setFullYear(year);
|
|
164
190
|
if (picker === 'year') {
|
|
165
191
|
value = String(year);
|
|
166
|
-
|
|
192
|
+
emitChange(value);
|
|
167
193
|
open = false;
|
|
168
194
|
return;
|
|
169
195
|
}
|
|
@@ -174,13 +200,13 @@
|
|
|
174
200
|
function chooseQuarter(index: number): void {
|
|
175
201
|
const key = `${viewDate.getFullYear()}-Q${index + 1}`;
|
|
176
202
|
value = key;
|
|
177
|
-
|
|
203
|
+
emitChange(key);
|
|
178
204
|
open = false;
|
|
179
205
|
}
|
|
180
206
|
|
|
181
207
|
function clear(): void {
|
|
182
208
|
value = null;
|
|
183
|
-
|
|
209
|
+
emitChange(null);
|
|
184
210
|
open = false;
|
|
185
211
|
}
|
|
186
212
|
|
|
@@ -191,7 +217,7 @@
|
|
|
191
217
|
</script>
|
|
192
218
|
|
|
193
219
|
{#if !panel}
|
|
194
|
-
<DateTimeInput {...nativeProps} mode="date" bind:value {disabled} class={className} onchange={
|
|
220
|
+
<DateTimeInput {...nativeProps} mode="date" bind:value {defaultValue} {disabled} class={className} onchange={emitChange} />
|
|
195
221
|
{:else}
|
|
196
222
|
<Popover.Root bind:open>
|
|
197
223
|
<Popover.Trigger {disabled} class={cn('w-full', className)}>
|
|
@@ -202,6 +228,8 @@
|
|
|
202
228
|
disabled={disabled}
|
|
203
229
|
aria-label={nativeProps.ariaLabel}
|
|
204
230
|
class="svadmin-date-picker__trigger"
|
|
231
|
+
data-size={size !== 'default' ? size : undefined}
|
|
232
|
+
data-status={status !== 'normal' ? status : undefined}
|
|
205
233
|
>
|
|
206
234
|
<span class={value ? 'text-foreground' : 'text-muted-foreground'}>{formatValue(value) || resolvedPlaceholder}</span>
|
|
207
235
|
<ChevronRight class="h-4 w-4 rotate-90 opacity-50" />
|
|
@@ -259,11 +287,11 @@
|
|
|
259
287
|
{#if presets.length > 0}
|
|
260
288
|
<div class="mt-2 flex flex-wrap gap-1 border-t border-border pt-2">
|
|
261
289
|
{#each presets as preset (preset.value)}
|
|
262
|
-
<Button type="button" variant="ghost" size="sm" onclick={() => { value = preset.value;
|
|
290
|
+
<Button type="button" variant="ghost" size="sm" onclick={() => { value = preset.value; emitChange(preset.value); open = false; }}>{preset.label}</Button>
|
|
263
291
|
{/each}
|
|
264
292
|
</div>
|
|
265
293
|
{/if}
|
|
266
|
-
{#if value}
|
|
294
|
+
{#if value && allowClear && !disabled}
|
|
267
295
|
<div class="mt-1 flex justify-end border-t border-border pt-1">
|
|
268
296
|
<Button type="button" variant="ghost" size="sm" onclick={clear}>{copy.clear}</Button>
|
|
269
297
|
</div>
|
|
@@ -16,6 +16,14 @@ interface Props extends NativeProps {
|
|
|
16
16
|
placeholder?: string;
|
|
17
17
|
/** 覆盖 ConfigProvider 与 i18n 的面板语言。不传则保持原有默认路径。 */
|
|
18
18
|
locale?: string;
|
|
19
|
+
/** Whether clear button is enabled (defaults to true) */
|
|
20
|
+
allowClear?: boolean;
|
|
21
|
+
/** Size tier */
|
|
22
|
+
size?: 'mini' | 'small' | 'default' | 'large';
|
|
23
|
+
/** Status validation styling */
|
|
24
|
+
status?: 'error' | 'warning' | 'normal';
|
|
25
|
+
defaultValue?: string | null;
|
|
26
|
+
onChange?: (value: string | null) => void;
|
|
19
27
|
onchange?: (value: string | null) => void;
|
|
20
28
|
}
|
|
21
29
|
export type DatePickerProps = Props;
|
|
@@ -35,12 +35,20 @@
|
|
|
35
35
|
describedby?: string | undefined;
|
|
36
36
|
startAriaLabel?: string | undefined;
|
|
37
37
|
endAriaLabel?: string | undefined;
|
|
38
|
+
separator?: string | undefined;
|
|
39
|
+
placeholder?: [string, string] | string | undefined;
|
|
40
|
+
allowClear?: boolean | undefined;
|
|
41
|
+
size?: 'mini' | 'small' | 'default' | 'large' | undefined;
|
|
42
|
+
status?: 'error' | 'warning' | 'normal' | undefined;
|
|
38
43
|
class?: string | undefined;
|
|
44
|
+
defaultValue?: DateRangeInputValue | null | undefined;
|
|
45
|
+
onChange?: ((value: DateRangeInputValue) => void) | undefined;
|
|
39
46
|
onchange?: ((value: DateRangeInputValue) => void) | undefined;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
let {
|
|
43
50
|
value = $bindable({ start: null, end: null }),
|
|
51
|
+
defaultValue,
|
|
44
52
|
mode = 'date',
|
|
45
53
|
valueMode = 'civil',
|
|
46
54
|
timeZone,
|
|
@@ -60,11 +68,24 @@
|
|
|
60
68
|
describedby,
|
|
61
69
|
startAriaLabel,
|
|
62
70
|
endAriaLabel,
|
|
71
|
+
separator,
|
|
72
|
+
placeholder,
|
|
73
|
+
allowClear = true,
|
|
74
|
+
size = 'default',
|
|
75
|
+
status = 'normal',
|
|
63
76
|
class: className = '',
|
|
77
|
+
onChange,
|
|
64
78
|
onchange,
|
|
65
79
|
}: Props = $props();
|
|
66
80
|
|
|
67
81
|
const i18n = useTranslation();
|
|
82
|
+
const resolvedSeparator = $derived(separator ?? i18n.t('dateInput.to'));
|
|
83
|
+
const startPlaceholder = $derived(
|
|
84
|
+
Array.isArray(placeholder) ? placeholder[0] : typeof placeholder === 'string' ? placeholder : undefined
|
|
85
|
+
);
|
|
86
|
+
const endPlaceholder = $derived(
|
|
87
|
+
Array.isArray(placeholder) ? placeholder[1] : typeof placeholder === 'string' ? placeholder : undefined
|
|
88
|
+
);
|
|
68
89
|
const instantMode = $derived(valueMode === 'instant');
|
|
69
90
|
const startMax = $derived(!instantMode && value?.end && (!max || value.end < max) ? value.end : max);
|
|
70
91
|
const endMin = $derived(!instantMode && value?.start && (!min || value.start > min) ? value.start : min);
|
|
@@ -92,6 +113,25 @@
|
|
|
92
113
|
&& dateInputAllowed(end, mode, min, max, disabledDate);
|
|
93
114
|
}
|
|
94
115
|
|
|
116
|
+
const emitChange = (result: DateRangeInputValue): void => {
|
|
117
|
+
onchange?.(result);
|
|
118
|
+
onChange?.(result);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
let initialized = false;
|
|
122
|
+
$effect.pre(() => {
|
|
123
|
+
if (initialized) return;
|
|
124
|
+
initialized = true;
|
|
125
|
+
// 宿主显式传 null 时保持 null(清空语义),只有默认值才补齐。
|
|
126
|
+
if (value === null || value === undefined) {
|
|
127
|
+
if (defaultValue !== undefined && defaultValue !== null) value = { ...defaultValue };
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (value.start === null && value.end === null && defaultValue !== undefined && defaultValue !== null) {
|
|
131
|
+
value = { ...defaultValue };
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
95
135
|
function choosePreset(event: Event): void {
|
|
96
136
|
const select = event.currentTarget;
|
|
97
137
|
if (!(select instanceof HTMLSelectElement)) return;
|
|
@@ -100,17 +140,28 @@
|
|
|
100
140
|
if (disabled || !preset || !presetAllowed(preset)) return;
|
|
101
141
|
const result = { ...preset.value };
|
|
102
142
|
value = result;
|
|
103
|
-
|
|
143
|
+
emitChange(result);
|
|
104
144
|
}
|
|
105
145
|
|
|
106
146
|
function update(part: 'start' | 'end', next: string | null): void {
|
|
107
147
|
const result: DateRangeInputValue = { start: value?.start ?? null, end: value?.end ?? null, [part]: next };
|
|
108
148
|
value = result;
|
|
109
|
-
|
|
149
|
+
emitChange(result);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function clearRange(): void {
|
|
153
|
+
const result: DateRangeInputValue = { start: null, end: null };
|
|
154
|
+
value = result;
|
|
155
|
+
emitChange(result);
|
|
110
156
|
}
|
|
111
157
|
</script>
|
|
112
158
|
|
|
113
|
-
<div
|
|
159
|
+
<div
|
|
160
|
+
class={cn('flex items-center rounded-md', className)}
|
|
161
|
+
data-date-range-input
|
|
162
|
+
data-size={size !== 'default' ? size : undefined}
|
|
163
|
+
data-status={status !== 'normal' ? status : undefined}
|
|
164
|
+
>
|
|
114
165
|
{#if presets.length > 0}
|
|
115
166
|
<Select
|
|
116
167
|
value=""
|
|
@@ -135,6 +186,7 @@
|
|
|
135
186
|
timeZone, min, max: startMax, step, disabledDate,
|
|
136
187
|
id: startId, name: startName, describedby,
|
|
137
188
|
maxInstant: instantMode ? validInstant(value?.end) : undefined,
|
|
189
|
+
placeholder: startPlaceholder,
|
|
138
190
|
})}
|
|
139
191
|
{disabled}
|
|
140
192
|
{required}
|
|
@@ -142,7 +194,7 @@
|
|
|
142
194
|
ariaLabel={startAriaLabel ?? i18n.t('common.startDate')}
|
|
143
195
|
onchange={(next) => update('start', next)}
|
|
144
196
|
/>
|
|
145
|
-
<span aria-hidden="true">{
|
|
197
|
+
<span aria-hidden="true" class="mx-1.5 text-xs text-muted-foreground">{resolvedSeparator}</span>
|
|
146
198
|
<DateTimeInput
|
|
147
199
|
value={value?.end ?? null}
|
|
148
200
|
{mode}
|
|
@@ -152,6 +204,7 @@
|
|
|
152
204
|
timeZone, min: endMin, max, step, disabledDate,
|
|
153
205
|
id: endId, name: endName, describedby,
|
|
154
206
|
minInstant: instantMode ? validInstant(value?.start) : undefined,
|
|
207
|
+
placeholder: endPlaceholder,
|
|
155
208
|
})}
|
|
156
209
|
{disabled}
|
|
157
210
|
{required}
|
|
@@ -159,4 +212,14 @@
|
|
|
159
212
|
ariaLabel={endAriaLabel ?? i18n.t('common.endDate')}
|
|
160
213
|
onchange={(next) => update('end', next)}
|
|
161
214
|
/>
|
|
215
|
+
{#if allowClear && (value?.start || value?.end) && !disabled}
|
|
216
|
+
<button
|
|
217
|
+
type="button"
|
|
218
|
+
aria-label="Clear date range"
|
|
219
|
+
class="ml-1 text-muted-foreground hover:text-foreground text-xs p-1 rounded transition-colors"
|
|
220
|
+
onclick={clearRange}
|
|
221
|
+
>
|
|
222
|
+
✕
|
|
223
|
+
</button>
|
|
224
|
+
{/if}
|
|
162
225
|
</div>
|