svelte-comp 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of svelte-comp might be problematic. Click here for more details.
- package/README.md +1 -1
- package/package.json +1 -1
- package/dist/App.svelte +0 -551
- package/dist/App.svelte.d.ts +0 -3
- package/dist/Container.svelte +0 -60
- package/dist/Container.svelte.d.ts +0 -12
- package/dist/app.css +0 -235
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -6
- package/dist/lang.d.ts +0 -1081
- package/dist/lang.js +0 -1096
- package/dist/lib/Accordion.svelte +0 -155
- package/dist/lib/Accordion.svelte.d.ts +0 -40
- package/dist/lib/Button.svelte +0 -170
- package/dist/lib/Button.svelte.d.ts +0 -53
- package/dist/lib/Card.svelte +0 -103
- package/dist/lib/Card.svelte.d.ts +0 -42
- package/dist/lib/Carousel.svelte +0 -293
- package/dist/lib/Carousel.svelte.d.ts +0 -13
- package/dist/lib/CheckBox.svelte +0 -210
- package/dist/lib/CheckBox.svelte.d.ts +0 -53
- package/dist/lib/CodeView.svelte +0 -307
- package/dist/lib/CodeView.svelte.d.ts +0 -64
- package/dist/lib/ColorPicker.svelte +0 -161
- package/dist/lib/ColorPicker.svelte.d.ts +0 -40
- package/dist/lib/DatePicker.svelte +0 -170
- package/dist/lib/DatePicker.svelte.d.ts +0 -53
- package/dist/lib/Dialog.svelte +0 -235
- package/dist/lib/Dialog.svelte.d.ts +0 -58
- package/dist/lib/Field.svelte +0 -299
- package/dist/lib/Field.svelte.d.ts +0 -8
- package/dist/lib/FilePicker.svelte +0 -241
- package/dist/lib/FilePicker.svelte.d.ts +0 -52
- package/dist/lib/Form.svelte +0 -438
- package/dist/lib/Form.svelte.d.ts +0 -20
- package/dist/lib/Hamburger.svelte +0 -211
- package/dist/lib/Hamburger.svelte.d.ts +0 -52
- package/dist/lib/Menu.svelte +0 -623
- package/dist/lib/Menu.svelte.d.ts +0 -33
- package/dist/lib/PaginatedCard.svelte +0 -73
- package/dist/lib/PaginatedCard.svelte.d.ts +0 -11
- package/dist/lib/Pagination.svelte +0 -119
- package/dist/lib/Pagination.svelte.d.ts +0 -9
- package/dist/lib/PrimaryColorSelect.svelte +0 -113
- package/dist/lib/PrimaryColorSelect.svelte.d.ts +0 -9
- package/dist/lib/ProgressBar.svelte +0 -141
- package/dist/lib/ProgressBar.svelte.d.ts +0 -48
- package/dist/lib/ProgressCircle.svelte +0 -192
- package/dist/lib/ProgressCircle.svelte.d.ts +0 -39
- package/dist/lib/Radio.svelte +0 -189
- package/dist/lib/Radio.svelte.d.ts +0 -55
- package/dist/lib/SearchInput.svelte +0 -106
- package/dist/lib/SearchInput.svelte.d.ts +0 -13
- package/dist/lib/Select.svelte +0 -524
- package/dist/lib/Select.svelte.d.ts +0 -21
- package/dist/lib/Slider.svelte +0 -253
- package/dist/lib/Slider.svelte.d.ts +0 -56
- package/dist/lib/Splitter.svelte +0 -150
- package/dist/lib/Splitter.svelte.d.ts +0 -43
- package/dist/lib/Switch.svelte +0 -167
- package/dist/lib/Switch.svelte.d.ts +0 -42
- package/dist/lib/Table.svelte +0 -299
- package/dist/lib/Table.svelte.d.ts +0 -17
- package/dist/lib/Tabs.svelte +0 -213
- package/dist/lib/Tabs.svelte.d.ts +0 -48
- package/dist/lib/ThemeToggle.svelte +0 -127
- package/dist/lib/ThemeToggle.svelte.d.ts +0 -32
- package/dist/lib/TimePicker.svelte +0 -269
- package/dist/lib/TimePicker.svelte.d.ts +0 -48
- package/dist/lib/Toast.svelte +0 -226
- package/dist/lib/Toast.svelte.d.ts +0 -14
- package/dist/lib/Tooltip.svelte +0 -110
- package/dist/lib/Tooltip.svelte.d.ts +0 -40
- package/dist/lib/index.d.ts +0 -32
- package/dist/lib/index.js +0 -33
- package/dist/lib/lang.d.ts +0 -158
- package/dist/lib/lang.js +0 -150
- package/dist/lib/types/index.d.ts +0 -111
- package/dist/lib/types/index.js +0 -26
- package/dist/main.d.ts +0 -3
- package/dist/main.js +0 -7
- package/dist/styles.css +0 -232
- package/dist/utils/index.d.ts +0 -34
- package/dist/utils/index.js +0 -268
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
<!-- src/lib/PaginatedCard.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
/**
|
|
4
|
-
* @component PaginatedCard
|
|
5
|
-
* @description A card component with built-in pagination. Renders items page by page inside a `Card` and appends `Pagination` in the footer.
|
|
6
|
-
*
|
|
7
|
-
* @prop items {Snippet[]} - Array of renderable snippets for each item
|
|
8
|
-
* @default []
|
|
9
|
-
*
|
|
10
|
-
* @prop itemsPerPage {number} - Items per page (must be >= 1)
|
|
11
|
-
* @default 1
|
|
12
|
-
*
|
|
13
|
-
* @prop header {Snippet} - Optional `Card` header content
|
|
14
|
-
*
|
|
15
|
-
* @prop footer {Snippet} - Custom footer content shown above pagination
|
|
16
|
-
*
|
|
17
|
-
* @prop class {string} - Extra classes passed to the underlying `Card`
|
|
18
|
-
* @default ""
|
|
19
|
-
*
|
|
20
|
-
* @note Maintains internal `currentPage` state (starts at `1`).
|
|
21
|
-
* @note `totalPages` is clamped to at least `1`; empty `items` still yields one page.
|
|
22
|
-
* @note Pagination is always visible; your `footer` snippet renders before it.
|
|
23
|
-
* @note Uses `Pagination.svelte` internally with `{ currentPage, totalPages, onPageChange }`.
|
|
24
|
-
* @note `itemsPerPage` must be `>= 1`; smaller values are not supported.
|
|
25
|
-
*/
|
|
26
|
-
import Card from "./Card.svelte";
|
|
27
|
-
import Pagination from "./Pagination.svelte";
|
|
28
|
-
import type { Snippet } from "svelte";
|
|
29
|
-
|
|
30
|
-
type Props = {
|
|
31
|
-
items?: Snippet[];
|
|
32
|
-
itemsPerPage?: number;
|
|
33
|
-
header?: Snippet;
|
|
34
|
-
footer?: Snippet;
|
|
35
|
-
class?: string;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
let {
|
|
39
|
-
items = [],
|
|
40
|
-
itemsPerPage = 1,
|
|
41
|
-
header,
|
|
42
|
-
footer,
|
|
43
|
-
class: externalClass = "",
|
|
44
|
-
}: Props = $props();
|
|
45
|
-
|
|
46
|
-
let currentPage = $state(1);
|
|
47
|
-
|
|
48
|
-
const totalPages = $derived(
|
|
49
|
-
Math.max(1, Math.ceil(items.length / itemsPerPage))
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const pageItems = $derived(
|
|
53
|
-
items.slice(
|
|
54
|
-
(currentPage - 1) * itemsPerPage,
|
|
55
|
-
(currentPage - 1) * itemsPerPage + itemsPerPage
|
|
56
|
-
)
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
function handlePageChange(p: number) {
|
|
60
|
-
currentPage = p;
|
|
61
|
-
}
|
|
62
|
-
</script>
|
|
63
|
-
|
|
64
|
-
{#snippet composedFooter()}
|
|
65
|
-
{#if footer}{@render footer?.()}{/if}
|
|
66
|
-
<Pagination {currentPage} {totalPages} onPageChange={handlePageChange} />
|
|
67
|
-
{/snippet}
|
|
68
|
-
|
|
69
|
-
<Card class={externalClass} {header} footer={composedFooter}>
|
|
70
|
-
{#each pageItems as it, idx (idx)}
|
|
71
|
-
{@render it?.()}
|
|
72
|
-
{/each}
|
|
73
|
-
</Card>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Snippet } from "svelte";
|
|
2
|
-
type Props = {
|
|
3
|
-
items?: Snippet[];
|
|
4
|
-
itemsPerPage?: number;
|
|
5
|
-
header?: Snippet;
|
|
6
|
-
footer?: Snippet;
|
|
7
|
-
class?: string;
|
|
8
|
-
};
|
|
9
|
-
declare const PaginatedCard: import("svelte").Component<Props, {}, "">;
|
|
10
|
-
type PaginatedCard = ReturnType<typeof PaginatedCard>;
|
|
11
|
-
export default PaginatedCard;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
<!-- src/lib/Pagination.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
/**
|
|
4
|
-
* @component Pagination
|
|
5
|
-
* @description Compact pagination component for table or list navigation.
|
|
6
|
-
*
|
|
7
|
-
* @prop currentPage {number} - The active page number (1-based)
|
|
8
|
-
*
|
|
9
|
-
* @prop totalPages {number} - Total number of pages available
|
|
10
|
-
*
|
|
11
|
-
* @prop onPageChange {(page: number) => void} - Fired when a page button is clicked
|
|
12
|
-
*
|
|
13
|
-
* @prop class {string} - Custom classes applied to the pagination wrapper
|
|
14
|
-
* @default ""
|
|
15
|
-
*
|
|
16
|
-
* @note Displays “Page X of Y” and numbered page buttons.
|
|
17
|
-
* @note Prev/next buttons are disabled at the edges.
|
|
18
|
-
* @note Shows up to 3 numbered buttons centered around the current page.
|
|
19
|
-
* @note Uses `aria-current=\"page\"` on the active page for accessibility.
|
|
20
|
-
* @note Buttons are native `<button>` elements for keyboard support.
|
|
21
|
-
*/
|
|
22
|
-
import { cx, times } from "../utils";
|
|
23
|
-
import Button from "./Button.svelte";
|
|
24
|
-
|
|
25
|
-
type Props = {
|
|
26
|
-
currentPage: number;
|
|
27
|
-
totalPages: number;
|
|
28
|
-
onPageChange: (page: number) => void;
|
|
29
|
-
class?: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
let {
|
|
33
|
-
currentPage,
|
|
34
|
-
totalPages,
|
|
35
|
-
onPageChange,
|
|
36
|
-
class: externalClass = "",
|
|
37
|
-
}: Props = $props();
|
|
38
|
-
|
|
39
|
-
const wrapperClass = $derived(
|
|
40
|
-
cx(
|
|
41
|
-
"flex flex-wrap items-center justify-center gap-2 text-xs text-[var(--color-text-muted)] py-0.5 overflow-visible",
|
|
42
|
-
externalClass
|
|
43
|
-
)
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
function nextPage() {
|
|
47
|
-
if (currentPage < totalPages) onPageChange(currentPage + 1);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function prevPage() {
|
|
51
|
-
if (currentPage > 1) onPageChange(currentPage - 1);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getVisiblePages(): number[] {
|
|
55
|
-
const maxVisible = 3;
|
|
56
|
-
if (totalPages <= maxVisible) return times(totalPages, (i) => i + 1);
|
|
57
|
-
|
|
58
|
-
let start = currentPage - 1;
|
|
59
|
-
if (start < 1) start = 1;
|
|
60
|
-
if (start + maxVisible - 1 > totalPages)
|
|
61
|
-
start = totalPages - maxVisible + 1;
|
|
62
|
-
|
|
63
|
-
return times(maxVisible, (i) => start + i);
|
|
64
|
-
}
|
|
65
|
-
</script>
|
|
66
|
-
|
|
67
|
-
<div class={wrapperClass}>
|
|
68
|
-
<span class="pagination-count">Page {currentPage} of {totalPages}</span>
|
|
69
|
-
|
|
70
|
-
<Button
|
|
71
|
-
onClick={prevPage}
|
|
72
|
-
disabled={currentPage === 1}
|
|
73
|
-
sz="xs"
|
|
74
|
-
variant="secondary"
|
|
75
|
-
class="pagination-btn"
|
|
76
|
-
>
|
|
77
|
-
<
|
|
78
|
-
</Button>
|
|
79
|
-
|
|
80
|
-
{#each getVisiblePages() as page (page)}
|
|
81
|
-
<Button
|
|
82
|
-
onClick={() => onPageChange(page)}
|
|
83
|
-
sz="xs"
|
|
84
|
-
variant={currentPage === page ? "primary" : "secondary"}
|
|
85
|
-
aria-current={currentPage === page ? "page" : undefined}
|
|
86
|
-
class="pagination-btn"
|
|
87
|
-
>
|
|
88
|
-
{page}
|
|
89
|
-
</Button>
|
|
90
|
-
{/each}
|
|
91
|
-
|
|
92
|
-
<Button
|
|
93
|
-
onClick={nextPage}
|
|
94
|
-
disabled={currentPage === totalPages}
|
|
95
|
-
sz="xs"
|
|
96
|
-
variant="secondary"
|
|
97
|
-
class="pagination-btn"
|
|
98
|
-
>
|
|
99
|
-
>
|
|
100
|
-
</Button>
|
|
101
|
-
</div>
|
|
102
|
-
|
|
103
|
-
<style>
|
|
104
|
-
@media (max-width: 640px) {
|
|
105
|
-
:global(.pagination-btn) {
|
|
106
|
-
font-size: 10px;
|
|
107
|
-
line-height: 1;
|
|
108
|
-
height: 20px;
|
|
109
|
-
padding: 0 6px;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
@media (max-width: 480px) {
|
|
114
|
-
:global(.pagination-count) {
|
|
115
|
-
display: none;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
</style>
|
|
119
|
-
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
type Props = {
|
|
2
|
-
currentPage: number;
|
|
3
|
-
totalPages: number;
|
|
4
|
-
onPageChange: (page: number) => void;
|
|
5
|
-
class?: string;
|
|
6
|
-
};
|
|
7
|
-
declare const Pagination: import("svelte").Component<Props, {}, "">;
|
|
8
|
-
type Pagination = ReturnType<typeof Pagination>;
|
|
9
|
-
export default Pagination;
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
<!-- src/lib/PrimaryColorSelect.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
/**
|
|
4
|
-
* @component PrimaryColorSelect
|
|
5
|
-
* @description Theme primary-color selector built on top of Select. Provides a fixed palette,
|
|
6
|
-
* handles persistence, and updates the global <html> attribute.
|
|
7
|
-
*
|
|
8
|
-
* @prop sz {SizeKey} - Sizing preset passed directly to Select
|
|
9
|
-
* @options xs|sm|md|lg|xl
|
|
10
|
-
* @default sm
|
|
11
|
-
*
|
|
12
|
-
* @prop label {string} - Custom label text. Falls back to localized copy when omitted.
|
|
13
|
-
*
|
|
14
|
-
* @prop class {string} - Extra classes forwarded to the underlying Select component
|
|
15
|
-
* @default ""
|
|
16
|
-
*
|
|
17
|
-
* @note The palette is predefined internally (`{ value, label, swatch }`).
|
|
18
|
-
* @note Selected value is stored in localStorage under "primary".
|
|
19
|
-
* @note The `html` element receives `data-primary="{value}"` for theme styling.
|
|
20
|
-
* @note Uses the same onChange contract as Select and forwards palette options as-is.
|
|
21
|
-
*/
|
|
22
|
-
import { getContext } from "svelte";
|
|
23
|
-
import Select from "./Select.svelte";
|
|
24
|
-
import type { PrimaryKey, PaletteOption, SizeKey } from "./types";
|
|
25
|
-
import { TEXTS } from "./lang";
|
|
26
|
-
|
|
27
|
-
type Props = {
|
|
28
|
-
sz?: SizeKey;
|
|
29
|
-
label?: string;
|
|
30
|
-
class?: string;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
let { sz = "sm", label, class: externalClass = "" }: Props = $props();
|
|
34
|
-
|
|
35
|
-
const langCtx =
|
|
36
|
-
getContext<{ value: keyof typeof TEXTS } | undefined>("lang") ?? null;
|
|
37
|
-
const langKey = $derived(langCtx?.value ?? "en");
|
|
38
|
-
const L = $derived(TEXTS[langKey].components.primaryColorSelect);
|
|
39
|
-
|
|
40
|
-
const labelFinal = $derived(label ?? L.text);
|
|
41
|
-
|
|
42
|
-
const palette: PaletteOption[] = [
|
|
43
|
-
{
|
|
44
|
-
value: "default",
|
|
45
|
-
label: "Indigo",
|
|
46
|
-
swatch: "oklch(62.3% 0.214 259.8deg)",
|
|
47
|
-
},
|
|
48
|
-
{ value: "cyan", label: "Cyan", swatch: "oklch(71.5% 0.143 215.221)" },
|
|
49
|
-
{ value: "red", label: "Red", swatch: "oklch(58% 0.24 30deg)" },
|
|
50
|
-
{ value: "green", label: "Green", swatch: "oklch(65% 0.22 140deg)" },
|
|
51
|
-
{ value: "yellow", label: "Yellow", swatch: "oklch(75% 0.18 90deg)" },
|
|
52
|
-
{ value: "pink", label: "Pink", swatch: "oklch(70% 0.25 350deg)" },
|
|
53
|
-
{ value: "orange", label: "Orange", swatch: "oklch(72% 0.22 60deg)" },
|
|
54
|
-
{ value: "purple", label: "Purple", swatch: "oklch(55% 0.22 290deg)" },
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
const paletteMap = palette.reduce<Record<PrimaryKey, PaletteOption>>(
|
|
58
|
-
(acc, option) => {
|
|
59
|
-
acc[option.value] = option;
|
|
60
|
-
return acc;
|
|
61
|
-
},
|
|
62
|
-
{} as Record<PrimaryKey, PaletteOption>
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
let selected = $state<PrimaryKey>("default");
|
|
66
|
-
let mounted = $state(false);
|
|
67
|
-
|
|
68
|
-
function isPrimaryKey(value: unknown): value is PrimaryKey {
|
|
69
|
-
return typeof value === "string" && value in paletteMap;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
$effect(() => {
|
|
73
|
-
if (!mounted) {
|
|
74
|
-
try {
|
|
75
|
-
if (typeof window !== "undefined") {
|
|
76
|
-
const saved = localStorage.getItem("primary");
|
|
77
|
-
if (isPrimaryKey(saved)) {
|
|
78
|
-
selected = saved;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
// ignore unavailable storage/environment
|
|
83
|
-
}
|
|
84
|
-
mounted = true;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
$effect(() => {
|
|
89
|
-
if (mounted) {
|
|
90
|
-
try {
|
|
91
|
-
if (typeof document !== "undefined") {
|
|
92
|
-
document.documentElement.setAttribute("data-primary", selected);
|
|
93
|
-
}
|
|
94
|
-
if (typeof window !== "undefined") {
|
|
95
|
-
localStorage.setItem("primary", selected);
|
|
96
|
-
}
|
|
97
|
-
} catch {
|
|
98
|
-
// ignore unavailable storage/environment
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
</script>
|
|
103
|
-
|
|
104
|
-
<Select
|
|
105
|
-
{sz}
|
|
106
|
-
label={labelFinal}
|
|
107
|
-
options={palette}
|
|
108
|
-
value={selected}
|
|
109
|
-
onChange={(v) => {
|
|
110
|
-
if (isPrimaryKey(v)) selected = v;
|
|
111
|
-
}}
|
|
112
|
-
class={externalClass}
|
|
113
|
-
/>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { SizeKey } from "./types";
|
|
2
|
-
type Props = {
|
|
3
|
-
sz?: SizeKey;
|
|
4
|
-
label?: string;
|
|
5
|
-
class?: string;
|
|
6
|
-
};
|
|
7
|
-
declare const PrimaryColorSelect: import("svelte").Component<Props, {}, "">;
|
|
8
|
-
type PrimaryColorSelect = ReturnType<typeof PrimaryColorSelect>;
|
|
9
|
-
export default PrimaryColorSelect;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
<!-- src/lib/ProgressBar.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
/**
|
|
4
|
-
* @component ProgressBar
|
|
5
|
-
* @description A simple and accessible progress bar component that visually represents task completion.
|
|
6
|
-
*
|
|
7
|
-
* @prop value {number} - Current progress value from 0 to 100
|
|
8
|
-
* @default 0
|
|
9
|
-
*
|
|
10
|
-
* @prop indeterminate {boolean} - Enables the animated indeterminate state
|
|
11
|
-
* @default false
|
|
12
|
-
*
|
|
13
|
-
* @prop sz {SizeKey} - Controls the bar height
|
|
14
|
-
* @options xs|sm|md|lg|xl
|
|
15
|
-
* @default md
|
|
16
|
-
*
|
|
17
|
-
* @prop variant {ComponentVariant} - Visual style of the progress bar
|
|
18
|
-
* @options default|neutral
|
|
19
|
-
* @default default
|
|
20
|
-
*
|
|
21
|
-
* @prop class {string} - Additional CSS classes for the wrapper element
|
|
22
|
-
* @default ""
|
|
23
|
-
*
|
|
24
|
-
* @prop label {string} - Optional text label displayed above the bar
|
|
25
|
-
* @default ""
|
|
26
|
-
*
|
|
27
|
-
* @prop disabled {boolean} - Applies a muted inactive visual style
|
|
28
|
-
* @default false
|
|
29
|
-
*
|
|
30
|
-
* @note Indeterminate animation for unknown progress.
|
|
31
|
-
* @note Auto-clamping between 0 and 100.
|
|
32
|
-
* @note Adaptive height based on size.
|
|
33
|
-
* @note Theming support via CSS variables.
|
|
34
|
-
* @note Fully accessible with proper `aria` roles.
|
|
35
|
-
* @note No invalid ARIA attributes.
|
|
36
|
-
*/
|
|
37
|
-
import type { HTMLAttributes } from "svelte/elements";
|
|
38
|
-
import { type SizeKey, type ComponentVariant, TEXT } from "./types";
|
|
39
|
-
import { cx, clamp } from "../utils";
|
|
40
|
-
|
|
41
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
42
|
-
value?: number;
|
|
43
|
-
indeterminate?: boolean;
|
|
44
|
-
sz?: SizeKey;
|
|
45
|
-
variant?: ComponentVariant;
|
|
46
|
-
class?: string;
|
|
47
|
-
label?: string;
|
|
48
|
-
disabled?: boolean;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
let {
|
|
52
|
-
value = 0,
|
|
53
|
-
indeterminate = false,
|
|
54
|
-
sz = "md",
|
|
55
|
-
variant = "default",
|
|
56
|
-
class: externalClass = "",
|
|
57
|
-
label = "",
|
|
58
|
-
disabled = false,
|
|
59
|
-
...rest
|
|
60
|
-
}: Props = $props();
|
|
61
|
-
|
|
62
|
-
const pct = $derived(`${clamp(value, 0, 100)}%`);
|
|
63
|
-
|
|
64
|
-
const sizeTrack = $derived(
|
|
65
|
-
{
|
|
66
|
-
xs: "h-[4px]",
|
|
67
|
-
sm: "h-[5px]",
|
|
68
|
-
md: "h-[6px]",
|
|
69
|
-
lg: "h-[7px]",
|
|
70
|
-
xl: "h-[8px]",
|
|
71
|
-
}[sz]
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const bar = $derived(
|
|
75
|
-
variant === "neutral"
|
|
76
|
-
? "bg-[var(--color-bg-secondary)]"
|
|
77
|
-
: "bg-[var(--color-bg-primary)]"
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
const rootClass = $derived(
|
|
81
|
-
cx(
|
|
82
|
-
"relative flex flex-col gap-1 w-full data-[disabled=true]:opacity-[var(--opacity-disabled)] data-[disabled=true]:cursor-not-allowed",
|
|
83
|
-
externalClass
|
|
84
|
-
)
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const trackClass = $derived(
|
|
88
|
-
cx(
|
|
89
|
-
"absolute top-1/2 -translate-y-1/2 w-full bg-[var(--border-color-default)] rounded overflow-hidden",
|
|
90
|
-
sizeTrack
|
|
91
|
-
)
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const barClass = $derived(cx("h-full", bar));
|
|
95
|
-
</script>
|
|
96
|
-
|
|
97
|
-
<div
|
|
98
|
-
class={rootClass}
|
|
99
|
-
role="progressbar"
|
|
100
|
-
aria-valuemin="0"
|
|
101
|
-
aria-valuemax="100"
|
|
102
|
-
aria-valuenow={indeterminate ? undefined : Math.round(clamp(value, 0, 100))}
|
|
103
|
-
data-disabled={disabled ? "true" : undefined}
|
|
104
|
-
{...rest}
|
|
105
|
-
>
|
|
106
|
-
{#if label}
|
|
107
|
-
<span class={cx("text-[var(--color-text-muted)] select-none", TEXT[sz])}>
|
|
108
|
-
{label}
|
|
109
|
-
</span>
|
|
110
|
-
{/if}
|
|
111
|
-
|
|
112
|
-
<div class="relative w-full h-10">
|
|
113
|
-
<div class={trackClass}>
|
|
114
|
-
{#if indeterminate}
|
|
115
|
-
<div class={cx(barClass, "pb-indet")}></div>
|
|
116
|
-
{:else}
|
|
117
|
-
<div
|
|
118
|
-
class={cx(barClass, "transition-[width]")}
|
|
119
|
-
style={`width:${pct}`}
|
|
120
|
-
></div>
|
|
121
|
-
{/if}
|
|
122
|
-
</div>
|
|
123
|
-
</div>
|
|
124
|
-
</div>
|
|
125
|
-
|
|
126
|
-
<style>
|
|
127
|
-
:global {
|
|
128
|
-
@keyframes pb-indeterminate {
|
|
129
|
-
0% {
|
|
130
|
-
transform: translateX(-100%);
|
|
131
|
-
}
|
|
132
|
-
100% {
|
|
133
|
-
transform: translateX(250%);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
.pb-indet {
|
|
138
|
-
width: 40%;
|
|
139
|
-
animation: pb-indeterminate 2s linear infinite;
|
|
140
|
-
}
|
|
141
|
-
</style>
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @component ProgressBar
|
|
3
|
-
* @description A simple and accessible progress bar component that visually represents task completion.
|
|
4
|
-
*
|
|
5
|
-
* @prop value {number} - Current progress value from 0 to 100
|
|
6
|
-
* @default 0
|
|
7
|
-
*
|
|
8
|
-
* @prop indeterminate {boolean} - Enables the animated indeterminate state
|
|
9
|
-
* @default false
|
|
10
|
-
*
|
|
11
|
-
* @prop sz {SizeKey} - Controls the bar height
|
|
12
|
-
* @options xs|sm|md|lg|xl
|
|
13
|
-
* @default md
|
|
14
|
-
*
|
|
15
|
-
* @prop variant {ComponentVariant} - Visual style of the progress bar
|
|
16
|
-
* @options default|neutral
|
|
17
|
-
* @default default
|
|
18
|
-
*
|
|
19
|
-
* @prop class {string} - Additional CSS classes for the wrapper element
|
|
20
|
-
* @default ""
|
|
21
|
-
*
|
|
22
|
-
* @prop label {string} - Optional text label displayed above the bar
|
|
23
|
-
* @default ""
|
|
24
|
-
*
|
|
25
|
-
* @prop disabled {boolean} - Applies a muted inactive visual style
|
|
26
|
-
* @default false
|
|
27
|
-
*
|
|
28
|
-
* @note Indeterminate animation for unknown progress.
|
|
29
|
-
* @note Auto-clamping between 0 and 100.
|
|
30
|
-
* @note Adaptive height based on size.
|
|
31
|
-
* @note Theming support via CSS variables.
|
|
32
|
-
* @note Fully accessible with proper `aria` roles.
|
|
33
|
-
* @note No invalid ARIA attributes.
|
|
34
|
-
*/
|
|
35
|
-
import type { HTMLAttributes } from "svelte/elements";
|
|
36
|
-
import { type SizeKey, type ComponentVariant } from "./types";
|
|
37
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
38
|
-
value?: number;
|
|
39
|
-
indeterminate?: boolean;
|
|
40
|
-
sz?: SizeKey;
|
|
41
|
-
variant?: ComponentVariant;
|
|
42
|
-
class?: string;
|
|
43
|
-
label?: string;
|
|
44
|
-
disabled?: boolean;
|
|
45
|
-
};
|
|
46
|
-
declare const ProgressBar: import("svelte").Component<Props, {}, "">;
|
|
47
|
-
type ProgressBar = ReturnType<typeof ProgressBar>;
|
|
48
|
-
export default ProgressBar;
|