Site

Compare table

The site's plan comparison: a table per group, its head (the group's title and the plans' names) sticking under the page header while the group scrolls, then a row per line with a value in #A3A3A3, a White check or nothing for each plan. Names can carry a tip and a link, lines the Soon tag; on phones one plan at a time.

Install

React apps get the React files; every other stack gets the web component.

npx spyglass-ds add compare-table
<script type="module" src="/spyglass-ds/elements/compare-table.js"></script>
Usage and access, four plans
UsageFreeCreatorProEnterprise
One credit is one record returned: one creative, one creator or one brand.500 a month5,000 a month13,000+ a monthCustom
What happens once a month’s credits are used.Stops$2 per 1K$1.50 per 1KVolume pricing
Pay as you goNot includedNot includedIncludedNot included
Cap what Pro can spend in a month.SoonNot includedNot includedIncludedNot included
AccessFreeCreatorProEnterprise
REST APICall it from your own code.IncludedIncludedIncludedIncluded
MCP serverAsk from any MCP client. No API key needed.IncludedIncludedIncludedIncluded
Priority supportNot includedNot includedIncludedIncluded

Usage

Under a pricing table, to compare plans line by line: usage, what each plan includes, access, support.

Never

  • Colored checks or crosses: a plan without the line shows nothing
  • Long sentences in a cell: a value or a check
  • More than four plans: the cells get too narrow

A cell is true (included, read out as "Included"), '' (not included) or a short value. labels changes the words for the tag and for assistive tech. The site hides the table on phones; it still works there, one plan at a time.

Adds with it: pricing-table

Props

The web component takes the same as attributes or properties (<spyglass-compare-table>); title is heading there.

<CompareTable>

PropTypeDefault
plansComparePlan[]
groupsCompareGroup[]
defaultPlanstring

The plan shown first on phones (a plan's key).

labels{ soon?: string, included?: string, notIncluded?: string, pick?: string }

The words for assistive tech and the tag.

classNamestring

Examples

The same example in React and as web components; both render identically.

react/examples/compare-table/Compare.tsx
import { CompareTable, type CompareGroup } from '@/react/components/site/CompareTable'
// Two of Acme's groups across four plans; on phones, Pro first.

const plans = [
  {
    "key": "free",
    "name": "Free"
  },
  {
    "key": "creator",
    "name": "Creator"
  },
  {
    "key": "pro",
    "name": "Pro"
  },
  {
    "key": "enterprise",
    "name": "Enterprise"
  }
]

const groups: CompareGroup[] = [
  {
    "title": "Usage",
    "rows": [
      {
        "label": "Credits",
        "tip": "One credit is one record returned: one creative, one creator or one brand.",
        "cells": [
          "500 a month",
          "5,000 a month",
          "13,000+ a month",
          "Custom"
        ]
      },
      {
        "label": "After your credits",
        "tip": "What happens once a month’s credits are used.",
        "cells": [
          "Stops",
          "$2 per 1K",
          "$1.50 per 1K",
          "Volume pricing"
        ]
      },
      {
        "label": "Pay as you go",
        "cells": [
          "",
          "",
          true,
          ""
        ]
      },
      {
        "label": "Spend limits",
        "tip": "Cap what Pro can spend in a month.",
        "soon": true,
        "cells": [
          "",
          "",
          true,
          ""
        ]
      }
    ]
  },
  {
    "title": "Access",
    "rows": [
      {
        "label": "REST API",
        "tip": "Call it from your own code.",
        "href": "#api",
        "cells": [
          true,
          true,
          true,
          true
        ]
      },
      {
        "label": "MCP server",
        "tip": "Ask from any MCP client. No API key needed.",
        "href": "#mcp",
        "cells": [
          true,
          true,
          true,
          true
        ]
      },
      {
        "label": "Priority support",
        "cells": [
          "",
          "",
          true,
          true
        ]
      }
    ]
  }
]

export default function Compare() {
  return (
    <div className="px-4 py-12 md:px-12">
      <CompareTable plans={plans} groups={groups} defaultPlan="pro" />
    </div>
  )
}
elements/examples/compare-table/Compare.html
<!-- Two of Acme's groups across four plans; on phones, Pro first. -->
<div class="px-4 py-12 md:px-12">
  <spyglass-compare-table default-plan="pro" plans='[{"key":"free","name":"Free"},{"key":"creator","name":"Creator"},{"key":"pro","name":"Pro"},{"key":"enterprise","name":"Enterprise"}]' groups='[{"title":"Usage","rows":[{"label":"Credits","tip":"One credit is one record returned: one creative, one creator or one brand.","cells":["500 a month","5,000 a month","13,000+ a month","Custom"]},{"label":"After your credits","tip":"What happens once a month’s credits are used.","cells":["Stops","$2 per 1K","$1.50 per 1K","Volume pricing"]},{"label":"Pay as you go","cells":["","",true,""]},{"label":"Spend limits","tip":"Cap what Pro can spend in a month.","soon":true,"cells":["","",true,""]}]},{"title":"Access","rows":[{"label":"REST API","tip":"Call it from your own code.","href":"#api","cells":[true,true,true,true]},{"label":"MCP server","tip":"Ask from any MCP client. No API key needed.","href":"#mcp","cells":[true,true,true,true]},{"label":"Priority support","cells":["","",true,true]}]}]'></spyglass-compare-table>
</div>

Source

react/components/site/CompareTable.tsx
'use client'
import { useId, useState } from 'react'
import { Segmented } from '@/react/components/site/Segmented'
import { cn } from '@/react/lib/cn'

// The site's plan comparison (pages/Pricing CompareTable.tsx, Pricing.module.css .compare*): one table per group, its
// head sticking under the page header while the group scrolls (the title in Funnel Display 32/36, 40/44 from 1024, and
// the plans' names 20/24, fading out over its last 48px), then a row per line: the name in DM Sans 16/24 White, each
// plan's cell a value in #A3A3A3, a White 24px disc with a Black check when included, or nothing. Rows ruled apart by
// #363636 hairlines, 16px in; 96px between groups (64 on phones). A name with a `tip` takes a dotted underline and
// shows the tip above it on hover (after 80ms) or focus, rising 4px over 160ms; with `href` it is a link. `soon` adds
// the small Soon tag. On phones the table shows one plan at a time, picked with the segmented switch in each head.
export type CompareCell = true | '' | string

export interface CompareRow {
  label: string
  /** A short explanation, shown above the name on hover or focus. */
  tip?: string
  /** Makes the name a link. */
  href?: string
  /** Adds the Soon tag. */
  soon?: boolean
  /** One per plan: true (included), '' (not included) or a value. */
  cells: CompareCell[]
}

export interface CompareGroup {
  title: string
  rows: CompareRow[]
}

export interface ComparePlan {
  key: string
  name: string
}

export interface CompareTableProps {
  plans: ComparePlan[]
  groups: CompareGroup[]
  /** The plan shown first on phones (a plan's key). */
  defaultPlan?: string
  /** The words for assistive tech and the tag. */
  labels?: { soon?: string, included?: string, notIncluded?: string, pick?: string }
  className?: string
}

const LABELS = { soon: 'Soon', included: 'Included', notIncluded: 'Not included', pick: 'Plan' }

function Name({ row, soon }: { row: CompareRow, soon: string }) {
  const tipId = useId()
  const tag = row.soon ? <span className="ds-compare-soon rounded-ds-sm bg-surface-subtle px-2 py-1 text-fg-soft">{soon}</span> : null
  const term = 'ds-compare-link type-body text-fg'
  return (
    <span className="inline-flex flex-wrap items-center gap-2">
      {row.tip ? (
        <span className="ds-compare-term relative">
          {row.href
            ? <a className={term} href={row.href} aria-describedby={tipId}>{row.label}</a>
            : <button type="button" className={cn(term, 'cursor-default border-0 bg-transparent p-0 text-start')} aria-describedby={tipId}>{row.label}</button>}
          <span id={tipId} role="tooltip" className="ds-compare-tip pointer-events-none absolute bottom-[calc(100%+var(--ds-space-sm))] left-0 w-max rounded-panel bg-surface-subtle px-4 py-3 type-ui text-fg shadow-[inset_0_0_0_var(--ds-border-hairline)_var(--ds-color-edge)]">{row.tip}</span>
        </span>
      ) : <span className="type-body text-fg">{row.label}</span>}
      {tag}
    </span>
  )
}

export function CompareTable({ plans, groups, defaultPlan, labels, className }: CompareTableProps) {
  const l = { ...LABELS, ...labels }
  const [pick, setPick] = useState(defaultPlan ?? plans[0]?.key)
  const cols = { gridTemplateColumns: `minmax(0, 2fr) repeat(${plans.length}, minmax(0, 1fr))` }
  const row = 'grid items-center gap-x-4 max-md:grid-cols-[minmax(0,1fr)_auto]! md:gap-x-6'
  const shown = (key: string) => (key === pick ? '' : 'max-md:hidden')
  return (
    <div data-ds="compare-table" className={cn('grid text-fg', className)}>
      <style href="ds-compare-table" precedence="ds">{css}</style>
      {groups.map((g) => (
        <table key={g.title} aria-label={g.title} className="block border-collapse pb-16 last:pb-0 md:pb-24">
          <thead className="ds-compare-head sticky top-16 z-2 block py-4 md:pt-6 md:pb-12 lg:top-header">
            <tr className={cn(row, 'max-md:block')} style={cols}>
              <th scope="col" className="p-0 text-start type-heading-2 lg:type-figure">{g.title}</th>
              {plans.map((p) => <th key={p.key} scope="col" className="p-0 text-start type-heading-4 max-md:hidden">{p.name}</th>)}
            </tr>
            <tr className="mt-4 block md:hidden">
              <td className="block p-0" colSpan={plans.length + 1}>
                <Segmented label={l.pick} block value={pick} onValueChange={setPick} options={plans.map((p) => ({ key: p.key, label: p.name }))} />
              </td>
            </tr>
          </thead>
          <tbody className="block">
            {g.rows.map((r) => (
              <tr key={r.label} className={cn(row, 'border-edge py-4 not-first:border-t')} style={cols}>
                <th scope="row" className="min-w-0 p-0 text-start font-normal"><Name row={r} soon={l.soon} /></th>
                {r.cells.map((v, i) => (
                  <td key={plans[i]?.key ?? i} className={cn('p-0 text-start max-md:text-end', shown(plans[i]?.key))}>
                    {v === true ? (
                      <span className="inline-grid size-6 place-items-center rounded-full bg-fg align-middle text-(--ds-color-black)">
                        <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className="size-4"><path d="M4 8.5 6.75 11.25 12 5.5" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" /></svg>
                        <span className="sr-only">{l.included}</span>
                      </span>
                    ) : v === '' ? <span className="sr-only">{l.notIncluded}</span> : <span className="type-body text-fg-muted tabular-nums">{v}</span>}
                  </td>
                ))}
              </tr>
            ))}
          </tbody>
        </table>
      ))}
    </div>
  )
}

export default CompareTable

// The head's fade (the site's 48px ramp to the page ground) and the tip's timing: shown on focus at once, on a fine
// pointer's hover after 80ms; leaving, it fades over 160ms before it is hidden.
const css = `
.ds-compare-head {
  --fade: var(--ds-space-3xl);
  background: linear-gradient(to bottom, var(--ds-color-surface) calc(100% - var(--fade)), color-mix(in srgb, var(--ds-color-surface) 85%, transparent) calc(100% - var(--fade) * 0.75), color-mix(in srgb, var(--ds-color-surface) 60%, transparent) calc(100% - var(--fade) * 0.5), color-mix(in srgb, var(--ds-color-surface) 30%, transparent) calc(100% - var(--fade) * 0.25), transparent);
}
.ds-compare-term:hover, .ds-compare-term:focus-within { z-index: 3; }
.ds-compare-soon { font-family: var(--ds-font-text); font-size: var(--ds-text-caption); line-height: var(--ds-text-caption-leading); font-weight: var(--ds-font-weight-medium); }
.ds-compare-link {
  text-decoration: underline dotted var(--ds-color-fg-muted);
  text-decoration-thickness: var(--ds-border-hairline);
  text-underline-offset: var(--ds-space-xs);
  transition: text-decoration-color var(--ds-duration-micro) var(--ds-easing-out);
}
.ds-compare-link:focus-visible { outline: 2px solid var(--ds-color-fg); outline-offset: var(--ds-space-xs); border-radius: var(--ds-radius-sm); }
.ds-compare-tip {
  max-width: min(var(--ds-compare-tip-w), calc(100vw - 2 * var(--ds-layout-gutter)));
  opacity: 0; visibility: hidden; translate: 0 var(--ds-space-xs);
  transition: opacity var(--ds-duration-micro) var(--ds-easing-out), translate var(--ds-duration-micro) var(--ds-easing-out), visibility 0s linear var(--ds-duration-micro);
}
.ds-compare-term:focus-within .ds-compare-tip {
  opacity: 1; visibility: visible; translate: 0 0;
  transition: opacity var(--ds-duration-micro) var(--ds-easing-out), translate var(--ds-duration-micro) var(--ds-easing-out);
}
@media (hover: hover) and (pointer: fine) {
  .ds-compare-link:hover { text-decoration-color: var(--ds-color-fg); }
  .ds-compare-term:hover .ds-compare-tip {
    opacity: 1; visibility: visible; translate: 0 0;
    transition: opacity var(--ds-duration-micro) var(--ds-easing-out) var(--ds-compare-tip-delay), translate var(--ds-duration-micro) var(--ds-easing-out) var(--ds-compare-tip-delay);
  }
}
@media (prefers-reduced-motion: reduce) { .ds-compare-tip { translate: none; } }
`
react/lib/cn.ts
// 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(' ')
}
elements/components/site/compare-table.ts
import { html, nothing } from 'lit'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import '@/elements/components/site/segmented'
import styles from 'virtual:tw'

// CompareTable.tsx as <spyglass-compare-table>: the site's plan comparison, a table per group with its head sticking
// under the page header, values, White checks or nothing per plan, tips on the names (hover after 80ms, or focus), the
// Soon tag; on phones one plan at a time, picked in each head. `plans` ({ key, name }), `groups` ({ title, rows: [{
// label, tip, href, soon, cells }] }; a cell is true, '' or a value), `default-plan` and `labels` ({ soon, included,
// notIncluded, pick }).
export type CompareCell = true | '' | string
export interface CompareRow { label: string; tip?: string; href?: string; soon?: boolean; cells: CompareCell[] }
export interface CompareGroup { title: string; rows: CompareRow[] }
export interface ComparePlan { key: string; name: string }

const LABELS = { soon: 'Soon', included: 'Included', notIncluded: 'Not included', pick: 'Plan' }
const ROW = 'grid items-center gap-x-4 max-md:grid-cols-[minmax(0,1fr)_auto]! md:gap-x-6'
let uid = 0

/**
 * @summary The plan comparison table.
 */
export class CompareTable extends DsElement {
	static styles = [DsElement.styles, styles]
	protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="compare-table"]'))
	static properties = { plans: { type: Array }, groups: { type: Array }, defaultPlan: { attribute: 'default-plan' }, labels: { type: Object }, pick: { state: true } }
	plans: ComparePlan[] = []
	groups: CompareGroup[] = []
	/** The plan shown first on phones (a plan's key). */
	defaultPlan?: string
	/** The words for assistive tech and the tag. */
	labels?: Partial<typeof LABELS>
	private pick?: string
	private tipBase = `ds-compare-${++uid}`

	private name(r: CompareRow, soon: string, tipId: string) {
		const tag = r.soon ? html`<span class="ds-compare-soon rounded-ds-sm bg-surface-subtle px-2 py-1 text-fg-soft">${soon}</span>` : nothing
		const term = 'ds-compare-link type-body text-fg'
		return html`<span class="inline-flex flex-wrap items-center gap-2">${r.tip ? html`<span class="ds-compare-term relative">${r.href ? html`<a class=${term} href=${r.href} aria-describedby=${tipId}>${r.label}</a>` : html`<button type="button" class=${`${term} cursor-default border-0 bg-transparent p-0 text-start`} aria-describedby=${tipId}>${r.label}</button>`}<span id=${tipId} role="tooltip" class="ds-compare-tip pointer-events-none absolute bottom-[calc(100%+var(--ds-space-sm))] left-0 w-max rounded-panel bg-surface-subtle px-4 py-3 type-ui text-fg shadow-[inset_0_0_0_var(--ds-border-hairline)_var(--ds-color-edge)]">${r.tip}</span></span>` : html`<span class="type-body text-fg">${r.label}</span>`}${tag}</span>`
	}

	render() {
		const l = { ...LABELS, ...this.labels }
		const plans = this.plans ?? []
		const pick = this.pick ?? this.defaultPlan ?? plans[0]?.key
		const cols = `grid-template-columns: minmax(0, 2fr) repeat(${plans.length}, minmax(0, 1fr))`
		const options = plans.map((p) => ({ key: p.key, label: p.name }))
		return html`<div data-ds="compare-table" class="grid text-fg">${(this.groups ?? []).map((g, gi) => html`<table aria-label=${g.title} class="block border-collapse pb-16 last:pb-0 md:pb-24"><thead class="ds-compare-head sticky top-16 z-2 block py-4 md:pt-6 md:pb-12 lg:top-header"><tr class=${`${ROW} max-md:block`} style=${cols}><th scope="col" class="p-0 text-start type-heading-2 lg:type-figure">${g.title}</th>${plans.map((p) => html`<th scope="col" class="p-0 text-start type-heading-4 max-md:hidden">${p.name}</th>`)}</tr><tr class="mt-4 block md:hidden"><td class="block p-0" colspan=${plans.length + 1}><spyglass-segmented label=${l.pick} block .options=${options} value=${pick ?? ''} @change=${(e: Event) => { this.pick = (e.target as HTMLElement & { value: string }).value }}></spyglass-segmented></td></tr></thead><tbody class="block">${g.rows.map((r, ri) => html`<tr class=${`${ROW} border-edge py-4 not-first:border-t`} style=${cols}><th scope="row" class="min-w-0 p-0 text-start font-normal">${this.name(r, l.soon, `${this.tipBase}-${gi}-${ri}`)}</th>${r.cells.map((v, i) => html`<td class=${`p-0 text-start max-md:text-end ${plans[i]?.key === pick ? '' : 'max-md:hidden'}`}>${v === true ? html`<span class="inline-grid size-6 place-items-center rounded-full bg-fg align-middle text-(--ds-color-black)"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class="size-4"><path d="M4 8.5 6.75 11.25 12 5.5" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="sr-only">${l.included}</span></span>` : v === '' ? html`<span class="sr-only">${l.notIncluded}</span>` : html`<span class="type-body text-fg-muted tabular-nums">${v}</span>`}</td>`)}</tr>`)}</tbody></table>`)}</div>`
	}
}

define('compare-table', CompareTable)
elements/components/site/compare-table.css
.ds-compare-head {
  --fade: var(--ds-space-3xl);
  background: linear-gradient(to bottom, var(--ds-color-surface) calc(100% - var(--fade)), color-mix(in srgb, var(--ds-color-surface) 85%, transparent) calc(100% - var(--fade) * 0.75), color-mix(in srgb, var(--ds-color-surface) 60%, transparent) calc(100% - var(--fade) * 0.5), color-mix(in srgb, var(--ds-color-surface) 30%, transparent) calc(100% - var(--fade) * 0.25), transparent);
}
.ds-compare-term:hover, .ds-compare-term:focus-within { z-index: 3; }
.ds-compare-soon { font-family: var(--ds-font-text); font-size: var(--ds-text-caption); line-height: var(--ds-text-caption-leading); font-weight: var(--ds-font-weight-medium); }
.ds-compare-link {
  text-decoration: underline dotted var(--ds-color-fg-muted);
  text-decoration-thickness: var(--ds-border-hairline);
  text-underline-offset: var(--ds-space-xs);
  transition: text-decoration-color var(--ds-duration-micro) var(--ds-easing-out);
}
.ds-compare-link:focus-visible { outline: 2px solid var(--ds-color-fg); outline-offset: var(--ds-space-xs); border-radius: var(--ds-radius-sm); }
.ds-compare-tip {
  max-width: min(var(--ds-compare-tip-w), calc(100vw - 2 * var(--ds-layout-gutter)));
  opacity: 0; visibility: hidden; translate: 0 var(--ds-space-xs);
  transition: opacity var(--ds-duration-micro) var(--ds-easing-out), translate var(--ds-duration-micro) var(--ds-easing-out), visibility 0s linear var(--ds-duration-micro);
}
.ds-compare-term:focus-within .ds-compare-tip {
  opacity: 1; visibility: visible; translate: 0 0;
  transition: opacity var(--ds-duration-micro) var(--ds-easing-out), translate var(--ds-duration-micro) var(--ds-easing-out);
}
@media (hover: hover) and (pointer: fine) {
  .ds-compare-link:hover { text-decoration-color: var(--ds-color-fg); }
  .ds-compare-term:hover .ds-compare-tip {
    opacity: 1; visibility: visible; translate: 0 0;
    transition: opacity var(--ds-duration-micro) var(--ds-easing-out) var(--ds-compare-tip-delay), translate var(--ds-duration-micro) var(--ds-easing-out) var(--ds-compare-tip-delay);
  }
}
@media (prefers-reduced-motion: reduce) { .ds-compare-tip { translate: none; } }

Reference: Site pages/Pricing (CompareTable.tsx, CompareTable.module.css, Pricing.module.css .compare*): rows on a 2fr and 1fr grid, 24px apart, ruled by --line, 16px in; the sticky head at --header-h with the 48px fade; titles h4 to h3 at 1024; the dotted --text-3 underline and the tip on --raised after --dur-menu-intent; the phone picker is the segmented switch.