@vertly/dashboard-grid 0.1.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/README.md +72 -0
- package/dist/index.cjs +732 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +691 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @vertly/dashboard-grid
|
|
2
|
+
|
|
3
|
+
A fluid, drag-and-drop dashboard grid component for React, with its
|
|
4
|
+
row/column layout math included. Widgets live in rows, can be reordered,
|
|
5
|
+
dragged between rows, resized against their row neighbor, and rows
|
|
6
|
+
themselves can be reordered and resized. Built on
|
|
7
|
+
[`react-dnd`](https://react-dnd.github.io/react-dnd/).
|
|
8
|
+
|
|
9
|
+
This package renders layout only — it has no opinion on what a widget's
|
|
10
|
+
content is, how it's persisted, or what your "add widget" / "configure
|
|
11
|
+
widget" flows look like. You supply those via callbacks and render props.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { DashboardGrid, type DashboardGridWidgetData, type RowLike } from '@vertly/dashboard-grid';
|
|
17
|
+
|
|
18
|
+
interface MyWidget extends DashboardGridWidgetData {
|
|
19
|
+
title: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function MyDashboard({ rows, widgets }: { rows: RowLike[]; widgets: Record<string, MyWidget> }) {
|
|
23
|
+
return (
|
|
24
|
+
<DashboardGrid<MyWidget>
|
|
25
|
+
rows={rows}
|
|
26
|
+
widgets={widgets}
|
|
27
|
+
onUpdateLayout={(rows, colSpans) => saveLayout(rows, colSpans)}
|
|
28
|
+
onDeleteWidget={(widgetId) => deleteWidget(widgetId)}
|
|
29
|
+
renderRowEdgeAdd={({ rowId, edge }) => <AddWidgetButton rowId={rowId} edge={edge} />}
|
|
30
|
+
renderWidgetMenu={(widget, { onConfigure, onDelete }) => (
|
|
31
|
+
<WidgetMenu onConfigure={onConfigure} onDelete={onDelete} />
|
|
32
|
+
)}
|
|
33
|
+
renderWidgetConfigDialog={({ widget, open, onOpenChange }) => (
|
|
34
|
+
<WidgetConfigDialog widget={widget} open={open} onOpenChange={onOpenChange} />
|
|
35
|
+
)}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Each widget's `content` (a `ReactNode`) is rendered as-is — render it
|
|
42
|
+
yourself (e.g. server-side, or in a parent Server Component) and pass the
|
|
43
|
+
result down, rather than having this component fetch or render widget data
|
|
44
|
+
itself.
|
|
45
|
+
|
|
46
|
+
## Layout math
|
|
47
|
+
|
|
48
|
+
The row/column layout functions the component is built on
|
|
49
|
+
(`placeItemAt`, `placeItemInNewRow`, `removeItemFromRow`, `resizeItemPair`,
|
|
50
|
+
`resizeRow`, `moveRow`, `rebalanceRow`, `canPlaceInRow`, and the `RowLike`/
|
|
51
|
+
`SizedItem` types and `COLS`/`ZONE_WIDTH_PX`/etc. constants) are also
|
|
52
|
+
exported directly, in case you want to drive the same layout model without
|
|
53
|
+
this component — e.g. computing/validating a layout server-side. They're
|
|
54
|
+
plain functions with no React or DOM dependency.
|
|
55
|
+
|
|
56
|
+
## Peer dependencies
|
|
57
|
+
|
|
58
|
+
`react`, `react-dom`, `react-dnd`, `react-dnd-html5-backend`, `lucide-react`.
|
|
59
|
+
|
|
60
|
+
## Styling
|
|
61
|
+
|
|
62
|
+
Ships with a small set of Tailwind utility classNames (using shadcn-style
|
|
63
|
+
CSS variable tokens like `border-border`, `bg-muted`, `text-primary`).
|
|
64
|
+
Bring a Tailwind v4 setup with those tokens defined, or override the
|
|
65
|
+
relevant selectors in your own global CSS.
|
|
66
|
+
|
|
67
|
+
## Props
|
|
68
|
+
|
|
69
|
+
See `DashboardGridProps` in the package's type definitions for the full
|
|
70
|
+
list: `rows`, `widgets`, `readOnly`, `saveDebounceMs`, `onUpdateLayout`,
|
|
71
|
+
`onDeleteWidget`, `renderRowEdgeAdd`, `renderWidgetMenu`,
|
|
72
|
+
`renderWidgetConfigDialog`.
|