@glasshome/ui 1.28.0 → 1.29.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/ui",
3
- "version": "1.28.0",
3
+ "version": "1.29.1",
4
4
  "description": "SolidJS component library for GlassHome, built on Kobalte",
5
5
  "keywords": [
6
6
  "components",
@@ -1,4 +1,16 @@
1
- import { For, type JSX, Show, splitProps } from "solid-js";
1
+ import {
2
+ type Accessor,
3
+ createEffect,
4
+ createMemo,
5
+ createSignal,
6
+ For,
7
+ type JSX,
8
+ on,
9
+ onCleanup,
10
+ onMount,
11
+ Show,
12
+ splitProps,
13
+ } from "solid-js";
2
14
  import { SECTION_PADDING } from "../lib/section-tokens.js";
3
15
  import { cn } from "../lib/utils.js";
4
16
  import { Button } from "./button.js";
@@ -271,6 +283,74 @@ export function TableError(props: { message: JSX.Element; onRetry: () => void })
271
283
  );
272
284
  }
273
285
 
286
+ /** The end of a long table: asks for the next page as it nears the viewport, or on press. */
287
+ export function TableLoadMore(props: {
288
+ hasMore: boolean;
289
+ loading?: boolean;
290
+ onLoadMore: () => void;
291
+ label?: string;
292
+ class?: string;
293
+ }) {
294
+ let sentinel: HTMLDivElement | undefined;
295
+ onMount(() => {
296
+ if (!sentinel || typeof IntersectionObserver === "undefined") return;
297
+ const target = sentinel;
298
+ let frame = 0;
299
+ const observer = new IntersectionObserver(
300
+ (entries) => {
301
+ if (!entries[0]?.isIntersecting || !props.hasMore || props.loading) return;
302
+ props.onLoadMore();
303
+ // A page too short to push the sentinel out of view never fires again on its own.
304
+ cancelAnimationFrame(frame);
305
+ frame = requestAnimationFrame(() => {
306
+ observer.unobserve(target);
307
+ observer.observe(target);
308
+ });
309
+ },
310
+ { rootMargin: "400px" },
311
+ );
312
+ observer.observe(target);
313
+ onCleanup(() => {
314
+ cancelAnimationFrame(frame);
315
+ observer.disconnect();
316
+ });
317
+ });
318
+ return (
319
+ <div
320
+ ref={sentinel}
321
+ data-slot="table-load-more"
322
+ class={cn("flex justify-center py-3", props.class)}
323
+ >
324
+ <Show when={props.hasMore}>
325
+ <Button
326
+ variant="ghost"
327
+ size="sm"
328
+ disabled={props.loading}
329
+ onClick={() => props.onLoadMore()}
330
+ >
331
+ {props.loading ? "Loading…" : (props.label ?? "Show more")}
332
+ </Button>
333
+ </Show>
334
+ </div>
335
+ );
336
+ }
337
+
338
+ /** Draws a long list a page at a time; `resetOn` changing (a filter, a sort) starts over at one page. */
339
+ export function createTableWindow<T>(
340
+ items: Accessor<T[]>,
341
+ options: { pageSize?: number; resetOn?: Accessor<unknown> } = {},
342
+ ) {
343
+ const pageSize = options.pageSize ?? 50;
344
+ const [limit, setLimit] = createSignal(pageSize);
345
+ const resetOn = options.resetOn;
346
+ if (resetOn) createEffect(on(resetOn, () => setLimit(pageSize), { defer: true }));
347
+ return {
348
+ shown: createMemo(() => items().slice(0, limit())),
349
+ hasMore: () => items().length > limit(),
350
+ showMore: () => setLimit((n) => n + pageSize),
351
+ };
352
+ }
353
+
274
354
  const SKELETON_TITLE_WIDTHS = ["w-2/5", "w-1/3", "w-1/2", "w-2/5", "w-5/12"] as const;
275
355
  const SKELETON_META_WIDTHS = ["w-1/2", "w-2/5", "w-3/5", "w-1/2", "w-3/5"] as const;
276
356
 
@@ -86,7 +86,7 @@ const MODAL_HEADER_ACTION = "flex shrink-0 items-center gap-2";
86
86
  * - The reserved scrollbar lives inside the right inset, so the content column
87
87
  * ends where the Header's and Footer's do. */
88
88
  const MODAL_BODY =
89
- "gh-scroll gh-stagger flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-w))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3 in-data-[slot=bottom-sheet-content]:pl-4 in-data-[slot=bottom-sheet-content]:pr-[calc(var(--spacing)*4-var(--scrollbar-w))] [[data-slot=bottom-sheet-handle]+&]:pt-1";
89
+ "gh-scroll gh-stagger flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto overscroll-contain [touch-action:pan-y_pinch-zoom] [scrollbar-gutter:stable] pl-6 pr-[calc(var(--spacing)*6-var(--scrollbar-gutter,var(--scrollbar-w)))] pt-6 pb-6 [[data-slot$='-header']~&]:pt-3 [&:has(~[data-slot$='-footer'])]:pb-3 in-data-[slot=bottom-sheet-content]:pl-4 in-data-[slot=bottom-sheet-content]:pr-[calc(var(--spacing)*4-var(--scrollbar-gutter,var(--scrollbar-w)))] [[data-slot=bottom-sheet-handle]+&]:pt-1";
90
90
 
91
91
  const MODAL_FOOTER =
92
92
  "gh-stagger flex shrink-0 flex-col-reverse gap-2 px-6 pt-3 pb-6 sm:flex-row sm:justify-end in-data-[slot=bottom-sheet-content]:px-4";
@@ -143,10 +143,19 @@ export function createModalParts(slot: string): ModalParts {
143
143
  * inside a sheet must yield the gesture to its own scroll, whichever family
144
144
  * rendered it. */
145
145
  const Body: Component<ModalBodyProps> = (props) => {
146
- const [local, rest] = splitProps(props, ["class", "as"]);
146
+ const [local, rest] = splitProps(props, ["class", "as", "ref"]);
147
+ let el: HTMLElement | undefined;
148
+ // Overlay scrollbars reserve no gutter, so the right inset subtracts what the platform actually reserved.
149
+ onMount(() => {
150
+ if (el) el.style.setProperty("--scrollbar-gutter", `${el.offsetWidth - el.clientWidth}px`);
151
+ });
147
152
  return (
148
153
  <Dynamic
149
154
  component={local.as ?? "div"}
155
+ ref={(node: HTMLElement) => {
156
+ el = node;
157
+ if (typeof local.ref === "function") local.ref(node as HTMLDivElement);
158
+ }}
150
159
  data-slot={`${slot}-body`}
151
160
  data-sheet-scroll=""
152
161
  class={cn(MODAL_BODY, local.class)}
@@ -132,9 +132,11 @@ export {
132
132
  TableEmpty,
133
133
  TableError,
134
134
  TableFilterSelect,
135
+ TableLoadMore,
135
136
  TableSearchInput,
136
137
  TableSkeleton,
137
138
  TableSortHeader,
139
+ createTableWindow,
138
140
  } from "./data-table.js";
139
141
  export {
140
142
  Dialog,