Widget grid
Widgets on 12 columns. In edit mode: drag, resize, arrows. One column when narrow.
import { WidgetGrid, dashboardPlace, dashboardSync, dashboardNextSlot } from "@forgeron/ui";This month
- Revenue
- €48.2k
- up +12.4%
- Leads
- 212
- down −6%
Quota
36of 50 · 72%Close
- Behindunder 35
- Close35 to 50
- On target50 and over
Pipeline
- Lead480
- Qualified21244%
- Won3818%
Overall 7.9% of Lead reach Won
| Stage | Count | Of the first stage | Of the stage before |
|---|---|---|---|
| Lead | 480 | 100% | |
| Qualified | 212 | 44% | 44% |
| Won | 38 | 8% | 18% |
Sources
100Total
| Slice | Value | Share |
|---|---|---|
| Web | 60 | 60% |
| Referral | 30 | 30% |
| Events | 10 | 10% |
import { Donut, Funnel, Gauge, KpiRow, WidgetFrame, WidgetGrid } from "@forgeron/ui";
const widgets = [
{
id: "kpi",
label: "Key figures",
content: (
<WidgetFrame title="This month">
<KpiRow
items={[
{ label: "Revenue", value: "€48.2k", delta: 0.124 },
{ label: "Leads", value: "212", delta: -0.06 },
]}
/>
</WidgetFrame>
),
},
{
id: "quota",
label: "Quota",
content: (
<WidgetFrame title="Quota">
<Gauge title="Quarter" value={36} target={50} size={160} />
</WidgetFrame>
),
},
{
id: "funnel",
label: "Funnel",
content: (
<WidgetFrame title="Pipeline">
<Funnel
title="Deals"
items={[
{ label: "Lead", value: 480 },
{ label: "Qualified", value: 212 },
{ label: "Won", value: 38 },
]}
/>
</WidgetFrame>
),
},
{
id: "sources",
label: "Sources",
content: (
<WidgetFrame title="Sources">
<Donut
title="Leads"
size={120}
items={[
{ label: "Web", value: 60 },
{ label: "Referral", value: 30 },
{ label: "Events", value: 10 },
]}
/>
</WidgetFrame>
),
},
];
export default function Default() {
return (
<div style={{ width: "100%" }}>
<WidgetGrid
widgets={widgets}
rowHeight={120}
defaultLayout={[
{ id: "kpi", x: 0, y: 0, w: 8, h: 2 },
{ id: "quota", x: 8, y: 0, w: 4, h: 3 },
{ id: "funnel", x: 0, y: 2, w: 4, h: 4 },
{ id: "sources", x: 4, y: 2, w: 4, h: 4 },
]}
/>
</div>
);
}Quota
36of 50 · 72%Close
- Behindunder 35
- Close35 to 50
- On target50 and over
Channel mix
- Sales70
- Support110
| Bar | Chat | Total | |
|---|---|---|---|
| Sales | 40 | 30 | 70 |
| Support | 20 | 90 | 110 |
[{"id":"quota","x":0,"y":0,"w":4,"h":3},{"id":"mix","x":4,"y":0,"w":8,"h":3}]// Edit mode: drag a widget by its body, its corner to resize; arrows move, Shift and arrows resize.
// The layout is plain data: this page prints it.
import {
Button,
Gauge,
Heatmap,
StackedBar,
WidgetFrame,
WidgetGrid,
type WidgetLayout,
} from "@forgeron/ui";
import { useState, type ReactNode } from "react";
const catalog: Record<string, { label: string; render: () => ReactNode }> = {
quota: {
label: "Quota",
render: () => <Gauge title="Quarter" value={36} target={50} size={160} />,
},
mix: {
label: "Channel mix",
render: () => (
<StackedBar
title="Channels"
normalize
series={[
{ key: "mail", label: "Mail" },
{ key: "chat", label: "Chat" },
]}
items={[
{ label: "Sales", values: { mail: 40, chat: 30 } },
{ label: "Support", values: { mail: 20, chat: 90 } },
]}
/>
),
},
heat: {
label: "Activity",
render: () => (
<Heatmap
title="Activity"
rows={["Sales", "Ops"]}
columns={["Mon", "Tue", "Wed", "Thu", "Fri"]}
values={[
[4, 9, 12, 7, 3],
[1, 3, 5, 8, 6],
]}
/>
),
},
};
export default function Editable() {
const [editing, setEditing] = useState(true);
const [ids, setIds] = useState(["quota", "mix"]);
const [layout, setLayout] = useState<WidgetLayout[]>([
{ id: "quota", x: 0, y: 0, w: 4, h: 3 },
{ id: "mix", x: 4, y: 0, w: 8, h: 3 },
]);
const missing = Object.keys(catalog).filter((id) => !ids.includes(id));
return (
<div style={{ display: "flex", flexDirection: "column", gap: 12, width: "100%" }}>
<div>
<Button size="sm" onClick={() => setEditing((e) => !e)}>
{editing ? "Done" : "Edit layout"}
</Button>
</div>
<WidgetGrid
editing={editing}
rowHeight={110}
layout={layout}
onLayoutChange={setLayout}
widgets={ids.map((id) => ({
id,
label: catalog[id]!.label,
minW: 3,
minH: 2,
content: <WidgetFrame title={catalog[id]!.label}>{catalog[id]!.render()}</WidgetFrame>,
}))}
onRemoveWidget={(id) => setIds((now) => now.filter((x) => x !== id))}
onAddWidget={missing.length ? () => setIds((now) => [...now, missing[0]!]) : undefined}
/>
<pre
style={{
margin: 0,
whiteSpace: "pre-wrap",
wordBreak: "break-all",
font: "11.5px/18px var(--font-mono)",
color: "var(--ink-muted)",
}}
>
{JSON.stringify(layout)}
</pre>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
widgets | { id, label, content, locked?, minW?, minH?, maxW?, maxH? }[] | — | What the grid shows; label names it in the edit controls. |
layout / defaultLayout / onLayoutChange | { id, x, y, w, h }[] | — | Where each widget sits, in cells. Plain data: save it. A widget without a place takes the first free slot. |
editing / defaultEditing / onEditingChange | boolean | false | Edit mode. Drag by the body, resize by the corner; arrows move, Shift and arrows resize, Delete removes. |
columns | number | 12 | Columns of the grid. |
rowHeight / gap | number | 96 / 12 | In px. |
collapseBelow | number | 640 | Under this width the grid is one column, in reading order. |
onRemoveWidget | (id) => void | — | Shows a remove button on each widget in edit mode. The page drops the widget. |
onAddWidget / addLabel | () => void / string | — | Shows the add button above the grid in edit mode. |
label | string | "Dashboard" | Names the region. |
empty | ReactNode | — | Shown when there is no widget. |
className | string | — | Extra classes. |