Skip to content

Tutorial: a sales dashboard

In this tutorial you build a sales dashboard: three figures in cards, a line chart with a range switch, and a table of recent orders. Each step says what Hozo turned the code into, so by the end you know what the build does with the primitives, Tailwind classes and components you write.

Every step’s code is built in CI exactly as written, one step at a time, from packed packages. You need Node.js 20.19 or newer, which is what Vite 8 needs.

The starter is the project from the Vite guide: Vite, React, and Hozo’s plugin, already set up.

sh
npx degit iray-tno/hozo/templates/vite dashboardcd dashboardnpm installnpm run dev

Open the address npm run dev prints. You should see “Hello, Hozo” and a button that counts. To skip installing anything, open the starter in StackBlitz instead and follow along there.

Two files did the setup. vite.config.ts adds hozo() before react(), and src/theme.css is the stylesheet that holds the design tokens. The Vite guide explains both.

@hozo/ui has the components a dashboard is made of: cards, stacks, badges, a segmented control. Install it:

sh
npm install @hozo/ui

Its components use their own design tokens (bg-hozo-surface, text-hozo-text and the like). Import them into the theme, next to the starter’s own:

src/theme.css
@import "tailwindcss";@import "@hozo/ui/theme.css";@theme {  --color-brand: oklch(62% 0.19 258);}

The tokens follow the system’s light or dark setting.

The data is static, so the page has something to show without a backend:

src/data.ts
// Static data: this tutorial is about the screen, not a backend.// A `type`, not an `interface`: a chart takes `Record<string, unknown>` rows,// and only a type alias is assignable to one.export type Month = { month: string; online: number; store: number }export const REVENUE: readonly Month[] = [  { month: 'Jul', online: 58_400, store: 35_200 },  { month: 'Aug', online: 61_900, store: 33_800 },  { month: 'Sep', online: 64_200, store: 37_600 },  { month: 'Oct', online: 69_700, store: 39_100 },  { month: 'Nov', online: 78_300, store: 44_500 },  { month: 'Dec', online: 91_600, store: 52_300 },]export type Status = 'Paid' | 'Shipped' | 'Refunded'export interface Order {  id: string  customer: string  total: number  status: Status}export const ORDERS: readonly Order[] = [  { id: '#1048', customer: 'Aiko Tanaka', total: 64, status: 'Paid' },  { id: '#1047', customer: 'Marcus Lee', total: 45, status: 'Shipped' },  { id: '#1046', customer: 'Sofia Rossi', total: 54, status: 'Shipped' },  { id: '#1045', customer: 'Noah Martin', total: 56, status: 'Refunded' },]export const money = (value: number) =>  new Intl.NumberFormat('en-US', {    style: 'currency',    currency: 'USD',    maximumFractionDigits: 0,  }).format(value)

Now replace the starter’s counter with a header and the three figures:

src/App.tsx
import { Header, Heading, Main, Section, Text, View } from '@hozo/core'import { Card, Stack } from '@hozo/ui'import { money, ORDERS, REVENUE } from './data.ts'export default function App() {  const revenue = REVENUE.reduce((sum, month) => sum + month.online + month.store, 0)  const online = REVENUE.reduce((sum, month) => sum + month.online, 0)  const figures = [    { label: 'Revenue', value: money(revenue) },    { label: 'Online share', value: `${Math.round((online / revenue) * 100)}%` },    { label: 'Orders this week', value: String(ORDERS.length) },  ]  return (    <View className="min-h-screen bg-hozo-surface-sunken">      <Header className="border-b border-hozo-border bg-hozo-surface px-6 py-4">        <Heading level={1} className="text-2xl font-bold text-hozo-text">          Sales overview        </Heading>      </Header>      <Main className="mx-auto flex max-w-5xl flex-col gap-6 p-6">        <Section accessibilityLabel="Key figures" className="grid grid-cols-1 gap-4 sm:grid-cols-3">          {figures.map((figure) => (            <Card key={figure.label}>              <Stack gap="tight">                <Text className="text-sm text-hozo-text-muted">{figure.label}</Text>                <Text className="text-2xl font-bold text-hozo-text">{figure.value}</Text>              </Stack>            </Card>          ))}        </Section>      </Main>    </View>  )}

In the browser, the page is a list of figures in cards. Open the developer tools and look at the elements:

  • Header is a <header>, Main a <main>, and Heading level={1} an <h1>. A screen reader can jump to each.
  • Section with an accessibilityLabel is a <section aria-label="Key figures">, a region landmark with a name.
  • The classes on the primitives became plain CSS classes, generated by the build. There is no style runtime.

You wrote React Native’s vocabulary (View, Text), not HTML tags. That is what lets the same component compile to React Native for iOS and Android.

sh
npm install @hozo/charts

The chart gets its own file, with its own state: which range it shows.

src/RevenueChart.tsx
import { LineChart } from '@hozo/charts'import { Heading, View } from '@hozo/core'import { Card, SegmentedControl, Stack } from '@hozo/ui'import { useState } from 'react'import { money, REVENUE } from './data.ts'const RANGES = [  { value: '3', label: '3 months' },  { value: '6', label: '6 months' },]export function RevenueChart() {  const [range, setRange] = useState('6')  const months = REVENUE.slice(-Number(range))  return (    <Card>      <Stack gap="normal">        <View className="flex flex-row flex-wrap items-center justify-between gap-2">          <Heading level={2} className="text-lg font-semibold text-hozo-text">            Revenue by month          </Heading>          <SegmentedControl            options={RANGES}            accessibilityLabel="Range"            value={range}            onValueChange={setRange}          />        </View>        <LineChart          accessibilityLabel="Revenue by month, online and in store"          data={months}          x={{ key: 'month', label: 'Month' }}          y={{ label: 'Revenue', format: money }}          series={[            { key: 'online', label: 'Online' },            { key: 'store', label: 'In store' },          ]}          height={260}          points        />      </Stack>    </Card>  )}

Add it below the figures:

src/App.tsx
import { Header, Heading, Main, Section, Text, View } from '@hozo/core'import { Card, Stack } from '@hozo/ui'import { money, ORDERS, REVENUE } from './data.ts'import { RevenueChart } from './RevenueChart.tsx'export default function App() {  const revenue = REVENUE.reduce((sum, month) => sum + month.online + month.store, 0)  const online = REVENUE.reduce((sum, month) => sum + month.online, 0)  const figures = [    { label: 'Revenue', value: money(revenue) },    { label: 'Online share', value: `${Math.round((online / revenue) * 100)}%` },    { label: 'Orders this week', value: String(ORDERS.length) },  ]  return (    <View className="min-h-screen bg-hozo-surface-sunken">      <Header className="border-b border-hozo-border bg-hozo-surface px-6 py-4">        <Heading level={1} className="text-2xl font-bold text-hozo-text">          Sales overview        </Heading>      </Header>      <Main className="mx-auto flex max-w-5xl flex-col gap-6 p-6">        <Section accessibilityLabel="Key figures" className="grid grid-cols-1 gap-4 sm:grid-cols-3">          {figures.map((figure) => (            <Card key={figure.label}>              <Stack gap="tight">                <Text className="text-sm text-hozo-text-muted">{figure.label}</Text>                <Text className="text-2xl font-bold text-hozo-text">{figure.value}</Text>              </Stack>            </Card>          ))}        </Section>        <RevenueChart />      </Main>    </View>  )}

Switch the range between three and six months, and the chart redraws.

  • The chart is SVG. Its accessibilityLabel names it, and the same numbers are also in a <table>, so a screen reader user hears each month’s values, formatted with money, rather than the shape of a line.
  • SegmentedControl is a radiogroup named “Range”. The arrow keys move between its options.
src/RecentOrders.tsx
import {  Heading,  Table,  TableBody,  TableCell,  TableHead,  TableHeader,  TableRow,  View,} from '@hozo/core'import { Badge, Card, Stack } from '@hozo/ui'import { money, ORDERS } from './data.ts'const TONE = { Paid: 'accent', Shipped: 'neutral', Refunded: 'danger' } as constconst head =  'border-b border-hozo-border px-3 py-2 text-left text-xs font-semibold uppercase text-hozo-text-muted'const cell = 'border-b border-hozo-border-subtle px-3 py-2 text-left text-sm text-hozo-text-body'export function RecentOrders() {  return (    <Card>      <Stack gap="normal">        <Heading level={2} className="text-lg font-semibold text-hozo-text">          Recent orders        </Heading>        {/* On a phone the table scrolls inside its card, not the whole page. */}        <View className="overflow-x-auto">          <Table accessibilityLabel="Recent orders" className="w-full border-collapse">            <TableHeader>              <TableRow>                <TableHead scope="col" className={head}>                  Order                </TableHead>                <TableHead scope="col" className={head}>                  Customer                </TableHead>                <TableHead scope="col" className={head}>                  Total                </TableHead>                <TableHead scope="col" className={head}>                  Status                </TableHead>              </TableRow>            </TableHeader>            <TableBody>              {ORDERS.map((order) => (                <TableRow key={order.id}>                  <TableCell className={cell}>{order.id}</TableCell>                  <TableCell className={cell}>{order.customer}</TableCell>                  <TableCell className={cell}>{money(order.total)}</TableCell>                  <TableCell className={cell}>                    <Badge tone={TONE[order.status]}>{order.status}</Badge>                  </TableCell>                </TableRow>              ))}            </TableBody>          </Table>        </View>      </Stack>    </Card>  )}

And add it below the chart:

src/App.tsx
import { Header, Heading, Main, Section, Text, View } from '@hozo/core'import { Card, Stack } from '@hozo/ui'import { money, ORDERS, REVENUE } from './data.ts'import { RecentOrders } from './RecentOrders.tsx'import { RevenueChart } from './RevenueChart.tsx'export default function App() {  const revenue = REVENUE.reduce((sum, month) => sum + month.online + month.store, 0)  const online = REVENUE.reduce((sum, month) => sum + month.online, 0)  const figures = [    { label: 'Revenue', value: money(revenue) },    { label: 'Online share', value: `${Math.round((online / revenue) * 100)}%` },    { label: 'Orders this week', value: String(ORDERS.length) },  ]  return (    <View className="min-h-screen bg-hozo-surface-sunken">      <Header className="border-b border-hozo-border bg-hozo-surface px-6 py-4">        <Heading level={1} className="text-2xl font-bold text-hozo-text">          Sales overview        </Heading>      </Header>      <Main className="mx-auto flex max-w-5xl flex-col gap-6 p-6">        <Section accessibilityLabel="Key figures" className="grid grid-cols-1 gap-4 sm:grid-cols-3">          {figures.map((figure) => (            <Card key={figure.label}>              <Stack gap="tight">                <Text className="text-sm text-hozo-text-muted">{figure.label}</Text>                <Text className="text-2xl font-bold text-hozo-text">{figure.value}</Text>              </Stack>            </Card>          ))}        </Section>        <RevenueChart />        <RecentOrders />      </Main>    </View>  )}

Table, TableHead and TableCell are a <table> with real <th scope="col"> headers, so a screen reader announces “Customer” when you move along a row. On React Native the same components give the rows and cells table semantics.

sh
npm run build

dist/ now holds the page, ready for any static host: HTML, one stylesheet and the JavaScript. npm run preview serves it to check.