@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 = options
81
- .filter((option) => localValues[String(option.value)])
82
- .map((option) => option.value);
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
- // $defived
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
- {#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}
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
 
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.36",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "svelte",