@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 = options
85
- .filter((option) => localValues[String(option.value)])
86
- .map((option) => option.value);
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
- // $defived
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
- bind:value={localValues[String(option.value)]}
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>
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@14ch/svelte-ui",
3
3
  "description": "Modern Svelte UI components library with TypeScript support",
4
4
  "private": false,
5
- "version": "0.0.35",
5
+ "version": "0.0.36",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "svelte",