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