svelte-comp 1.3.5 → 1.3.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.
- package/LICENSE.md +21 -21
- package/README.md +101 -101
- package/dist/App.svelte +1046 -1046
- package/dist/Container.svelte +59 -59
- package/dist/app.css +234 -234
- package/dist/app.d.ts +10 -10
- package/dist/lib/Accordion.svelte +155 -155
- package/dist/lib/Badge.svelte +44 -44
- package/dist/lib/Button.svelte +185 -185
- package/dist/lib/Calendar.svelte +384 -384
- package/dist/lib/Card.svelte +103 -103
- package/dist/lib/Carousel.svelte +293 -293
- package/dist/lib/CheckBox.svelte +210 -210
- package/dist/lib/CodeView.svelte +308 -308
- package/dist/lib/ColorPicker.svelte +159 -159
- package/dist/lib/ContextMenu.svelte +328 -328
- package/dist/lib/DatePicker.svelte +246 -246
- package/dist/lib/Dialog.svelte +233 -233
- package/dist/lib/Field.svelte +299 -299
- package/dist/lib/FilePicker.svelte +295 -295
- package/dist/lib/Form.svelte +438 -438
- package/dist/lib/Hamburger.svelte +217 -217
- package/dist/lib/InstallPWA.svelte +94 -94
- package/dist/lib/Menu.svelte +623 -623
- package/dist/lib/NoticeBase.svelte +140 -140
- package/dist/lib/PaginatedCard.svelte +73 -73
- package/dist/lib/Pagination.svelte +119 -119
- package/dist/lib/PrimaryColorSelect.svelte +111 -111
- package/dist/lib/ProgressBar.svelte +141 -141
- package/dist/lib/ProgressCircle.svelte +190 -190
- package/dist/lib/Radio.svelte +189 -189
- package/dist/lib/SearchInput.svelte +104 -104
- package/dist/lib/Select.svelte +524 -524
- package/dist/lib/Slider.svelte +253 -253
- package/dist/lib/Splitter.svelte +159 -159
- package/dist/lib/Switch.svelte +168 -168
- package/dist/lib/Table.svelte +299 -299
- package/dist/lib/Tabs.svelte +213 -213
- package/dist/lib/ThemeToggle.svelte +128 -128
- package/dist/lib/TimePicker.svelte +312 -312
- package/dist/lib/TimePickerNew.svelte +634 -634
- package/dist/lib/Toast.svelte +123 -123
- package/dist/lib/Tooltip.svelte +110 -110
- package/dist/lib/Topbar.svelte +112 -112
- package/dist/styles.css +234 -234
- package/package.json +52 -52
package/dist/lib/Carousel.svelte
CHANGED
|
@@ -1,293 +1,293 @@
|
|
|
1
|
-
<!-- src/lib/Carousel.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
/**
|
|
4
|
-
* @component Carousel
|
|
5
|
-
* @description A responsive carousel component to display a sequence of items with optional autoplay, navigation arrows, and dots.
|
|
6
|
-
*
|
|
7
|
-
* @prop items {CarouselItem[]} - Array of carousel items
|
|
8
|
-
* @default []
|
|
9
|
-
*
|
|
10
|
-
* @prop sz {SizeKey} - Size variant controlling text scale and rounding
|
|
11
|
-
* @options xs|sm|md|lg|xl
|
|
12
|
-
* @default md
|
|
13
|
-
*
|
|
14
|
-
* @prop autoplay {boolean} - Enables automatic slide rotation
|
|
15
|
-
* @default false
|
|
16
|
-
*
|
|
17
|
-
* @prop interval {number} - Interval between slides in milliseconds
|
|
18
|
-
* @default 5000
|
|
19
|
-
*
|
|
20
|
-
* @prop showDots {boolean} - Shows navigation dots
|
|
21
|
-
* @default true
|
|
22
|
-
*
|
|
23
|
-
* @prop showArrows {boolean} - Shows navigation arrows
|
|
24
|
-
* @default true
|
|
25
|
-
*
|
|
26
|
-
* @prop class {string} - Additional classes for the carousel container
|
|
27
|
-
* @default ""
|
|
28
|
-
*
|
|
29
|
-
* @note Supports touch gestures (swipe left/right).
|
|
30
|
-
* @note Autoplay pauses automatically when unmounted.
|
|
31
|
-
* @note Uses `Card.svelte` internally for slide structure.
|
|
32
|
-
* @note Navigation dots and arrows appear only if there’s more than one item.
|
|
33
|
-
* @note Accessible via `aria-label`, `aria-current`, and keyboard focus on controls.
|
|
34
|
-
*/
|
|
35
|
-
import Card from "./Card.svelte";
|
|
36
|
-
import type { HTMLAttributes } from "svelte/elements";
|
|
37
|
-
import { TEXT, type SizeKey, type CarouselItem } from "./types";
|
|
38
|
-
import { cx } from "../utils";
|
|
39
|
-
|
|
40
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
41
|
-
items?: CarouselItem[];
|
|
42
|
-
sz?: SizeKey;
|
|
43
|
-
autoplay?: boolean;
|
|
44
|
-
interval?: number;
|
|
45
|
-
showDots?: boolean;
|
|
46
|
-
showArrows?: boolean;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
let {
|
|
50
|
-
items = [],
|
|
51
|
-
sz = "md",
|
|
52
|
-
autoplay = false,
|
|
53
|
-
interval = 5000,
|
|
54
|
-
showDots = true,
|
|
55
|
-
showArrows = true,
|
|
56
|
-
class: externalClass = "",
|
|
57
|
-
...rest
|
|
58
|
-
}: Props = $props();
|
|
59
|
-
|
|
60
|
-
let current = $state(0);
|
|
61
|
-
let autoplayTimer = $state<ReturnType<typeof setInterval> | null>(null);
|
|
62
|
-
|
|
63
|
-
const hasItems = $derived(items.length > 0);
|
|
64
|
-
|
|
65
|
-
const base =
|
|
66
|
-
"relative w-full overflow-hidden rounded-[var(--radius-lg)] bg-[var(--color-bg-surface)]";
|
|
67
|
-
|
|
68
|
-
const sizes: Record<SizeKey, string> = {
|
|
69
|
-
xs: cx("rounded-[var(--radius-md)]", TEXT.xs),
|
|
70
|
-
sm: cx("rounded-[var(--radius-md)]", TEXT.sm),
|
|
71
|
-
md: cx("rounded-[var(--radius-lg)]", TEXT.md),
|
|
72
|
-
lg: cx("rounded-[var(--radius-lg)]", TEXT.lg),
|
|
73
|
-
xl: cx("rounded-[var(--radius-xl)]", TEXT.xl),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const contentSize: Record<SizeKey, string> = {
|
|
77
|
-
xs: "p-[calc(var(--spacing-sm)+var(--spacing-xs))] gap-[var(--spacing-sm)]",
|
|
78
|
-
sm: "p-[var(--spacing-md)] gap-[calc(var(--spacing-sm)+var(--spacing-xs)/2)]",
|
|
79
|
-
md: "p-[calc(var(--spacing-md)+var(--spacing-xs))] gap-[calc(var(--spacing-sm)+var(--spacing-xs))]",
|
|
80
|
-
lg: "p-[calc(var(--spacing-md)+var(--spacing-sm))] gap-[var(--spacing-md)]",
|
|
81
|
-
xl: "p-[var(--spacing-xl)] gap-[calc(var(--spacing-md)+var(--spacing-xs))]",
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const arrowSize: Record<SizeKey, string> = {
|
|
85
|
-
xs: "w-7 h-7",
|
|
86
|
-
sm: "w-8 h-8",
|
|
87
|
-
md: "w-9 h-9",
|
|
88
|
-
lg: "w-10 h-10",
|
|
89
|
-
xl: "w-11 h-11",
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const dotSize: Record<SizeKey, string> = {
|
|
93
|
-
xs: "w-1.5 h-1.5",
|
|
94
|
-
sm: "w-2 h-2",
|
|
95
|
-
md: "w-[10px] h-[10px]",
|
|
96
|
-
lg: "w-3 h-3",
|
|
97
|
-
xl: "w-[14px] h-[14px]",
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const componentClass = $derived(cx(base, sizes[sz], externalClass));
|
|
101
|
-
|
|
102
|
-
const minH: Record<SizeKey, string> = {
|
|
103
|
-
xs: "min-h-[200px]",
|
|
104
|
-
sm: "min-h-[240px]",
|
|
105
|
-
md: "min-h-[300px]",
|
|
106
|
-
lg: "min-h-[360px]",
|
|
107
|
-
xl: "min-h-[420px]",
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const viewportClass = $derived(cx("relative w-full", minH[sz]));
|
|
111
|
-
const bodyClass = $derived(cx("flex flex-col", contentSize[sz]));
|
|
112
|
-
|
|
113
|
-
const imgMax: Record<SizeKey, string> = {
|
|
114
|
-
xs: "max-h-28",
|
|
115
|
-
sm: "max-h-32",
|
|
116
|
-
md: "max-h-40",
|
|
117
|
-
lg: "max-h-48",
|
|
118
|
-
xl: "max-h-56",
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const imgClass = $derived(cx("w-full object-cover", imgMax[sz]));
|
|
122
|
-
|
|
123
|
-
const arrowClass = $derived(
|
|
124
|
-
cx(
|
|
125
|
-
arrowSize[sz],
|
|
126
|
-
"rounded-full bg-[var(--color-bg-surface)] shadow-[0_8px_16px_var(--shadow-color)] flex items-center justify-center [color:var(--color-text-default)] hover:bg-[var(--color-bg-hover)] transition-colors focus-visible:ring-2 focus-visible:ring-[var(--border-color-focus)] focus:outline-none"
|
|
127
|
-
)
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const dotClass = $derived(
|
|
131
|
-
cx(
|
|
132
|
-
dotSize[sz],
|
|
133
|
-
"rounded-full transition-all duration-[var(--transition-fast)] focus-visible:ring-2 focus-visible:ring-[var(--border-color-focus)] focus:outline-none"
|
|
134
|
-
)
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
$effect(() => {
|
|
138
|
-
if (!hasItems) current = 0;
|
|
139
|
-
else if (current >= items.length) current = items.length - 1;
|
|
140
|
-
else if (current < 0) current = 0;
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
const next = () => {
|
|
144
|
-
if (!hasItems) return;
|
|
145
|
-
current = (current + 1) % items.length;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const prev = () => {
|
|
149
|
-
if (!hasItems) return;
|
|
150
|
-
current = (current - 1 + items.length) % items.length;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const goTo = (index: number) => {
|
|
154
|
-
if (index >= 0 && index < items.length) current = index;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
$effect(() => {
|
|
158
|
-
if (autoplay && hasItems && items.length > 1) {
|
|
159
|
-
autoplayTimer = setInterval(next, Math.max(1000, interval));
|
|
160
|
-
}
|
|
161
|
-
return () => {
|
|
162
|
-
if (autoplayTimer) {
|
|
163
|
-
clearInterval(autoplayTimer);
|
|
164
|
-
autoplayTimer = null;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
let touchStartX = 0;
|
|
170
|
-
let touchEndX = 0;
|
|
171
|
-
|
|
172
|
-
function handleTouchStart(event: TouchEvent) {
|
|
173
|
-
touchStartX = event.touches[0].clientX;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function handleTouchEnd(event: TouchEvent) {
|
|
177
|
-
touchEndX = event.changedTouches[0].clientX;
|
|
178
|
-
const diff = touchStartX - touchEndX;
|
|
179
|
-
if (Math.abs(diff) <= 50) return;
|
|
180
|
-
if (diff > 0) next();
|
|
181
|
-
else prev();
|
|
182
|
-
}
|
|
183
|
-
</script>
|
|
184
|
-
|
|
185
|
-
<div
|
|
186
|
-
aria-label="Carousel"
|
|
187
|
-
class={componentClass}
|
|
188
|
-
ontouchstart={handleTouchStart}
|
|
189
|
-
ontouchend={handleTouchEnd}
|
|
190
|
-
{...rest}
|
|
191
|
-
>
|
|
192
|
-
<div class="relative">
|
|
193
|
-
<div class={viewportClass}>
|
|
194
|
-
{#each items as item, i (item.id ?? i)}
|
|
195
|
-
{#snippet header()}
|
|
196
|
-
{#if item.image}
|
|
197
|
-
<img
|
|
198
|
-
src={item.image}
|
|
199
|
-
alt={item.title || `Slide ${i + 1}`}
|
|
200
|
-
class={imgClass}
|
|
201
|
-
/>
|
|
202
|
-
{/if}
|
|
203
|
-
{/snippet}
|
|
204
|
-
|
|
205
|
-
<div
|
|
206
|
-
class="transition-opacity duration-[var(--transition-normal)] ease-in-out"
|
|
207
|
-
class:opacity-100={i === current}
|
|
208
|
-
class:opacity-0={i !== current}
|
|
209
|
-
class:block={i === current}
|
|
210
|
-
class:hidden={i !== current}
|
|
211
|
-
>
|
|
212
|
-
<Card {sz} {header} flushHeader={true} class="h-auto flex flex-col">
|
|
213
|
-
<div class={cx(bodyClass, "flex-1 overflow-auto min-h-0")}>
|
|
214
|
-
{#if item.title}
|
|
215
|
-
<h3 class="font-semibold [color:var(--color-text-default)]">
|
|
216
|
-
{item.title}
|
|
217
|
-
</h3>
|
|
218
|
-
{/if}
|
|
219
|
-
{#if item.content}
|
|
220
|
-
<p class="[color:var(--color-text-muted)]">
|
|
221
|
-
{item.content}
|
|
222
|
-
</p>
|
|
223
|
-
{/if}
|
|
224
|
-
{@render item.children?.()}
|
|
225
|
-
</div>
|
|
226
|
-
</Card>
|
|
227
|
-
</div>
|
|
228
|
-
{/each}
|
|
229
|
-
|
|
230
|
-
{#if !hasItems}
|
|
231
|
-
<div
|
|
232
|
-
class="flex items-center justify-center h-full [color:var(--color-text-muted)]"
|
|
233
|
-
>
|
|
234
|
-
No items to display
|
|
235
|
-
</div>
|
|
236
|
-
{/if}
|
|
237
|
-
</div>
|
|
238
|
-
|
|
239
|
-
{#if showArrows && hasItems && items.length > 1}
|
|
240
|
-
<button
|
|
241
|
-
type="button"
|
|
242
|
-
onclick={prev}
|
|
243
|
-
class={cx("absolute left-2 top-1/2 -translate-y-1/2", arrowClass)}
|
|
244
|
-
aria-label="Previous slide"
|
|
245
|
-
>
|
|
246
|
-
<svg
|
|
247
|
-
width="16"
|
|
248
|
-
height="16"
|
|
249
|
-
viewBox="0 0 16 16"
|
|
250
|
-
fill="none"
|
|
251
|
-
stroke="currentColor"
|
|
252
|
-
stroke-width="2"
|
|
253
|
-
>
|
|
254
|
-
<path d="M10 12L6 8L10 4" />
|
|
255
|
-
</svg>
|
|
256
|
-
</button>
|
|
257
|
-
<button
|
|
258
|
-
type="button"
|
|
259
|
-
onclick={next}
|
|
260
|
-
class={cx("absolute right-2 top-1/2 -translate-y-1/2", arrowClass)}
|
|
261
|
-
aria-label="Next slide"
|
|
262
|
-
>
|
|
263
|
-
<svg
|
|
264
|
-
width="16"
|
|
265
|
-
height="16"
|
|
266
|
-
viewBox="0 0 16 16"
|
|
267
|
-
fill="none"
|
|
268
|
-
stroke="currentColor"
|
|
269
|
-
stroke-width="2"
|
|
270
|
-
>
|
|
271
|
-
<path d="M6 4L10 8L6 12" />
|
|
272
|
-
</svg>
|
|
273
|
-
</button>
|
|
274
|
-
{/if}
|
|
275
|
-
</div>
|
|
276
|
-
|
|
277
|
-
{#if showDots && hasItems && items.length > 1}
|
|
278
|
-
<div class="flex justify-center gap-[var(--spacing-sm)] p-[var(--spacing-md)]">
|
|
279
|
-
{#each items as item, i (item.id ?? i)}
|
|
280
|
-
<button
|
|
281
|
-
type="button"
|
|
282
|
-
onclick={() => goTo(i)}
|
|
283
|
-
class={dotClass}
|
|
284
|
-
class:bg-[var(--color-bg-primary)]={i === current}
|
|
285
|
-
class:bg-[var(--color-bg-secondary)]={i !== current}
|
|
286
|
-
class:hover:bg-[var(--color-bg-primary)]={i !== current}
|
|
287
|
-
aria-label={`Go to slide ${item.title ?? `#${i + 1}`}`}
|
|
288
|
-
aria-current={i === current ? "true" : undefined}
|
|
289
|
-
></button>
|
|
290
|
-
{/each}
|
|
291
|
-
</div>
|
|
292
|
-
{/if}
|
|
293
|
-
</div>
|
|
1
|
+
<!-- src/lib/Carousel.svelte -->
|
|
2
|
+
<script lang="ts">
|
|
3
|
+
/**
|
|
4
|
+
* @component Carousel
|
|
5
|
+
* @description A responsive carousel component to display a sequence of items with optional autoplay, navigation arrows, and dots.
|
|
6
|
+
*
|
|
7
|
+
* @prop items {CarouselItem[]} - Array of carousel items
|
|
8
|
+
* @default []
|
|
9
|
+
*
|
|
10
|
+
* @prop sz {SizeKey} - Size variant controlling text scale and rounding
|
|
11
|
+
* @options xs|sm|md|lg|xl
|
|
12
|
+
* @default md
|
|
13
|
+
*
|
|
14
|
+
* @prop autoplay {boolean} - Enables automatic slide rotation
|
|
15
|
+
* @default false
|
|
16
|
+
*
|
|
17
|
+
* @prop interval {number} - Interval between slides in milliseconds
|
|
18
|
+
* @default 5000
|
|
19
|
+
*
|
|
20
|
+
* @prop showDots {boolean} - Shows navigation dots
|
|
21
|
+
* @default true
|
|
22
|
+
*
|
|
23
|
+
* @prop showArrows {boolean} - Shows navigation arrows
|
|
24
|
+
* @default true
|
|
25
|
+
*
|
|
26
|
+
* @prop class {string} - Additional classes for the carousel container
|
|
27
|
+
* @default ""
|
|
28
|
+
*
|
|
29
|
+
* @note Supports touch gestures (swipe left/right).
|
|
30
|
+
* @note Autoplay pauses automatically when unmounted.
|
|
31
|
+
* @note Uses `Card.svelte` internally for slide structure.
|
|
32
|
+
* @note Navigation dots and arrows appear only if there’s more than one item.
|
|
33
|
+
* @note Accessible via `aria-label`, `aria-current`, and keyboard focus on controls.
|
|
34
|
+
*/
|
|
35
|
+
import Card from "./Card.svelte";
|
|
36
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
37
|
+
import { TEXT, type SizeKey, type CarouselItem } from "./types";
|
|
38
|
+
import { cx } from "../utils";
|
|
39
|
+
|
|
40
|
+
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
41
|
+
items?: CarouselItem[];
|
|
42
|
+
sz?: SizeKey;
|
|
43
|
+
autoplay?: boolean;
|
|
44
|
+
interval?: number;
|
|
45
|
+
showDots?: boolean;
|
|
46
|
+
showArrows?: boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let {
|
|
50
|
+
items = [],
|
|
51
|
+
sz = "md",
|
|
52
|
+
autoplay = false,
|
|
53
|
+
interval = 5000,
|
|
54
|
+
showDots = true,
|
|
55
|
+
showArrows = true,
|
|
56
|
+
class: externalClass = "",
|
|
57
|
+
...rest
|
|
58
|
+
}: Props = $props();
|
|
59
|
+
|
|
60
|
+
let current = $state(0);
|
|
61
|
+
let autoplayTimer = $state<ReturnType<typeof setInterval> | null>(null);
|
|
62
|
+
|
|
63
|
+
const hasItems = $derived(items.length > 0);
|
|
64
|
+
|
|
65
|
+
const base =
|
|
66
|
+
"relative w-full overflow-hidden rounded-[var(--radius-lg)] bg-[var(--color-bg-surface)]";
|
|
67
|
+
|
|
68
|
+
const sizes: Record<SizeKey, string> = {
|
|
69
|
+
xs: cx("rounded-[var(--radius-md)]", TEXT.xs),
|
|
70
|
+
sm: cx("rounded-[var(--radius-md)]", TEXT.sm),
|
|
71
|
+
md: cx("rounded-[var(--radius-lg)]", TEXT.md),
|
|
72
|
+
lg: cx("rounded-[var(--radius-lg)]", TEXT.lg),
|
|
73
|
+
xl: cx("rounded-[var(--radius-xl)]", TEXT.xl),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const contentSize: Record<SizeKey, string> = {
|
|
77
|
+
xs: "p-[calc(var(--spacing-sm)+var(--spacing-xs))] gap-[var(--spacing-sm)]",
|
|
78
|
+
sm: "p-[var(--spacing-md)] gap-[calc(var(--spacing-sm)+var(--spacing-xs)/2)]",
|
|
79
|
+
md: "p-[calc(var(--spacing-md)+var(--spacing-xs))] gap-[calc(var(--spacing-sm)+var(--spacing-xs))]",
|
|
80
|
+
lg: "p-[calc(var(--spacing-md)+var(--spacing-sm))] gap-[var(--spacing-md)]",
|
|
81
|
+
xl: "p-[var(--spacing-xl)] gap-[calc(var(--spacing-md)+var(--spacing-xs))]",
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const arrowSize: Record<SizeKey, string> = {
|
|
85
|
+
xs: "w-7 h-7",
|
|
86
|
+
sm: "w-8 h-8",
|
|
87
|
+
md: "w-9 h-9",
|
|
88
|
+
lg: "w-10 h-10",
|
|
89
|
+
xl: "w-11 h-11",
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const dotSize: Record<SizeKey, string> = {
|
|
93
|
+
xs: "w-1.5 h-1.5",
|
|
94
|
+
sm: "w-2 h-2",
|
|
95
|
+
md: "w-[10px] h-[10px]",
|
|
96
|
+
lg: "w-3 h-3",
|
|
97
|
+
xl: "w-[14px] h-[14px]",
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const componentClass = $derived(cx(base, sizes[sz], externalClass));
|
|
101
|
+
|
|
102
|
+
const minH: Record<SizeKey, string> = {
|
|
103
|
+
xs: "min-h-[200px]",
|
|
104
|
+
sm: "min-h-[240px]",
|
|
105
|
+
md: "min-h-[300px]",
|
|
106
|
+
lg: "min-h-[360px]",
|
|
107
|
+
xl: "min-h-[420px]",
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const viewportClass = $derived(cx("relative w-full", minH[sz]));
|
|
111
|
+
const bodyClass = $derived(cx("flex flex-col", contentSize[sz]));
|
|
112
|
+
|
|
113
|
+
const imgMax: Record<SizeKey, string> = {
|
|
114
|
+
xs: "max-h-28",
|
|
115
|
+
sm: "max-h-32",
|
|
116
|
+
md: "max-h-40",
|
|
117
|
+
lg: "max-h-48",
|
|
118
|
+
xl: "max-h-56",
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const imgClass = $derived(cx("w-full object-cover", imgMax[sz]));
|
|
122
|
+
|
|
123
|
+
const arrowClass = $derived(
|
|
124
|
+
cx(
|
|
125
|
+
arrowSize[sz],
|
|
126
|
+
"rounded-full bg-[var(--color-bg-surface)] shadow-[0_8px_16px_var(--shadow-color)] flex items-center justify-center [color:var(--color-text-default)] hover:bg-[var(--color-bg-hover)] transition-colors focus-visible:ring-2 focus-visible:ring-[var(--border-color-focus)] focus:outline-none"
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const dotClass = $derived(
|
|
131
|
+
cx(
|
|
132
|
+
dotSize[sz],
|
|
133
|
+
"rounded-full transition-all duration-[var(--transition-fast)] focus-visible:ring-2 focus-visible:ring-[var(--border-color-focus)] focus:outline-none"
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
$effect(() => {
|
|
138
|
+
if (!hasItems) current = 0;
|
|
139
|
+
else if (current >= items.length) current = items.length - 1;
|
|
140
|
+
else if (current < 0) current = 0;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const next = () => {
|
|
144
|
+
if (!hasItems) return;
|
|
145
|
+
current = (current + 1) % items.length;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const prev = () => {
|
|
149
|
+
if (!hasItems) return;
|
|
150
|
+
current = (current - 1 + items.length) % items.length;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const goTo = (index: number) => {
|
|
154
|
+
if (index >= 0 && index < items.length) current = index;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
$effect(() => {
|
|
158
|
+
if (autoplay && hasItems && items.length > 1) {
|
|
159
|
+
autoplayTimer = setInterval(next, Math.max(1000, interval));
|
|
160
|
+
}
|
|
161
|
+
return () => {
|
|
162
|
+
if (autoplayTimer) {
|
|
163
|
+
clearInterval(autoplayTimer);
|
|
164
|
+
autoplayTimer = null;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
let touchStartX = 0;
|
|
170
|
+
let touchEndX = 0;
|
|
171
|
+
|
|
172
|
+
function handleTouchStart(event: TouchEvent) {
|
|
173
|
+
touchStartX = event.touches[0].clientX;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function handleTouchEnd(event: TouchEvent) {
|
|
177
|
+
touchEndX = event.changedTouches[0].clientX;
|
|
178
|
+
const diff = touchStartX - touchEndX;
|
|
179
|
+
if (Math.abs(diff) <= 50) return;
|
|
180
|
+
if (diff > 0) next();
|
|
181
|
+
else prev();
|
|
182
|
+
}
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<div
|
|
186
|
+
aria-label="Carousel"
|
|
187
|
+
class={componentClass}
|
|
188
|
+
ontouchstart={handleTouchStart}
|
|
189
|
+
ontouchend={handleTouchEnd}
|
|
190
|
+
{...rest}
|
|
191
|
+
>
|
|
192
|
+
<div class="relative">
|
|
193
|
+
<div class={viewportClass}>
|
|
194
|
+
{#each items as item, i (item.id ?? i)}
|
|
195
|
+
{#snippet header()}
|
|
196
|
+
{#if item.image}
|
|
197
|
+
<img
|
|
198
|
+
src={item.image}
|
|
199
|
+
alt={item.title || `Slide ${i + 1}`}
|
|
200
|
+
class={imgClass}
|
|
201
|
+
/>
|
|
202
|
+
{/if}
|
|
203
|
+
{/snippet}
|
|
204
|
+
|
|
205
|
+
<div
|
|
206
|
+
class="transition-opacity duration-[var(--transition-normal)] ease-in-out"
|
|
207
|
+
class:opacity-100={i === current}
|
|
208
|
+
class:opacity-0={i !== current}
|
|
209
|
+
class:block={i === current}
|
|
210
|
+
class:hidden={i !== current}
|
|
211
|
+
>
|
|
212
|
+
<Card {sz} {header} flushHeader={true} class="h-auto flex flex-col">
|
|
213
|
+
<div class={cx(bodyClass, "flex-1 overflow-auto min-h-0")}>
|
|
214
|
+
{#if item.title}
|
|
215
|
+
<h3 class="font-semibold [color:var(--color-text-default)]">
|
|
216
|
+
{item.title}
|
|
217
|
+
</h3>
|
|
218
|
+
{/if}
|
|
219
|
+
{#if item.content}
|
|
220
|
+
<p class="[color:var(--color-text-muted)]">
|
|
221
|
+
{item.content}
|
|
222
|
+
</p>
|
|
223
|
+
{/if}
|
|
224
|
+
{@render item.children?.()}
|
|
225
|
+
</div>
|
|
226
|
+
</Card>
|
|
227
|
+
</div>
|
|
228
|
+
{/each}
|
|
229
|
+
|
|
230
|
+
{#if !hasItems}
|
|
231
|
+
<div
|
|
232
|
+
class="flex items-center justify-center h-full [color:var(--color-text-muted)]"
|
|
233
|
+
>
|
|
234
|
+
No items to display
|
|
235
|
+
</div>
|
|
236
|
+
{/if}
|
|
237
|
+
</div>
|
|
238
|
+
|
|
239
|
+
{#if showArrows && hasItems && items.length > 1}
|
|
240
|
+
<button
|
|
241
|
+
type="button"
|
|
242
|
+
onclick={prev}
|
|
243
|
+
class={cx("absolute left-2 top-1/2 -translate-y-1/2", arrowClass)}
|
|
244
|
+
aria-label="Previous slide"
|
|
245
|
+
>
|
|
246
|
+
<svg
|
|
247
|
+
width="16"
|
|
248
|
+
height="16"
|
|
249
|
+
viewBox="0 0 16 16"
|
|
250
|
+
fill="none"
|
|
251
|
+
stroke="currentColor"
|
|
252
|
+
stroke-width="2"
|
|
253
|
+
>
|
|
254
|
+
<path d="M10 12L6 8L10 4" />
|
|
255
|
+
</svg>
|
|
256
|
+
</button>
|
|
257
|
+
<button
|
|
258
|
+
type="button"
|
|
259
|
+
onclick={next}
|
|
260
|
+
class={cx("absolute right-2 top-1/2 -translate-y-1/2", arrowClass)}
|
|
261
|
+
aria-label="Next slide"
|
|
262
|
+
>
|
|
263
|
+
<svg
|
|
264
|
+
width="16"
|
|
265
|
+
height="16"
|
|
266
|
+
viewBox="0 0 16 16"
|
|
267
|
+
fill="none"
|
|
268
|
+
stroke="currentColor"
|
|
269
|
+
stroke-width="2"
|
|
270
|
+
>
|
|
271
|
+
<path d="M6 4L10 8L6 12" />
|
|
272
|
+
</svg>
|
|
273
|
+
</button>
|
|
274
|
+
{/if}
|
|
275
|
+
</div>
|
|
276
|
+
|
|
277
|
+
{#if showDots && hasItems && items.length > 1}
|
|
278
|
+
<div class="flex justify-center gap-[var(--spacing-sm)] p-[var(--spacing-md)]">
|
|
279
|
+
{#each items as item, i (item.id ?? i)}
|
|
280
|
+
<button
|
|
281
|
+
type="button"
|
|
282
|
+
onclick={() => goTo(i)}
|
|
283
|
+
class={dotClass}
|
|
284
|
+
class:bg-[var(--color-bg-primary)]={i === current}
|
|
285
|
+
class:bg-[var(--color-bg-secondary)]={i !== current}
|
|
286
|
+
class:hover:bg-[var(--color-bg-primary)]={i !== current}
|
|
287
|
+
aria-label={`Go to slide ${item.title ?? `#${i + 1}`}`}
|
|
288
|
+
aria-current={i === current ? "true" : undefined}
|
|
289
|
+
></button>
|
|
290
|
+
{/each}
|
|
291
|
+
</div>
|
|
292
|
+
{/if}
|
|
293
|
+
</div>
|