Blocks / Widget frame

Widget frame

A titled box for a chart: menu, loading, error with retry, empty, and full size in a dialog.

import { WidgetFrame } from "@forgeron/ui";
/01 → Default

Revenue by region

Last 30 days

By region
  • EMEA€84k
  • Americas€61k
  • APAC€33k
Updated 2 minutes ago
import { BarChart, WidgetFrame } from "@forgeron/ui";

export default function Default() {
  return (
    <div style={{ width: "100%", maxWidth: 440, height: 280 }}>
      <WidgetFrame
        title="Revenue by region"
        subtitle="Last 30 days"
        expandable
        menu={[
          { id: "refresh", label: "Refresh" },
          { id: "export", label: "Export CSV" },
          { separator: true },
          { id: "remove", label: "Remove", danger: true },
        ]}
        onMenuSelect={() => {}}
        footer="Updated 2 minutes ago"
      >
        <BarChart
          title="By region"
          highlight="EMEA"
          format={(n) => `€${n}k`}
          data={[
            { label: "EMEA", value: 84 },
            { label: "Americas", value: 61 },
            { label: "APAC", value: 33 },
          ]}
        />
      </WidgetFrame>
    </div>
  );
}
/02 → States

Open tickets

By team

Loading
import { Segmented, WidgetFrame } from "@forgeron/ui";
import { useState } from "react";

type State = "ready" | "loading" | "error" | "empty";

export default function States() {
  const [state, setState] = useState<State>("loading");
  return (
    <div
      style={{ display: "flex", flexDirection: "column", gap: 12, width: "100%", maxWidth: 440 }}
    >
      <Segmented
        label="State"
        value={state}
        onChange={(next) => setState(next as State)}
        options={(["ready", "loading", "error", "empty"] as const).map((s) => ({
          value: s,
          label: s,
        }))}
      />
      <div style={{ height: 220 }}>
        <WidgetFrame
          title="Open tickets"
          subtitle="By team"
          loading={state === "loading"}
          error={state === "error" ? "The ticket service did not answer." : undefined}
          onRetry={() => setState("loading")}
          empty={state === "empty"}
        >
          <p style={{ margin: 0 }}>37 open, 12 waiting for a customer.</p>
        </WidgetFrame>
      </div>
    </div>
  );
}
API → Props
PropTypeDefaultDescription
title / subtitleReactNode—The heading and one line under it.
menu / onMenuSelectActionMenuEntry[] / (id) => void—The rows of the … menu.
expandableboolean—A button opens the content in a dialog. expanded, defaultExpanded and onExpandedChange control it.
loadingboolean—Skeletons in place of the content.
error / onRetryReactNode / () => void—A message and a Retry button. error true gives the default message.
empty / emptyTextboolean / ReactNode—Nothing to show for these filters.
dragHandleReactNode—Before the title: the grip to drag by.
actions / footerReactNode—Controls before the menu; a line under the content.
headingLevel2 | 3 | 43Of the title.
classNamestring—Extra classes.