@glasshome/ui 1.28.0 → 1.29.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/SPEC.md +1 -0
- package/dist/solid/data-table.d.ts +18 -1
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +926 -884
- package/package.json +1 -1
- package/src/solid/data-table.tsx +81 -1
- package/src/solid/index.ts +2 -0
package/package.json
CHANGED
package/src/solid/data-table.tsx
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import {
|
|
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
|
|
package/src/solid/index.ts
CHANGED