Blocks / View header

View header

The bar above a list: title, view tabs, then filter, display and the main action.

import { ViewHeader, LayoutSwitch } from "@forgeron/ui";
/01 → Default

Issues

import { PlusSignIcon } from "@forgeron/icons";
import { IconButton, ViewHeader } from "@forgeron/ui";
import { useState } from "react";

export default function Default() {
  const [tab, setTab] = useState("active");
  return (
    <div style={{ width: 320, border: "1px solid var(--line)" }}>
      <ViewHeader
        title="Issues"
        tabs={[
          { value: "all", label: "All issues" },
          { value: "active", label: "Active", count: 12 },
          { value: "backlog", label: "Backlog" },
        ]}
        tab={tab}
        onTabChange={setTab}
        action={<IconButton icon={PlusSignIcon} label="New issue" variant="boxed" size="sm" />}
      />
    </div>
  );
}
/02 → List view
Assignee
List grouped by status, ordered by priority.
import { BarChartIcon, Loading03Icon, PlusSignIcon, UserIcon } from "@forgeron/icons";
import {
  Avatar,
  Button,
  DisplayMenu,
  FilterBar,
  FilterMenu,
  Icon,
  PRIORITY_NAMES,
  PriorityGlyph,
  STATUS_NAMES,
  StatusGlyph,
  ViewHeader,
  type DisplayOptions,
  type Filter,
  type FilterField,
  type PriorityLevel,
  type StatusKind,
} from "@forgeron/ui";
import { useState } from "react";

const people = ["Camille Roy", "Hugo Bernard", "Léa Martin", "Nadia Petit", "Tom Garnier"];

const fields: FilterField[] = [
  {
    id: "status",
    label: "Status",
    icon: Loading03Icon,
    options: (["backlog", "todo", "progress", "review", "done"] as StatusKind[]).map((s) => ({
      value: s,
      label: STATUS_NAMES[s],
      glyph: <StatusGlyph status={s} />,
    })),
  },
  {
    id: "priority",
    label: "Priority",
    icon: BarChartIcon,
    options: ([1, 2, 3, 4, 0] as PriorityLevel[]).map((p) => ({
      value: String(p),
      label: PRIORITY_NAMES[p],
      glyph: <PriorityGlyph level={p} />,
    })),
  },
  {
    id: "assignee",
    label: "Assignee",
    icon: UserIcon,
    options: people.map((p) => ({ value: p, label: p, glyph: <Avatar name={p} size={16} /> })),
  },
];

export default function ListView() {
  const [tab, setTab] = useState("active");
  const [filters, setFilters] = useState<Filter[]>([
    { field: "assignee", operator: "is", values: ["Camille Roy"] },
  ]);
  const [display, setDisplay] = useState<DisplayOptions>({
    layout: "list",
    grouping: "status",
    ordering: "priority",
    toggles: { subIssues: true },
    properties: ["id", "status", "priority", "assignee"],
  });
  return (
    <div style={{ width: "100%", border: "1px solid var(--line)" }}>
      <ViewHeader
        breadcrumb={[{ label: "Operations", href: "#operations" }, { label: "Issues" }]}
        tabs={[
          { value: "all", label: "All issues" },
          { value: "active", label: "Active", count: 8 },
          { value: "backlog", label: "Backlog" },
        ]}
        tab={tab}
        onTabChange={setTab}
        filter={<FilterMenu fields={fields} value={filters} onChange={setFilters} />}
        display={
          <DisplayMenu
            value={display}
            onChange={setDisplay}
            groupings={[
              { value: "status", label: "Status" },
              { value: "assignee", label: "Assignee" },
              { value: "none", label: "No grouping" },
            ]}
            orderings={[
              { value: "priority", label: "Priority" },
              { value: "due", label: "Due date" },
            ]}
            toggles={[{ id: "subIssues", label: "Show sub-issues" }]}
            properties={[
              { id: "id", label: "ID" },
              { id: "status", label: "Status" },
              { id: "priority", label: "Priority" },
              { id: "assignee", label: "Assignee" },
            ]}
          />
        }
        action={
          <Button variant="primary" size="sm" kbd="C">
            <Icon icon={PlusSignIcon} size={12} variant="mono" />
            New issue
          </Button>
        }
      />
      <FilterBar fields={fields} value={filters} onChange={setFilters} />
      <div style={{ padding: 24, color: "var(--ink-muted)" }}>
        {display.layout === "list" ? "List" : "Board"} grouped by {display.grouping}, ordered by{" "}
        {display.ordering}.
      </div>
    </div>
  );
}
/03 → On a phone

My issues

import { Folder01Icon, PlusSignIcon } from "@forgeron/icons";
import {
  DisplayMenu,
  FilterMenu,
  IconButton,
  ViewHeader,
  type DisplayOptions,
  type Filter,
  type FilterField,
} from "@forgeron/ui";
import { useState } from "react";

const fields: FilterField[] = [
  {
    id: "project",
    label: "Project",
    icon: Folder01Icon,
    options: ["Q4 closing", "Supplier portal", "Odoo bridge"].map((p) => ({ value: p, label: p })),
  },
];

export default function OnAPhone() {
  const [tab, setTab] = useState("all");
  const [filters, setFilters] = useState<Filter[]>([]);
  const [display, setDisplay] = useState<DisplayOptions>({
    layout: "list",
    grouping: "status",
    ordering: "priority",
    toggles: {},
    properties: ["id", "status"],
  });
  return (
    <div style={{ width: 360, border: "1px solid var(--line)" }}>
      <ViewHeader
        title="My issues"
        tabs={[
          { value: "all", label: "Assigned", count: 14 },
          { value: "created", label: "Created" },
          { value: "subscribed", label: "Subscribed" },
          { value: "activity", label: "Activity" },
        ]}
        tab={tab}
        onTabChange={setTab}
        filter={<FilterMenu fields={fields} value={filters} onChange={setFilters} />}
        display={
          <DisplayMenu
            value={display}
            onChange={setDisplay}
            groupings={[{ value: "status", label: "Status" }]}
            orderings={[{ value: "priority", label: "Priority" }]}
          />
        }
        action={<IconButton icon={PlusSignIcon} label="New issue" variant="boxed" size="sm" />}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
breadcrumbBreadcrumbItem[]—Where the view sits; takes the place of the title.
titleReactNode—The name of the view.
tabs{ value, label, count?, href? }[][]The views; the count shows on the current tab only. href makes links.
tabstring—The current tab's value.
onTabChange(value: string) => void—Called when a tab without href is chosen.
filterReactNode—The filter button: a FilterMenu.
switcherReactNode—The layouts as icons before the filter: a LayoutSwitch.
displayReactNode—The display button: a DisplayMenu.
actionReactNode—The main action: a primary Button such as New issue, with its kbd.
classNamestring—Extra classes.