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
package/dist/lib/Carousel.svelte
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
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 type { SizeKey, 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: "rounded-[var(--radius-md)] text-sm",
|
|
70
|
-
sm: "rounded-[var(--radius-md)] text-base",
|
|
71
|
-
md: "rounded-[var(--radius-lg)] text-lg",
|
|
72
|
-
lg: "rounded-[var(--radius-lg)] text-xl",
|
|
73
|
-
xl: "rounded-[var(--radius-xl)] text-2xl",
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const contentSize: Record<SizeKey, string> = {
|
|
77
|
-
xs: "p-3 gap-2",
|
|
78
|
-
sm: "p-4 gap-2.5",
|
|
79
|
-
md: "p-5 gap-3",
|
|
80
|
-
lg: "p-6 gap-4",
|
|
81
|
-
xl: "p-8 gap-5",
|
|
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-lg 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-200 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, 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-300 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-2 p-4">
|
|
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,13 +0,0 @@
|
|
|
1
|
-
import type { HTMLAttributes } from "svelte/elements";
|
|
2
|
-
import type { SizeKey, CarouselItem } from "./types";
|
|
3
|
-
type Props = HTMLAttributes<HTMLDivElement> & {
|
|
4
|
-
items?: CarouselItem[];
|
|
5
|
-
sz?: SizeKey;
|
|
6
|
-
autoplay?: boolean;
|
|
7
|
-
interval?: number;
|
|
8
|
-
showDots?: boolean;
|
|
9
|
-
showArrows?: boolean;
|
|
10
|
-
};
|
|
11
|
-
declare const Carousel: import("svelte").Component<Props, {}, "">;
|
|
12
|
-
type Carousel = ReturnType<typeof Carousel>;
|
|
13
|
-
export default Carousel;
|
package/dist/lib/CheckBox.svelte
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
<!-- src/lib/CheckBox.svelte -->
|
|
2
|
-
<script lang="ts">
|
|
3
|
-
/**
|
|
4
|
-
* @component CheckBox
|
|
5
|
-
* @description Accessible custom checkbox with `indeterminate` support.
|
|
6
|
-
*
|
|
7
|
-
* @prop label {string} - Text label shown next to the checkbox
|
|
8
|
-
*
|
|
9
|
-
* @prop sz {SizeKey} - Size option
|
|
10
|
-
* @options xs|sm|md|lg|xl
|
|
11
|
-
* @default md
|
|
12
|
-
*
|
|
13
|
-
* @prop variant {ComponentVariant} - Visual style preset
|
|
14
|
-
* @options default|neutral
|
|
15
|
-
* @default default
|
|
16
|
-
*
|
|
17
|
-
* @prop indeterminate {boolean} - Enables the mixed state
|
|
18
|
-
* @default false
|
|
19
|
-
*
|
|
20
|
-
* @prop checked {boolean} - Controlled checked state (bindable)
|
|
21
|
-
* @default false
|
|
22
|
-
*
|
|
23
|
-
* @prop onChange {(checked: boolean) => void} - Fired when the checkbox toggles
|
|
24
|
-
*
|
|
25
|
-
* @prop class {string} - Extra classes applied to the root container
|
|
26
|
-
* @default ""
|
|
27
|
-
*
|
|
28
|
-
* @prop invalid {boolean} - Marks the field invalid and sets `aria-invalid`
|
|
29
|
-
* @default false
|
|
30
|
-
*
|
|
31
|
-
* @prop describedBy {string} - ID of helper or error text for accessibility
|
|
32
|
-
*
|
|
33
|
-
* @note Fully bindable via `bind:checked`; `onChange` receives the final boolean.
|
|
34
|
-
* @note `indeterminate` is applied to the underlying input and reported as `aria-checked="mixed"`.
|
|
35
|
-
* @note Clicking the custom box while `indeterminate` clears it and sets `checked=true`.
|
|
36
|
-
* @note `invalid` maps to `aria-invalid`; `describedBy` maps to `aria-describedby`.
|
|
37
|
-
* @note SVG check and dash are inline; colors adapt per `variant` (`neutral` uses border color).
|
|
38
|
-
* @note Sizes scale the control box (`xs → xl`).
|
|
39
|
-
*/
|
|
40
|
-
import type { HTMLInputAttributes } from "svelte/elements";
|
|
41
|
-
import { type SizeKey, type ComponentVariant, TEXT } from "./types";
|
|
42
|
-
import { cx, uid } from "../utils";
|
|
43
|
-
|
|
44
|
-
type Props = HTMLInputAttributes & {
|
|
45
|
-
label?: string;
|
|
46
|
-
sz?: SizeKey;
|
|
47
|
-
variant?: ComponentVariant;
|
|
48
|
-
indeterminate?: boolean;
|
|
49
|
-
checked?: boolean;
|
|
50
|
-
onChange?: (checked: boolean) => void;
|
|
51
|
-
class?: string;
|
|
52
|
-
invalid?: boolean;
|
|
53
|
-
describedBy?: string;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
let {
|
|
57
|
-
label,
|
|
58
|
-
sz = "md",
|
|
59
|
-
variant = "default",
|
|
60
|
-
indeterminate = false,
|
|
61
|
-
checked = $bindable(false),
|
|
62
|
-
onChange,
|
|
63
|
-
class: externalClass = "",
|
|
64
|
-
invalid = false,
|
|
65
|
-
describedBy,
|
|
66
|
-
...rest
|
|
67
|
-
}: Props = $props();
|
|
68
|
-
|
|
69
|
-
const inputId = $derived(rest.id ?? uid("chk-"));
|
|
70
|
-
|
|
71
|
-
const sizeClasses = {
|
|
72
|
-
xs: "w-3 h-3",
|
|
73
|
-
sm: "w-3.5 h-3.5",
|
|
74
|
-
md: "w-4 h-4",
|
|
75
|
-
lg: "w-[18px] h-[18px]",
|
|
76
|
-
xl: "w-5 h-5",
|
|
77
|
-
} as const;
|
|
78
|
-
|
|
79
|
-
const gapBySize: Record<SizeKey, string> = {
|
|
80
|
-
xs: "gap-1.5",
|
|
81
|
-
sm: "gap-2",
|
|
82
|
-
md: "gap-2.5",
|
|
83
|
-
lg: "gap-3",
|
|
84
|
-
xl: "gap-3.5",
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const variants = $derived(
|
|
88
|
-
variant === "neutral"
|
|
89
|
-
? {
|
|
90
|
-
checked: "bg-transparent border-[var(--border-color-strong)]",
|
|
91
|
-
unchecked: "bg-transparent border-[var(--border-color-default)]",
|
|
92
|
-
mixed: "bg-transparent border-[var(--border-color-strong)]",
|
|
93
|
-
}
|
|
94
|
-
: {
|
|
95
|
-
checked:
|
|
96
|
-
"bg-[var(--color-bg-primary)] border-[var(--color-bg-primary)]",
|
|
97
|
-
unchecked:
|
|
98
|
-
"bg-[var(--color-bg-surface)] border-[var(--border-color-default)]",
|
|
99
|
-
mixed:
|
|
100
|
-
"bg-[var(--color-bg-secondary)] border-[var(--border-color-default)]",
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const boxBase =
|
|
105
|
-
"rounded-[var(--radius-sm)] border border-solid cursor-pointer transition-all duration-[var(--transition-fast)] ease-[var(--timing-default)] flex items-center justify-center";
|
|
106
|
-
|
|
107
|
-
const focusFromPeer =
|
|
108
|
-
"peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--border-color-focus)] peer-focus-visible:border-[var(--border-color-focus)]";
|
|
109
|
-
|
|
110
|
-
const state = $derived(
|
|
111
|
-
indeterminate ? "mixed" : checked ? "checked" : "unchecked"
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const strokeColor = $derived(
|
|
115
|
-
variant === "neutral"
|
|
116
|
-
? state === "checked" || state === "mixed"
|
|
117
|
-
? "var(--border-color-strong)"
|
|
118
|
-
: "var(--border-color-default)"
|
|
119
|
-
: "white"
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const rootClass = $derived(
|
|
123
|
-
cx(
|
|
124
|
-
"inline-flex items-center cursor-pointer select-none",
|
|
125
|
-
gapBySize[sz],
|
|
126
|
-
externalClass
|
|
127
|
-
)
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const checkboxClass = $derived(
|
|
131
|
-
cx(
|
|
132
|
-
boxBase,
|
|
133
|
-
focusFromPeer,
|
|
134
|
-
sizeClasses[sz],
|
|
135
|
-
state === "checked" && variants.checked,
|
|
136
|
-
state === "mixed" && variants.mixed,
|
|
137
|
-
state === "unchecked" && variants.unchecked,
|
|
138
|
-
"peer-disabled:opacity-[var(--opacity-disabled)] peer-disabled:cursor-not-allowed"
|
|
139
|
-
)
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
const labelClass = $derived(
|
|
143
|
-
cx(
|
|
144
|
-
TEXT[sz],
|
|
145
|
-
"[color:var(--color-text-muted)] font-medium peer-disabled:cursor-not-allowed"
|
|
146
|
-
)
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
function handleClick(e: MouseEvent) {
|
|
150
|
-
if (indeterminate) {
|
|
151
|
-
e.preventDefault();
|
|
152
|
-
checked = true;
|
|
153
|
-
indeterminate = false;
|
|
154
|
-
onChange?.(true);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
</script>
|
|
158
|
-
|
|
159
|
-
<label class={rootClass} for={inputId}>
|
|
160
|
-
<input
|
|
161
|
-
id={inputId}
|
|
162
|
-
type="checkbox"
|
|
163
|
-
bind:checked
|
|
164
|
-
{...rest}
|
|
165
|
-
class="sr-only peer"
|
|
166
|
-
aria-checked={indeterminate ? "mixed" : checked}
|
|
167
|
-
aria-invalid={invalid || undefined}
|
|
168
|
-
aria-describedby={describedBy}
|
|
169
|
-
onchange={() => {
|
|
170
|
-
if (indeterminate) indeterminate = false;
|
|
171
|
-
onChange?.(checked);
|
|
172
|
-
}}
|
|
173
|
-
/>
|
|
174
|
-
|
|
175
|
-
<span
|
|
176
|
-
data-state={state}
|
|
177
|
-
class={checkboxClass}
|
|
178
|
-
onclick={handleClick}
|
|
179
|
-
aria-hidden="true"
|
|
180
|
-
>
|
|
181
|
-
{#if indeterminate}
|
|
182
|
-
<svg
|
|
183
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
184
|
-
viewBox="0 0 24 24"
|
|
185
|
-
fill="none"
|
|
186
|
-
stroke={strokeColor}
|
|
187
|
-
stroke-width="3"
|
|
188
|
-
stroke-linecap="round"
|
|
189
|
-
>
|
|
190
|
-
<line x1="4" y1="12" x2="20" y2="12" />
|
|
191
|
-
</svg>
|
|
192
|
-
{:else if checked}
|
|
193
|
-
<svg
|
|
194
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
195
|
-
viewBox="0 0 24 24"
|
|
196
|
-
fill="none"
|
|
197
|
-
stroke={strokeColor}
|
|
198
|
-
stroke-width="3"
|
|
199
|
-
stroke-linecap="round"
|
|
200
|
-
stroke-linejoin="round"
|
|
201
|
-
>
|
|
202
|
-
<polyline points="20 6 9 17 4 12" />
|
|
203
|
-
</svg>
|
|
204
|
-
{/if}
|
|
205
|
-
</span>
|
|
206
|
-
|
|
207
|
-
{#if label}
|
|
208
|
-
<span class={labelClass}>{label}</span>
|
|
209
|
-
{/if}
|
|
210
|
-
</label>
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @component CheckBox
|
|
3
|
-
* @description Accessible custom checkbox with `indeterminate` support.
|
|
4
|
-
*
|
|
5
|
-
* @prop label {string} - Text label shown next to the checkbox
|
|
6
|
-
*
|
|
7
|
-
* @prop sz {SizeKey} - Size option
|
|
8
|
-
* @options xs|sm|md|lg|xl
|
|
9
|
-
* @default md
|
|
10
|
-
*
|
|
11
|
-
* @prop variant {ComponentVariant} - Visual style preset
|
|
12
|
-
* @options default|neutral
|
|
13
|
-
* @default default
|
|
14
|
-
*
|
|
15
|
-
* @prop indeterminate {boolean} - Enables the mixed state
|
|
16
|
-
* @default false
|
|
17
|
-
*
|
|
18
|
-
* @prop checked {boolean} - Controlled checked state (bindable)
|
|
19
|
-
* @default false
|
|
20
|
-
*
|
|
21
|
-
* @prop onChange {(checked: boolean) => void} - Fired when the checkbox toggles
|
|
22
|
-
*
|
|
23
|
-
* @prop class {string} - Extra classes applied to the root container
|
|
24
|
-
* @default ""
|
|
25
|
-
*
|
|
26
|
-
* @prop invalid {boolean} - Marks the field invalid and sets `aria-invalid`
|
|
27
|
-
* @default false
|
|
28
|
-
*
|
|
29
|
-
* @prop describedBy {string} - ID of helper or error text for accessibility
|
|
30
|
-
*
|
|
31
|
-
* @note Fully bindable via `bind:checked`; `onChange` receives the final boolean.
|
|
32
|
-
* @note `indeterminate` is applied to the underlying input and reported as `aria-checked="mixed"`.
|
|
33
|
-
* @note Clicking the custom box while `indeterminate` clears it and sets `checked=true`.
|
|
34
|
-
* @note `invalid` maps to `aria-invalid`; `describedBy` maps to `aria-describedby`.
|
|
35
|
-
* @note SVG check and dash are inline; colors adapt per `variant` (`neutral` uses border color).
|
|
36
|
-
* @note Sizes scale the control box (`xs → xl`).
|
|
37
|
-
*/
|
|
38
|
-
import type { HTMLInputAttributes } from "svelte/elements";
|
|
39
|
-
import { type SizeKey, type ComponentVariant } from "./types";
|
|
40
|
-
type Props = HTMLInputAttributes & {
|
|
41
|
-
label?: string;
|
|
42
|
-
sz?: SizeKey;
|
|
43
|
-
variant?: ComponentVariant;
|
|
44
|
-
indeterminate?: boolean;
|
|
45
|
-
checked?: boolean;
|
|
46
|
-
onChange?: (checked: boolean) => void;
|
|
47
|
-
class?: string;
|
|
48
|
-
invalid?: boolean;
|
|
49
|
-
describedBy?: string;
|
|
50
|
-
};
|
|
51
|
-
declare const CheckBox: import("svelte").Component<Props, {}, "checked">;
|
|
52
|
-
type CheckBox = ReturnType<typeof CheckBox>;
|
|
53
|
-
export default CheckBox;
|