@14ch/svelte-ui 0.0.35 → 0.0.36
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.
|
@@ -61,34 +61,18 @@
|
|
|
61
61
|
onchange = () => {} // No params for type inference
|
|
62
62
|
}: CheckboxGroupProps = $props();
|
|
63
63
|
|
|
64
|
-
let localValues: Record<string, boolean> = $state(
|
|
65
|
-
Object.fromEntries(options.map((opt) => [String(opt.value), (value ?? []).includes(opt.value)]))
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// =========================================================================
|
|
69
|
-
// Effects
|
|
70
|
-
// =========================================================================
|
|
71
|
-
$effect(() => {
|
|
72
|
-
options.forEach((option) => {
|
|
73
|
-
const key = String(option.value);
|
|
74
|
-
if (!(key in localValues)) {
|
|
75
|
-
localValues[key] = (value ?? []).includes(option.value);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
64
|
// =========================================================================
|
|
81
65
|
// Methods
|
|
82
66
|
// =========================================================================
|
|
83
|
-
const handleChange = () => {
|
|
84
|
-
value =
|
|
85
|
-
|
|
86
|
-
.
|
|
67
|
+
const handleChange = (optionValue: OptionValue, checked: boolean) => {
|
|
68
|
+
value = checked
|
|
69
|
+
? [...(value ?? []), optionValue]
|
|
70
|
+
: (value ?? []).filter((v) => v !== optionValue);
|
|
87
71
|
onchange(value);
|
|
88
72
|
};
|
|
89
73
|
|
|
90
74
|
// =========================================================================
|
|
91
|
-
// $
|
|
75
|
+
// $derived
|
|
92
76
|
// =========================================================================
|
|
93
77
|
const gapStyle = $derived(gap !== undefined ? getStyleFromNumber(gap) : undefined);
|
|
94
78
|
const minOptionWidthStyle = $derived(getStyleFromNumber(minOptionWidth));
|
|
@@ -104,12 +88,12 @@
|
|
|
104
88
|
{#each options as option (option.value)}
|
|
105
89
|
<li class="checkbox-group__option">
|
|
106
90
|
<Checkbox
|
|
107
|
-
|
|
91
|
+
value={(value ?? []).includes(option.value)}
|
|
108
92
|
{size}
|
|
109
|
-
{disabled}
|
|
93
|
+
disabled={disabled || (option.disabled ?? false)}
|
|
110
94
|
{required}
|
|
111
95
|
{reducedMotion}
|
|
112
|
-
onchange={handleChange}
|
|
96
|
+
onchange={(checked) => handleChange(option.value, checked)}
|
|
113
97
|
>
|
|
114
98
|
{option.label}
|
|
115
99
|
</Checkbox>
|