@classic-homes/theme-svelte 1.1.2 → 1.2.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.
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
DEFAULT_PANEL_STATE,
|
|
18
18
|
DEFAULT_CONSTRAINTS,
|
|
19
19
|
DEFAULT_CARD_CONFIG,
|
|
20
|
+
DEFAULT_TAB_WIDTH,
|
|
20
21
|
CARD_HEADER_HEIGHT,
|
|
21
22
|
CARD_EXPANDED_RATIO,
|
|
22
23
|
CARD_MIN_WIDTH,
|
|
@@ -84,6 +85,17 @@
|
|
|
84
85
|
constraints?: PanelConstraints;
|
|
85
86
|
/** Card mode configuration */
|
|
86
87
|
cardConfig?: CardConfig;
|
|
88
|
+
/**
|
|
89
|
+
* Length (px) of the collapsed tab along its edge. Fixed rather than
|
|
90
|
+
* content-sized; raise it for longer titles. Defaults to 220.
|
|
91
|
+
*/
|
|
92
|
+
tabWidth?: number;
|
|
93
|
+
/**
|
|
94
|
+
* Distance (px) of the collapsed tab from its pinned edge. Use it to clear
|
|
95
|
+
* fixed app chrome — a sticky header, a toolbar — that would otherwise
|
|
96
|
+
* cover the tab. Defaults to 0.
|
|
97
|
+
*/
|
|
98
|
+
tabInset?: number;
|
|
87
99
|
/** Disable close button */
|
|
88
100
|
disableClose?: boolean;
|
|
89
101
|
/** Disable resize functionality */
|
|
@@ -127,6 +139,8 @@
|
|
|
127
139
|
actions = [],
|
|
128
140
|
constraints = {},
|
|
129
141
|
cardConfig = {},
|
|
142
|
+
tabWidth = DEFAULT_TAB_WIDTH,
|
|
143
|
+
tabInset = 0,
|
|
130
144
|
disableClose = false,
|
|
131
145
|
disableResize = false,
|
|
132
146
|
disableDrag = false,
|
|
@@ -1153,6 +1167,8 @@
|
|
|
1153
1167
|
{subtitle}
|
|
1154
1168
|
{edge}
|
|
1155
1169
|
{disableClose}
|
|
1170
|
+
{tabWidth}
|
|
1171
|
+
{tabInset}
|
|
1156
1172
|
onclick={handleTabClick}
|
|
1157
1173
|
onClose={handleClose}
|
|
1158
1174
|
offset={internalTabOffset}
|
|
@@ -33,6 +33,17 @@ interface Props {
|
|
|
33
33
|
constraints?: PanelConstraints;
|
|
34
34
|
/** Card mode configuration */
|
|
35
35
|
cardConfig?: CardConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Length (px) of the collapsed tab along its edge. Fixed rather than
|
|
38
|
+
* content-sized; raise it for longer titles. Defaults to 220.
|
|
39
|
+
*/
|
|
40
|
+
tabWidth?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Distance (px) of the collapsed tab from its pinned edge. Use it to clear
|
|
43
|
+
* fixed app chrome — a sticky header, a toolbar — that would otherwise
|
|
44
|
+
* cover the tab. Defaults to 0.
|
|
45
|
+
*/
|
|
46
|
+
tabInset?: number;
|
|
36
47
|
/** Disable close button */
|
|
37
48
|
disableClose?: boolean;
|
|
38
49
|
/** Disable resize functionality */
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { cn } from '../utils.js';
|
|
3
3
|
import type { PanelEdge } from '@classic-homes/data-panel-core';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
constrainTabOffset,
|
|
6
|
+
getTabTransform,
|
|
7
|
+
getTabBounds,
|
|
8
|
+
TAB_THICKNESS,
|
|
9
|
+
DEFAULT_TAB_WIDTH,
|
|
10
|
+
} from '@classic-homes/data-panel-core';
|
|
5
11
|
|
|
6
12
|
interface Props {
|
|
7
13
|
/** Tab label/title */
|
|
@@ -19,6 +25,18 @@
|
|
|
19
25
|
offset?: number;
|
|
20
26
|
/** Called with the new offset after the tab is dragged along its edge */
|
|
21
27
|
onOffsetChange?: (offset: number) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Length (px) of the tab along its edge. Fixed rather than content-sized so
|
|
30
|
+
* the tab's geometry is pure pixel math in every browser; raise it for
|
|
31
|
+
* longer labels. Defaults to 220.
|
|
32
|
+
*/
|
|
33
|
+
tabWidth?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Distance (px) from the pinned edge. Use it to clear fixed app chrome — a
|
|
36
|
+
* sticky header, a toolbar — that would otherwise cover the tab. Defaults
|
|
37
|
+
* to 0 (flush with the edge).
|
|
38
|
+
*/
|
|
39
|
+
tabInset?: number;
|
|
22
40
|
/** Additional class */
|
|
23
41
|
class?: string;
|
|
24
42
|
}
|
|
@@ -32,6 +50,8 @@
|
|
|
32
50
|
disableClose = false,
|
|
33
51
|
offset = 0,
|
|
34
52
|
onOffsetChange,
|
|
53
|
+
tabWidth = DEFAULT_TAB_WIDTH,
|
|
54
|
+
tabInset = 0,
|
|
35
55
|
class: className,
|
|
36
56
|
}: Props = $props();
|
|
37
57
|
|
|
@@ -39,35 +59,32 @@
|
|
|
39
59
|
|
|
40
60
|
const positionClasses = $derived<string>(
|
|
41
61
|
{
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
bottom: 'bottom-0 left-1/2 rounded-t-lg border-b-0',
|
|
62
|
+
// Border classes are in the chip's pre-rotation frame: its bottom rotates
|
|
63
|
+
// to the attached (edge) side and its top corners to the viewport-facing
|
|
64
|
+
// corners, so both side edges drop the bottom border and round the top.
|
|
65
|
+
// The anchored axis is set inline (see insetStyle) so tabInset can move it.
|
|
66
|
+
left: 'top-1/2 rounded-t-lg border-b-0',
|
|
67
|
+
right: 'top-1/2 rounded-t-lg border-b-0',
|
|
68
|
+
top: 'left-1/2 rounded-b-lg border-t-0',
|
|
69
|
+
bottom: 'left-1/2 rounded-t-lg border-b-0',
|
|
51
70
|
}[edge]
|
|
52
71
|
);
|
|
53
72
|
|
|
73
|
+
// Distance from the anchored edge. Pushes the tab clear of fixed app chrome
|
|
74
|
+
// (header, toolbar) that would otherwise cover it. The transform is relative
|
|
75
|
+
// to the tab's own box, so shifting the anchor leaves the geometry intact.
|
|
76
|
+
const insetStyle = $derived<string>(`${edge}: ${tabInset}px;`);
|
|
77
|
+
|
|
54
78
|
const draggable = $derived(!!onOffsetChange);
|
|
55
79
|
|
|
56
|
-
let btn = $state<HTMLDivElement | null>(null);
|
|
57
80
|
let dragOffset = $state<number | null>(null);
|
|
58
81
|
const effectiveOffset = $derived(dragOffset ?? offset);
|
|
59
82
|
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
edge === 'left'
|
|
66
|
-
? `translate(calc(-50% + ${SIDE_HALF}px), calc(-50% + ${effectiveOffset}px)) rotate(90deg)`
|
|
67
|
-
: edge === 'right'
|
|
68
|
-
? `translate(calc(50% - ${SIDE_HALF}px), calc(-50% + ${effectiveOffset}px)) rotate(-90deg)`
|
|
69
|
-
: `translateX(calc(-50% + ${effectiveOffset}px))`
|
|
70
|
-
);
|
|
83
|
+
// Geometry is entirely pixel-based (see getTabTransform): the tab carries an
|
|
84
|
+
// explicit width so nothing has to resolve a percentage against a
|
|
85
|
+
// content-sized box while a rotation is composed onto it.
|
|
86
|
+
const tabTransform = $derived<string>(getTabTransform(edge, tabWidth, effectiveOffset));
|
|
87
|
+
const tabBounds = $derived(getTabBounds(edge, tabWidth));
|
|
71
88
|
|
|
72
89
|
// Non-reactive drag bookkeeping.
|
|
73
90
|
let drag = { startX: 0, startY: 0, startOffset: 0, moved: false, pointerId: -1 };
|
|
@@ -93,12 +110,10 @@
|
|
|
93
110
|
if (drag.pointerId !== e.pointerId || !el.hasPointerCapture(e.pointerId)) return;
|
|
94
111
|
const delta = isVertical ? e.clientY - drag.startY : e.clientX - drag.startX;
|
|
95
112
|
if (Math.abs(delta) > 3) drag.moved = true;
|
|
96
|
-
const rect = btn?.getBoundingClientRect();
|
|
97
|
-
const tabSize = { width: rect?.width ?? 160, height: rect?.height ?? 48 };
|
|
98
113
|
dragOffset = constrainTabOffset(
|
|
99
114
|
drag.startOffset + delta,
|
|
100
115
|
edge,
|
|
101
|
-
|
|
116
|
+
tabBounds,
|
|
102
117
|
window.innerWidth,
|
|
103
118
|
window.innerHeight
|
|
104
119
|
);
|
|
@@ -148,27 +163,24 @@
|
|
|
148
163
|
|
|
149
164
|
function clampOffset() {
|
|
150
165
|
if (!onOffsetChange) return;
|
|
151
|
-
const rect = btn?.getBoundingClientRect();
|
|
152
|
-
if (!rect) return;
|
|
153
166
|
const clamped = constrainTabOffset(
|
|
154
167
|
offset,
|
|
155
168
|
edge,
|
|
156
|
-
|
|
169
|
+
tabBounds,
|
|
157
170
|
window.innerWidth,
|
|
158
171
|
window.innerHeight
|
|
159
172
|
);
|
|
160
173
|
if (clamped !== offset) onOffsetChange(clamped);
|
|
161
174
|
}
|
|
162
175
|
|
|
163
|
-
// Re-clamp the persisted offset to the current
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
// land the tab off-screen. Runs on mount and whenever edge/offset/size change.
|
|
176
|
+
// Re-clamp the persisted offset to the current geometry: an offset saved under
|
|
177
|
+
// a different edge, tabWidth, or viewport can land the tab off-screen. The
|
|
178
|
+
// tab's bounds are known from its props, so this never measures the DOM.
|
|
167
179
|
$effect(() => {
|
|
168
180
|
// Track the reactive inputs so this re-runs when they change.
|
|
169
181
|
void edge;
|
|
170
182
|
void offset;
|
|
171
|
-
void
|
|
183
|
+
void tabBounds;
|
|
172
184
|
if (dragOffset !== null) return;
|
|
173
185
|
clampOffset();
|
|
174
186
|
});
|
|
@@ -187,14 +199,19 @@
|
|
|
187
199
|
container carries the position/transform and the pointer-drag handlers. -->
|
|
188
200
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
189
201
|
<div
|
|
190
|
-
bind:this={btn}
|
|
191
202
|
class={cn(
|
|
192
|
-
|
|
203
|
+
// Same layer as the expanded panel: the tab is the only way to bring the
|
|
204
|
+
// panel back, so it must never sit under chrome the panel covers.
|
|
205
|
+
'fixed z-50 flex items-center gap-2 border border-border bg-background px-2.5 py-1.5 shadow-md focus-within:ring-2 focus-within:ring-ring',
|
|
193
206
|
draggable && 'cursor-grab touch-none active:cursor-grabbing',
|
|
194
207
|
positionClasses,
|
|
195
208
|
className
|
|
196
209
|
)}
|
|
197
|
-
style={
|
|
210
|
+
style={`${insetStyle} width: ${tabWidth}px; ${
|
|
211
|
+
/* Side tabs rotate, so they need a fixed thickness for a deterministic edge
|
|
212
|
+
hug; top/bottom stay content-height. */
|
|
213
|
+
isVertical ? `height: ${TAB_THICKNESS}px; ` : ''
|
|
214
|
+
}transform-origin: 0 0; transform: ${tabTransform};`}
|
|
198
215
|
onpointerdown={handlePointerDown}
|
|
199
216
|
onpointermove={draggable ? handlePointerMove : undefined}
|
|
200
217
|
onpointerup={draggable ? handlePointerUp : undefined}
|
|
@@ -15,6 +15,18 @@ interface Props {
|
|
|
15
15
|
offset?: number;
|
|
16
16
|
/** Called with the new offset after the tab is dragged along its edge */
|
|
17
17
|
onOffsetChange?: (offset: number) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Length (px) of the tab along its edge. Fixed rather than content-sized so
|
|
20
|
+
* the tab's geometry is pure pixel math in every browser; raise it for
|
|
21
|
+
* longer labels. Defaults to 220.
|
|
22
|
+
*/
|
|
23
|
+
tabWidth?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Distance (px) from the pinned edge. Use it to clear fixed app chrome — a
|
|
26
|
+
* sticky header, a toolbar — that would otherwise cover the tab. Defaults
|
|
27
|
+
* to 0 (flush with the edge).
|
|
28
|
+
*/
|
|
29
|
+
tabInset?: number;
|
|
18
30
|
/** Additional class */
|
|
19
31
|
class?: string;
|
|
20
32
|
}
|