@dorsk/tsumikit 0.43.1 → 0.44.0

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.
@@ -120,10 +120,9 @@
120
120
  focusAt(b.length - 1);
121
121
  }
122
122
  }
123
- function select(item: MenuItem) {
123
+ function select(item: MenuItem, close: () => void) {
124
124
  if (item.disabled) return;
125
- // Close the popover, then run the action.
126
- listEl?.closest<HTMLElement>('[popover]')?.hidePopover();
125
+ close();
127
126
  item.onselect();
128
127
  }
129
128
  </script>
@@ -158,6 +157,7 @@
158
157
  onopen?.();
159
158
  }}
160
159
  >
160
+ {#snippet children({ close }: { close: () => void })}
161
161
  <div bind:this={listEl} role="none" class="menu" data-tsu="Menu" tabindex="-1" {onkeydown}>
162
162
  {#each items as item (item.label)}
163
163
  <button
@@ -169,7 +169,7 @@
169
169
  class:on={item.pressed}
170
170
  disabled={item.disabled}
171
171
  tabindex="-1"
172
- onclick={() => select(item)}
172
+ onclick={() => select(item, close)}
173
173
  >
174
174
  {#if item.content}
175
175
  {@render item.content(item)}
@@ -189,6 +189,7 @@
189
189
  </button>
190
190
  {/each}
191
191
  </div>
192
+ {/snippet}
192
193
  </Popover>
193
194
 
194
195
  <style>
@@ -50,8 +50,9 @@
50
50
  label: string;
51
51
  /** Trigger content (rendered inside a button that owns the popover wiring). */
52
52
  trigger: Snippet;
53
- /** Panel content. */
54
- children: Snippet;
53
+ /** Panel content. Receives `{ close }` to dismiss the panel from inside;
54
+ * zero-argument snippets keep working. */
55
+ children: Snippet<[{ close: () => void }]>;
55
56
  /** Extra class on the trigger button — style it from your own scoped CSS,
56
57
  * no :global needed (you supply the class). */
57
58
  triggerClass?: string;
@@ -98,6 +99,12 @@
98
99
  let opened = $state(false);
99
100
  let open = $state(false);
100
101
 
102
+ function close() {
103
+ try {
104
+ panelEl?.hidePopover();
105
+ } catch {}
106
+ }
107
+
101
108
  function reposition() {
102
109
  if (triggerEl && panelEl) place(triggerEl, panelEl, placement, gap);
103
110
  }
@@ -166,7 +173,7 @@
166
173
  ontoggle={onToggle}
167
174
  >
168
175
  {#if opened}
169
- {@render children()}
176
+ {@render children({ close })}
170
177
  {/if}
171
178
  </div>
172
179
 
@@ -12,8 +12,11 @@ type $$ComponentProps = {
12
12
  label: string;
13
13
  /** Trigger content (rendered inside a button that owns the popover wiring). */
14
14
  trigger: Snippet;
15
- /** Panel content. */
16
- children: Snippet;
15
+ /** Panel content. Receives `{ close }` to dismiss the panel from inside;
16
+ * zero-argument snippets keep working. */
17
+ children: Snippet<[{
18
+ close: () => void;
19
+ }]>;
17
20
  /** Extra class on the trigger button — style it from your own scoped CSS,
18
21
  * no :global needed (you supply the class). */
19
22
  triggerClass?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorsk/tsumikit",
3
- "version": "0.43.1",
3
+ "version": "0.44.0",
4
4
  "description": "Minimal, dependency-free Svelte 5 + pure-CSS UI kit. Token-driven atoms, molecules & layouts with theming out of the box.",
5
5
  "type": "module",
6
6
  "license": "MIT",