@14ch/svelte-ui 0.0.33 → 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
 
@@ -111,7 +111,6 @@
111
111
  $effect(() => {
112
112
  return subscribeUrlChange(() => {
113
113
  resolvedCurrentPath = getCurrentPath(currentPath);
114
- if (childrenVariant !== 'accordion') expandedParent = null;
115
114
  });
116
115
  });
117
116
 
@@ -129,7 +128,7 @@
129
128
  matchPath(resolvedCurrentPath, child.href, child, pathPrefix, customPathMatcher)
130
129
  )
131
130
  );
132
- if (activeParent) expandedParent = activeParent;
131
+ expandedParent = activeParent ?? null;
133
132
  });
134
133
 
135
134
  // =========================================================================
@@ -231,16 +230,6 @@
231
230
  }
232
231
  };
233
232
 
234
- const handleToggle = (item: MenuItem) => {
235
- if (childrenVariant === 'accordion') {
236
- // accordion: 開くのみ(再クリックで閉じない、他は自動的に閉じる)
237
- expandedParent = item;
238
- } else {
239
- // bar: トグル
240
- expandedParent = expandedParent === item ? null : item;
241
- }
242
- };
243
-
244
233
  // =========================================================================
245
234
  // $derived
246
235
  // =========================================================================
@@ -310,10 +299,6 @@
310
299
  {customPathMatcher}
311
300
  isChildrenVisible={(childrenVariant === 'bar' || childrenVariant === 'accordion') &&
312
301
  expandedParent === item}
313
- onChildrenToggle={handleToggle}
314
- onChildrenClose={() => {
315
- expandedParent = null;
316
- }}
317
302
  />
318
303
  {/each}
319
304
  </div>
@@ -55,11 +55,6 @@
55
55
  /** Whether this item's children are currently visible. */
56
56
  isChildrenVisible?: boolean;
57
57
 
58
- // イベントハンドラ
59
- /** For bar/accordion mode: called when this parent is clicked. */
60
- onChildrenToggle?: (item: MenuItem) => void;
61
- /** Called when a leaf item (no children) is clicked — used to close any open sub-menu. */
62
- onChildrenClose?: () => void;
63
58
  };
64
59
 
65
60
  let {
@@ -91,9 +86,6 @@
91
86
  isChild = false,
92
87
  isChildrenVisible = $bindable(false),
93
88
 
94
- // イベントハンドラ
95
- onChildrenToggle,
96
- onChildrenClose
97
89
  }: NavItemProps = $props();
98
90
 
99
91
  // =========================================================================
@@ -222,8 +214,6 @@
222
214
  popupMenuRef?.toggle();
223
215
  } else if (childrenVariant === 'bottom-sheet') {
224
216
  toggleOpen();
225
- } else if (childrenVariant !== 'expanded') {
226
- onChildrenToggle?.(item);
227
217
  }
228
218
  };
229
219
 
@@ -373,6 +363,7 @@
373
363
  role="menu"
374
364
  tabindex="-1"
375
365
  transition:fly={{ y: 100, duration: 250 }}
366
+ onclick={closeOpen}
376
367
  onkeydown={(e) => handleChildKeyDown(e, true)}
377
368
  bind:this={bottomSheetEl}
378
369
  >
@@ -393,7 +384,6 @@
393
384
  {customPathMatcher}
394
385
  isSelected={isChildSelected(child)}
395
386
  isDisabled={child.disabled ?? false}
396
- onChildrenClose={closeOpen}
397
387
  />
398
388
  {/each}
399
389
  </div>
@@ -418,7 +408,6 @@
418
408
  data-nav-item={!isChild ? '' : undefined}
419
409
  data-nav-item-child={isChild ? '' : undefined}
420
410
  data-testid="nav-item"
421
- onclick={onChildrenClose}
422
411
  >
423
412
  {#if item.icon}
424
413
  <div class="nav-item__icon">
@@ -33,10 +33,6 @@ export type NavItemProps = {
33
33
  isChild?: boolean;
34
34
  /** Whether this item's children are currently visible. */
35
35
  isChildrenVisible?: boolean;
36
- /** For bar/accordion mode: called when this parent is clicked. */
37
- onChildrenToggle?: (item: MenuItem) => void;
38
- /** Called when a leaf item (no children) is clicked — used to close any open sub-menu. */
39
- onChildrenClose?: () => void;
40
36
  };
41
37
  declare const NavItem: import("svelte").Component<NavItemProps, {}, "isChildrenVisible">;
42
38
  type NavItem = ReturnType<typeof NavItem>;
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.33",
5
+ "version": "0.0.35",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "svelte",