@glasshome/ui 1.15.0 → 1.16.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.
- package/dist/solid/data-table.d.ts +34 -4
- package/dist/solid/index.d.ts +2 -2
- package/dist/solid/index.js +1633 -1557
- package/dist/solid/section-card.d.ts +10 -0
- package/package.json +1 -1
- package/src/solid/data-table.tsx +80 -4
- 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;
|
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>
|