@14ch/svelte-ui 0.0.34 → 0.0.35
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.
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
<script lang="ts">
|
|
4
4
|
import type { Option, OptionValue } from '../types/options';
|
|
5
5
|
import Checkbox from './Checkbox.svelte';
|
|
6
|
-
import { onMount } from 'svelte';
|
|
7
6
|
import { getStyleFromNumber } from '../utils/style';
|
|
8
7
|
import type { BivariantValueHandler } from '../types/callbackHandlers';
|
|
9
8
|
|
|
@@ -62,14 +61,19 @@
|
|
|
62
61
|
onchange = () => {} // No params for type inference
|
|
63
62
|
}: CheckboxGroupProps = $props();
|
|
64
63
|
|
|
65
|
-
let localValues: Record<string, boolean> = $state(
|
|
64
|
+
let localValues: Record<string, boolean> = $state(
|
|
65
|
+
Object.fromEntries(options.map((opt) => [String(opt.value), (value ?? []).includes(opt.value)]))
|
|
66
|
+
);
|
|
66
67
|
|
|
67
68
|
// =========================================================================
|
|
68
|
-
//
|
|
69
|
+
// Effects
|
|
69
70
|
// =========================================================================
|
|
70
|
-
|
|
71
|
+
$effect(() => {
|
|
71
72
|
options.forEach((option) => {
|
|
72
|
-
|
|
73
|
+
const key = String(option.value);
|
|
74
|
+
if (!(key in localValues)) {
|
|
75
|
+
localValues[key] = (value ?? []).includes(option.value);
|
|
76
|
+
}
|
|
73
77
|
});
|
|
74
78
|
});
|
|
75
79
|
|
|
@@ -98,20 +102,18 @@
|
|
|
98
102
|
style:--internal-checkbox-group-min-option-width={minOptionWidthStyle}
|
|
99
103
|
>
|
|
100
104
|
{#each options as option (option.value)}
|
|
101
|
-
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
</li>
|
|
114
|
-
{/if}
|
|
105
|
+
<li class="checkbox-group__option">
|
|
106
|
+
<Checkbox
|
|
107
|
+
bind:value={localValues[String(option.value)]}
|
|
108
|
+
{size}
|
|
109
|
+
{disabled}
|
|
110
|
+
{required}
|
|
111
|
+
{reducedMotion}
|
|
112
|
+
onchange={handleChange}
|
|
113
|
+
>
|
|
114
|
+
{option.label}
|
|
115
|
+
</Checkbox>
|
|
116
|
+
</li>
|
|
115
117
|
{/each}
|
|
116
118
|
</ul>
|
|
117
119
|
|