Pages
Dashboard page
A product dashboard: a side rail, the title and one White button, four figures on cards and the latest rows in a hairline table.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add dashboard-page<script type="module" src="/spyglass-ds/elements/dashboard-page.js"></script>Overview
New search- 1,284Searches this month
- 3,716Credits left
- 42Brands tracked
- 96Alerts sent
Recent searches
| Search | Results | When |
|---|---|---|
| Running shoes, longest-running ads | 128 | Today |
| Skincare UGC, before and after | 64 | Yesterday |
| Energy drinks on TikTok | 212 | Monday |
Usage
The overview screen of the product; data comes through content.
Never
- New colors, shadows or type sizes added to a section: use the items' props
- More than one White button in a view
- Real people or customers in the copy: Acme only
sections lists the sections to show, in order (head, stats, table); a key left out is not shown.
Adds with it: button, creative-card, logo
Props
The web component takes the same as attributes or properties (<spyglass-dashboard-page>); title is heading there.
<DashboardPage>
| Prop | Type | Default |
|---|---|---|
content | DashboardContent | |
sections | readonly DashboardSection[] The sections to show, in order; all of them in the page order by default (leave one out to omit it). | |
className | string |
Examples
The same example in React and as web components; both render identically.
import { DashboardPage } from '@/react/components/pages/DashboardPage'
// The dashboard page with its own copy (Acme).
export default function Page() {
return <DashboardPage />
}<!-- The dashboard page with its own copy (Acme). -->
<spyglass-dashboard-page></spyglass-dashboard-page>Source
import { Button } from '@/react/components/ui/Button'
import { Logo } from '@/react/components/visuals/Logo'
import { dashboardContent, type DashboardContent, dashboardSections, type DashboardSection } from '@/lib/pages/dashboard'
import { cn } from '@/react/lib/cn'
import { pageSections } from '@/lib/image'
import { Fragment, type ReactNode } from 'react'
// A product dashboard in the site's look: a side rail on #1A1A1A with the lockup and the sections (14/20 links that fill
// #262626 under the pointer, the current one White on it), and the main area on Black with the title and the one White
// button, four figures on #262626 cards (Funnel Display 40/44 over a #A3A3A3 label), and the latest rows in a hairline
// table on a card. The rail sits on top on phones. Data comes through `content`.
export interface DashboardPageProps {
content?: DashboardContent
/** The sections to show, in order; all of them in the page order by default (leave one out to omit it). */
sections?: readonly DashboardSection[]
className?: string
}
const LINK = 'flex h-control-xs items-center rounded-control px-3 type-ui text-fg-soft transition-[color,background-color] duration-160 ease-out hover:bg-surface-raised hover:text-fg aria-[current=page]:bg-surface-raised aria-[current=page]:text-fg'
export function DashboardPage({ content: c = dashboardContent, sections, className }: DashboardPageProps) {
const parts: Record<DashboardSection, ReactNode> = {
head: (
<div className="flex flex-wrap items-center justify-between gap-4">
<h1 className="type-heading-2">{c.title}</h1>
<Button href={c.action.href}>{c.action.label}</Button>
</div>
),
stats: (
<ul role="list" className="m-0 grid list-none grid-cols-1 gap-4 p-0 sm:grid-cols-2 xl:grid-cols-4">
{c.stats.map((s) => (
<li key={s.label} className="grid gap-2 rounded-container bg-surface-raised p-6">
<span className="type-figure">{s.value}</span>
<span className="type-ui text-fg-muted">{s.label}</span>
</li>
))}
</ul>
),
table: (
<section className="grid gap-4 rounded-container bg-surface-raised p-6">
<h2 className="type-heading-3">{c.tableTitle}</h2>
<div className="overflow-x-auto fade-x">
<table className="w-full border-collapse type-ui">
<thead>
<tr>{c.columns.map((col, i) => <th key={col} className={cn('border-b border-edge-surface py-2.5 type-label font-medium text-fg-muted', i === 0 ? 'text-left' : 'text-right')}>{col}</th>)}</tr>
</thead>
<tbody>
{c.rows.map((r) => <tr key={r[0]}>{r.map((cell, i) => <td key={i} className={cn('border-b border-edge-surface py-3', i === 0 ? 'text-left text-fg' : 'text-right tabular-nums text-fg-soft')}>{cell}</td>)}</tr>)}
</tbody>
</table>
</div>
</section>
),
}
return (
<div data-ds="dashboard-page" className={cn('grid min-h-dvh grid-cols-[minmax(0,1fr)] bg-surface text-fg lg:grid-cols-[256px_minmax(0,1fr)]', className)}>
<aside className="flex min-w-0 flex-col gap-6 border-b border-edge bg-surface-subtle p-4 lg:border-r lg:border-b-0">
<a href="/" aria-label="Home" className="self-start rounded-control px-2 py-2"><Logo height={20} /></a>
<nav aria-label="Sections">
<ul role="list" className="m-0 flex list-none gap-1 overflow-x-auto p-0 fade-x lg:flex-col">
{c.nav.map((n) => <li key={n.href} className="shrink-0"><a href={n.href} aria-current={n.current ? 'page' : undefined} className={LINK}>{n.label}</a></li>)}
</ul>
</nav>
</aside>
<main className="grid min-w-0 content-start gap-8 p-6 lg:p-10">
{pageSections(dashboardSections, sections).map((k) => <Fragment key={k}>{parts[k]}</Fragment>)}
</main>
</div>
)
}
export default DashboardPage// The dashboard's sample data for Acme: the nav, four figures and the latest rows. Both flavors read this file; an app
// passes its own through `content`.
export const dashboardContent = {
nav: [
{ label: 'Overview', href: '#overview', current: true },
{ label: 'Search', href: '#search' },
{ label: 'Boards', href: '#boards' },
{ label: 'Alerts', href: '#alerts' },
{ label: 'Settings', href: '#settings' },
],
title: 'Overview',
action: { label: 'New search', href: '#search' },
stats: [
{ label: 'Searches this month', value: '1,284' },
{ label: 'Credits left', value: '3,716' },
{ label: 'Brands tracked', value: '42' },
{ label: 'Alerts sent', value: '96' },
],
tableTitle: 'Recent searches',
columns: ['Search', 'Results', 'When'],
rows: [
['Running shoes, longest-running ads', '128', 'Today'],
['Skincare UGC, before and after', '64', 'Yesterday'],
['Energy drinks on TikTok', '212', 'Monday'],
],
}
export type DashboardContent = typeof dashboardContent
/** The dashboard's sections in order; pass `sections` to reorder them or leave some out. */
export const dashboardSections = ['head', 'stats', 'table'] as const
export type DashboardSection = (typeof dashboardSections)[number]// Joins class names, skipping falsy ones: cn('a', on && 'b', ['c', undefined]). It does not merge conflicting
// utilities (no tailwind-merge), as Vue's class binding does not: the library's classes are written not to compete,
// and a className from the caller is appended after them, as Vue appends a fallthrough class.
export type ClassValue = string | false | null | undefined | 0 | ClassValue[]
export function cn(...values: ClassValue[]): string {
const out: string[] = []
for (const v of values) {
if (!v) continue
if (Array.isArray(v)) {
const s = cn(...v)
if (s) out.push(s)
}
else out.push(v)
}
return out.join(' ')
}import { html } from 'lit'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { dashboardContent, type DashboardContent, dashboardSections, type DashboardSection } from '@/lib/pages/dashboard'
import { ifDefined } from 'lit/directives/if-defined.js'
import '@/elements/components/ui/button'
import '@/elements/components/visuals/logo'
import styles from 'virtual:tw'
import { pageSections } from '@/lib/image'
// DashboardPage.tsx as <spyglass-dashboard-page>: the side rail, the title and button, four figures and the latest
// rows. `content` replaces the data.
const LINK = 'flex h-control-xs items-center rounded-control px-3 type-ui text-fg-soft transition-[color,background-color] duration-160 ease-out hover:bg-surface-raised hover:text-fg aria-[current=page]:bg-surface-raised aria-[current=page]:text-fg'
/**
* @summary A product dashboard: a rail, figures and a table.
*/
export class DashboardPage extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="dashboard-page"]'))
static properties = { content: { type: Object }, sections: { type: Array } }
/** The data (lib/pages/dashboard.ts by default). */
content: DashboardContent = dashboardContent
/** The sections to show, in order (a list of names); all of them in the page order by default. */
sections?: DashboardSection[]
render() {
const c = this.content ?? dashboardContent
const parts: Record<DashboardSection, unknown> = {
head: html`<div class="flex flex-wrap items-center justify-between gap-4"><h1 class="type-heading-2">${c.title}</h1><spyglass-button href=${c.action.href}>${c.action.label}</spyglass-button></div>`,
stats: html`<ul role="list" class="m-0 grid list-none grid-cols-1 gap-4 p-0 sm:grid-cols-2 xl:grid-cols-4">${c.stats.map((s) => html`<li class="grid gap-2 rounded-container bg-surface-raised p-6"><span class="type-figure">${s.value}</span><span class="type-ui text-fg-muted">${s.label}</span></li>`)}</ul>`,
table: html`<section class="grid gap-4 rounded-container bg-surface-raised p-6"><h2 class="type-heading-3">${c.tableTitle}</h2><div class="overflow-x-auto fade-x"><table class="w-full border-collapse type-ui"><thead><tr>${c.columns.map((col, i) => html`<th class=${i === 0 ? 'border-b border-edge-surface py-2.5 type-label font-medium text-fg-muted text-left' : 'border-b border-edge-surface py-2.5 type-label font-medium text-fg-muted text-right'}>${col}</th>`)}</tr></thead><tbody>${c.rows.map((r) => html`<tr>${r.map((cell, i) => html`<td class=${i === 0 ? 'border-b border-edge-surface py-3 text-left text-fg' : 'border-b border-edge-surface py-3 text-right tabular-nums text-fg-soft'}>${cell}</td>`)}</tr>`)}</tbody></table></div></section>`,
}
return html`<div data-ds="dashboard-page" class="grid min-h-dvh grid-cols-[minmax(0,1fr)] bg-surface text-fg lg:grid-cols-[256px_minmax(0,1fr)]"><aside class="flex min-w-0 flex-col gap-6 border-b border-edge bg-surface-subtle p-4 lg:border-r lg:border-b-0"><a href="/" aria-label="Home" class="self-start rounded-control px-2 py-2"><spyglass-logo height="20"></spyglass-logo></a><nav aria-label="Sections"><ul role="list" class="m-0 flex list-none gap-1 overflow-x-auto p-0 fade-x lg:flex-col">${c.nav.map((n) => html`<li class="shrink-0"><a href=${n.href} aria-current=${ifDefined(n.current ? 'page' : undefined)} class=${LINK}>${n.label}</a></li>`)}</ul></nav></aside><main class="grid min-w-0 content-start gap-8 p-6 lg:p-10">${pageSections(dashboardSections, this.sections).map((k) => parts[k])}</main></div>`
}
}
define('dashboard-page', DashboardPage)Reference: Built from the library and the site's surfaces (cards on --surface, the rail on --raised, hairlines, the 36px links of the header).