@dorsk/tsumikit 0.43.1 → 0.44.1
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -63,8 +64,10 @@
|
|
|
63
64
|
variant?: TriggerVariant;
|
|
64
65
|
tone?: TriggerTone;
|
|
65
66
|
size?: TriggerSize;
|
|
66
|
-
/** Shared square box scale (`--box-xs/sm/md/lg`) for an icon-only trigger
|
|
67
|
-
* the default trigger
|
|
67
|
+
/** Shared square box scale (`--box-xs/sm/md/lg`) for an icon-only trigger,
|
|
68
|
+
* pinning the square exactly. The default trigger floors at the `sm` box
|
|
69
|
+
* and grows with its content; override that floor from `triggerClass`
|
|
70
|
+
* with `--pop-box`. */
|
|
68
71
|
box?: 'xs' | 'sm' | 'md' | 'lg';
|
|
69
72
|
/** Use the shared `--control-height` toolbar/composer contract. */
|
|
70
73
|
control?: boolean;
|
|
@@ -98,6 +101,12 @@
|
|
|
98
101
|
let opened = $state(false);
|
|
99
102
|
let open = $state(false);
|
|
100
103
|
|
|
104
|
+
function close() {
|
|
105
|
+
try {
|
|
106
|
+
panelEl?.hidePopover();
|
|
107
|
+
} catch {}
|
|
108
|
+
}
|
|
109
|
+
|
|
101
110
|
function reposition() {
|
|
102
111
|
if (triggerEl && panelEl) place(triggerEl, panelEl, placement, gap);
|
|
103
112
|
}
|
|
@@ -166,7 +175,7 @@
|
|
|
166
175
|
ontoggle={onToggle}
|
|
167
176
|
>
|
|
168
177
|
{#if opened}
|
|
169
|
-
{@render children()}
|
|
178
|
+
{@render children({ close })}
|
|
170
179
|
{/if}
|
|
171
180
|
</div>
|
|
172
181
|
|
|
@@ -177,13 +186,16 @@
|
|
|
177
186
|
/* Default trigger chrome. Zero specificity (`:where`) so any consumer class
|
|
178
187
|
(triggerClass) overrides it; `:not(.bare)` keeps it off bare triggers such
|
|
179
188
|
as the Timestamp <time>, which stay plain inline text. */
|
|
189
|
+
/* The square is one knob, `--pop-box`: the `box` prop sets it inline, and a
|
|
190
|
+
consumer's `triggerClass` can set it too (`--pop-box: var(--box-xs)`) — a
|
|
191
|
+
plain width/height there would not have beaten a `min-*` floor. */
|
|
180
192
|
:where(.pop-trigger:not(.bare)) {
|
|
181
193
|
display: inline-flex;
|
|
182
194
|
align-items: center;
|
|
183
195
|
justify-content: center;
|
|
184
|
-
min-height: var(--box-
|
|
185
|
-
min-width: var(--box-
|
|
186
|
-
padding: var(--sp-
|
|
196
|
+
min-height: var(--pop-box, var(--box-sm));
|
|
197
|
+
min-width: var(--pop-box, var(--box-sm));
|
|
198
|
+
padding: var(--sp-1);
|
|
187
199
|
border: 1px solid transparent;
|
|
188
200
|
border-radius: var(--r-md);
|
|
189
201
|
background: transparent;
|
|
@@ -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
|
-
|
|
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;
|
|
@@ -25,8 +28,10 @@ type $$ComponentProps = {
|
|
|
25
28
|
variant?: TriggerVariant;
|
|
26
29
|
tone?: TriggerTone;
|
|
27
30
|
size?: TriggerSize;
|
|
28
|
-
/** Shared square box scale (`--box-xs/sm/md/lg`) for an icon-only trigger
|
|
29
|
-
* the default trigger
|
|
31
|
+
/** Shared square box scale (`--box-xs/sm/md/lg`) for an icon-only trigger,
|
|
32
|
+
* pinning the square exactly. The default trigger floors at the `sm` box
|
|
33
|
+
* and grows with its content; override that floor from `triggerClass`
|
|
34
|
+
* with `--pop-box`. */
|
|
30
35
|
box?: 'xs' | 'sm' | 'md' | 'lg';
|
|
31
36
|
/** Use the shared `--control-height` toolbar/composer contract. */
|
|
32
37
|
control?: boolean;
|
package/package.json
CHANGED