@tabelhadev/tabelhawebui 0.28.4
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/LICENSE +661 -0
- package/README.md +222 -0
- package/README.pt-BR.md +217 -0
- package/dist/actions/click-outside.d.ts +3 -0
- package/dist/actions/click-outside.js +12 -0
- package/dist/actions/combobox-keyboard-nav.d.ts +9 -0
- package/dist/actions/combobox-keyboard-nav.js +28 -0
- package/dist/actions/focus-trap.d.ts +1 -0
- package/dist/actions/focus-trap.js +34 -0
- package/dist/actions/scroll-lock.d.ts +1 -0
- package/dist/actions/scroll-lock.js +17 -0
- package/dist/components/actions/Button.svelte +169 -0
- package/dist/components/actions/Button.svelte.d.ts +19 -0
- package/dist/components/appshell/AppShell.svelte +50 -0
- package/dist/components/appshell/AppShell.svelte.d.ts +19 -0
- package/dist/components/appshell/AppShellBottomNav.svelte +67 -0
- package/dist/components/appshell/AppShellBottomNav.svelte.d.ts +9 -0
- package/dist/components/appshell/AppShellContent.svelte +38 -0
- package/dist/components/appshell/AppShellContent.svelte.d.ts +10 -0
- package/dist/components/appshell/AppShellSidebar.svelte +196 -0
- package/dist/components/appshell/AppShellSidebar.svelte.d.ts +15 -0
- package/dist/components/appshell/types.d.ts +6 -0
- package/dist/components/appshell/types.js +1 -0
- package/dist/components/appshell/utils.d.ts +1 -0
- package/dist/components/appshell/utils.js +3 -0
- package/dist/components/card/Card.svelte +31 -0
- package/dist/components/card/Card.svelte.d.ts +9 -0
- package/dist/components/card/CardAction.svelte +57 -0
- package/dist/components/card/CardAction.svelte.d.ts +10 -0
- package/dist/components/card/CardContent.svelte +25 -0
- package/dist/components/card/CardContent.svelte.d.ts +8 -0
- package/dist/components/card/CardDescription.svelte +24 -0
- package/dist/components/card/CardDescription.svelte.d.ts +8 -0
- package/dist/components/card/CardFooter.svelte +25 -0
- package/dist/components/card/CardFooter.svelte.d.ts +8 -0
- package/dist/components/card/CardHeader.svelte +54 -0
- package/dist/components/card/CardHeader.svelte.d.ts +10 -0
- package/dist/components/card/CardTitle.svelte +25 -0
- package/dist/components/card/CardTitle.svelte.d.ts +8 -0
- package/dist/components/chat/ChatMessage.svelte +104 -0
- package/dist/components/chat/ChatMessage.svelte.d.ts +10 -0
- package/dist/components/choice/Listbox.svelte +183 -0
- package/dist/components/choice/Listbox.svelte.d.ts +15 -0
- package/dist/components/choice/MultiSelect.svelte +278 -0
- package/dist/components/choice/MultiSelect.svelte.d.ts +18 -0
- package/dist/components/choice/Rating.svelte +91 -0
- package/dist/components/choice/Rating.svelte.d.ts +12 -0
- package/dist/components/choice/Toggle.svelte +112 -0
- package/dist/components/choice/Toggle.svelte.d.ts +12 -0
- package/dist/components/feedback/Badge.svelte +66 -0
- package/dist/components/feedback/Badge.svelte.d.ts +9 -0
- package/dist/components/feedback/ErrorPage.svelte +99 -0
- package/dist/components/feedback/ErrorPage.svelte.d.ts +13 -0
- package/dist/components/feedback/Message.svelte +130 -0
- package/dist/components/feedback/Message.svelte.d.ts +14 -0
- package/dist/components/feedback/ProgressBar.svelte +69 -0
- package/dist/components/feedback/ProgressBar.svelte.d.ts +8 -0
- package/dist/components/feedback/Skeleton.svelte +47 -0
- package/dist/components/feedback/Skeleton.svelte.d.ts +9 -0
- package/dist/components/feedback/Status.svelte +75 -0
- package/dist/components/feedback/Status.svelte.d.ts +10 -0
- package/dist/components/feedback/StatusPill.svelte +94 -0
- package/dist/components/feedback/StatusPill.svelte.d.ts +13 -0
- package/dist/components/feedback/Toaster.svelte +122 -0
- package/dist/components/feedback/Toaster.svelte.d.ts +7 -0
- package/dist/components/feedback/Tooltip.svelte +126 -0
- package/dist/components/feedback/Tooltip.svelte.d.ts +10 -0
- package/dist/components/feedback/toast.svelte.d.ts +27 -0
- package/dist/components/feedback/toast.svelte.js +23 -0
- package/dist/components/forms/Checkbox.svelte +96 -0
- package/dist/components/forms/Checkbox.svelte.d.ts +11 -0
- package/dist/components/forms/DatePicker.svelte +372 -0
- package/dist/components/forms/DatePicker.svelte.d.ts +21 -0
- package/dist/components/forms/Field.svelte +47 -0
- package/dist/components/forms/Field.svelte.d.ts +11 -0
- package/dist/components/forms/FileUpload.svelte +504 -0
- package/dist/components/forms/FileUpload.svelte.d.ts +43 -0
- package/dist/components/forms/Input.svelte +93 -0
- package/dist/components/forms/Input.svelte.d.ts +9 -0
- package/dist/components/forms/Label.svelte +30 -0
- package/dist/components/forms/Label.svelte.d.ts +10 -0
- package/dist/components/forms/Radio.svelte +80 -0
- package/dist/components/forms/Radio.svelte.d.ts +11 -0
- package/dist/components/forms/Select.svelte +322 -0
- package/dist/components/forms/Select.svelte.d.ts +22 -0
- package/dist/components/forms/TagInput.svelte +336 -0
- package/dist/components/forms/TagInput.svelte.d.ts +16 -0
- package/dist/components/forms/Textarea.svelte +64 -0
- package/dist/components/forms/Textarea.svelte.d.ts +9 -0
- package/dist/components/landing/Landing.svelte +47 -0
- package/dist/components/landing/Landing.svelte.d.ts +8 -0
- package/dist/components/landing/LandingFeatures.svelte +92 -0
- package/dist/components/landing/LandingFeatures.svelte.d.ts +15 -0
- package/dist/components/landing/LandingHero.svelte +92 -0
- package/dist/components/landing/LandingHero.svelte.d.ts +13 -0
- package/dist/components/landing/LandingRoadmap.svelte +42 -0
- package/dist/components/landing/LandingRoadmap.svelte.d.ts +11 -0
- package/dist/components/landing/LandingSection.svelte +25 -0
- package/dist/components/landing/LandingSection.svelte.d.ts +9 -0
- package/dist/components/landing/LandingSectionHeading.svelte +19 -0
- package/dist/components/landing/LandingSectionHeading.svelte.d.ts +10 -0
- package/dist/components/landing/LandingSteps.svelte +100 -0
- package/dist/components/landing/LandingSteps.svelte.d.ts +13 -0
- package/dist/components/layout/BracketLink.svelte +41 -0
- package/dist/components/layout/BracketLink.svelte.d.ts +9 -0
- package/dist/components/layout/Divider.svelte +70 -0
- package/dist/components/layout/Divider.svelte.d.ts +9 -0
- package/dist/components/layout/Eyebrow.svelte +24 -0
- package/dist/components/layout/Eyebrow.svelte.d.ts +8 -0
- package/dist/components/layout/PageHeader.svelte +106 -0
- package/dist/components/layout/PageHeader.svelte.d.ts +15 -0
- package/dist/components/layout/PageSeo.svelte +34 -0
- package/dist/components/layout/PageSeo.svelte.d.ts +10 -0
- package/dist/components/layout/PageShell.svelte +25 -0
- package/dist/components/layout/PageShell.svelte.d.ts +8 -0
- package/dist/components/layout/Panel.svelte +105 -0
- package/dist/components/layout/Panel.svelte.d.ts +12 -0
- package/dist/components/layout/Prose.svelte +101 -0
- package/dist/components/layout/Prose.svelte.d.ts +7 -0
- package/dist/components/layout/RuleCard.svelte +63 -0
- package/dist/components/layout/RuleCard.svelte.d.ts +13 -0
- package/dist/components/layout/SectionHeading.svelte +57 -0
- package/dist/components/layout/SectionHeading.svelte.d.ts +10 -0
- package/dist/components/layout/StatTile.svelte +76 -0
- package/dist/components/layout/StatTile.svelte.d.ts +12 -0
- package/dist/components/layout/TerminalWindow.svelte +81 -0
- package/dist/components/layout/TerminalWindow.svelte.d.ts +9 -0
- package/dist/components/layout/Wordmark.svelte +26 -0
- package/dist/components/layout/Wordmark.svelte.d.ts +8 -0
- package/dist/components/list/List.svelte +40 -0
- package/dist/components/list/List.svelte.d.ts +13 -0
- package/dist/components/list/ListItem.svelte +81 -0
- package/dist/components/list/ListItem.svelte.d.ts +13 -0
- package/dist/components/marketing/MarketingShell.svelte +170 -0
- package/dist/components/marketing/MarketingShell.svelte.d.ts +23 -0
- package/dist/components/marketing/MarketingShellFooter.svelte +92 -0
- package/dist/components/marketing/MarketingShellFooter.svelte.d.ts +14 -0
- package/dist/components/navigation/Accordion.svelte +110 -0
- package/dist/components/navigation/Accordion.svelte.d.ts +15 -0
- package/dist/components/navigation/Carousel.svelte +115 -0
- package/dist/components/navigation/Carousel.svelte.d.ts +12 -0
- package/dist/components/navigation/InstructionStep.svelte +115 -0
- package/dist/components/navigation/InstructionStep.svelte.d.ts +10 -0
- package/dist/components/navigation/InstructionSteps.svelte +39 -0
- package/dist/components/navigation/InstructionSteps.svelte.d.ts +8 -0
- package/dist/components/navigation/Nav.svelte +102 -0
- package/dist/components/navigation/Nav.svelte.d.ts +14 -0
- package/dist/components/navigation/Stepper.svelte +112 -0
- package/dist/components/navigation/Stepper.svelte.d.ts +12 -0
- package/dist/components/navigation/TabCard.svelte +62 -0
- package/dist/components/navigation/TabCard.svelte.d.ts +10 -0
- package/dist/components/navigation/Tabs.svelte +83 -0
- package/dist/components/navigation/Tabs.svelte.d.ts +12 -0
- package/dist/components/navigation/ThemeToggle.svelte +118 -0
- package/dist/components/navigation/ThemeToggle.svelte.d.ts +20 -0
- package/dist/components/overlay/Dialog.svelte +200 -0
- package/dist/components/overlay/Dialog.svelte.d.ts +19 -0
- package/dist/components/overlay/DialogActions.svelte +50 -0
- package/dist/components/overlay/DialogActions.svelte.d.ts +9 -0
- package/dist/components/overlay/Dropdown.svelte +110 -0
- package/dist/components/overlay/Dropdown.svelte.d.ts +10 -0
- package/dist/components/overlay/FloatingActionPill.svelte +96 -0
- package/dist/components/overlay/FloatingActionPill.svelte.d.ts +14 -0
- package/dist/components/overlay/Sidebar.svelte +258 -0
- package/dist/components/overlay/Sidebar.svelte.d.ts +18 -0
- package/dist/components/table/Table.svelte +550 -0
- package/dist/components/table/Table.svelte.d.ts +42 -0
- package/dist/components/timeline/Timeline.svelte +25 -0
- package/dist/components/timeline/Timeline.svelte.d.ts +8 -0
- package/dist/components/timeline/TimelineItem.svelte +220 -0
- package/dist/components/timeline/TimelineItem.svelte.d.ts +18 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.js +149 -0
- package/dist/theme/theme.css +348 -0
- package/package.json +52 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
label,
|
|
7
|
+
error,
|
|
8
|
+
children,
|
|
9
|
+
class: className = '',
|
|
10
|
+
...rest
|
|
11
|
+
}: {
|
|
12
|
+
label: string;
|
|
13
|
+
error?: string;
|
|
14
|
+
children: Snippet;
|
|
15
|
+
class?: string;
|
|
16
|
+
} & HTMLAttributes<HTMLDivElement> = $props();
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div class="twui-field {className}" {...rest}>
|
|
20
|
+
<span class="twui-field-label">{label}</span>
|
|
21
|
+
{@render children()}
|
|
22
|
+
{#if error}
|
|
23
|
+
<p class="twui-field-error" role="alert">{error}</p>
|
|
24
|
+
{/if}
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
<style>
|
|
28
|
+
.twui-field {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: 6px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.twui-field-label {
|
|
35
|
+
font-family: var(--twui-font-mono);
|
|
36
|
+
font-size: 13px;
|
|
37
|
+
font-weight: 500;
|
|
38
|
+
color: var(--twui-ink);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.twui-field-error {
|
|
42
|
+
margin: 0;
|
|
43
|
+
font-family: var(--twui-font-mono);
|
|
44
|
+
font-size: 12px;
|
|
45
|
+
color: var(--twui-danger);
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
label: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
children: Snippet;
|
|
7
|
+
class?: string;
|
|
8
|
+
} & HTMLAttributes<HTMLDivElement>;
|
|
9
|
+
declare const Field: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
|
+
type Field = ReturnType<typeof Field>;
|
|
11
|
+
export default Field;
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type FileUploadMode = 'basic' | 'advanced';
|
|
3
|
+
export type FileUploadErrorKind = 'size' | 'type' | 'limit';
|
|
4
|
+
export type FileUploadError = { kind: FileUploadErrorKind; file: File };
|
|
5
|
+
export type FileUploadProgress = (file: File, percent: number) => void;
|
|
6
|
+
export type FileUploadHandler = (
|
|
7
|
+
files: File[],
|
|
8
|
+
report: FileUploadProgress
|
|
9
|
+
) => void | Promise<void>;
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import type { Snippet } from 'svelte';
|
|
14
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
15
|
+
import ProgressBar from '../feedback/ProgressBar.svelte';
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
mode = 'advanced',
|
|
19
|
+
accept = '',
|
|
20
|
+
maxFileSize = undefined,
|
|
21
|
+
fileLimit = undefined,
|
|
22
|
+
multiple = true,
|
|
23
|
+
auto = false,
|
|
24
|
+
disabled = false,
|
|
25
|
+
invalid = false,
|
|
26
|
+
customUpload = false,
|
|
27
|
+
uploadHandler = undefined,
|
|
28
|
+
files = $bindable([]),
|
|
29
|
+
chooseLabel = 'Escolher arquivos',
|
|
30
|
+
uploadLabel = 'Enviar',
|
|
31
|
+
cancelLabel = 'Cancelar',
|
|
32
|
+
showUploadButton = false,
|
|
33
|
+
showCancelButton = false,
|
|
34
|
+
onSelect = undefined,
|
|
35
|
+
onRemove = undefined,
|
|
36
|
+
onClear = undefined,
|
|
37
|
+
onProgress = undefined,
|
|
38
|
+
onUpload = undefined,
|
|
39
|
+
onError = undefined,
|
|
40
|
+
empty = undefined,
|
|
41
|
+
content = undefined,
|
|
42
|
+
file = undefined,
|
|
43
|
+
header = undefined,
|
|
44
|
+
toolbar = undefined,
|
|
45
|
+
class: className = '',
|
|
46
|
+
...rest
|
|
47
|
+
}: {
|
|
48
|
+
mode?: FileUploadMode;
|
|
49
|
+
accept?: string;
|
|
50
|
+
maxFileSize?: number;
|
|
51
|
+
fileLimit?: number;
|
|
52
|
+
multiple?: boolean;
|
|
53
|
+
auto?: boolean;
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
invalid?: boolean;
|
|
56
|
+
customUpload?: boolean;
|
|
57
|
+
uploadHandler?: FileUploadHandler;
|
|
58
|
+
files?: File[];
|
|
59
|
+
chooseLabel?: string;
|
|
60
|
+
uploadLabel?: string;
|
|
61
|
+
cancelLabel?: string;
|
|
62
|
+
showUploadButton?: boolean;
|
|
63
|
+
showCancelButton?: boolean;
|
|
64
|
+
onSelect?: (chosen: File[]) => void;
|
|
65
|
+
onRemove?: (file: File) => void;
|
|
66
|
+
onClear?: () => void;
|
|
67
|
+
onProgress?: (file: File, percent: number) => void;
|
|
68
|
+
onUpload?: (files: File[]) => void;
|
|
69
|
+
onError?: (error: FileUploadError) => void;
|
|
70
|
+
empty?: Snippet;
|
|
71
|
+
content?: Snippet;
|
|
72
|
+
file?: Snippet<[file: File, progress: number | undefined]>;
|
|
73
|
+
header?: Snippet;
|
|
74
|
+
toolbar?: Snippet;
|
|
75
|
+
class?: string;
|
|
76
|
+
} & HTMLAttributes<HTMLDivElement> = $props();
|
|
77
|
+
|
|
78
|
+
let inputEl: HTMLInputElement | undefined = $state();
|
|
79
|
+
let dragDepth = 0;
|
|
80
|
+
let dragActive = $state(false);
|
|
81
|
+
let uploading = $state(false);
|
|
82
|
+
const progress = $state(new Map<File, number>());
|
|
83
|
+
|
|
84
|
+
function matchesAccept(file: File): boolean {
|
|
85
|
+
const patterns = accept
|
|
86
|
+
.split(',')
|
|
87
|
+
.map((pattern) => pattern.trim().toLowerCase())
|
|
88
|
+
.filter(Boolean);
|
|
89
|
+
if (patterns.length === 0) return true;
|
|
90
|
+
const name = file.name.toLowerCase();
|
|
91
|
+
const type = (file.type || '').toLowerCase();
|
|
92
|
+
return patterns.some((pattern) => {
|
|
93
|
+
if (pattern === '.*' || pattern === '*/*') return true;
|
|
94
|
+
if (pattern.startsWith('.')) return name.endsWith(pattern);
|
|
95
|
+
if (pattern.endsWith('/*')) return type.startsWith(pattern.slice(0, -1));
|
|
96
|
+
return type === pattern;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function validate(file: File): FileUploadError | null {
|
|
101
|
+
if (maxFileSize !== undefined && file.size > maxFileSize) {
|
|
102
|
+
return { kind: 'size', file };
|
|
103
|
+
}
|
|
104
|
+
if (accept && !matchesAccept(file)) {
|
|
105
|
+
return { kind: 'type', file };
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function openPicker() {
|
|
111
|
+
if (disabled) return;
|
|
112
|
+
inputEl?.click();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function addFiles(incoming: File[] | FileList) {
|
|
116
|
+
if (disabled) return;
|
|
117
|
+
const candidates = multiple
|
|
118
|
+
? Array.from(incoming)
|
|
119
|
+
: [Array.from(incoming)[0]].filter((f): f is File => f !== undefined);
|
|
120
|
+
const accepted: File[] = [];
|
|
121
|
+
for (const candidate of candidates) {
|
|
122
|
+
if (fileLimit !== undefined && files.length + accepted.length >= fileLimit) {
|
|
123
|
+
onError?.({ kind: 'limit', file: candidate });
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const error = validate(candidate);
|
|
127
|
+
if (error) {
|
|
128
|
+
onError?.(error);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
accepted.push(candidate);
|
|
132
|
+
}
|
|
133
|
+
if (accepted.length === 0) return;
|
|
134
|
+
files = [...files, ...accepted];
|
|
135
|
+
onSelect?.(accepted);
|
|
136
|
+
if (auto && customUpload && uploadHandler) {
|
|
137
|
+
startUpload(accepted);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function onInputChange(event: Event) {
|
|
142
|
+
const input = event.currentTarget as HTMLInputElement;
|
|
143
|
+
if (input.files) addFiles(input.files);
|
|
144
|
+
input.value = '';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function removeFile(file: File) {
|
|
148
|
+
files = files.filter((item) => item !== file);
|
|
149
|
+
progress.delete(file);
|
|
150
|
+
onRemove?.(file);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function clearFiles() {
|
|
154
|
+
files = [];
|
|
155
|
+
progress.clear();
|
|
156
|
+
onClear?.();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function startUpload(toUpload: File[]) {
|
|
160
|
+
if (!customUpload || !uploadHandler) return;
|
|
161
|
+
uploading = true;
|
|
162
|
+
try {
|
|
163
|
+
for (const item of toUpload) progress.set(item, 0);
|
|
164
|
+
await uploadHandler(toUpload, (file, percent) => {
|
|
165
|
+
progress.set(file, percent);
|
|
166
|
+
onProgress?.(file, percent);
|
|
167
|
+
});
|
|
168
|
+
} finally {
|
|
169
|
+
uploading = false;
|
|
170
|
+
}
|
|
171
|
+
onUpload?.(toUpload);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function onDragEnter(event: DragEvent) {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
dragDepth += 1;
|
|
177
|
+
dragActive = true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function onDragOver(event: DragEvent) {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
if (event.dataTransfer) event.dataTransfer.dropEffect = 'copy';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function onDragLeave(event: DragEvent) {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
dragDepth -= 1;
|
|
188
|
+
if (dragDepth <= 0) {
|
|
189
|
+
dragDepth = 0;
|
|
190
|
+
dragActive = false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function onDrop(event: DragEvent) {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
dragDepth = 0;
|
|
197
|
+
dragActive = false;
|
|
198
|
+
if (disabled) return;
|
|
199
|
+
if (event.dataTransfer?.files.length) addFiles(event.dataTransfer.files);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function formatSize(bytes: number): string {
|
|
203
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
204
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
205
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
206
|
+
}
|
|
207
|
+
</script>
|
|
208
|
+
|
|
209
|
+
<div
|
|
210
|
+
class="twui-fileupload twui-fileupload-{mode} {className}"
|
|
211
|
+
{...rest}
|
|
212
|
+
>
|
|
213
|
+
{#if header}
|
|
214
|
+
<div class="twui-fileupload-header">{@render header()}</div>
|
|
215
|
+
{/if}
|
|
216
|
+
|
|
217
|
+
<button
|
|
218
|
+
type="button"
|
|
219
|
+
class="twui-fileupload-dropzone {dragActive ? 'twui-fileupload-dropzone-active' : ''} {invalid ? 'twui-fileupload-invalid' : ''}"
|
|
220
|
+
disabled={disabled}
|
|
221
|
+
onclick={openPicker}
|
|
222
|
+
ondragenter={onDragEnter}
|
|
223
|
+
ondragover={onDragOver}
|
|
224
|
+
ondragleave={onDragLeave}
|
|
225
|
+
ondrop={onDrop}
|
|
226
|
+
>
|
|
227
|
+
{#if files.length === 0}
|
|
228
|
+
{#if empty}
|
|
229
|
+
{@render empty()}
|
|
230
|
+
{:else}
|
|
231
|
+
<span class="twui-fileupload-choose-label">{chooseLabel}</span>
|
|
232
|
+
{/if}
|
|
233
|
+
{:else if content}
|
|
234
|
+
{@render content()}
|
|
235
|
+
{:else}
|
|
236
|
+
<span class="twui-fileupload-choose-label">{chooseLabel}</span>
|
|
237
|
+
{/if}
|
|
238
|
+
{#if mode === 'basic' && files.length > 0}
|
|
239
|
+
<span class="twui-fileupload-count" aria-hidden="true">{files.length}</span>
|
|
240
|
+
{/if}
|
|
241
|
+
</button>
|
|
242
|
+
|
|
243
|
+
{#if mode === 'advanced' && files.length > 0}
|
|
244
|
+
<ul class="twui-fileupload-list">
|
|
245
|
+
{#each files as selected (selected)}
|
|
246
|
+
{#if file}
|
|
247
|
+
{@render file(selected, progress.get(selected))}
|
|
248
|
+
{:else}
|
|
249
|
+
<li class="twui-fileupload-item">
|
|
250
|
+
<div class="twui-fileupload-item-info">
|
|
251
|
+
<span class="twui-fileupload-item-name">{selected.name}</span>
|
|
252
|
+
<span class="twui-fileupload-item-size">{formatSize(selected.size)}</span>
|
|
253
|
+
</div>
|
|
254
|
+
{#if progress.get(selected) !== undefined}
|
|
255
|
+
<ProgressBar value={progress.get(selected)} label={false} />
|
|
256
|
+
{/if}
|
|
257
|
+
<button
|
|
258
|
+
type="button"
|
|
259
|
+
class="twui-fileupload-item-remove"
|
|
260
|
+
disabled={disabled}
|
|
261
|
+
aria-label={'Remover ' + selected.name}
|
|
262
|
+
onclick={() => removeFile(selected)}
|
|
263
|
+
>
|
|
264
|
+
✕
|
|
265
|
+
</button>
|
|
266
|
+
</li>
|
|
267
|
+
{/if}
|
|
268
|
+
{/each}
|
|
269
|
+
</ul>
|
|
270
|
+
{/if}
|
|
271
|
+
|
|
272
|
+
{#if toolbar}
|
|
273
|
+
<div class="twui-fileupload-toolbar">{@render toolbar()}</div>
|
|
274
|
+
{/if}
|
|
275
|
+
|
|
276
|
+
{#if mode === 'advanced' && files.length > 0 && (showUploadButton || showCancelButton)}
|
|
277
|
+
<div class="twui-fileupload-actions">
|
|
278
|
+
{#if showUploadButton}
|
|
279
|
+
<button
|
|
280
|
+
type="button"
|
|
281
|
+
class="twui-fileupload-upload"
|
|
282
|
+
disabled={disabled || uploading}
|
|
283
|
+
onclick={() => startUpload(files)}
|
|
284
|
+
>
|
|
285
|
+
{uploadLabel}
|
|
286
|
+
</button>
|
|
287
|
+
{/if}
|
|
288
|
+
{#if showCancelButton}
|
|
289
|
+
<button
|
|
290
|
+
type="button"
|
|
291
|
+
class="twui-fileupload-cancel"
|
|
292
|
+
disabled={disabled}
|
|
293
|
+
onclick={clearFiles}
|
|
294
|
+
>
|
|
295
|
+
{cancelLabel}
|
|
296
|
+
</button>
|
|
297
|
+
{/if}
|
|
298
|
+
</div>
|
|
299
|
+
{/if}
|
|
300
|
+
|
|
301
|
+
<input
|
|
302
|
+
bind:this={inputEl}
|
|
303
|
+
class="twui-fileupload-input"
|
|
304
|
+
type="file"
|
|
305
|
+
{accept}
|
|
306
|
+
{multiple}
|
|
307
|
+
disabled={disabled}
|
|
308
|
+
tabindex="-1"
|
|
309
|
+
aria-invalid={invalid}
|
|
310
|
+
onchange={onInputChange}
|
|
311
|
+
/>
|
|
312
|
+
</div>
|
|
313
|
+
|
|
314
|
+
<style>
|
|
315
|
+
.twui-fileupload {
|
|
316
|
+
display: flex;
|
|
317
|
+
flex-direction: column;
|
|
318
|
+
gap: 8px;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.twui-fileupload-dropzone {
|
|
322
|
+
display: flex;
|
|
323
|
+
flex-direction: column;
|
|
324
|
+
align-items: center;
|
|
325
|
+
justify-content: center;
|
|
326
|
+
gap: 6px;
|
|
327
|
+
width: 100%;
|
|
328
|
+
min-height: 96px;
|
|
329
|
+
padding: 16px;
|
|
330
|
+
border: 1px dashed var(--twui-rule);
|
|
331
|
+
background: var(--twui-paper);
|
|
332
|
+
font-family: var(--twui-font-mono);
|
|
333
|
+
font-size: 14px;
|
|
334
|
+
color: var(--twui-ink);
|
|
335
|
+
text-align: center;
|
|
336
|
+
cursor: pointer;
|
|
337
|
+
outline: none;
|
|
338
|
+
transition:
|
|
339
|
+
border-color 0.15s ease,
|
|
340
|
+
background 0.15s ease,
|
|
341
|
+
color 0.15s ease,
|
|
342
|
+
box-shadow 0.15s ease;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.twui-fileupload-dropzone:hover,
|
|
346
|
+
.twui-fileupload-dropzone:focus-visible {
|
|
347
|
+
border-color: var(--twui-accent);
|
|
348
|
+
color: var(--twui-accent);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
.twui-fileupload-dropzone-active {
|
|
352
|
+
border-color: var(--twui-accent);
|
|
353
|
+
background: var(--twui-accent-soft);
|
|
354
|
+
color: var(--twui-accent);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.twui-fileupload-dropzone:disabled {
|
|
358
|
+
opacity: 0.5;
|
|
359
|
+
cursor: not-allowed;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.twui-fileupload-invalid,
|
|
363
|
+
.twui-fileupload-invalid:hover,
|
|
364
|
+
.twui-fileupload-invalid:focus-visible {
|
|
365
|
+
border-color: var(--twui-danger);
|
|
366
|
+
color: var(--twui-danger);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.twui-fileupload-choose-label {
|
|
370
|
+
font-family: var(--twui-font-mono);
|
|
371
|
+
font-size: 13px;
|
|
372
|
+
font-weight: 500;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
.twui-fileupload-count {
|
|
376
|
+
display: inline-flex;
|
|
377
|
+
align-items: center;
|
|
378
|
+
justify-content: center;
|
|
379
|
+
min-width: 18px;
|
|
380
|
+
height: 18px;
|
|
381
|
+
padding: 0 4px;
|
|
382
|
+
border: 1px solid var(--twui-accent);
|
|
383
|
+
border-radius: 9px;
|
|
384
|
+
font-size: 10px;
|
|
385
|
+
line-height: 1;
|
|
386
|
+
color: var(--twui-accent);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.twui-fileupload-basic .twui-fileupload-dropzone {
|
|
390
|
+
display: inline-flex;
|
|
391
|
+
flex-direction: row;
|
|
392
|
+
width: auto;
|
|
393
|
+
min-height: 0;
|
|
394
|
+
padding: 8px 12px;
|
|
395
|
+
border-style: solid;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
.twui-fileupload-list {
|
|
399
|
+
display: flex;
|
|
400
|
+
flex-direction: column;
|
|
401
|
+
gap: 6px;
|
|
402
|
+
padding: 0;
|
|
403
|
+
margin: 0;
|
|
404
|
+
list-style: none;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.twui-fileupload-item {
|
|
408
|
+
display: flex;
|
|
409
|
+
align-items: center;
|
|
410
|
+
gap: 10px;
|
|
411
|
+
padding: 8px 10px;
|
|
412
|
+
border: 1px solid var(--twui-rule);
|
|
413
|
+
background: var(--twui-paper);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
.twui-fileupload-item-info {
|
|
417
|
+
display: flex;
|
|
418
|
+
flex-direction: column;
|
|
419
|
+
gap: 2px;
|
|
420
|
+
min-width: 0;
|
|
421
|
+
flex: 1;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
.twui-fileupload-item-name {
|
|
425
|
+
font-family: var(--twui-font-mono);
|
|
426
|
+
font-size: 12px;
|
|
427
|
+
color: var(--twui-ink);
|
|
428
|
+
overflow: hidden;
|
|
429
|
+
text-overflow: ellipsis;
|
|
430
|
+
white-space: nowrap;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
.twui-fileupload-item-size {
|
|
434
|
+
font-family: var(--twui-font-mono);
|
|
435
|
+
font-size: 10px;
|
|
436
|
+
color: var(--twui-ink-faint);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
.twui-fileupload-item-remove {
|
|
440
|
+
display: inline-flex;
|
|
441
|
+
align-items: center;
|
|
442
|
+
justify-content: center;
|
|
443
|
+
flex-shrink: 0;
|
|
444
|
+
width: 22px;
|
|
445
|
+
height: 22px;
|
|
446
|
+
padding: 0;
|
|
447
|
+
border: 1px solid var(--twui-rule);
|
|
448
|
+
background: var(--twui-paper-raised);
|
|
449
|
+
font-family: var(--twui-font-mono);
|
|
450
|
+
font-size: 10px;
|
|
451
|
+
line-height: 1;
|
|
452
|
+
color: var(--twui-ink-soft);
|
|
453
|
+
cursor: pointer;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.twui-fileupload-item-remove:hover {
|
|
457
|
+
border-color: var(--twui-danger);
|
|
458
|
+
color: var(--twui-danger);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
.twui-fileupload-actions {
|
|
462
|
+
display: flex;
|
|
463
|
+
gap: 8px;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
.twui-fileupload-upload,
|
|
467
|
+
.twui-fileupload-cancel {
|
|
468
|
+
padding: 6px 12px;
|
|
469
|
+
border: 1px solid var(--twui-rule);
|
|
470
|
+
background: var(--twui-paper-raised);
|
|
471
|
+
font-family: var(--twui-font-mono);
|
|
472
|
+
font-size: 12px;
|
|
473
|
+
color: var(--twui-ink);
|
|
474
|
+
cursor: pointer;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
.twui-fileupload-upload:hover {
|
|
478
|
+
border-color: var(--twui-accent);
|
|
479
|
+
color: var(--twui-accent);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.twui-fileupload-cancel:hover {
|
|
483
|
+
border-color: var(--twui-danger);
|
|
484
|
+
color: var(--twui-danger);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
.twui-fileupload-upload:disabled,
|
|
488
|
+
.twui-fileupload-cancel:disabled {
|
|
489
|
+
opacity: 0.5;
|
|
490
|
+
cursor: not-allowed;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
.twui-fileupload-input {
|
|
494
|
+
position: absolute;
|
|
495
|
+
width: 1px;
|
|
496
|
+
height: 1px;
|
|
497
|
+
padding: 0;
|
|
498
|
+
margin: -1px;
|
|
499
|
+
overflow: hidden;
|
|
500
|
+
clip-path: inset(50%);
|
|
501
|
+
border: 0;
|
|
502
|
+
white-space: nowrap;
|
|
503
|
+
}
|
|
504
|
+
</style>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type FileUploadMode = 'basic' | 'advanced';
|
|
2
|
+
export type FileUploadErrorKind = 'size' | 'type' | 'limit';
|
|
3
|
+
export type FileUploadError = {
|
|
4
|
+
kind: FileUploadErrorKind;
|
|
5
|
+
file: File;
|
|
6
|
+
};
|
|
7
|
+
export type FileUploadProgress = (file: File, percent: number) => void;
|
|
8
|
+
export type FileUploadHandler = (files: File[], report: FileUploadProgress) => void | Promise<void>;
|
|
9
|
+
import type { Snippet } from 'svelte';
|
|
10
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
11
|
+
type $$ComponentProps = {
|
|
12
|
+
mode?: FileUploadMode;
|
|
13
|
+
accept?: string;
|
|
14
|
+
maxFileSize?: number;
|
|
15
|
+
fileLimit?: number;
|
|
16
|
+
multiple?: boolean;
|
|
17
|
+
auto?: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
invalid?: boolean;
|
|
20
|
+
customUpload?: boolean;
|
|
21
|
+
uploadHandler?: FileUploadHandler;
|
|
22
|
+
files?: File[];
|
|
23
|
+
chooseLabel?: string;
|
|
24
|
+
uploadLabel?: string;
|
|
25
|
+
cancelLabel?: string;
|
|
26
|
+
showUploadButton?: boolean;
|
|
27
|
+
showCancelButton?: boolean;
|
|
28
|
+
onSelect?: (chosen: File[]) => void;
|
|
29
|
+
onRemove?: (file: File) => void;
|
|
30
|
+
onClear?: () => void;
|
|
31
|
+
onProgress?: (file: File, percent: number) => void;
|
|
32
|
+
onUpload?: (files: File[]) => void;
|
|
33
|
+
onError?: (error: FileUploadError) => void;
|
|
34
|
+
empty?: Snippet;
|
|
35
|
+
content?: Snippet;
|
|
36
|
+
file?: Snippet<[file: File, progress: number | undefined]>;
|
|
37
|
+
header?: Snippet;
|
|
38
|
+
toolbar?: Snippet;
|
|
39
|
+
class?: string;
|
|
40
|
+
} & HTMLAttributes<HTMLDivElement>;
|
|
41
|
+
declare const FileUpload: import("svelte").Component<$$ComponentProps, {}, "files">;
|
|
42
|
+
type FileUpload = ReturnType<typeof FileUpload>;
|
|
43
|
+
export default FileUpload;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
|
+
|
|
4
|
+
let {
|
|
5
|
+
class: className = '',
|
|
6
|
+
value = $bindable(''),
|
|
7
|
+
files = $bindable(undefined),
|
|
8
|
+
type = 'text',
|
|
9
|
+
invalid = false,
|
|
10
|
+
...rest
|
|
11
|
+
}: HTMLInputAttributes & {
|
|
12
|
+
value?: string;
|
|
13
|
+
files?: FileList | undefined;
|
|
14
|
+
invalid?: boolean;
|
|
15
|
+
} = $props();
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
{#if type === 'file'}
|
|
19
|
+
<input
|
|
20
|
+
{...rest}
|
|
21
|
+
type="file"
|
|
22
|
+
bind:files
|
|
23
|
+
aria-invalid={invalid}
|
|
24
|
+
class="twui-input twui-input-file {invalid ? 'twui-input-invalid' : ''} {className}"
|
|
25
|
+
/>
|
|
26
|
+
{:else}
|
|
27
|
+
<input
|
|
28
|
+
{...rest}
|
|
29
|
+
{type}
|
|
30
|
+
value={value}
|
|
31
|
+
oninput={(e) => (value = e.currentTarget.value)}
|
|
32
|
+
aria-invalid={invalid}
|
|
33
|
+
class="twui-input {invalid ? 'twui-input-invalid' : ''} {className}"
|
|
34
|
+
/>
|
|
35
|
+
{/if}
|
|
36
|
+
|
|
37
|
+
<style>
|
|
38
|
+
.twui-input {
|
|
39
|
+
width: 100%;
|
|
40
|
+
padding: 8px 12px;
|
|
41
|
+
border: 1px solid var(--twui-rule);
|
|
42
|
+
background: var(--twui-paper);
|
|
43
|
+
font-family: var(--twui-font-mono);
|
|
44
|
+
font-size: 14px;
|
|
45
|
+
color: var(--twui-ink);
|
|
46
|
+
outline: none;
|
|
47
|
+
transition:
|
|
48
|
+
border-color 0.15s ease,
|
|
49
|
+
box-shadow 0.15s ease;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.twui-input::placeholder {
|
|
53
|
+
color: var(--twui-ink-faint);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.twui-input:focus-visible {
|
|
57
|
+
border-color: var(--twui-accent);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.twui-input:disabled {
|
|
61
|
+
opacity: 0.5;
|
|
62
|
+
cursor: not-allowed;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.twui-input-invalid {
|
|
66
|
+
border-color: var(--twui-danger);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.twui-input-invalid:focus-visible {
|
|
70
|
+
border-color: var(--twui-danger);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.twui-input-file {
|
|
74
|
+
display: inline-flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.twui-input-file::file-selector-button {
|
|
79
|
+
margin-right: 8px;
|
|
80
|
+
padding: 4px 10px;
|
|
81
|
+
border: 1px solid var(--twui-rule);
|
|
82
|
+
background: var(--twui-paper-raised);
|
|
83
|
+
font-family: var(--twui-font-mono);
|
|
84
|
+
font-size: 12px;
|
|
85
|
+
color: var(--twui-ink);
|
|
86
|
+
cursor: pointer;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.twui-input-file::file-selector-button:hover {
|
|
90
|
+
border-color: var(--twui-accent);
|
|
91
|
+
color: var(--twui-accent);
|
|
92
|
+
}
|
|
93
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
2
|
+
type $$ComponentProps = HTMLInputAttributes & {
|
|
3
|
+
value?: string;
|
|
4
|
+
files?: FileList | undefined;
|
|
5
|
+
invalid?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const Input: import("svelte").Component<$$ComponentProps, {}, "value" | "files">;
|
|
8
|
+
type Input = ReturnType<typeof Input>;
|
|
9
|
+
export default Input;
|