@glasshome/ui 1.36.0 → 1.37.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.
- package/SPEC.md +11 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -3
- package/dist/lib/dock-slot-classes.d.ts +1 -0
- package/dist/lib/hold.d.ts +33 -1
- package/dist/lib/motion-classes.d.ts +2 -0
- package/dist/solid/dock-edit.d.ts +28 -0
- package/dist/solid/dock-paging.d.ts +13 -0
- package/dist/solid/dock.d.ts +18 -1
- package/dist/solid/face-toggle.d.ts +17 -0
- package/dist/solid/glyph-tile.d.ts +18 -0
- package/dist/solid/icon-picker.d.ts +4 -0
- package/dist/solid/index.d.ts +7 -3
- package/dist/solid/index.js +5521 -4892
- package/dist/solid/popover.d.ts +3 -1
- package/dist/solid/preview-tile.d.ts +14 -0
- package/dist/solid/slot-button.d.ts +9 -0
- package/dist/{utils-BhU5YZKh.js → utils-Duqv3Sgo.js} +680 -624
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/lib/dock-slot-classes.ts +4 -0
- package/src/lib/hold.ts +154 -3
- package/src/lib/motion-classes.ts +11 -0
- package/src/solid/dashboard-preview.tsx +21 -4
- package/src/solid/dock-edit.tsx +267 -0
- package/src/solid/dock-paging.ts +37 -0
- package/src/solid/dock.tsx +254 -73
- package/src/solid/face-toggle.tsx +93 -0
- package/src/solid/glyph-tile.tsx +77 -0
- package/src/solid/icon-picker.tsx +40 -21
- package/src/solid/index.ts +7 -3
- package/src/solid/picker-trigger.tsx +7 -0
- package/src/solid/popover.tsx +13 -2
- package/src/solid/preview-tile.tsx +75 -4
- package/src/solid/slot-button.tsx +45 -0
- package/src/styles/theme.css +31 -0
package/src/solid/dock.tsx
CHANGED
|
@@ -14,10 +14,18 @@ import {
|
|
|
14
14
|
} from "solid-js";
|
|
15
15
|
import { Dynamic } from "solid-js/web";
|
|
16
16
|
import { CARD_SURFACE } from "../lib/card-classes.js";
|
|
17
|
-
import {
|
|
17
|
+
import { DOCK_SLOT_SHAPE } from "../lib/dock-slot-classes.js";
|
|
18
|
+
import {
|
|
19
|
+
DOCK_ARRIVE_MOTION,
|
|
20
|
+
DOCK_EDIT_MOTION,
|
|
21
|
+
HOLD_MOTION,
|
|
22
|
+
PRESS_DIP,
|
|
23
|
+
} from "../lib/motion-classes.js";
|
|
18
24
|
import { cn } from "../lib/utils.js";
|
|
19
25
|
import { Badge } from "./badge.js";
|
|
26
|
+
import { createDockReorder, DockMoveGrip } from "./dock-edit.js";
|
|
20
27
|
import { pageCount, pageOf, pageOffset, stripWidth } from "./dock-paging.js";
|
|
28
|
+
import { Icon } from "./icon.js";
|
|
21
29
|
import { SelectionHighlight, SelectionScope } from "./selection.js";
|
|
22
30
|
import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
|
|
23
31
|
|
|
@@ -31,17 +39,33 @@ interface DockItem {
|
|
|
31
39
|
badge?: number;
|
|
32
40
|
/** Something dragged is held over this item and will land here on release. */
|
|
33
41
|
isDropTarget?: boolean;
|
|
42
|
+
/** Shows the remove badge while editing; false for an item that cannot leave (default true). */
|
|
43
|
+
removable?: boolean;
|
|
34
44
|
}
|
|
35
45
|
|
|
46
|
+
type DockPlacement = "bottom" | "left" | "right";
|
|
47
|
+
|
|
36
48
|
interface DockProps extends ComponentProps<"div"> {
|
|
37
49
|
items: DockItem[];
|
|
38
50
|
dockMode?: "floating" | "docked";
|
|
51
|
+
/** The viewport edge the dock sits on; a side edge pages its strip vertically. */
|
|
52
|
+
placement?: DockPlacement;
|
|
53
|
+
/** Items that just landed: each glows once, and the dock turns to the first one's page. */
|
|
54
|
+
arrivedIds?: string[];
|
|
39
55
|
/** Where a hold started, relative to the surface; `fired` once it has triggered. */
|
|
40
56
|
hold?: { x: number; y: number; fired: boolean } | null;
|
|
41
57
|
/** A rim light that orbits for as long as a mode is on. */
|
|
42
58
|
glow?: boolean;
|
|
43
59
|
/** Where a drag from outside the dock is pointing, in client coordinates. */
|
|
44
60
|
dragPoint?: { x: number; y: number } | null;
|
|
61
|
+
/** Edit mode: items sway and carry a remove badge, a dashed add slot ends the strip, items drag to reorder. */
|
|
62
|
+
editing?: boolean;
|
|
63
|
+
onRemove?: (id: string) => void;
|
|
64
|
+
onAdd?: () => void;
|
|
65
|
+
/** The full id order after a drag or an Alt+arrow move. */
|
|
66
|
+
onReorder?: (ids: string[]) => void;
|
|
67
|
+
/** While editing, a grip on the outer edge carries the whole dock to a screen edge; fires once on release over one. */
|
|
68
|
+
onMovePlacement?: (placement: DockPlacement) => void;
|
|
45
69
|
}
|
|
46
70
|
|
|
47
71
|
interface DockIconButtonProps extends ComponentProps<"button"> {
|
|
@@ -51,6 +75,8 @@ interface DockIconButtonProps extends ComponentProps<"button"> {
|
|
|
51
75
|
/** Wears the selection highlight: the active item, or the one a drag would land on. */
|
|
52
76
|
lit?: boolean;
|
|
53
77
|
badge?: number;
|
|
78
|
+
/** Plays the arrival glow once. */
|
|
79
|
+
arrived?: boolean;
|
|
54
80
|
}
|
|
55
81
|
|
|
56
82
|
const DOCK_PAGE_MS = 300;
|
|
@@ -66,6 +92,7 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
|
|
|
66
92
|
"badge",
|
|
67
93
|
"type",
|
|
68
94
|
"lit",
|
|
95
|
+
"arrived",
|
|
69
96
|
]);
|
|
70
97
|
const isElement = () => typeof local.icon !== "function";
|
|
71
98
|
|
|
@@ -75,16 +102,21 @@ const DockIconButton: Component<DockIconButtonProps> = (props) => {
|
|
|
75
102
|
type="button"
|
|
76
103
|
data-slot="dock-item"
|
|
77
104
|
class={cn(
|
|
78
|
-
"group relative isolate
|
|
105
|
+
"group relative isolate transition-transform duration-(--duration-micro)",
|
|
106
|
+
DOCK_SLOT_SHAPE,
|
|
79
107
|
PRESS_DIP,
|
|
80
108
|
local.class,
|
|
81
109
|
)}
|
|
82
110
|
aria-label={local.label}
|
|
83
111
|
aria-current={local.isActive ? "page" : undefined}
|
|
84
112
|
data-lit={local.lit ? "" : undefined}
|
|
113
|
+
data-arrived={local.arrived ? "" : undefined}
|
|
85
114
|
{...rest}
|
|
86
115
|
>
|
|
87
116
|
<SelectionHighlight />
|
|
117
|
+
<Show when={local.arrived}>
|
|
118
|
+
<span data-slot="dock-item-arrival" aria-hidden="true" class={DOCK_ARRIVE_MOTION} />
|
|
119
|
+
</Show>
|
|
88
120
|
<div
|
|
89
121
|
data-slot="dock-item-icon"
|
|
90
122
|
class={cn(
|
|
@@ -127,7 +159,16 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
127
159
|
"hold",
|
|
128
160
|
"glow",
|
|
129
161
|
"dragPoint",
|
|
162
|
+
"placement",
|
|
163
|
+
"arrivedIds",
|
|
164
|
+
"editing",
|
|
165
|
+
"onRemove",
|
|
166
|
+
"onAdd",
|
|
167
|
+
"onReorder",
|
|
168
|
+
"onMovePlacement",
|
|
130
169
|
]);
|
|
170
|
+
const placement = () => local.placement ?? "bottom";
|
|
171
|
+
const vertical = () => placement() !== "bottom";
|
|
131
172
|
// The drain plays where the fill grew, so the point outlives the hold.
|
|
132
173
|
const [holdPoint, setHoldPoint] = createSignal({ x: 0, y: 0, r: 0 });
|
|
133
174
|
let surfaceRef: HTMLDivElement | undefined;
|
|
@@ -148,7 +189,8 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
148
189
|
const [needsScroll, setNeedsScroll] = createSignal(false);
|
|
149
190
|
const [pages, setPages] = createSignal(1);
|
|
150
191
|
const [page, setPage] = createSignal(0);
|
|
151
|
-
|
|
192
|
+
// The strip's length along the dock's axis: width at the bottom, height on a side edge.
|
|
193
|
+
const [viewportSpan, setViewportSpan] = createSignal(0);
|
|
152
194
|
|
|
153
195
|
// A memo: the items list is rebuilt on every hover change, and only a new active item may scroll the strip.
|
|
154
196
|
const activeIndex = createMemo(() => {
|
|
@@ -160,68 +202,122 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
160
202
|
const i = local.items.findIndex((it) => it.isDropTarget);
|
|
161
203
|
return i < 0 ? activeIndex() : i;
|
|
162
204
|
});
|
|
205
|
+
const arrivedSet = createMemo(() => new Set(local.arrivedIds ?? []));
|
|
206
|
+
const reorder = createDockReorder({
|
|
207
|
+
bar: () => containerRef,
|
|
208
|
+
vertical,
|
|
209
|
+
ids: () => local.items.map((it) => it.id),
|
|
210
|
+
enabled: () => Boolean(local.editing && local.onReorder),
|
|
211
|
+
onReorder: (ids) => local.onReorder?.(ids),
|
|
212
|
+
});
|
|
213
|
+
const cellStyle = (id: string): JSX.CSSProperties => {
|
|
214
|
+
const slots = reorder.preview();
|
|
215
|
+
const style: JSX.CSSProperties = {};
|
|
216
|
+
if (slots) style.order = Math.max(0, slots.indexOf(id));
|
|
217
|
+
if (reorder.dragId() === id)
|
|
218
|
+
style.translate = vertical() ? `0 ${reorder.lift()}px` : `${reorder.lift()}px 0`;
|
|
219
|
+
return style;
|
|
220
|
+
};
|
|
221
|
+
const onItemKeyDown = (e: KeyboardEvent, id: string) => {
|
|
222
|
+
if (!local.editing || !e.altKey) return;
|
|
223
|
+
const step = { ArrowLeft: -1, ArrowUp: -1, ArrowRight: 1, ArrowDown: 1 }[e.key];
|
|
224
|
+
if (step !== -1 && step !== 1) return;
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
reorder.nudge(id, step);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const scrollSize = (el: HTMLElement) => (vertical() ? el.scrollHeight : el.scrollWidth);
|
|
230
|
+
const viewSize = (el: HTMLElement) => (vertical() ? el.clientHeight : el.clientWidth);
|
|
231
|
+
const scrollPos = (el: HTMLElement) => (vertical() ? el.scrollTop : el.scrollLeft);
|
|
232
|
+
const edgeStart = (rect: DOMRect) => (vertical() ? rect.top : rect.left);
|
|
163
233
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
234
|
+
const gapSize = () => {
|
|
235
|
+
if (!containerRef) return 0;
|
|
236
|
+
const style = getComputedStyle(containerRef);
|
|
237
|
+
return Number.parseFloat(vertical() ? style.rowGap : style.columnGap) || 0;
|
|
238
|
+
};
|
|
239
|
+
const itemSize = () => {
|
|
240
|
+
const rect = containerRef?.querySelector('[data-slot="dock-item"]')?.getBoundingClientRect();
|
|
241
|
+
return (vertical() ? rect?.height : rect?.width) ?? 0;
|
|
242
|
+
};
|
|
168
243
|
|
|
169
|
-
const
|
|
244
|
+
const padAlong = (el: Element) => {
|
|
170
245
|
const style = getComputedStyle(el);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
246
|
+
const [a, b] = vertical()
|
|
247
|
+
? [style.paddingTop, style.paddingBottom]
|
|
248
|
+
: [style.paddingLeft, style.paddingRight];
|
|
249
|
+
return (Number.parseFloat(a) || 0) + (Number.parseFloat(b) || 0);
|
|
174
250
|
};
|
|
175
251
|
|
|
176
|
-
// The
|
|
177
|
-
// so measuring it asks the strip how
|
|
178
|
-
const
|
|
252
|
+
// The room the app gave the dock. Never the surface: it shrink-wraps this strip,
|
|
253
|
+
// so measuring it asks the strip how big the strip is.
|
|
254
|
+
const availableSpan = () => {
|
|
179
255
|
const box = containerRef?.closest<HTMLElement>('[data-slot="dock"]');
|
|
180
256
|
if (!box || !surfaceRef) return 0;
|
|
181
|
-
return box
|
|
257
|
+
return viewSize(box) - padAlong(box) - padAlong(surfaceRef);
|
|
182
258
|
};
|
|
183
259
|
|
|
184
260
|
const checkOverflow = () => {
|
|
185
261
|
if (!containerRef) return;
|
|
186
|
-
const
|
|
187
|
-
const
|
|
262
|
+
const side = vertical() ? "height" : "width";
|
|
263
|
+
const other = vertical() ? "width" : "height";
|
|
264
|
+
containerRef.style.removeProperty(other);
|
|
265
|
+
const available = availableSpan();
|
|
266
|
+
const overflowing = available > 0 && scrollSize(containerRef) > available + 1;
|
|
188
267
|
if (overflowing) {
|
|
189
|
-
const trimmed = stripWidth(available,
|
|
190
|
-
if (trimmed > 0) containerRef.style
|
|
191
|
-
} else if (containerRef.style
|
|
192
|
-
containerRef.style
|
|
268
|
+
const trimmed = stripWidth(available, itemSize(), gapSize());
|
|
269
|
+
if (trimmed > 0) containerRef.style[side] = `${trimmed}px`;
|
|
270
|
+
} else if (containerRef.style[side]) {
|
|
271
|
+
containerRef.style[side] = "";
|
|
193
272
|
}
|
|
194
273
|
setNeedsScroll(overflowing);
|
|
195
|
-
const viewport = containerRef
|
|
196
|
-
|
|
197
|
-
setPages(pageCount(containerRef
|
|
198
|
-
setPage(pageOf(containerRef
|
|
274
|
+
const viewport = viewSize(containerRef);
|
|
275
|
+
setViewportSpan(viewport);
|
|
276
|
+
setPages(pageCount(scrollSize(containerRef), viewport));
|
|
277
|
+
setPage(pageOf(scrollPos(containerRef), viewport));
|
|
199
278
|
};
|
|
200
279
|
|
|
201
280
|
const goToPage = (next: number) => {
|
|
202
281
|
if (!containerRef) return;
|
|
203
|
-
containerRef
|
|
204
|
-
|
|
205
|
-
behavior: "smooth",
|
|
206
|
-
|
|
282
|
+
const to = pageOffset(next, viewportSpan(), scrollSize(containerRef));
|
|
283
|
+
containerRef.scrollTo(
|
|
284
|
+
vertical() ? { top: to, behavior: "smooth" } : { left: to, behavior: "smooth" },
|
|
285
|
+
);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const turnToItem = (index: number) => {
|
|
289
|
+
if (!containerRef || !needsScroll() || viewportSpan() <= 0) return;
|
|
290
|
+
const item = containerRef.querySelectorAll('[data-slot="dock-item"]')[index];
|
|
291
|
+
if (!item) return;
|
|
292
|
+
// The strip only: scrollIntoView would also scroll the page and any frame embedding it.
|
|
293
|
+
const offset =
|
|
294
|
+
edgeStart(item.getBoundingClientRect()) -
|
|
295
|
+
edgeStart(containerRef.getBoundingClientRect()) +
|
|
296
|
+
scrollPos(containerRef);
|
|
297
|
+
goToPage(Math.floor(offset / viewportSpan()));
|
|
207
298
|
};
|
|
208
299
|
|
|
209
300
|
// A drag cannot click a page dot, so resting on the dot row turns to the page under it.
|
|
210
301
|
createEffect(() => {
|
|
211
|
-
const point = local.dragPoint;
|
|
302
|
+
const point = local.dragPoint ?? reorder.point();
|
|
212
303
|
if (!point || pages() < 2 || !surfaceRef || !containerRef) return;
|
|
213
304
|
const strip = containerRef.getBoundingClientRect();
|
|
214
305
|
const surface = surfaceRef.getBoundingClientRect();
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
point.y <= surface.bottom
|
|
218
|
-
point.x >= surface.left &&
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
306
|
+
const place = placement();
|
|
307
|
+
const inSurfaceAlong = vertical()
|
|
308
|
+
? point.y >= surface.top && point.y <= surface.bottom
|
|
309
|
+
: point.x >= surface.left && point.x <= surface.right;
|
|
310
|
+
const pastStrip =
|
|
311
|
+
place === "left"
|
|
312
|
+
? point.x > strip.right && point.x <= surface.right
|
|
313
|
+
: place === "right"
|
|
314
|
+
? point.x < strip.left && point.x >= surface.left
|
|
315
|
+
: point.y > strip.bottom && point.y <= surface.bottom;
|
|
316
|
+
if (!pastStrip || !inSurfaceAlong) return;
|
|
317
|
+
const ratio = vertical()
|
|
318
|
+
? (point.y - surface.top) / surface.height
|
|
319
|
+
: (point.x - surface.left) / surface.width;
|
|
320
|
+
const target = Math.min(pages() - 1, Math.floor(ratio * pages()));
|
|
225
321
|
if (target === page()) return;
|
|
226
322
|
const timer = setTimeout(() => goToPage(target), DOCK_PAGE_MS);
|
|
227
323
|
onCleanup(() => clearTimeout(timer));
|
|
@@ -230,17 +326,21 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
230
326
|
// The active dashboard may sit on another page after a switch elsewhere.
|
|
231
327
|
createEffect(() => {
|
|
232
328
|
const i = activeIndex();
|
|
233
|
-
if (i
|
|
234
|
-
const item = containerRef.querySelectorAll('[data-slot="dock-item"]')[i];
|
|
235
|
-
if (!item || viewportWidth() <= 0) return;
|
|
236
|
-
// The strip only: scrollIntoView would also scroll the page and any frame embedding it.
|
|
237
|
-
const left =
|
|
238
|
-
item.getBoundingClientRect().left -
|
|
239
|
-
containerRef.getBoundingClientRect().left +
|
|
240
|
-
containerRef.scrollLeft;
|
|
241
|
-
goToPage(Math.floor(left / viewportWidth()));
|
|
329
|
+
if (i !== null) turnToItem(i);
|
|
242
330
|
});
|
|
243
331
|
|
|
332
|
+
// A newcomer may land on a page nobody is looking at; turn there once.
|
|
333
|
+
createEffect(
|
|
334
|
+
on(
|
|
335
|
+
() => local.arrivedIds?.join("\n") ?? "",
|
|
336
|
+
() => {
|
|
337
|
+
const first = local.items.findIndex((it) => arrivedSet().has(it.id));
|
|
338
|
+
if (first >= 0) requestAnimationFrame(() => turnToItem(first));
|
|
339
|
+
},
|
|
340
|
+
{ defer: true },
|
|
341
|
+
),
|
|
342
|
+
);
|
|
343
|
+
|
|
244
344
|
// Measured in the next frame's callbacks, which run before it paints: the first
|
|
245
345
|
// dock anyone sees already has its pages, so the dot row never shifts it later.
|
|
246
346
|
onMount(() => {
|
|
@@ -256,9 +356,9 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
256
356
|
});
|
|
257
357
|
});
|
|
258
358
|
|
|
259
|
-
// The box pads by mode, so switching
|
|
359
|
+
// The box pads by mode and the strip runs along the edge, so either switching changes the room it has.
|
|
260
360
|
createEffect(
|
|
261
|
-
on([() => local.items.length, dockMode], () => {
|
|
361
|
+
on([() => local.items.length, dockMode, vertical], () => {
|
|
262
362
|
const frame = requestAnimationFrame(checkOverflow);
|
|
263
363
|
onCleanup(() => cancelAnimationFrame(frame));
|
|
264
364
|
}),
|
|
@@ -267,8 +367,10 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
267
367
|
return (
|
|
268
368
|
<div
|
|
269
369
|
data-slot="dock"
|
|
370
|
+
data-placement={placement()}
|
|
270
371
|
class={cn(
|
|
271
372
|
"flex max-w-full items-center justify-center",
|
|
373
|
+
vertical() && "h-full max-h-full",
|
|
272
374
|
dockMode() === "floating" ? "p-1 sm:p-2" : "",
|
|
273
375
|
local.class,
|
|
274
376
|
)}
|
|
@@ -280,12 +382,22 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
280
382
|
class={cn(
|
|
281
383
|
// isolate: the layers behind the icons stay inside the dock even with blur off.
|
|
282
384
|
"pointer-events-auto relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
|
|
385
|
+
vertical() && "max-h-full flex-col",
|
|
386
|
+
// A flush side dock runs the whole edge.
|
|
387
|
+
vertical() && dockMode() === "docked" && "h-full",
|
|
283
388
|
// Room for the page dots inside the glass; outside it they sit on
|
|
284
389
|
// the screen edge and get clipped.
|
|
285
|
-
pages() > 1 &&
|
|
390
|
+
pages() > 1 &&
|
|
391
|
+
{
|
|
392
|
+
bottom: "pb-4 sm:pb-5",
|
|
393
|
+
left: "pr-4 sm:pr-5",
|
|
394
|
+
right: "pl-4 sm:pl-5",
|
|
395
|
+
}[placement()],
|
|
286
396
|
CARD_SURFACE,
|
|
287
397
|
"[--glass-lift:0.55]",
|
|
288
|
-
dockMode() === "floating"
|
|
398
|
+
dockMode() === "floating"
|
|
399
|
+
? "rounded-xl"
|
|
400
|
+
: { bottom: "rounded-t-xl", left: "rounded-r-xl", right: "rounded-l-xl" }[placement()],
|
|
289
401
|
)}
|
|
290
402
|
>
|
|
291
403
|
<div
|
|
@@ -320,42 +432,108 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
320
432
|
<div
|
|
321
433
|
ref={containerRef}
|
|
322
434
|
data-slot="dock-bar"
|
|
435
|
+
data-reordering={reorder.dragId() ? "" : undefined}
|
|
323
436
|
onScroll={() => {
|
|
324
|
-
if (containerRef) setPage(pageOf(containerRef
|
|
437
|
+
if (containerRef) setPage(pageOf(scrollPos(containerRef), viewportSpan()));
|
|
325
438
|
}}
|
|
326
439
|
class={cn(
|
|
327
|
-
|
|
440
|
+
// A carried item moves its snap point, and the strip would chase it.
|
|
441
|
+
"flex items-center gap-0.5 data-[reordering]:snap-none sm:gap-1",
|
|
442
|
+
vertical() && "flex-col",
|
|
328
443
|
needsScroll()
|
|
329
|
-
?
|
|
444
|
+
? vertical()
|
|
445
|
+
? "scrollbar-hide snap-y snap-mandatory overflow-y-auto overscroll-y-contain scroll-smooth"
|
|
446
|
+
: "scrollbar-hide snap-x snap-mandatory overflow-x-auto overscroll-x-contain scroll-smooth"
|
|
330
447
|
: "overflow-visible",
|
|
331
448
|
!needsScroll() && "justify-center",
|
|
332
449
|
)}
|
|
333
450
|
style={{
|
|
334
|
-
"min-width": needsScroll() ? "auto" : "fit-content",
|
|
451
|
+
[vertical() ? "min-height" : "min-width"]: needsScroll() ? "auto" : "fit-content",
|
|
335
452
|
}}
|
|
336
453
|
>
|
|
337
|
-
<SelectionScope
|
|
454
|
+
<SelectionScope
|
|
455
|
+
marker="lit"
|
|
456
|
+
class={cn("flex items-center gap-0.5 sm:gap-1", vertical() && "flex-col")}
|
|
457
|
+
>
|
|
338
458
|
<Index each={local.items}>
|
|
339
459
|
{(item, i) => (
|
|
340
|
-
<
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
460
|
+
<div
|
|
461
|
+
data-slot="dock-cell"
|
|
462
|
+
data-editing={local.editing ? "" : undefined}
|
|
463
|
+
data-dragging={reorder.dragId() === item().id ? "" : undefined}
|
|
464
|
+
class={cn(
|
|
465
|
+
"relative",
|
|
466
|
+
DOCK_EDIT_MOTION,
|
|
467
|
+
local.editing && "touch-none select-none",
|
|
468
|
+
)}
|
|
469
|
+
style={cellStyle(item().id)}
|
|
470
|
+
onPointerDown={(e) => reorder.begin(item().id, e)}
|
|
471
|
+
onMouseDown={reorder.onMouseDown}
|
|
472
|
+
on:click={{ handleEvent: reorder.onClickCapture, capture: true }}
|
|
473
|
+
>
|
|
474
|
+
<DockIconButton
|
|
475
|
+
class={needsScroll() ? "snap-start" : undefined}
|
|
476
|
+
icon={item().icon}
|
|
477
|
+
label={item().label}
|
|
478
|
+
onClick={item().onClick}
|
|
479
|
+
onKeyDown={(e: KeyboardEvent) => onItemKeyDown(e, item().id)}
|
|
480
|
+
isActive={item().isActive}
|
|
481
|
+
lit={i === pillIndex()}
|
|
482
|
+
badge={item().badge}
|
|
483
|
+
arrived={arrivedSet().has(item().id)}
|
|
484
|
+
data-drop-target={item().isDropTarget ? "" : undefined}
|
|
485
|
+
data-dock-id={item().id}
|
|
486
|
+
/>
|
|
487
|
+
<Show when={local.editing && local.onRemove && item().removable !== false}>
|
|
488
|
+
<button
|
|
489
|
+
type="button"
|
|
490
|
+
data-slot="dock-item-remove"
|
|
491
|
+
aria-label={`Remove ${item().label}`}
|
|
492
|
+
onClick={() => local.onRemove?.(item().id)}
|
|
493
|
+
class={cn(
|
|
494
|
+
"bg-destructive text-destructive-foreground absolute top-0 left-0 z-10 flex size-5 items-center justify-center rounded-full shadow-sm",
|
|
495
|
+
"before:absolute before:-top-2 before:right-0 before:bottom-0 before:-left-2",
|
|
496
|
+
)}
|
|
497
|
+
>
|
|
498
|
+
<Icon icon="lucide:minus" width={12} height={12} />
|
|
499
|
+
</button>
|
|
500
|
+
</Show>
|
|
501
|
+
</div>
|
|
351
502
|
)}
|
|
352
503
|
</Index>
|
|
504
|
+
<Show when={local.editing && local.onAdd}>
|
|
505
|
+
<button
|
|
506
|
+
type="button"
|
|
507
|
+
data-slot="dock-add"
|
|
508
|
+
aria-label="Add to dock"
|
|
509
|
+
onClick={() => local.onAdd?.()}
|
|
510
|
+
style={{ order: local.items.length }}
|
|
511
|
+
class={cn(
|
|
512
|
+
"text-muted-foreground border-foreground/30 hover:text-foreground hover:border-foreground/60 shrink-0 border-2 border-dashed transition-colors duration-(--duration-state)",
|
|
513
|
+
DOCK_SLOT_SHAPE,
|
|
514
|
+
PRESS_DIP,
|
|
515
|
+
needsScroll() && "snap-start",
|
|
516
|
+
)}
|
|
517
|
+
>
|
|
518
|
+
<Icon icon="lucide:plus" width={20} height={20} />
|
|
519
|
+
</button>
|
|
520
|
+
</Show>
|
|
353
521
|
</SelectionScope>
|
|
354
522
|
</div>
|
|
523
|
+
<Show when={local.editing && local.onMovePlacement}>
|
|
524
|
+
<DockMoveGrip placement={placement()} onMove={(next) => local.onMovePlacement?.(next)} />
|
|
525
|
+
</Show>
|
|
355
526
|
<Show when={pages() > 1}>
|
|
356
527
|
<div
|
|
357
528
|
data-slot="dock-pages"
|
|
358
|
-
class=
|
|
529
|
+
class={cn(
|
|
530
|
+
"pointer-events-auto absolute flex justify-center gap-1.5",
|
|
531
|
+
{
|
|
532
|
+
bottom: "inset-x-0 bottom-1.5",
|
|
533
|
+
left: "inset-y-0 right-1.5 flex-col items-center",
|
|
534
|
+
right: "inset-y-0 left-1.5 flex-col items-center",
|
|
535
|
+
}[placement()],
|
|
536
|
+
)}
|
|
359
537
|
>
|
|
360
538
|
<Index each={Array.from({ length: pages() })}>
|
|
361
539
|
{(_, i) => (
|
|
@@ -365,8 +543,11 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
365
543
|
aria-current={page() === i ? "true" : undefined}
|
|
366
544
|
onClick={() => goToPage(i)}
|
|
367
545
|
class={cn(
|
|
368
|
-
"transition-glass
|
|
369
|
-
|
|
546
|
+
"transition-glass rounded-full",
|
|
547
|
+
vertical() ? "w-1.5" : "h-1.5",
|
|
548
|
+
page() === i
|
|
549
|
+
? cn("bg-foreground/70", vertical() ? "h-4" : "w-4")
|
|
550
|
+
: cn("bg-foreground/25", vertical() ? "h-1.5" : "w-1.5"),
|
|
370
551
|
)}
|
|
371
552
|
/>
|
|
372
553
|
)}
|
|
@@ -378,5 +559,5 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
378
559
|
);
|
|
379
560
|
};
|
|
380
561
|
|
|
381
|
-
export type { DockIconButtonProps, DockItem, DockProps };
|
|
562
|
+
export type { DockIconButtonProps, DockItem, DockPlacement, DockProps };
|
|
382
563
|
export { Dock };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ToggleGroup as ToggleGroupPrimitive } from "@kobalte/core/toggle-group";
|
|
2
|
+
import { createContext, createMemo, type JSX, Show, useContext } from "solid-js";
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { Avatar, AvatarFallback } from "./avatar.js";
|
|
5
|
+
import { Icon } from "./icon.js";
|
|
6
|
+
|
|
7
|
+
const LockedContext = createContext<() => ReadonlySet<string>>(() => new Set<string>());
|
|
8
|
+
|
|
9
|
+
/** People and screens to turn on or off. Faces in `lockedIds` always count: shown on, never reported in `onChange`. */
|
|
10
|
+
export function FaceToggleGroup(props: {
|
|
11
|
+
/** The faces turned on by choice; locked ones are on without being listed. */
|
|
12
|
+
value: string[];
|
|
13
|
+
onChange: (value: string[]) => void;
|
|
14
|
+
lockedIds?: readonly string[];
|
|
15
|
+
"aria-label": string;
|
|
16
|
+
class?: string;
|
|
17
|
+
children: JSX.Element;
|
|
18
|
+
}) {
|
|
19
|
+
const locked = createMemo(() => new Set(props.lockedIds ?? []));
|
|
20
|
+
const pressed = () => [...new Set([...props.value, ...locked()])];
|
|
21
|
+
return (
|
|
22
|
+
<LockedContext.Provider value={locked}>
|
|
23
|
+
<ToggleGroupPrimitive
|
|
24
|
+
multiple
|
|
25
|
+
data-slot="face-toggle-group"
|
|
26
|
+
aria-label={props["aria-label"]}
|
|
27
|
+
value={pressed()}
|
|
28
|
+
onChange={(next: string[]) => props.onChange(next.filter((id) => !locked().has(id)))}
|
|
29
|
+
class={cn("flex flex-wrap gap-x-3 gap-y-2", props.class)}
|
|
30
|
+
>
|
|
31
|
+
{props.children}
|
|
32
|
+
</ToggleGroupPrimitive>
|
|
33
|
+
</LockedContext.Provider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function FaceToggle(props: {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
kind: "person" | "screen";
|
|
41
|
+
class?: string;
|
|
42
|
+
}) {
|
|
43
|
+
const locked = useContext(LockedContext);
|
|
44
|
+
const isLocked = () => locked().has(props.id);
|
|
45
|
+
return (
|
|
46
|
+
<ToggleGroupPrimitive.Item
|
|
47
|
+
value={props.id}
|
|
48
|
+
data-slot="face-toggle"
|
|
49
|
+
aria-disabled={isLocked() ? "true" : undefined}
|
|
50
|
+
class={cn(
|
|
51
|
+
"group/face-toggle focus-visible:ring-ring/50 flex w-16 min-w-0 touch-manipulation flex-col items-center gap-1 rounded-lg py-0.5 text-xs font-medium outline-none focus-visible:ring-[3px] aria-disabled:cursor-default",
|
|
52
|
+
props.class,
|
|
53
|
+
)}
|
|
54
|
+
>
|
|
55
|
+
<span aria-hidden="true" class="relative">
|
|
56
|
+
<Avatar class="group-data-[pressed]/face-toggle:ring-primary group-data-[pressed]/face-toggle:ring-offset-background size-11 opacity-50 transition-opacity duration-200 group-active/face-toggle:scale-[0.97] group-data-[pressed]/face-toggle:opacity-100 group-data-[pressed]/face-toggle:ring-2 group-data-[pressed]/face-toggle:ring-offset-2">
|
|
57
|
+
<AvatarFallback>
|
|
58
|
+
<Show when={props.kind === "screen"} fallback={props.name.slice(0, 1)}>
|
|
59
|
+
<Icon icon="lucide:monitor-smartphone" width={18} height={18} />
|
|
60
|
+
</Show>
|
|
61
|
+
</AvatarFallback>
|
|
62
|
+
</Avatar>
|
|
63
|
+
<Show
|
|
64
|
+
when={isLocked()}
|
|
65
|
+
fallback={
|
|
66
|
+
<span
|
|
67
|
+
data-slot="face-toggle-check"
|
|
68
|
+
class="bg-primary text-primary-foreground border-background absolute -right-1 -bottom-1 hidden size-4 items-center justify-center rounded-full border-2 group-data-[pressed]/face-toggle:flex"
|
|
69
|
+
>
|
|
70
|
+
<Icon icon="lucide:check" width={10} height={10} />
|
|
71
|
+
</span>
|
|
72
|
+
}
|
|
73
|
+
>
|
|
74
|
+
<span
|
|
75
|
+
data-slot="face-toggle-lock"
|
|
76
|
+
class="bg-muted text-foreground border-background absolute -right-1 -bottom-1 flex size-4 items-center justify-center rounded-full border-2"
|
|
77
|
+
>
|
|
78
|
+
<Icon icon="lucide:lock" width={10} height={10} />
|
|
79
|
+
</span>
|
|
80
|
+
</Show>
|
|
81
|
+
</span>
|
|
82
|
+
<span
|
|
83
|
+
data-slot="face-toggle-name"
|
|
84
|
+
class="text-muted-foreground group-data-[pressed]/face-toggle:text-foreground max-w-full truncate transition-colors duration-200"
|
|
85
|
+
>
|
|
86
|
+
{props.name}
|
|
87
|
+
</span>
|
|
88
|
+
<Show when={isLocked()}>
|
|
89
|
+
<span class="sr-only">always sees it</span>
|
|
90
|
+
</Show>
|
|
91
|
+
</ToggleGroupPrimitive.Item>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ToggleGroup as ToggleGroupPrimitive } from "@kobalte/core/toggle-group";
|
|
2
|
+
import { type JSX, onCleanup, onMount, Show } from "solid-js";
|
|
3
|
+
import { FIELD_CHROME } from "../lib/input-classes.js";
|
|
4
|
+
import { SCROLL_TRACK_FADE, trackScroll } from "../lib/scroll-track.js";
|
|
5
|
+
import { cn } from "../lib/utils.js";
|
|
6
|
+
import { Icon } from "./icon.js";
|
|
7
|
+
|
|
8
|
+
/** Tiles that scroll sideways below `sm` and wrap from `sm` up. Tapping the picked tile again clears the pick. */
|
|
9
|
+
export function GlyphTileGroup(props: {
|
|
10
|
+
value: string | null;
|
|
11
|
+
onChange: (value: string | null) => void;
|
|
12
|
+
"aria-label": string;
|
|
13
|
+
class?: string;
|
|
14
|
+
children: JSX.Element;
|
|
15
|
+
}) {
|
|
16
|
+
let group: HTMLDivElement | undefined;
|
|
17
|
+
onMount(() => {
|
|
18
|
+
if (group) onCleanup(trackScroll(group, "[data-pressed]", "data-pressed"));
|
|
19
|
+
});
|
|
20
|
+
return (
|
|
21
|
+
<ToggleGroupPrimitive
|
|
22
|
+
ref={group}
|
|
23
|
+
data-slot="glyph-tile-group"
|
|
24
|
+
aria-label={props["aria-label"]}
|
|
25
|
+
value={props.value}
|
|
26
|
+
onChange={props.onChange}
|
|
27
|
+
class={cn(
|
|
28
|
+
`flex snap-x snap-proximity [scrollbar-width:none] gap-2 overflow-x-auto overscroll-x-contain py-0.5 [&::-webkit-scrollbar]:hidden ${SCROLL_TRACK_FADE} sm:flex-wrap sm:overflow-visible`,
|
|
29
|
+
props.class,
|
|
30
|
+
)}
|
|
31
|
+
>
|
|
32
|
+
{props.children}
|
|
33
|
+
</ToggleGroupPrimitive>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A glyph over a name: a room, a kind, a place. A `badge` icon marks it while picked. */
|
|
38
|
+
export function GlyphTile(props: {
|
|
39
|
+
value: string;
|
|
40
|
+
icon: string;
|
|
41
|
+
label: string;
|
|
42
|
+
/** Shown in the corner only while this tile is picked. */
|
|
43
|
+
badge?: string;
|
|
44
|
+
class?: string;
|
|
45
|
+
}) {
|
|
46
|
+
return (
|
|
47
|
+
<ToggleGroupPrimitive.Item
|
|
48
|
+
value={props.value}
|
|
49
|
+
data-slot="glyph-tile"
|
|
50
|
+
class={cn(
|
|
51
|
+
FIELD_CHROME,
|
|
52
|
+
"transition-glass group/glyph-tile focus-visible:ring-ring/50 relative flex h-17 w-22 shrink-0 touch-manipulation snap-start flex-col items-center justify-center gap-1.5 rounded-2xl px-1 text-xs font-medium duration-200 outline-none focus-visible:ring-[3px] active:scale-[0.97] data-[pressed]:[--glass-base:color-mix(in_oklab,var(--primary)_16%,var(--input))] data-[pressed]:[--glass-edge:var(--primary)]",
|
|
53
|
+
props.class,
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
<span
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
data-slot="glyph-tile-ring"
|
|
59
|
+
class="ring-primary transition-glass pointer-events-none absolute inset-0 rounded-[inherit] ring-inset group-data-[pressed]/glyph-tile:ring-2"
|
|
60
|
+
/>
|
|
61
|
+
<Icon icon={props.icon} width={22} height={22} class="text-foreground shrink-0" />
|
|
62
|
+
<span data-slot="glyph-tile-label" class="text-foreground max-w-full truncate">
|
|
63
|
+
{props.label}
|
|
64
|
+
</span>
|
|
65
|
+
<Show when={props.badge}>
|
|
66
|
+
{(badge) => (
|
|
67
|
+
<span
|
|
68
|
+
data-slot="glyph-tile-badge"
|
|
69
|
+
class="bg-primary text-primary-foreground absolute top-1 right-1 z-10 hidden size-[18px] items-center justify-center rounded-full group-data-[pressed]/glyph-tile:flex"
|
|
70
|
+
>
|
|
71
|
+
<Icon icon={badge()} width={12} height={12} />
|
|
72
|
+
</span>
|
|
73
|
+
)}
|
|
74
|
+
</Show>
|
|
75
|
+
</ToggleGroupPrimitive.Item>
|
|
76
|
+
);
|
|
77
|
+
}
|