@omnigrid/react 0.1.10 → 0.1.12
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/README.md +59 -37
- package/dist/OmniGrid.d.ts +7 -3
- package/dist/OmniGrid.js +98 -34
- package/dist/index.d.ts +1 -1
- package/dist/overlays.d.ts +13 -0
- package/dist/overlays.js +58 -0
- package/dist/useGrid.js +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,37 +1,59 @@
|
|
|
1
|
-
# @omnigrid/react
|
|
2
|
-
|
|
3
|
-
React adapter and renderer for OmniGrid. Renders the headless core engine into the DOM using React.
|
|
4
|
-
|
|
5
|
-
## What it provides
|
|
6
|
-
|
|
7
|
-
- **`<OmniGrid />`** — React component that accepts `GridOptions` and renders a fully virtualized, 2D scrolled data grid
|
|
8
|
-
- **`useGrid()`** — hook that creates and manages a `GridCore` instance with full lifecycle handling
|
|
9
|
-
- **Cell / Row pooling** — reusable React content via DOM-pool integration for minimal re-renders
|
|
10
|
-
- **Styles and default theme** — required structural styles and light/dark default colors are included automatically
|
|
11
|
-
- **`transpilePackages`-ready** — works out of the box with Next.js and other bundlers
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```tsx
|
|
16
|
-
import { OmniGrid } from "@omnigrid/react";
|
|
17
|
-
import { useMemo } from "react";
|
|
18
|
-
|
|
19
|
-
const columns = useMemo(() => [...], []);
|
|
20
|
-
const data = [...];
|
|
21
|
-
|
|
22
|
-
<OmniGrid columns={columns} data={data} />;
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
# @omnigrid/react
|
|
2
|
+
|
|
3
|
+
React adapter and renderer for OmniGrid. Renders the headless core engine into the DOM using React.
|
|
4
|
+
|
|
5
|
+
## What it provides
|
|
6
|
+
|
|
7
|
+
- **`<OmniGrid />`** — React component that accepts `GridOptions` and renders a fully virtualized, 2D scrolled data grid
|
|
8
|
+
- **`useGrid()`** — hook that creates and manages a `GridCore` instance with full lifecycle handling
|
|
9
|
+
- **Cell / Row pooling** — reusable React content via DOM-pool integration for minimal re-renders
|
|
10
|
+
- **Styles and default theme** — required structural styles and light/dark default colors are included automatically
|
|
11
|
+
- **`transpilePackages`-ready** — works out of the box with Next.js and other bundlers
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { OmniGrid } from "@omnigrid/react";
|
|
17
|
+
import { useMemo } from "react";
|
|
18
|
+
|
|
19
|
+
const columns = useMemo(() => [...], []);
|
|
20
|
+
const data = [...];
|
|
21
|
+
|
|
22
|
+
<OmniGrid columns={columns} data={data} />;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Overlays
|
|
26
|
+
|
|
27
|
+
The adapter renders body-only overlays below the sticky header. While one is active, vertical
|
|
28
|
+
scrolling and its scrollbar are disabled; horizontal scrolling remains available for
|
|
29
|
+
`noMatchingRows` (or when `blockScroll: false`). Use `scope: "full"` to cover the header and
|
|
30
|
+
body as well.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { OmniGrid, type OverlayComponentProps } from "@omnigrid/react";
|
|
34
|
+
|
|
35
|
+
function LoadError<T>({ message }: OverlayComponentProps<T>) {
|
|
36
|
+
return <div role="alert">{message ?? "Unable to load rows"}</div>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
<OmniGrid
|
|
40
|
+
columns={columns}
|
|
41
|
+
data={data}
|
|
42
|
+
overlayComponents={{ error: LoadError }}
|
|
43
|
+
onGridReady={(grid) => grid.showOverlay({ type: "error", message: "Please retry" })}
|
|
44
|
+
/>;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
To customize the table's color style, install a compatible `@omnigrid/*-theme`
|
|
48
|
+
package and import it in the application after `@omnigrid/react`. Theme packages
|
|
49
|
+
include their own light and dark variants; they are not light/dark mode toggles.
|
|
50
|
+
|
|
51
|
+
## Links
|
|
52
|
+
|
|
53
|
+
- **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/adapters/react
|
|
54
|
+
- **Demo:** https://omnigrid-demo.vercel.app/
|
|
55
|
+
- **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
MIT © KRZK Apps
|
package/dist/OmniGrid.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
-
import type { GridOptions, SlotRenderContext } from "@omnigrid/core";
|
|
1
|
+
import { type ComponentType, type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
import type { GridOptions, OverlayComponent as CoreOverlayComponent, OverlayComponentProps as CoreOverlayComponentProps, SlotRenderContext } from "@omnigrid/core";
|
|
3
3
|
/**
|
|
4
4
|
* Registry of native adapter components for `SlotComponentContent`:
|
|
5
5
|
* slotComponents={{ ["my-widget"]: (payload, context) => <MyWidget .../> }}
|
|
@@ -7,10 +7,13 @@ import type { GridOptions, SlotRenderContext } from "@omnigrid/core";
|
|
|
7
7
|
export interface SlotRendererRegistry<T> {
|
|
8
8
|
[kind: string]: (payload: unknown, context: SlotRenderContext<T>) => ReactNode;
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export type OverlayComponentProps<T> = CoreOverlayComponentProps<T>;
|
|
11
|
+
type OverlayComponent<T> = ComponentType<CoreOverlayComponentProps<T>> | CoreOverlayComponent<T>;
|
|
12
|
+
export interface GridProps<T> extends Omit<GridOptions<T>, "overlayComponents"> {
|
|
11
13
|
className?: string;
|
|
12
14
|
style?: CSSProperties;
|
|
13
15
|
slotComponents?: SlotRendererRegistry<T>;
|
|
16
|
+
overlayComponents?: Record<string, OverlayComponent<T>>;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* React adapter over the headless core.
|
|
@@ -38,3 +41,4 @@ export interface GridProps<T> extends GridOptions<T> {
|
|
|
38
41
|
* `slotComponents`.
|
|
39
42
|
*/
|
|
40
43
|
export declare function OmniGrid<T>({ className, style, slotComponents, ...options }: GridProps<T>): import("react").JSX.Element;
|
|
44
|
+
export {};
|
package/dist/OmniGrid.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { flushSync } from "react-dom";
|
|
4
4
|
import { DomPool } from "@omnigrid/core";
|
|
5
5
|
import { contentToReactNode } from "./content";
|
|
6
6
|
import { computeGroupSegments } from "./groupHeader";
|
|
7
7
|
import { PooledRowPane } from "./pooledRow";
|
|
8
8
|
import { createCellRoot } from "./reactRoot";
|
|
9
|
+
import { renderDefaultOverlay } from "./overlays";
|
|
9
10
|
import { useGrid } from "./useGrid";
|
|
10
11
|
function getCellValue(row, column) {
|
|
11
12
|
if (column.valueGetter)
|
|
@@ -91,6 +92,11 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
91
92
|
// re-allocated on every render cycle.
|
|
92
93
|
const renderContext = useMemo(() => ({ api: grid, state, slot: undefined }), [grid, state]);
|
|
93
94
|
const buildRenderContext = useCallback(() => renderContext, [renderContext]);
|
|
95
|
+
const onGridReadyRef = useRef(options.onGridReady);
|
|
96
|
+
onGridReadyRef.current = options.onGridReady;
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
onGridReadyRef.current?.(grid);
|
|
99
|
+
}, [grid]);
|
|
94
100
|
const autoHeight = style?.height === undefined;
|
|
95
101
|
const rowHeight = grid.getState().rowHeight;
|
|
96
102
|
// Column-group header stack: `headerRowCount` group rows (one per depth) above
|
|
@@ -119,6 +125,12 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
119
125
|
const viewportStyle = { ...style, height: autoHeight ? measuredHeight : style?.height };
|
|
120
126
|
const suppressRowHoverHighlight = options.suppressRowHoverHighlight ?? false;
|
|
121
127
|
const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null].filter(Boolean).join(" ");
|
|
128
|
+
const overlayState = state.overlay;
|
|
129
|
+
const overlayScope = overlayState.type ? (overlayState.scope ?? "bodyOnly") : undefined;
|
|
130
|
+
const overlayBlocksHorizontalScroll = overlayState.type
|
|
131
|
+
? (overlayState.blockScroll ?? overlayState.type !== "noMatchingRows")
|
|
132
|
+
: false;
|
|
133
|
+
const isFullOverlay = overlayScope === "full";
|
|
122
134
|
/**
|
|
123
135
|
* Bridge between the core's headless content and React: a factory for the
|
|
124
136
|
* current render context (the registry is read live via the ref).
|
|
@@ -377,10 +389,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
377
389
|
useLayoutEffect(() => {
|
|
378
390
|
if (!isMeasured || autoHeight)
|
|
379
391
|
return;
|
|
380
|
-
//
|
|
381
|
-
//
|
|
392
|
+
// Scrollbar and gutter changes alter clientWidth; sync it before paint
|
|
393
|
+
// so columns remain aligned when an overlay locks vertical scrolling.
|
|
382
394
|
measureViewport();
|
|
383
|
-
}, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport]);
|
|
395
|
+
}, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport, overlayScope]);
|
|
384
396
|
/**
|
|
385
397
|
* Sync the DomPool after every structural re-render.
|
|
386
398
|
* This runs only when React actually re-renders (data / columns /
|
|
@@ -479,6 +491,43 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
479
491
|
return (_jsx("div", { className: `omnigrid-slot-item-group omnigrid-slot-pos-${position}`, children: group.map((mount) => (_jsx("div", { className: "omnigrid-slot-item", children: resolveSlotContent(mount, context) }, mount.id))) }, position));
|
|
480
492
|
}) }));
|
|
481
493
|
};
|
|
494
|
+
/**
|
|
495
|
+
* Resolves a React component, legacy headless renderer, or built-in overlay
|
|
496
|
+
* for the active state.
|
|
497
|
+
*/
|
|
498
|
+
function renderOverlayContent(overlay) {
|
|
499
|
+
if (!overlay || !overlay.type)
|
|
500
|
+
return null;
|
|
501
|
+
const registeredRenderer = typeof overlay.component === "string"
|
|
502
|
+
? optionsRef.current.overlayComponents?.[overlay.component]
|
|
503
|
+
: optionsRef.current.overlayComponents?.[overlay.type];
|
|
504
|
+
const component = typeof overlay.component === "function" || (typeof overlay.component === "object" && overlay.component !== null)
|
|
505
|
+
? overlay.component
|
|
506
|
+
: registeredRenderer;
|
|
507
|
+
const isLegacyRenderer = typeof component === "function" && component.length >= 2;
|
|
508
|
+
if (component && !isLegacyRenderer) {
|
|
509
|
+
return createElement(component, {
|
|
510
|
+
type: overlay.type,
|
|
511
|
+
message: overlay.message,
|
|
512
|
+
payload: overlay.payload,
|
|
513
|
+
state: grid.getState(),
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
const customRenderer = component ?? registeredRenderer;
|
|
517
|
+
if (isLegacyRenderer && typeof customRenderer === "function") {
|
|
518
|
+
return contentToReactNode(customRenderer(overlay.payload, grid.getState()), {
|
|
519
|
+
registry: slotComponentsRef.current,
|
|
520
|
+
context: buildRenderContext,
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
if (overlay.component !== undefined) {
|
|
524
|
+
return contentToReactNode(overlay.payload, {
|
|
525
|
+
registry: slotComponentsRef.current,
|
|
526
|
+
context: buildRenderContext,
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
return renderDefaultOverlay(overlay);
|
|
530
|
+
}
|
|
482
531
|
const pinnedLeftWidth = viewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
|
|
483
532
|
const pinnedRightWidth = viewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
|
|
484
533
|
const scrollableWidth = Math.max(0, viewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
|
|
@@ -496,6 +545,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
496
545
|
// correctly on the horizontal axis because sticky positioning is not
|
|
497
546
|
// affected by the clip.
|
|
498
547
|
const needsHorizontalScroll = viewportData.totalWidth > grid.getState().viewport.width;
|
|
548
|
+
const overlayHeight = Math.max(0, (autoHeight ? measuredHeight : state.viewport.height) - headerHeight);
|
|
499
549
|
const renderHeaderCells = (columns, originX) => columns.map((item) => {
|
|
500
550
|
const deepestDepth = hasGroups ? (viewportData.columnGroupDepth.get(item.index) ?? -1) : -1;
|
|
501
551
|
const gapRows = headerRowCount - 1 - deepestDepth;
|
|
@@ -577,41 +627,55 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
577
627
|
top: headerHeight,
|
|
578
628
|
width,
|
|
579
629
|
} }));
|
|
580
|
-
return (_jsxs("div", { className: "omnigrid-layout", style: style, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"),
|
|
630
|
+
return (_jsxs("div", { className: "omnigrid-layout", style: { ...style, position: "relative", ...(isFullOverlay ? { overflow: "hidden" } : {}) }, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"), _jsxs("div", { ref: viewportRef, className: viewportClassName, onScroll: handleScroll, style: {
|
|
581
631
|
...viewportStyle,
|
|
582
632
|
flex: "1 1 0",
|
|
583
633
|
height: autoHeight ? measuredHeight : "100%",
|
|
584
634
|
minHeight: 0,
|
|
585
635
|
minWidth: 0,
|
|
586
|
-
overflowX: needsHorizontalScroll ? "auto" : "hidden",
|
|
587
|
-
overflowY: autoHeight ? "hidden" : "auto",
|
|
636
|
+
overflowX: isFullOverlay || (overlayScope === "bodyOnly" && overlayBlocksHorizontalScroll) ? "hidden" : needsHorizontalScroll ? "auto" : "hidden",
|
|
637
|
+
overflowY: isFullOverlay || overlayScope === "bodyOnly" || autoHeight ? "hidden" : "auto",
|
|
588
638
|
position: "relative",
|
|
589
|
-
scrollbarGutter: verticalScrollbarGutter,
|
|
639
|
+
scrollbarGutter: overlayScope === "bodyOnly" ? "auto" : verticalScrollbarGutter,
|
|
590
640
|
width: "100%",
|
|
591
|
-
}, children: _jsxs("div", { style: {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
641
|
+
}, children: [_jsxs("div", { style: {
|
|
642
|
+
display: "flex",
|
|
643
|
+
height: rowTotalHeight,
|
|
644
|
+
position: "relative",
|
|
645
|
+
width: `max(100%, ${viewportData.totalWidth}px)`,
|
|
646
|
+
}, children: [hasPinnedLeft && (_jsxs("div", { className: "omnigrid-pinned omnigrid-pinned-left", style: {
|
|
647
|
+
height: rowTotalHeight,
|
|
648
|
+
left: 0,
|
|
649
|
+
position: "sticky",
|
|
650
|
+
top: 0,
|
|
651
|
+
width: `${pinnedLeftWidth}px`,
|
|
652
|
+
zIndex: 3,
|
|
653
|
+
}, children: [renderHeader(viewportData.pinnedLeftColumns, 0, `${pinnedLeftWidth}px`, true), renderRowsLayer(pinnedLeftRowsLayerRef, `${pinnedLeftWidth}px`)] })), _jsxs("div", { className: "omnigrid-scrollable", style: {
|
|
654
|
+
flex: hasPins ? `1 0 ${scrollableWidth}px` : "1 1 auto",
|
|
655
|
+
minWidth: 0,
|
|
656
|
+
position: "relative",
|
|
657
|
+
width: centralWidth,
|
|
658
|
+
zIndex: 1,
|
|
659
|
+
}, children: [renderHeader(viewportData.columns, pinnedLeftWidth, "100%", false), renderRowsLayer(rowsLayerRef, "100%")] }), hasPinnedRight && (_jsxs("div", { className: "omnigrid-pinned omnigrid-pinned-right", style: {
|
|
660
|
+
height: rowTotalHeight,
|
|
661
|
+
position: "sticky",
|
|
662
|
+
right: 0,
|
|
663
|
+
top: 0,
|
|
664
|
+
width: `${pinnedRightWidth}px`,
|
|
665
|
+
zIndex: 3,
|
|
666
|
+
}, children: [renderHeader(viewportData.pinnedRightColumns, pinnedLeftWidth + scrollableWidth, `${pinnedRightWidth}px`, true), renderRowsLayer(pinnedRightRowsLayerRef, `${pinnedRightWidth}px`)] }))] }), overlayState.type && overlayScope === "bodyOnly" && (
|
|
667
|
+
// Keep the sticky overlay anchored to the body viewport without adding
|
|
668
|
+
// its height to the scrollable content's natural dimensions.
|
|
669
|
+
_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-body", role: "status", style: {
|
|
670
|
+
height: overlayHeight,
|
|
671
|
+
left: 0,
|
|
672
|
+
marginBottom: -overlayHeight,
|
|
673
|
+
marginTop: -rowTotalHeight,
|
|
674
|
+
pointerEvents: "auto",
|
|
675
|
+
position: "sticky",
|
|
676
|
+
right: 0,
|
|
677
|
+
top: headerHeight,
|
|
678
|
+
width: "100%",
|
|
679
|
+
zIndex: 4,
|
|
680
|
+
}, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
|
|
617
681
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export * from "@omnigrid/core";
|
|
|
4
4
|
export { PooledRowPane } from "./pooledRow";
|
|
5
5
|
export type { PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./pooledRow";
|
|
6
6
|
export { OmniGrid } from "./OmniGrid";
|
|
7
|
-
export type { GridProps, SlotRendererRegistry } from "./OmniGrid";
|
|
7
|
+
export type { GridProps, OverlayComponentProps, SlotRendererRegistry } from "./OmniGrid";
|
|
8
8
|
export { useGrid } from "./useGrid";
|
|
9
9
|
export type { UseGridResult } from "./useGrid";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { OverlayState } from "@omnigrid/core";
|
|
3
|
+
export interface OverlayProps {
|
|
4
|
+
/** Active overlay state (type + optional payload). */
|
|
5
|
+
overlay: OverlayState;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Builds the default overlay content for a given overlay state.
|
|
9
|
+
*
|
|
10
|
+
* For `custom` overlays, this returns null — the payload is rendered
|
|
11
|
+
* directly by `OmniGrid.renderOverlayContent` via `contentToReactNode`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderDefaultOverlay(overlay: OverlayState): ReactNode;
|
package/dist/overlays.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
function extractMessage(payload, fallback) {
|
|
3
|
+
if (typeof payload === "string")
|
|
4
|
+
return payload;
|
|
5
|
+
if (payload instanceof Error)
|
|
6
|
+
return payload.message;
|
|
7
|
+
if (payload && typeof payload === "object" && "message" in payload) {
|
|
8
|
+
return String(payload.message);
|
|
9
|
+
}
|
|
10
|
+
return fallback;
|
|
11
|
+
}
|
|
12
|
+
function LoadingOverlay(_payload, message) {
|
|
13
|
+
return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx("div", { className: "omnigrid-overlay-spinner", "aria-label": "Loading" }), _jsx("span", { className: "omnigrid-overlay-text", children: message ?? "Loading…" })] }));
|
|
14
|
+
}
|
|
15
|
+
function NoRowsOverlay(payload, message) {
|
|
16
|
+
return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(NoRowsIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", children: message ?? extractMessage(payload, "No data to display") })] }));
|
|
17
|
+
}
|
|
18
|
+
function NoMatchingRowsOverlay(payload, message) {
|
|
19
|
+
return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(NoMatchingRowsIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", children: message ?? extractMessage(payload, "No matching rows found") })] }));
|
|
20
|
+
}
|
|
21
|
+
function ErrorOverlay(payload, message) {
|
|
22
|
+
return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(ErrorIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", role: "alert", children: message ?? extractMessage(payload, "An error occurred") })] }));
|
|
23
|
+
}
|
|
24
|
+
const DEFAULT_OVERLAYS = {
|
|
25
|
+
loading: LoadingOverlay,
|
|
26
|
+
noRows: NoRowsOverlay,
|
|
27
|
+
noMatchingRows: NoMatchingRowsOverlay,
|
|
28
|
+
error: ErrorOverlay,
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Builds the default overlay content for a given overlay state.
|
|
32
|
+
*
|
|
33
|
+
* For `custom` overlays, this returns null — the payload is rendered
|
|
34
|
+
* directly by `OmniGrid.renderOverlayContent` via `contentToReactNode`.
|
|
35
|
+
*/
|
|
36
|
+
export function renderDefaultOverlay(overlay) {
|
|
37
|
+
const { type, payload, message } = overlay;
|
|
38
|
+
if (!type)
|
|
39
|
+
return null;
|
|
40
|
+
if (type === "custom")
|
|
41
|
+
return null;
|
|
42
|
+
const factory = DEFAULT_OVERLAYS[type];
|
|
43
|
+
if (!factory)
|
|
44
|
+
return null;
|
|
45
|
+
return factory(payload, message);
|
|
46
|
+
}
|
|
47
|
+
/** Inline SVG: empty / document icon. */
|
|
48
|
+
function NoRowsIcon() {
|
|
49
|
+
return (_jsxs("svg", { className: "omnigrid-overlay-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), _jsx("polyline", { points: "14 2 14 8 20 8" }), _jsx("line", { x1: "8", y1: "13", x2: "16", y2: "13" }), _jsx("line", { x1: "8", y1: "17", x2: "16", y2: "17" })] }));
|
|
50
|
+
}
|
|
51
|
+
/** Inline SVG: no results / search icon. */
|
|
52
|
+
function NoMatchingRowsIcon() {
|
|
53
|
+
return (_jsxs("svg", { className: "omnigrid-overlay-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "11", cy: "11", r: "8" }), _jsx("line", { x1: "21", y1: "21", x2: "15.657", y2: "15.657" }), _jsx("circle", { cx: "11", cy: "11", r: "1" }), _jsx("line", { x1: "8", y1: "8", x2: "8.5", y2: "8.5" })] }));
|
|
54
|
+
}
|
|
55
|
+
/** Inline SVG: error / warning icon. */
|
|
56
|
+
function ErrorIcon() {
|
|
57
|
+
return (_jsxs("svg", { className: "omnigrid-overlay-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("line", { x1: "15", y1: "9", x2: "9", y2: "15" }), _jsx("line", { x1: "9", y1: "9", x2: "15", y2: "15" })] }));
|
|
58
|
+
}
|
package/dist/useGrid.js
CHANGED
|
@@ -72,6 +72,19 @@ export function useGrid(options) {
|
|
|
72
72
|
grid.setColumns(options.columns);
|
|
73
73
|
}
|
|
74
74
|
}, [grid, options.columns]);
|
|
75
|
+
// Sync loading state. When `options.loading` is true, show the loading
|
|
76
|
+
// overlay; when false, hide it (auto-overlays like noRows take over).
|
|
77
|
+
const loadingSyncedRef = useRef(false);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (grid.isDestroyed())
|
|
80
|
+
return;
|
|
81
|
+
if (!loadingSyncedRef.current) {
|
|
82
|
+
loadingSyncedRef.current = true;
|
|
83
|
+
grid.setLoading(!!options.loading);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
grid.setLoading(!!options.loading);
|
|
87
|
+
}, [grid, options.loading]);
|
|
75
88
|
return {
|
|
76
89
|
grid,
|
|
77
90
|
state,
|