Blocks
Stat block
Numbers that say what the product does: Funnel Display figures over a line of DM Sans each, under a hairline or on the #262626 fill, four across.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add stat-block<script type="module" src="/spyglass-ds/elements/stat-block.js"></script>Every creative in one place.
- Networks in one index: Meta, TikTok, Instagram and YouTube.
- 4
- To add any brand or creator.
- 1 min
- Team seats on the Creator plan.
- Unlimited
- For your first month, then $20/month.
- $10
- Brands tracked
- 128
- Boards shared
- 42
- Alerts this week
- 9
- Seats in use
- 12
Usage
A section of facts on a home, product or about page. Every figure is true and checkable.
Never
- Invented, rounded-up or unsourced numbers
- Colored figures or icons beside them
- More than four numbers in a row
Props
The web component takes the same as attributes or properties (<spyglass-stat-block>); title is heading there.
<StatBlock>
| Prop | Type | Default |
|---|---|---|
stats | Stat[] | |
title | ReactNode A heading above the numbers. | |
variant | 'rule' | 'card' rule (a hairline above each) or card (the #262626 fill). | 'rule' |
className | string |
Examples
The same example in React and as web components; both render identically.
import { StatBlock } from '@/react/components/blocks/StatBlock'
// The figures the assets state, each under a hairline.
const stats = [
{ value: '4', label: 'Networks in one index: Meta, TikTok, Instagram and YouTube.' },
{ value: '1 min', label: 'To add any brand or creator.' },
{ value: 'Unlimited', label: 'Team seats on the Creator plan.' },
{ value: '$10', label: 'For your first month, then $20/month.' },
]
export default function Rule() {
return <StatBlock title="Every creative in one place." stats={stats} />
}<!-- The figures the assets state, each under a hairline. -->
<spyglass-stat-block heading="Every creative in one place." stats='[{"value":"4","label":"Networks in one index: Meta, TikTok, Instagram and YouTube."},{"value":"1 min","label":"To add any brand or creator."},{"value":"Unlimited","label":"Team seats on the Creator plan."},{"value":"$10","label":"For your first month, then $20/month."}]'></spyglass-stat-block>import { StatBlock } from '@/react/components/blocks/StatBlock'
// An Acme team's numbers, on the card fill.
const stats = [
{ value: '128', label: 'Brands tracked' },
{ value: '42', label: 'Boards shared' },
{ value: '9', label: 'Alerts this week' },
{ value: '12', label: 'Seats in use' },
]
export default function Cards() {
return <StatBlock stats={stats} variant="card" />
}<!-- An Acme team's numbers, on the card fill. -->
<spyglass-stat-block variant="card" stats='[{"value":"128","label":"Brands tracked"},{"value":"42","label":"Boards shared"},{"value":"9","label":"Alerts this week"},{"value":"12","label":"Seats in use"}]'></spyglass-stat-block>Source
import type { ReactNode } from 'react'
import { cn } from '@/react/lib/cn'
// Numbers that say what the product does, each a Funnel Display figure over a DM Sans line, the way the brand's copy
// leans on concrete numbers. `rule` sets each under a hairline on Black; `card` sets each on the #262626 fill. Four
// across on wide screens, two on phones. The numbers are facts: never round them up or invent them.
export interface Stat {
/** The figure: "4", "$10", "1 minute". */
value: string
/** What it counts, as a short line. */
label: string
}
export interface StatBlockProps {
stats: Stat[]
/** A heading above the numbers. */
title?: ReactNode
/** rule (a hairline above each) or card (the #262626 fill). */
variant?: 'rule' | 'card'
className?: string
}
export function StatBlock({ stats, title, variant = 'rule', className }: StatBlockProps) {
const card = variant === 'card'
return (
<section data-ds="stat-block" className={cn('grid gap-10 text-fg max-sm:gap-8', className)}>
{title && <h2 className="max-w-3xl type-section">{title}</h2>}
<dl className={cn('m-0 grid grid-cols-4 max-md:grid-cols-2', card ? 'gap-4' : 'gap-x-6 gap-y-10')}>
{stats.map((s) => (
<div key={s.label} className={cn('flex flex-col-reverse justify-end gap-3', card ? 'rounded-container bg-surface-raised p-6' : 'border-t border-edge-strong pt-6')}>
<dt className="type-ui text-fg-soft">{s.label}</dt>
<dd className="m-0 type-hero max-sm:type-heading-1">{s.value}</dd>
</div>
))}
</dl>
</section>
)
}
export default StatBlock// 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, nothing } from 'lit'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import styles from 'virtual:tw'
// StatBlock.tsx as <spyglass-stat-block>: Funnel Display figures over DM Sans lines (`stats`, a list of
// { value, label }), under a `heading` (React's `title`), each under a hairline (`rule`) or on the #262626 fill (`card`).
export interface Stat { value: string; label: string }
/**
* @summary Numbers: Funnel Display figures with a line each.
*/
export class StatBlock extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="stat-block"]'))
static properties = { stats: { type: Array }, heading: {}, variant: {} }
stats: Stat[] = []
/** A heading above the numbers (React's `title`). */
heading?: string
/** rule or card. */
variant: 'rule' | 'card' = 'rule'
render() {
const card = this.variant === 'card'
return html`<section data-ds="stat-block" class="grid gap-10 text-fg max-sm:gap-8">${this.heading ? html`<h2 class="max-w-3xl type-section">${this.heading}</h2>` : nothing}<dl class=${['m-0 grid grid-cols-4 max-md:grid-cols-2', card ? 'gap-4' : 'gap-x-6 gap-y-10'].join(' ')}>${(this.stats ?? []).map((s) => html`<div class=${['flex flex-col-reverse justify-end gap-3', card ? 'rounded-container bg-surface-raised p-6' : 'border-t border-edge-strong pt-6'].join(' ')}><dt class="type-ui text-fg-soft">${s.label}</dt><dd class="m-0 type-hero max-sm:type-heading-1">${s.value}</dd></div>`)}</dl></section>`
}
}
define('stat-block', StatBlock)Reference: Derived from the guidelines (voice: concrete numbers) and the card on Black; the figures in the example come from the assets' copy (four networks, a brand added in under a minute, unlimited seats, $10 for the first month).