svelora 3.0.1 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Accordion/Accordion.svelte +66 -97
- package/dist/Alert/Alert.svelte +39 -64
- package/dist/Alert/Alert.svelte.d.ts +1 -1
- package/dist/Avatar/Avatar.svelte +35 -75
- package/dist/AvatarGroup/AvatarGroup.svelte +38 -55
- package/dist/Badge/Badge.svelte +28 -50
- package/dist/Banner/Banner.svelte +46 -41
- package/dist/Banner/Banner.svelte.d.ts +1 -1
- package/dist/Breadcrumb/Breadcrumb.svelte +32 -26
- package/dist/Button/Button.svelte +70 -138
- package/dist/Calendar/Calendar.svelte +94 -157
- package/dist/Calendar/Calendar.svelte.d.ts +1 -1
- package/dist/Card/Card.svelte +18 -31
- package/dist/Carousel/Carousel.svelte +118 -173
- package/dist/Checkbox/Checkbox.svelte +52 -97
- package/dist/CheckboxGroup/CheckboxGroup.svelte +62 -107
- package/dist/CheckboxGroup/CheckboxGroup.svelte.d.ts +1 -1
- package/dist/Chip/Chip.svelte +22 -34
- package/dist/CodeBlock/CodeBlock.svelte +42 -59
- package/dist/Collapsible/Collapsible.svelte +22 -38
- package/dist/Collapsible/Collapsible.svelte.d.ts +1 -1
- package/dist/Collapsible/CollapsibleTestWrapper.svelte +2 -5
- package/dist/Collapsible/CollapsibleTestWrapper.svelte.d.ts +1 -1
- package/dist/Command/Command.svelte +40 -77
- package/dist/Command/Command.svelte.d.ts +1 -1
- package/dist/Command/CommandTestWrapper.svelte +2 -10
- package/dist/Command/CommandTestWrapper.svelte.d.ts +1 -1
- package/dist/Container/Container.svelte +11 -14
- package/dist/ContextMenu/ContextMenu.svelte +51 -114
- package/dist/ContextMenu/ContextMenu.svelte.d.ts +1 -1
- package/dist/Drawer/Drawer.svelte +72 -110
- package/dist/Drawer/DrawerTriggerTestWrapper.svelte +1 -2
- package/dist/DropdownMenu/DropdownMenu.svelte +63 -124
- package/dist/DropdownMenu/DropdownMenu.svelte.d.ts +1 -1
- package/dist/DropdownMenu/DropdownMenuTriggerTestWrapper.svelte +2 -5
- package/dist/Editor/Editor.svelte +441 -576
- package/dist/Editor/Editor.svelte.d.ts +1 -1
- package/dist/Editor/EditorUrlPrompt.svelte +40 -53
- package/dist/Editor/SlashPopup.svelte +12 -24
- package/dist/Empty/Empty.svelte +32 -63
- package/dist/FieldGroup/FieldGroup.svelte +23 -38
- package/dist/FileUpload/FileUpload.svelte +242 -320
- package/dist/FileUpload/FileUpload.svelte.d.ts +1 -1
- package/dist/Fonts/Fonts.svelte +15 -37
- package/dist/Form/Form.svelte +112 -170
- package/dist/FormField/FormField.svelte +102 -135
- package/dist/Icon/Icon.svelte +7 -32
- package/dist/Input/Input.svelte +71 -141
- package/dist/Input/Input.svelte.d.ts +2 -2
- package/dist/Kbd/Kbd.svelte +18 -34
- package/dist/Link/Link.svelte +129 -196
- package/dist/LocaleButton/LocaleButton.svelte +165 -0
- package/dist/LocaleButton/LocaleButton.svelte.d.ts +5 -0
- package/dist/LocaleButton/index.d.ts +2 -0
- package/dist/LocaleButton/index.js +1 -0
- package/dist/LocaleButton/locale-button.types.d.ts +182 -0
- package/dist/LocaleButton/locale-button.types.js +1 -0
- package/dist/LocaleButton/locale-button.variants.d.ts +61 -0
- package/dist/LocaleButton/locale-button.variants.js +34 -0
- package/dist/Modal/Modal.svelte +52 -106
- package/dist/Modal/ModalTriggerTestWrapper.svelte +1 -2
- package/dist/Pagination/Pagination.svelte +48 -92
- package/dist/Pagination/pagination.variants.d.ts +1 -1
- package/dist/PinInput/PinInput.svelte +57 -111
- package/dist/PinInput/PinInput.svelte.d.ts +1 -1
- package/dist/Popover/Popover.svelte +28 -61
- package/dist/Popover/Popover.svelte.d.ts +1 -1
- package/dist/Progress/Progress.svelte +75 -94
- package/dist/RadioGroup/RadioGroup.svelte +54 -99
- package/dist/RadioGroup/RadioGroup.svelte.d.ts +1 -1
- package/dist/Select/Select.svelte +112 -269
- package/dist/Select/Select.svelte.d.ts +1 -1
- package/dist/SelectMenu/SelectMenu.svelte +211 -409
- package/dist/SelectMenu/SelectMenu.svelte.d.ts +1 -1
- package/dist/SelectMenu/SelectMenuFormFieldTestWrapper.svelte +3 -6
- package/dist/Separator/Separator.svelte +29 -44
- package/dist/Skeleton/Skeleton.svelte +11 -23
- package/dist/Slideover/Slideover.svelte +52 -106
- package/dist/Slideover/SlideoverTriggerTestWrapper.svelte +1 -2
- package/dist/Slider/Slider.svelte +48 -84
- package/dist/Slider/Slider.svelte.d.ts +1 -1
- package/dist/Stepper/Stepper.svelte +139 -132
- package/dist/Stepper/Stepper.svelte.d.ts +1 -1
- package/dist/Switch/Switch.svelte +62 -98
- package/dist/Table/Table.svelte +232 -283
- package/dist/Table/table.variants.d.ts +1 -1
- package/dist/Tabs/Tabs.svelte +96 -129
- package/dist/Tabs/Tabs.svelte.d.ts +1 -1
- package/dist/Textarea/Textarea.svelte +90 -173
- package/dist/Textarea/Textarea.svelte.d.ts +1 -1
- package/dist/ThemeModeButton/ThemeModeButton.svelte +16 -38
- package/dist/Timeline/Timeline.svelte +75 -54
- package/dist/Toast/Toaster.svelte +8 -25
- package/dist/Tooltip/Tooltip.svelte +34 -66
- package/dist/Tooltip/Tooltip.svelte.d.ts +1 -1
- package/dist/Tooltip/TooltipTestWrapper.svelte +2 -5
- package/dist/User/User.svelte +33 -49
- package/dist/docs/navigation.js +6 -0
- package/dist/hooks/HookContextProbe.svelte +2 -4
- package/dist/hooks/HookContextProvider.svelte +8 -6
- package/dist/hooks/HookEmitProbe.svelte +8 -11
- package/dist/i18n.d.ts +2 -0
- package/dist/i18n.js +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/svelora-docs.data.json +4 -2
- package/dist/theme.css +2 -0
- package/package.json +16 -8
|
@@ -1,150 +1,157 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
export type Props = StepperProps;
|
|
1
|
+
<script lang="ts" module>export {};
|
|
3
2
|
</script>
|
|
4
3
|
|
|
5
|
-
<script lang="ts">import { untrack } from
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const config = getComponentConfig('stepper', stepperDefaults);
|
|
13
|
-
let { ref = $bindable(null), as = 'div', items = [], value = $bindable(), defaultValue, onValueChange, api = $bindable(), linear = true, disabled = false, orientation = config.defaultVariants.orientation ?? 'horizontal', size = config.defaultVariants.size ?? 'md', color = config.defaultVariants.color ?? 'primary', content: showContent = true, class: className, ui, indicator: indicatorSlot, titleSlot, descriptionSlot, body, ...restProps }: Props = $props();
|
|
4
|
+
<script lang="ts">import { untrack } from "svelte";
|
|
5
|
+
import { getComponentConfig } from "../config.js";
|
|
6
|
+
import Icon from "../Icon/Icon.svelte";
|
|
7
|
+
import { stepperDefaults, stepperVariants } from "./stepper.variants.js";
|
|
8
|
+
const config = getComponentConfig("stepper", stepperDefaults);
|
|
9
|
+
let { ref = $bindable(null), as = "div", items = [], value = $bindable(), defaultValue, onValueChange, api = $bindable(), linear = true, disabled = false, orientation = config.defaultVariants.orientation ?? "horizontal", size = config.defaultVariants.size ?? "md", color = config.defaultVariants.color ?? "primary", content: showContent = true, class: className, ui, indicator: indicatorSlot, titleSlot, descriptionSlot, body, ...restProps } = $props();
|
|
14
10
|
if (value === undefined) {
|
|
15
|
-
|
|
11
|
+
value = untrack(() => defaultValue ?? items[0]?.value ?? 0);
|
|
16
12
|
}
|
|
17
|
-
let triggers
|
|
18
|
-
function getItemValue(item
|
|
19
|
-
|
|
13
|
+
let triggers = $state([]);
|
|
14
|
+
function getItemValue(item, index) {
|
|
15
|
+
return item.value ?? index;
|
|
20
16
|
}
|
|
21
17
|
const activeIndex = $derived(items.findIndex((item, i) => getItemValue(item, i) === value));
|
|
22
|
-
function getState(index
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return 'active';
|
|
27
|
-
return index < activeIndex ? 'completed' : 'pending';
|
|
18
|
+
function getState(index) {
|
|
19
|
+
if (activeIndex === -1) return "pending";
|
|
20
|
+
if (index === activeIndex) return "active";
|
|
21
|
+
return index < activeIndex ? "completed" : "pending";
|
|
28
22
|
}
|
|
29
|
-
function canActivate(index
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return true;
|
|
34
|
-
return index <= activeIndex + 1;
|
|
23
|
+
function canActivate(index) {
|
|
24
|
+
if (disabled || items[index]?.disabled) return false;
|
|
25
|
+
if (!linear) return true;
|
|
26
|
+
return index <= activeIndex + 1;
|
|
35
27
|
}
|
|
36
|
-
function setValue(next
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
onValueChange?.(next);
|
|
28
|
+
function setValue(next) {
|
|
29
|
+
if (next === value) return;
|
|
30
|
+
value = next;
|
|
31
|
+
onValueChange?.(next);
|
|
41
32
|
}
|
|
42
|
-
function handleClick(item
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setValue(getItemValue(item, index));
|
|
33
|
+
function handleClick(item, index) {
|
|
34
|
+
if (!canActivate(index)) return;
|
|
35
|
+
setValue(getItemValue(item, index));
|
|
46
36
|
}
|
|
47
|
-
function findEnabled(start
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return -1;
|
|
37
|
+
function findEnabled(start, dir) {
|
|
38
|
+
for (let i = start; i >= 0 && i < items.length; i += dir) {
|
|
39
|
+
if (!items[i]?.disabled) return i;
|
|
40
|
+
}
|
|
41
|
+
return -1;
|
|
53
42
|
}
|
|
54
|
-
function handleKeydown(e
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
target = findEnabled(items.length - 1, -1);
|
|
67
|
-
else
|
|
68
|
-
return;
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
if (target >= 0)
|
|
71
|
-
triggers[target]?.focus();
|
|
43
|
+
function handleKeydown(e, index) {
|
|
44
|
+
const horizontal = orientation === "horizontal";
|
|
45
|
+
const nextKey = horizontal ? "ArrowRight" : "ArrowDown";
|
|
46
|
+
const prevKey = horizontal ? "ArrowLeft" : "ArrowUp";
|
|
47
|
+
let target = -1;
|
|
48
|
+
if (e.key === nextKey) target = findEnabled(index + 1, 1);
|
|
49
|
+
else if (e.key === prevKey) target = findEnabled(index - 1, -1);
|
|
50
|
+
else if (e.key === "Home") target = findEnabled(0, 1);
|
|
51
|
+
else if (e.key === "End") target = findEnabled(items.length - 1, -1);
|
|
52
|
+
else return;
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
if (target >= 0) triggers[target]?.focus();
|
|
72
55
|
}
|
|
73
|
-
const apiInstance
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
},
|
|
99
|
-
get activeIndex() {
|
|
100
|
-
return activeIndex;
|
|
101
|
-
}
|
|
56
|
+
const apiInstance = {
|
|
57
|
+
next() {
|
|
58
|
+
if (activeIndex >= items.length - 1) return;
|
|
59
|
+
const target = items[activeIndex + 1];
|
|
60
|
+
if (!target) return;
|
|
61
|
+
setValue(getItemValue(target, activeIndex + 1));
|
|
62
|
+
},
|
|
63
|
+
prev() {
|
|
64
|
+
if (activeIndex <= 0) return;
|
|
65
|
+
const target = items[activeIndex - 1];
|
|
66
|
+
if (!target) return;
|
|
67
|
+
setValue(getItemValue(target, activeIndex - 1));
|
|
68
|
+
},
|
|
69
|
+
goTo(next) {
|
|
70
|
+
setValue(next);
|
|
71
|
+
},
|
|
72
|
+
get hasNext() {
|
|
73
|
+
return activeIndex >= 0 && activeIndex < items.length - 1;
|
|
74
|
+
},
|
|
75
|
+
get hasPrev() {
|
|
76
|
+
return activeIndex > 0;
|
|
77
|
+
},
|
|
78
|
+
get activeIndex() {
|
|
79
|
+
return activeIndex;
|
|
80
|
+
}
|
|
102
81
|
};
|
|
103
82
|
api = apiInstance;
|
|
104
|
-
const variantSlots = $derived(stepperVariants({
|
|
105
|
-
|
|
83
|
+
const variantSlots = $derived(stepperVariants({
|
|
84
|
+
orientation,
|
|
85
|
+
size,
|
|
86
|
+
color
|
|
87
|
+
}));
|
|
106
88
|
const classes = $derived.by(() => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
89
|
+
const c = config.slots;
|
|
90
|
+
const slots = variantSlots;
|
|
91
|
+
const u = ui ?? {};
|
|
92
|
+
const _item = slots.item({ class: [c.item, u.item] });
|
|
93
|
+
const _trigger = slots.trigger({ class: [c.trigger, u.trigger] });
|
|
94
|
+
const _container = slots.container({ class: [c.container, u.container] });
|
|
95
|
+
const _indicator = slots.indicator({ class: [c.indicator, u.indicator] });
|
|
96
|
+
const _separator = slots.separator({ class: [c.separator, u.separator] });
|
|
97
|
+
const _wrapper = slots.wrapper({ class: [c.wrapper, u.wrapper] });
|
|
98
|
+
const _title = slots.title({ class: [c.title, u.title] });
|
|
99
|
+
const _description = slots.description({ class: [c.description, u.description] });
|
|
100
|
+
const _content = slots.content({ class: [c.content, u.content] });
|
|
101
|
+
return {
|
|
102
|
+
root: slots.root({ class: [
|
|
103
|
+
c.root,
|
|
104
|
+
className,
|
|
105
|
+
u.root
|
|
106
|
+
] }),
|
|
107
|
+
list: slots.list({ class: [c.list, u.list] }),
|
|
108
|
+
item: (itemClass, itemUi) => itemClass || itemUi ? slots.item({ class: [
|
|
109
|
+
c.item,
|
|
110
|
+
u.item,
|
|
111
|
+
itemUi?.item,
|
|
112
|
+
itemClass
|
|
113
|
+
] }) : _item,
|
|
114
|
+
trigger: (itemUi) => itemUi ? slots.trigger({ class: [
|
|
115
|
+
c.trigger,
|
|
116
|
+
u.trigger,
|
|
117
|
+
itemUi.trigger
|
|
118
|
+
] }) : _trigger,
|
|
119
|
+
container: (itemUi) => itemUi ? slots.container({ class: [
|
|
120
|
+
c.container,
|
|
121
|
+
u.container,
|
|
122
|
+
itemUi.container
|
|
123
|
+
] }) : _container,
|
|
124
|
+
indicator: (itemUi) => itemUi ? slots.indicator({ class: [
|
|
125
|
+
c.indicator,
|
|
126
|
+
u.indicator,
|
|
127
|
+
itemUi.indicator
|
|
128
|
+
] }) : _indicator,
|
|
129
|
+
separator: (itemUi) => itemUi ? slots.separator({ class: [
|
|
130
|
+
c.separator,
|
|
131
|
+
u.separator,
|
|
132
|
+
itemUi.separator
|
|
133
|
+
] }) : _separator,
|
|
134
|
+
wrapper: (itemUi) => itemUi ? slots.wrapper({ class: [
|
|
135
|
+
c.wrapper,
|
|
136
|
+
u.wrapper,
|
|
137
|
+
itemUi.wrapper
|
|
138
|
+
] }) : _wrapper,
|
|
139
|
+
title: (itemUi) => itemUi ? slots.title({ class: [
|
|
140
|
+
c.title,
|
|
141
|
+
u.title,
|
|
142
|
+
itemUi.title
|
|
143
|
+
] }) : _title,
|
|
144
|
+
description: (itemUi) => itemUi ? slots.description({ class: [
|
|
145
|
+
c.description,
|
|
146
|
+
u.description,
|
|
147
|
+
itemUi.description
|
|
148
|
+
] }) : _description,
|
|
149
|
+
content: (itemUi) => itemUi ? slots.content({ class: [
|
|
150
|
+
c.content,
|
|
151
|
+
u.content,
|
|
152
|
+
itemUi.content
|
|
153
|
+
] }) : _content
|
|
154
|
+
};
|
|
148
155
|
});
|
|
149
156
|
</script>
|
|
150
157
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StepperProps } from './stepper.types.js';
|
|
2
2
|
export type Props = StepperProps;
|
|
3
|
-
declare const Stepper: import("svelte").Component<StepperProps, {}, "
|
|
3
|
+
declare const Stepper: import("svelte").Component<StepperProps, {}, "ref" | "value" | "api">;
|
|
4
4
|
type Stepper = ReturnType<typeof Stepper>;
|
|
5
5
|
export default Stepper;
|
|
@@ -1,103 +1,67 @@
|
|
|
1
|
-
<script lang="ts" module>
|
|
2
|
-
import type { SwitchProps } from './switch.types.js'
|
|
3
|
-
|
|
4
|
-
export type Props = SwitchProps
|
|
1
|
+
<script lang="ts" module>export {};
|
|
5
2
|
</script>
|
|
6
3
|
|
|
7
|
-
<script lang="ts">
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
color: resolvedColor,
|
|
69
|
-
size: resolvedSize,
|
|
70
|
-
loading,
|
|
71
|
-
required,
|
|
72
|
-
disabled: isDisabled ? true : undefined
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
const slots = $derived(switchVariants(variantOpts))
|
|
76
|
-
|
|
77
|
-
const classes = $derived({
|
|
78
|
-
root: slots.root({ class: [config.slots.root, className, ui?.root] }),
|
|
79
|
-
base: slots.base({ class: [config.slots.base, ui?.base] }),
|
|
80
|
-
container: slots.container({ class: [config.slots.container, ui?.container] }),
|
|
81
|
-
thumb: slots.thumb({ class: [config.slots.thumb, ui?.thumb] }),
|
|
82
|
-
wrapper: slots.wrapper({ class: [config.slots.wrapper, ui?.wrapper] }),
|
|
83
|
-
label: slots.label({ class: [config.slots.label, ui?.label] }),
|
|
84
|
-
description: slots.description({ class: [config.slots.description, ui?.description] })
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const iconClasses = $derived.by(() => {
|
|
88
|
-
if (!hasCheckedIcon && !hasUncheckedIcon)
|
|
89
|
-
return { checked: undefined, unchecked: undefined }
|
|
90
|
-
const iconUiClass = [config.slots.icon, ui?.icon]
|
|
91
|
-
return {
|
|
92
|
-
checked: hasCheckedIcon
|
|
93
|
-
? slots.icon({ class: iconUiClass, checked: true, unchecked: loading })
|
|
94
|
-
: undefined,
|
|
95
|
-
unchecked:
|
|
96
|
-
hasUncheckedIcon && !loading
|
|
97
|
-
? slots.icon({ class: iconUiClass, unchecked: true })
|
|
98
|
-
: undefined
|
|
99
|
-
}
|
|
100
|
-
})
|
|
4
|
+
<script lang="ts">import { Label, Switch, useId } from "bits-ui";
|
|
5
|
+
import { getComponentConfig, iconsDefaults } from "../config.js";
|
|
6
|
+
import { useFormField, useFormFieldEmit } from "../hooks/useFormField.svelte.js";
|
|
7
|
+
import Icon from "../Icon/Icon.svelte";
|
|
8
|
+
import { switchDefaults, switchVariants } from "./switch.variants.js";
|
|
9
|
+
const config = getComponentConfig("switch", switchDefaults);
|
|
10
|
+
const icons = getComponentConfig("icons", iconsDefaults);
|
|
11
|
+
let { ref = $bindable(null), checked = $bindable(false), onCheckedChange, ui, id, name, value, color = config.defaultVariants.color, size, disabled = false, required = false, loading = false, loadingIcon = icons.loading, checkedIcon, uncheckedIcon, label, description, labelSlot, descriptionSlot, class: className, ...restProps } = $props();
|
|
12
|
+
const formFieldContext = useFormField();
|
|
13
|
+
const emit = useFormFieldEmit();
|
|
14
|
+
const hasError = $derived(formFieldContext?.error !== undefined && formFieldContext?.error !== false);
|
|
15
|
+
const resolvedSize = $derived(size ?? formFieldContext?.size ?? config.defaultVariants.size);
|
|
16
|
+
const resolvedColor = $derived(hasError ? "error" : color);
|
|
17
|
+
const autoId = useId();
|
|
18
|
+
const resolvedId = $derived(id ?? formFieldContext?.ariaId ?? autoId);
|
|
19
|
+
const resolvedName = $derived(name ?? formFieldContext?.name);
|
|
20
|
+
const isDisabled = $derived(disabled || loading);
|
|
21
|
+
const ariaDescribedBy = $derived(!formFieldContext ? undefined : hasError ? `${formFieldContext.ariaId}-error` : `${formFieldContext.ariaId}-description ${formFieldContext.ariaId}-help`);
|
|
22
|
+
const hasCheckedIcon = $derived(loading || !!checkedIcon);
|
|
23
|
+
const hasUncheckedIcon = $derived(loading || !!uncheckedIcon);
|
|
24
|
+
const checkedIconName = $derived(loading ? loadingIcon : checkedIcon);
|
|
25
|
+
const uncheckedIconName = $derived(loading ? loadingIcon : uncheckedIcon);
|
|
26
|
+
const variantOpts = $derived({
|
|
27
|
+
color: resolvedColor,
|
|
28
|
+
size: resolvedSize,
|
|
29
|
+
loading,
|
|
30
|
+
required,
|
|
31
|
+
disabled: isDisabled ? true : undefined
|
|
32
|
+
});
|
|
33
|
+
const slots = $derived(switchVariants(variantOpts));
|
|
34
|
+
const classes = $derived({
|
|
35
|
+
root: slots.root({ class: [
|
|
36
|
+
config.slots.root,
|
|
37
|
+
className,
|
|
38
|
+
ui?.root
|
|
39
|
+
] }),
|
|
40
|
+
base: slots.base({ class: [config.slots.base, ui?.base] }),
|
|
41
|
+
container: slots.container({ class: [config.slots.container, ui?.container] }),
|
|
42
|
+
thumb: slots.thumb({ class: [config.slots.thumb, ui?.thumb] }),
|
|
43
|
+
wrapper: slots.wrapper({ class: [config.slots.wrapper, ui?.wrapper] }),
|
|
44
|
+
label: slots.label({ class: [config.slots.label, ui?.label] }),
|
|
45
|
+
description: slots.description({ class: [config.slots.description, ui?.description] })
|
|
46
|
+
});
|
|
47
|
+
const iconClasses = $derived.by(() => {
|
|
48
|
+
if (!hasCheckedIcon && !hasUncheckedIcon) return {
|
|
49
|
+
checked: undefined,
|
|
50
|
+
unchecked: undefined
|
|
51
|
+
};
|
|
52
|
+
const iconUiClass = [config.slots.icon, ui?.icon];
|
|
53
|
+
return {
|
|
54
|
+
checked: hasCheckedIcon ? slots.icon({
|
|
55
|
+
class: iconUiClass,
|
|
56
|
+
checked: true,
|
|
57
|
+
unchecked: loading
|
|
58
|
+
}) : undefined,
|
|
59
|
+
unchecked: hasUncheckedIcon && !loading ? slots.icon({
|
|
60
|
+
class: iconUiClass,
|
|
61
|
+
unchecked: true
|
|
62
|
+
}) : undefined
|
|
63
|
+
};
|
|
64
|
+
});
|
|
101
65
|
</script>
|
|
102
66
|
|
|
103
67
|
<div {...restProps} bind:this={ref} class={classes.root}>
|