@sentropic/design-system-svelte 0.34.72 → 0.34.73

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.
@@ -0,0 +1,243 @@
1
+ <script lang="ts" module>
2
+ import type { Snippet } from "svelte";
3
+
4
+ export type PanelSectionProps = {
5
+ id: string;
6
+ label: string;
7
+ children?: Snippet;
8
+ /** Optional header-trailing controls (buttons, counts…). */
9
+ actions?: Snippet;
10
+ class?: string;
11
+ };
12
+ </script>
13
+
14
+ <script lang="ts">
15
+ import { getContext } from "svelte";
16
+ import { ChevronDown } from "@lucide/svelte";
17
+ import { PANEL_STACK_KEY, type PanelStackContext } from "./PanelStack.svelte";
18
+
19
+ let { id, label, children, actions, class: className }: PanelSectionProps = $props();
20
+
21
+ // A PanelSection outside a PanelStack (no context) falls back to a fully
22
+ // expanded, scroll-owning, non-primary section so it still renders sanely in
23
+ // isolation — but the component is designed to always live inside a stack.
24
+ const stack = getContext<PanelStackContext | undefined>(PANEL_STACK_KEY);
25
+
26
+ let rootEl: HTMLElement | null = $state(null);
27
+ // The header is also registered (not just the root): split-primary's
28
+ // auto-collapse measures whichever section is CURRENTLY primary by its
29
+ // header height specifically — see PanelStack.svelte's `register` doc.
30
+ let headerEl: HTMLElement | null = $state(null);
31
+
32
+ // Register with the parent stack (mount order) so it can fall back to "the
33
+ // first section" whenever nothing else designates a scroll owner (unset or
34
+ // stale `expanded`/`primary`) — see PanelStack.svelte's `register`. Same
35
+ // register-in-an-effect / return-the-unregister-callback idiom as
36
+ // SelectableRow.
37
+ $effect(() => {
38
+ if (!stack || !rootEl || !headerEl) return;
39
+ return stack.register(id, rootEl, headerEl);
40
+ });
41
+
42
+ const triggerId = $derived(`st-panelSection-trigger-${id}`);
43
+ const regionId = $derived(`st-panelSection-region-${id}`);
44
+
45
+ const isPrimary = $derived(stack?.isPrimary(id) ?? false);
46
+ const expanded = $derived(stack?.isExpanded(id) ?? true);
47
+ const scrollOwner = $derived(stack?.isScrollOwner(id) ?? true);
48
+
49
+ function onTriggerClick() {
50
+ stack?.toggle(id);
51
+ }
52
+
53
+ const rootClasses = $derived(
54
+ ["st-panelSection", scrollOwner ? "st-panelSection--scrollOwner" : null, className]
55
+ .filter(Boolean)
56
+ .join(" ")
57
+ );
58
+
59
+ const bodyClasses = $derived(
60
+ [
61
+ "st-panelSection__body",
62
+ scrollOwner ? "st-panelSection__body--scrollOwner" : !expanded ? "st-panelSection__body--collapsed" : null
63
+ ]
64
+ .filter(Boolean)
65
+ .join(" ")
66
+ );
67
+ </script>
68
+
69
+ <div class={rootClasses} data-panel-section-id={id} bind:this={rootEl}>
70
+ <div class="st-panelSection__header" bind:this={headerEl}>
71
+ <h3 class="st-panelSection__heading">
72
+ {#if isPrimary}
73
+ <span class="st-panelSection__title st-panelSection__title--primary" id={triggerId}>
74
+ {label}
75
+ </span>
76
+ {:else}
77
+ <button
78
+ type="button"
79
+ class="st-panelSection__trigger"
80
+ aria-expanded={expanded ? "true" : "false"}
81
+ aria-controls={regionId}
82
+ id={triggerId}
83
+ onclick={onTriggerClick}
84
+ >
85
+ <span class="st-panelSection__title">{label}</span>
86
+ <span
87
+ class="st-panelSection__icon"
88
+ class:st-panelSection__icon--expanded={expanded}
89
+ aria-hidden="true"
90
+ >
91
+ <ChevronDown size={18} strokeWidth={2.25} />
92
+ </span>
93
+ </button>
94
+ {/if}
95
+ </h3>
96
+ {#if actions}
97
+ <div class="st-panelSection__actions">
98
+ {@render actions()}
99
+ </div>
100
+ {/if}
101
+ </div>
102
+ <!-- Mounted once, always — collapsing is purely a class/CSS concern (sizing
103
+ + hiding this region), never a conditional block. A chat session, a map
104
+ or any other stateful widget rendered here survives collapse/expand
105
+ without remounting; see AppShell's panelCollapse="accordion" region for
106
+ the same technique. -->
107
+ <div class={bodyClasses} role="region" id={regionId} aria-labelledby={triggerId}>
108
+ {@render children?.()}
109
+ </div>
110
+ </div>
111
+
112
+ <style>
113
+ .st-panelSection {
114
+ display: flex;
115
+ flex: 0 0 auto;
116
+ flex-direction: column;
117
+ min-block-size: 0;
118
+ }
119
+
120
+ /* The scroll-owning section grows to fill the stack; every other section
121
+ stays content-sized. */
122
+ .st-panelSection--scrollOwner {
123
+ flex: 1 1 0;
124
+ min-block-size: 0;
125
+ overflow: hidden;
126
+ }
127
+
128
+ .st-panelSection__header {
129
+ align-items: center;
130
+ display: flex;
131
+ flex: 0 0 auto;
132
+ }
133
+
134
+ .st-panelSection__heading {
135
+ flex: 1 1 auto;
136
+ margin: 0;
137
+ min-inline-size: 0;
138
+ }
139
+
140
+ .st-panelSection__trigger {
141
+ align-items: center;
142
+ background: transparent;
143
+ border: 0;
144
+ color: var(--st-component-accordion-text, inherit);
145
+ cursor: pointer;
146
+ display: flex;
147
+ font: inherit;
148
+ font-size: var(--st-component-accordion-fontSize, inherit);
149
+ font-weight: var(--st-component-accordion-fontWeight, 600);
150
+ gap: 0.75rem;
151
+ inline-size: 100%;
152
+ justify-content: space-between;
153
+ line-height: var(--st-component-accordion-lineHeight, normal);
154
+ padding: var(--st-component-accordion-paddingBlock, 0.875rem)
155
+ var(--st-component-accordion-paddingInline, 0.5rem);
156
+ text-align: start;
157
+ transition: background-color var(--st-motion-fast, 120ms) var(--st-motion-easing, ease);
158
+ }
159
+
160
+ .st-panelSection__trigger:hover {
161
+ background: var(--st-component-control-hoverBackground, var(--st-semantic-surface-subtle));
162
+ }
163
+
164
+ .st-panelSection__trigger:focus-visible {
165
+ outline: 2px solid var(--st-semantic-border-focus, var(--st-semantic-brand-default));
166
+ outline-offset: -2px;
167
+ }
168
+
169
+ .st-panelSection__title {
170
+ flex: 1 1 auto;
171
+ }
172
+
173
+ /* Primary heading (split-primary): same box/typography as a trigger's title
174
+ so switching shapes doesn't reflow the header row, but it is a plain
175
+ `<span>` inside the `<h3>` — never a `<button>` — because it cannot
176
+ collapse and a disclosure affordance would lie. */
177
+ .st-panelSection__title--primary {
178
+ color: var(--st-semantic-text-primary);
179
+ display: block;
180
+ font-weight: 600;
181
+ padding: var(--st-component-accordion-paddingBlock, 0.875rem)
182
+ var(--st-component-accordion-paddingInline, 0.5rem);
183
+ }
184
+
185
+ .st-panelSection__icon {
186
+ align-items: center;
187
+ block-size: 1.25rem;
188
+ color: var(--st-semantic-text-secondary);
189
+ display: inline-flex;
190
+ flex: 0 0 auto;
191
+ inline-size: 1.25rem;
192
+ justify-content: center;
193
+ transition: transform var(--st-motion-fast, 120ms) var(--st-motion-easing, ease);
194
+ }
195
+
196
+ .st-panelSection__icon--expanded {
197
+ transform: rotate(180deg);
198
+ }
199
+
200
+ .st-panelSection__actions {
201
+ align-items: center;
202
+ display: inline-flex;
203
+ flex: 0 0 auto;
204
+ gap: 0.5rem;
205
+ padding-inline-end: 0.5rem;
206
+ }
207
+
208
+ .st-panelSection__body {
209
+ color: var(--st-semantic-text-secondary);
210
+ flex: 0 0 auto;
211
+ line-height: 1.5;
212
+ overflow: hidden;
213
+ padding: 0 0.5rem 0.875rem;
214
+ }
215
+
216
+ /* THE single scroll owner across the whole stack: at any moment exactly one
217
+ PanelSection body carries this class (see PanelStack.svelte's context
218
+ contract, which is the only place deciding who gets it) — every other
219
+ body stays `overflow: hidden`, content-sized or collapsed to zero.
220
+
221
+ `min-block-size` is the floor split-primary's auto-collapse protects (see
222
+ PanelStack.svelte's `primaryMinHeight` prop): PanelStack emits that prop,
223
+ live, as this very custom property on its own root, so the JS threshold
224
+ and this CSS floor read the SAME number and can never drift apart. The
225
+ `160px` fallback only matters when a PanelSection renders without a
226
+ PanelStack ancestor at all. Harmless for sticky-item too (there is only
227
+ ever one scroll owner in that shape as well). */
228
+ .st-panelSection__body--scrollOwner {
229
+ flex: 1 1 0;
230
+ min-block-size: var(--st-component-panelStack-primaryMinBlockSize, 160px);
231
+ overflow: auto;
232
+ }
233
+
234
+ /* Collapsed (sticky-item, not the expanded item): header-only. The region
235
+ stays mounted — never removed — only sized to zero and hidden. */
236
+ .st-panelSection__body--collapsed {
237
+ block-size: 0;
238
+ max-block-size: 0;
239
+ overflow: hidden;
240
+ padding-block: 0;
241
+ visibility: hidden;
242
+ }
243
+ </style>
@@ -0,0 +1,13 @@
1
+ import type { Snippet } from "svelte";
2
+ export type PanelSectionProps = {
3
+ id: string;
4
+ label: string;
5
+ children?: Snippet;
6
+ /** Optional header-trailing controls (buttons, counts…). */
7
+ actions?: Snippet;
8
+ class?: string;
9
+ };
10
+ declare const PanelSection: import("svelte").Component<PanelSectionProps, {}, "">;
11
+ type PanelSection = ReturnType<typeof PanelSection>;
12
+ export default PanelSection;
13
+ //# sourceMappingURL=PanelSection.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelSection.svelte.d.ts","sourceRoot":"","sources":["../src/lib/PanelSection.svelte.ts"],"names":[],"mappings":"AAGE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAgGJ,QAAA,MAAM,YAAY,uDAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}