@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
- // Lifecycle
69
+ // Effects
69
70
  // =========================================================================
70
- onMount(() => {
71
+ $effect(() => {
71
72
  options.forEach((option) => {
72
- localValues[String(option.value)] = false;
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
- {#if localValues[String(option.value)] !== undefined}
102
- <li class="checkbox-group__option">
103
- <Checkbox
104
- bind:value={localValues[String(option.value)]}
105
- {size}
106
- {disabled}
107
- {required}
108
- {reducedMotion}
109
- onchange={handleChange}
110
- >
111
- {option.label}
112
- </Checkbox>
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
 
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.34",
5
+ "version": "0.0.35",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "svelte",