Block
Dashboard
A first page for an app: the Sidebar block, a row of Stats, a BarChart and a Table of what happened lately. Feed it numbers; it decides nothing about them.
Made of
Sidebar, Text, Card, Stat, BarChart, Table, TableRow, TableItem, Badge. Nothing else: the block's own CSS is layout, and every value in it is a token.
Use it
import { Dashboard } from 'rost/blocks/dashboard/Dashboard'
<Dashboard
logo={<Logo />} name="Accounts" links={links}
title="November"
tools={<Button>New invoice</Button>}
stats={[{ label: 'Paid this month', value: eur(paid), delta: 'Up 30% on October', tone: 'positive' }]}
chart={{ label: 'Income by month', data: months.map((m) => ({ label: m.short, value: m.income, valueText: eur(m.income) })) }}
recent={{ caption: 'Latest invoices', rows: invoices.map(toRow) }}
/> src/blocks/dashboard/Dashboard.tsx
import type { ReactNode } from 'react'
import { Sidebar, type SidebarLink } from '../sidebar/Sidebar'
import { Text } from '../../components/text/Text'
import { Card } from '../../components/card/Card'
import { Stat } from '../../components/stat/Stat'
import { BarChart } from '../../components/bar-chart/BarChart'
import { Table } from '../../components/table/Table'
import { TableRow } from '../../components/table-row/TableRow'
import { TableItem } from '../../components/table-item/TableItem'
import { Badge } from '../../components/badge/Badge'
import './dashboard.css'
export interface DashboardStat {
readonly label: ReactNode
readonly value: ReactNode
readonly delta?: ReactNode
readonly tone?: 'positive' | 'negative' | 'neutral'
}
export interface DashboardRow {
readonly id: string
readonly href?: string
readonly title: ReactNode
readonly description?: ReactNode
readonly status?: { readonly label: string; readonly tone: 'default' | 'positive' | 'warning' | 'negative' }
readonly amount: ReactNode
}
export interface DashboardProps {
/** The Sidebar block's props: the app's mark, name, links and action. */
readonly logo: ReactNode
readonly name: string
readonly links: readonly SidebarLink[]
readonly action?: ReactNode
readonly title: string
/** Buttons beside the title. */
readonly tools?: ReactNode
/** Up to four figures across the top. */
readonly stats: readonly DashboardStat[]
/** A handful of figures over time, the last one now. */
readonly chart: { readonly label: string; readonly data: readonly { label: string; value: number; valueText?: string }[] }
/** The latest things, with a caption. */
readonly recent: { readonly caption: string; readonly rows: readonly DashboardRow[] }
}
const b = 'rost-block-dashboard'
/**
* A first page for an app: the Sidebar block, a title, a row of Stats, a
* BarChart and a Table of what happened lately. Feed it numbers; it decides
* nothing about them. A Rost block: only Rost's components, and layout from its tokens.
*/
export function Dashboard({ logo, name, links, action, title, tools, stats, chart, recent }: DashboardProps) {
return (
<Sidebar logo={logo} name={name} links={links} action={action}>
<div className={b}>
<div className={`${b}__head`}>
<Text variant="sub-headline" as="h1">{title}</Text>
{tools && <div className={`${b}__tools`}>{tools}</div>}
</div>
<div className={`${b}__stats`}>
{stats.map((s, i) => <Card key={i}><Stat label={s.label} value={s.value} delta={s.delta} tone={s.tone} /></Card>)}
</div>
<div className={`${b}__body`}>
<Card as="section" className={`${b}__chart`} aria-label={chart.label}>
<Text variant="label" tone="secondary" as="h2">{chart.label}</Text>
<BarChart label={chart.label} data={chart.data} current={chart.data.length - 1} />
</Card>
<Card as="section" className={`${b}__recent`}>
<Table caption={recent.caption}>
{recent.rows.map((r) => (
<TableRow key={r.id} href={r.href}>
<TableItem header="row" description={r.description} trailing={r.status && <Badge status={r.status.tone}>{r.status.label}</Badge>}>{r.title}</TableItem>
<TableItem numeric>{r.amount}</TableItem>
</TableRow>
))}
</Table>
</Card>
</div>
</div>
</Sidebar>
)
}
Install
npx github:Runceanu/rost add dashboard It lands in src/rost/dashboard/, with every component it's made of. It's yours from there: change it as much as the app needs. Install has the rest.