@glasshome/ui 1.15.0 → 1.16.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/dist/solid/data-table.d.ts +34 -4
- package/dist/solid/dock-paging.d.ts +3 -1
- package/dist/solid/index.d.ts +2 -2
- package/dist/solid/index.js +1652 -1585
- package/dist/solid/section-card.d.ts +10 -0
- package/package.json +1 -1
- package/src/solid/data-table.tsx +81 -5
- package/src/solid/dock-paging.ts +4 -2
- package/src/solid/dock.tsx +29 -45
- package/src/solid/empty.tsx +1 -1
- package/src/solid/index.ts +3 -0
- package/src/solid/section-card.tsx +17 -0
- package/src/solid/tabs.tsx +36 -3
|
@@ -41,6 +41,16 @@ type ListRowProps = {
|
|
|
41
41
|
openLabel?: string;
|
|
42
42
|
class?: string;
|
|
43
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* One labelled fact: the name on the left, the value hard against the right.
|
|
46
|
+
* The counterpart of ListRow for a detail panel, where the rows are key/value
|
|
47
|
+
* rather than navigable items.
|
|
48
|
+
*/
|
|
49
|
+
export declare function FactRow(props: {
|
|
50
|
+
label: JSX.Element;
|
|
51
|
+
children: JSX.Element;
|
|
52
|
+
class?: string;
|
|
53
|
+
}): JSX.Element;
|
|
44
54
|
/**
|
|
45
55
|
* One item in a settings list. Fixed slots so every list reads the same
|
|
46
56
|
* whatever it holds; the row itself, not a nested button, is what you press.
|
package/package.json
CHANGED
package/src/solid/data-table.tsx
CHANGED
|
@@ -10,10 +10,11 @@ import { Skeleton } from "./skeleton.js";
|
|
|
10
10
|
import { TABLE_HEAD_CELL_CLASS, TABLE_HEAD_LABEL_CLASS } from "./table.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Generic data-table vocabulary:
|
|
13
|
+
* Generic data-table vocabulary: head strip, row height/padding, border
|
|
14
14
|
* treatment, hover, numeric alignment, toolbar (search/filter/sort), bulk bar,
|
|
15
|
-
* and empty/loading/error states.
|
|
16
|
-
*
|
|
15
|
+
* and empty/loading/error states. A list composes DataTableRow for the shared
|
|
16
|
+
* press and keyboard behaviour, or the class tokens for bespoke markup.
|
|
17
|
+
* Presentational only — no app data.
|
|
17
18
|
*
|
|
18
19
|
* Tables live inside a card; go edge-to-edge with `TABLE_BLEED` (cancels the
|
|
19
20
|
* card's p-3) and re-add the inset via the cell padding tokens.
|
|
@@ -32,7 +33,10 @@ export const TABLE_CELL_X = "px-4";
|
|
|
32
33
|
export const TABLE_ROW_CLASS =
|
|
33
34
|
"flex items-center gap-4 border-border/50 border-b px-4 py-2.5 transition-colors last:border-b-0 hover:bg-foreground/[0.03]";
|
|
34
35
|
export const TABLE_HEAD_CLASS = "flex items-center gap-4 border-border/50 border-b px-4 py-2";
|
|
35
|
-
|
|
36
|
+
/* No vertical cap: a table inside a page that already scrolls got a second
|
|
37
|
+
* scrollbar and hid most of its own rows. A list that genuinely boxes adds its
|
|
38
|
+
* own max-h. */
|
|
39
|
+
export const TABLE_SCROLL_CLASS = "overflow-x-auto gh-scroll";
|
|
36
40
|
export const TABLE_NUM_CELL_CLASS = "text-right text-muted-foreground text-xs tabular-nums";
|
|
37
41
|
|
|
38
42
|
export type SortDirection = "asc" | "desc";
|
|
@@ -115,6 +119,78 @@ export function TableSearchInput(props: {
|
|
|
115
119
|
);
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
/**
|
|
123
|
+
* One row of a flex data table. The row itself is what you press: activation
|
|
124
|
+
* rides on a real button covering it, the same mechanism `ListRow` uses, so a
|
|
125
|
+
* row reachable by Tab is also openable by Enter. Cells go in `children`;
|
|
126
|
+
* anything separately clickable goes in `actions`, which stacks above the
|
|
127
|
+
* overlay.
|
|
128
|
+
*/
|
|
129
|
+
export function DataTableRow(props: {
|
|
130
|
+
children: JSX.Element;
|
|
131
|
+
/** Activates the whole row. Requires `openLabel`. */
|
|
132
|
+
onOpen?: () => void;
|
|
133
|
+
/** The whole row is a link. Requires `openLabel`. */
|
|
134
|
+
href?: string;
|
|
135
|
+
/** Accessible name for the whole-row activation. */
|
|
136
|
+
openLabel?: string;
|
|
137
|
+
selected?: boolean;
|
|
138
|
+
actions?: JSX.Element;
|
|
139
|
+
class?: string;
|
|
140
|
+
}) {
|
|
141
|
+
const opens = () => props.onOpen !== undefined || props.href !== undefined;
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
data-slot="data-table-row"
|
|
145
|
+
data-state={props.selected ? "selected" : undefined}
|
|
146
|
+
class={cn(
|
|
147
|
+
TABLE_ROW_CLASS,
|
|
148
|
+
// Same selected treatment the semantic TableRow uses, keyed off the
|
|
149
|
+
// same data-state, so the two table families read alike.
|
|
150
|
+
"relative data-[state=selected]:bg-muted",
|
|
151
|
+
opens() && "cursor-pointer",
|
|
152
|
+
props.class,
|
|
153
|
+
)}
|
|
154
|
+
>
|
|
155
|
+
<Show when={props.href}>
|
|
156
|
+
{(href) => (
|
|
157
|
+
<a href={href()} class="absolute inset-0 outline-none">
|
|
158
|
+
<span class="sr-only">{props.openLabel}</span>
|
|
159
|
+
</a>
|
|
160
|
+
)}
|
|
161
|
+
</Show>
|
|
162
|
+
<Show when={props.href === undefined && props.onOpen}>
|
|
163
|
+
<button
|
|
164
|
+
type="button"
|
|
165
|
+
class="absolute inset-0 outline-none"
|
|
166
|
+
aria-label={props.openLabel}
|
|
167
|
+
onClick={() => props.onOpen?.()}
|
|
168
|
+
/>
|
|
169
|
+
</Show>
|
|
170
|
+
{props.children}
|
|
171
|
+
<Show when={props.actions}>
|
|
172
|
+
<div class="relative flex shrink-0 items-center gap-1">{props.actions}</div>
|
|
173
|
+
</Show>
|
|
174
|
+
</div>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Column header strip. `sticky` keeps the labels against the top of the
|
|
180
|
+
* scrollport while a long list scrolls under them, which needs its own
|
|
181
|
+
* background so rows do not read through the glass.
|
|
182
|
+
*/
|
|
183
|
+
export function DataTableHead(props: { children: JSX.Element; sticky?: boolean; class?: string }) {
|
|
184
|
+
return (
|
|
185
|
+
<div
|
|
186
|
+
data-slot="data-table-head"
|
|
187
|
+
class={cn(TABLE_HEAD_CLASS, props.sticky && "sticky top-0 z-10 bg-background", props.class)}
|
|
188
|
+
>
|
|
189
|
+
{props.children}
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
118
194
|
/** Sortable column header button. `align="end"` for numeric columns. */
|
|
119
195
|
export function TableSortHeader(props: {
|
|
120
196
|
label: string;
|
|
@@ -163,7 +239,7 @@ export function TableEmpty(props: {
|
|
|
163
239
|
action?: JSX.Element;
|
|
164
240
|
}) {
|
|
165
241
|
return (
|
|
166
|
-
<Empty class="gap-3 rounded-none
|
|
242
|
+
<Empty class="gap-3 rounded-none py-12">
|
|
167
243
|
<EmptyHeader>
|
|
168
244
|
<Show when={props.icon}>
|
|
169
245
|
<EmptyMedia media="icon">
|
package/src/solid/dock-paging.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
/** A page is one strip-width of items. The last one is whatever is left.
|
|
1
|
+
/** A page is one strip-width of items. The last one is whatever is left.
|
|
2
|
+
* The tolerance keeps a strip a sub-pixel over its viewport on one page: both
|
|
3
|
+
* numbers are rounded reads of the same box. */
|
|
2
4
|
export function pageCount(scrollWidth: number, viewport: number): number {
|
|
3
5
|
if (viewport <= 0) return 1;
|
|
4
|
-
return Math.max(1, Math.ceil(scrollWidth / viewport));
|
|
6
|
+
return Math.max(1, Math.ceil((scrollWidth - 1) / viewport));
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
/** The page a scroll position sits on, counting a half-page as turned. */
|
package/src/solid/dock.tsx
CHANGED
|
@@ -134,53 +134,38 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
134
134
|
const itemWidth = () =>
|
|
135
135
|
containerRef?.querySelector('[data-slot="dock-item"]')?.getBoundingClientRect().width ?? 0;
|
|
136
136
|
|
|
137
|
+
const padX = (el: Element) => {
|
|
138
|
+
const style = getComputedStyle(el);
|
|
139
|
+
return (
|
|
140
|
+
(Number.parseFloat(style.paddingLeft) || 0) + (Number.parseFloat(style.paddingRight) || 0)
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// The width the app gave the dock. Never the surface: it shrink-wraps this strip,
|
|
145
|
+
// so measuring it asks the strip how wide the strip is.
|
|
146
|
+
const availableWidth = () => {
|
|
147
|
+
const box = containerRef?.closest<HTMLElement>('[data-slot="dock"]');
|
|
148
|
+
if (!box || !surfaceRef) return 0;
|
|
149
|
+
return box.clientWidth - padX(box) - padX(surfaceRef);
|
|
150
|
+
};
|
|
151
|
+
|
|
137
152
|
const checkOverflow = () => {
|
|
138
153
|
if (!containerRef) return;
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
(Number.parseFloat(surfaceStyle.paddingLeft) || 0) +
|
|
147
|
-
(Number.parseFloat(surfaceStyle.paddingRight) || 0);
|
|
148
|
-
let siblingWidth = 0;
|
|
149
|
-
for (const child of Array.from(surface.children)) {
|
|
150
|
-
if (child === containerRef) continue;
|
|
151
|
-
const childStyle = getComputedStyle(child);
|
|
152
|
-
// The page dots overlay the bar out of flow; they do not narrow it.
|
|
153
|
-
if (childStyle.position === "absolute" || childStyle.position === "fixed") continue;
|
|
154
|
-
siblingWidth +=
|
|
155
|
-
child.getBoundingClientRect().width +
|
|
156
|
-
(Number.parseFloat(childStyle.marginLeft) || 0) +
|
|
157
|
-
(Number.parseFloat(childStyle.marginRight) || 0);
|
|
154
|
+
const available = availableWidth();
|
|
155
|
+
const overflowing = available > 0 && containerRef.scrollWidth > available + 1;
|
|
156
|
+
if (overflowing) {
|
|
157
|
+
const trimmed = stripWidth(available, itemWidth(), gapWidth());
|
|
158
|
+
if (trimmed > 0) containerRef.style.width = `${trimmed}px`;
|
|
159
|
+
} else if (containerRef.style.width) {
|
|
160
|
+
containerRef.style.width = "";
|
|
158
161
|
}
|
|
159
|
-
const availableWidth = surface.clientWidth - paddingX - siblingWidth;
|
|
160
|
-
const overflowing = containerRef.scrollWidth > availableWidth;
|
|
161
|
-
const trimmed = overflowing ? stripWidth(availableWidth, itemWidth(), gapWidth()) : 0;
|
|
162
|
-
if (trimmed > 0) containerRef.style.width = `${trimmed}px`;
|
|
163
162
|
setNeedsScroll(overflowing);
|
|
164
|
-
const viewport =
|
|
163
|
+
const viewport = containerRef.clientWidth;
|
|
165
164
|
setViewportWidth(viewport);
|
|
166
165
|
setPages(pageCount(containerRef.scrollWidth, viewport));
|
|
167
166
|
setPage(pageOf(containerRef.scrollLeft, viewport));
|
|
168
167
|
};
|
|
169
168
|
|
|
170
|
-
// The surface animates its width, so a read taken right after we set one is
|
|
171
|
-
// mid-transition: clearing our trim has to settle before the next measure.
|
|
172
|
-
let settleId: ReturnType<typeof setTimeout> | undefined;
|
|
173
|
-
const remeasure = () => {
|
|
174
|
-
if (!containerRef) return;
|
|
175
|
-
if (!containerRef.style.width) {
|
|
176
|
-
checkOverflow();
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
containerRef.style.width = "";
|
|
180
|
-
clearTimeout(settleId);
|
|
181
|
-
settleId = setTimeout(checkOverflow, 250);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
169
|
const goToPage = (next: number) => {
|
|
185
170
|
if (!containerRef) return;
|
|
186
171
|
containerRef.scrollTo({
|
|
@@ -198,26 +183,25 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
198
183
|
});
|
|
199
184
|
|
|
200
185
|
onMount(() => {
|
|
201
|
-
const timeoutId = setTimeout(
|
|
202
|
-
// Watching the bar would see its own trim and re-trim forever; the viewport
|
|
203
|
-
// is the only width the dock does not derive from itself.
|
|
186
|
+
const timeoutId = setTimeout(checkOverflow, 100);
|
|
204
187
|
let resizeTimeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
205
188
|
const onResize = () => {
|
|
206
189
|
clearTimeout(resizeTimeoutId);
|
|
207
|
-
resizeTimeoutId = setTimeout(
|
|
190
|
+
resizeTimeoutId = setTimeout(checkOverflow, 50);
|
|
208
191
|
};
|
|
209
192
|
window.addEventListener("resize", onResize);
|
|
210
193
|
onCleanup(() => {
|
|
211
194
|
clearTimeout(timeoutId);
|
|
212
195
|
clearTimeout(resizeTimeoutId);
|
|
213
|
-
clearTimeout(settleId);
|
|
214
196
|
window.removeEventListener("resize", onResize);
|
|
215
197
|
});
|
|
216
198
|
});
|
|
217
199
|
|
|
218
200
|
createEffect(() => {
|
|
219
201
|
local.items.length;
|
|
220
|
-
|
|
202
|
+
// The box pads by mode, so switching it changes the room the strip has.
|
|
203
|
+
dockMode();
|
|
204
|
+
const timeoutId = setTimeout(checkOverflow, 150);
|
|
221
205
|
onCleanup(() => clearTimeout(timeoutId));
|
|
222
206
|
});
|
|
223
207
|
|
|
@@ -236,7 +220,7 @@ const Dock: Component<DockProps> = (props) => {
|
|
|
236
220
|
data-slot="dock-surface"
|
|
237
221
|
class={cn(
|
|
238
222
|
// isolate: the layers behind the icons stay inside the dock even with blur off.
|
|
239
|
-
"relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
|
|
223
|
+
"pointer-events-auto relative isolate flex max-w-full items-center justify-center p-1.5 sm:p-2",
|
|
240
224
|
// Room for the page dots inside the glass; outside it they sit on
|
|
241
225
|
// the screen edge and get clipped.
|
|
242
226
|
pages() > 1 && "pb-4 sm:pb-5",
|
package/src/solid/empty.tsx
CHANGED
|
@@ -8,7 +8,7 @@ const Empty: Component<ComponentProps<"div">> = (props) => {
|
|
|
8
8
|
<div
|
|
9
9
|
data-slot="empty"
|
|
10
10
|
class={cn(
|
|
11
|
-
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg
|
|
11
|
+
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 text-balance rounded-lg p-6 text-center md:p-12",
|
|
12
12
|
local.class,
|
|
13
13
|
)}
|
|
14
14
|
{...rest}
|
package/src/solid/index.ts
CHANGED
|
@@ -123,6 +123,8 @@ export {
|
|
|
123
123
|
export { CopyButton } from "./copy-button.js";
|
|
124
124
|
export { CountPill } from "./count-pill.js";
|
|
125
125
|
export {
|
|
126
|
+
DataTableHead,
|
|
127
|
+
DataTableRow,
|
|
126
128
|
type SortDirection,
|
|
127
129
|
TABLE_BLEED,
|
|
128
130
|
TABLE_CELL_X,
|
|
@@ -334,6 +336,7 @@ export {
|
|
|
334
336
|
export { ScopeIndicator } from "./scope-indicator.js";
|
|
335
337
|
export { ScrollArea, ScrollBar } from "./scroll-area.js";
|
|
336
338
|
export {
|
|
339
|
+
FactRow,
|
|
337
340
|
type GlassSurface,
|
|
338
341
|
ListRow,
|
|
339
342
|
NOOP_GLASS,
|
|
@@ -146,6 +146,23 @@ type ListRowProps = {
|
|
|
146
146
|
class?: string;
|
|
147
147
|
};
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
* One labelled fact: the name on the left, the value hard against the right.
|
|
151
|
+
* The counterpart of ListRow for a detail panel, where the rows are key/value
|
|
152
|
+
* rather than navigable items.
|
|
153
|
+
*/
|
|
154
|
+
export function FactRow(props: { label: JSX.Element; children: JSX.Element; class?: string }) {
|
|
155
|
+
return (
|
|
156
|
+
<div
|
|
157
|
+
data-slot="fact-row"
|
|
158
|
+
class={cn("flex items-baseline justify-between gap-3 py-1.5", props.class)}
|
|
159
|
+
>
|
|
160
|
+
<span class="shrink-0 text-muted-foreground text-xs">{props.label}</span>
|
|
161
|
+
<span class="min-w-0 text-right text-sm">{props.children}</span>
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
149
166
|
/**
|
|
150
167
|
* One item in a settings list. Fixed slots so every list reads the same
|
|
151
168
|
* whatever it holds; the row itself, not a nested button, is what you press.
|
package/src/solid/tabs.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tabs as TabsPrimitive } from "@kobalte/core/tabs";
|
|
2
|
-
import { type Component, type ComponentProps, splitProps } from "solid-js";
|
|
2
|
+
import { type Component, type ComponentProps, onCleanup, onMount, splitProps } from "solid-js";
|
|
3
3
|
import { TRACK_SURFACE } from "../lib/card-classes.js";
|
|
4
4
|
import { PRESS_DIP, SETTLE_MOTION } from "../lib/motion-classes.js";
|
|
5
5
|
import { SEGMENT_ITEM } from "../lib/segment-classes.js";
|
|
@@ -30,21 +30,54 @@ const Tabs: Component<TabsProps> = (props) => {
|
|
|
30
30
|
);
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
/** Keeps the selected trigger centred in the scrolled track, so a deep link to
|
|
34
|
+
* a tab past the fold does not land on a track scrolled to the first one.
|
|
35
|
+
* Drives scrollLeft rather than scrollIntoView, which would scroll the page
|
|
36
|
+
* with it. */
|
|
37
|
+
function followSelection(list: HTMLElement): () => void {
|
|
38
|
+
const reveal = () => {
|
|
39
|
+
if (list.scrollWidth <= list.clientWidth) return;
|
|
40
|
+
const selected = list.querySelector("[data-selected]");
|
|
41
|
+
if (!selected) return;
|
|
42
|
+
const track = list.getBoundingClientRect();
|
|
43
|
+
const item = selected.getBoundingClientRect();
|
|
44
|
+
const left = list.scrollLeft + (item.left - track.left) - (track.width - item.width) / 2;
|
|
45
|
+
const smooth = !matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
46
|
+
list.scrollTo({ left, behavior: smooth ? "smooth" : "auto" });
|
|
47
|
+
};
|
|
48
|
+
// The track has no width during mount, so the first pass has to wait for
|
|
49
|
+
// layout or it measures a track that cannot scroll yet.
|
|
50
|
+
const first = requestAnimationFrame(reveal);
|
|
51
|
+
const observer = new MutationObserver(reveal);
|
|
52
|
+
observer.observe(list, { attributes: true, attributeFilter: ["data-selected"], subtree: true });
|
|
53
|
+
return () => {
|
|
54
|
+
cancelAnimationFrame(first);
|
|
55
|
+
observer.disconnect();
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
33
59
|
const TabsList: Component<ComponentProps<typeof TabsPrimitive.List>> = (props) => {
|
|
34
60
|
const [local, others] = splitProps(props, ["class", "children"]);
|
|
61
|
+
let listRef: HTMLDivElement | undefined;
|
|
62
|
+
onMount(() => {
|
|
63
|
+
if (listRef) onCleanup(followSelection(listRef));
|
|
64
|
+
});
|
|
35
65
|
return (
|
|
36
66
|
<TabsPrimitive.List
|
|
67
|
+
ref={listRef}
|
|
37
68
|
data-slot="tabs-list"
|
|
38
69
|
class={cn(
|
|
39
|
-
`inline-flex h-9 w-full items-center rounded-lg ${TRACK_SURFACE} p-1 text-muted-foreground`,
|
|
70
|
+
`scrollbar-hide inline-flex h-9 w-full items-center overflow-x-auto rounded-lg ${TRACK_SURFACE} p-1 text-muted-foreground`,
|
|
40
71
|
local.class,
|
|
41
72
|
)}
|
|
42
73
|
{...others}
|
|
43
74
|
>
|
|
75
|
+
{/* w-max so triggers keep their natural width and the track scrolls;
|
|
76
|
+
w-full alone squeezed them past the rounded edge, unreachable. */}
|
|
44
77
|
<SlidingIndicator
|
|
45
78
|
activeSelector="[data-selected]"
|
|
46
79
|
indicatorClass="rounded-md"
|
|
47
|
-
class="flex h-full w-full items-center gap-1"
|
|
80
|
+
class="flex h-full w-max min-w-full items-center gap-1"
|
|
48
81
|
>
|
|
49
82
|
{local.children}
|
|
50
83
|
</SlidingIndicator>
|