Site
Product example
The site's product example: the specs (endpoint, MCP tool, rate limit), the request as the code block in tabs beside the response panel from 1024 (the request staying in view as the page scrolls), the JSON scrolling across and fading at its edge, and optionally the creatives it returned, three across with a line each.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add product-example<script type="module" src="/spyglass-ds/elements/product-example.js"></script>Request and response: Find running shoe ads that ran for more than 30 days.
- Endpoint
- POST /media
- MCP tool
- searchMedia
- Rate limit
- 120 requests a minute
{
"count": 3,
"media": [
{
"id": "1001",
"brand": "Acme Run",
"platform": "Instagram",
"daysLive": 74
},
{
"id": "1002",
"brand": "Acme Trail",
"platform": "TikTok",
"daysLive": 61
},
{
"id": "1003",
"brand": "Acme Fit",
"platform": "Meta",
"daysLive": 48
}
]
}- Acme Run, 74 days live
- Acme Trail, 61 days live
- Acme Fit, 48 days live
Usage
Showing one real request and what comes back on a product or docs page.
Never
- A response the API does not return
- Keys or secrets in the code: use an environment variable
- Colored syntax highlighting
tabs are the code block's tabs ({ id, label, code, language }); media.items are creative cards (src, or Acme brand, tone and caption) with a meta line under each.
Adds with it: code-block, creative-card
Props
The web component takes the same as attributes or properties (<spyglass-product-example>); title is heading there.
<ProductExample>
| Prop | Type | Default |
|---|---|---|
question | string The question the request answers, read by assistive tech in the section's heading. | |
tabs | CodeTab[] The request, one tab each. | |
response | string The JSON that comes back. | |
specs | ProductExampleSpec[] | [] |
media | { label: string; items: (CreativeItem & { meta: string })[] } The creatives it returned, each with a line under it. | |
heading | string | 'Request and response' |
codeLabel | string | 'Request' |
responseLabel | string | 'Response' |
status | string | '200' |
copy | { label: string; copiedLabel: string; name: string } | { label: 'Copy', copiedLabel: 'Copied', name: 'Copy the request' } |
id | string Prefix for ids. | 'product' |
className | string |
Examples
The same example in React and as web components; both render identically.
import { ProductExample } from '@/react/components/site/ProductExample'
// A media search request in three tabs beside its response and the creatives it returned (Acme).
const tabs = [
{
"id": "mcp",
"label": "MCP",
"language": "bash",
"code": "# Ask your agent\nFind running shoe ads that ran for more than 30 days.\n\n# It calls searchMedia\nsearchMedia({\n \"query\": \"running shoe ads\",\n \"minDaysLive\": 30,\n \"limit\": 3\n})"
},
{
"id": "rest",
"label": "REST",
"language": "bash",
"code": "curl -X POST https://api.acme.com/v1/media \\\n -H \"Authorization: Bearer $ACME_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"query\": \"running shoe ads\",\n \"minDaysLive\": 30,\n \"limit\": 3\n }'"
},
{
"id": "python",
"label": "Python",
"language": "python",
"code": "import os\nfrom acme import Acme\n\nclient = Acme(token=os.environ[\"ACME_API_KEY\"])\n\nresult = client.search_media(\n query=\"running shoe ads\",\n min_days_live=30,\n limit=3,\n)"
}
]
const response = "{\n \"count\": 3,\n \"media\": [\n {\n \"id\": \"1001\",\n \"brand\": \"Acme Run\",\n \"platform\": \"Instagram\",\n \"daysLive\": 74\n },\n {\n \"id\": \"1002\",\n \"brand\": \"Acme Trail\",\n \"platform\": \"TikTok\",\n \"daysLive\": 61\n },\n {\n \"id\": \"1003\",\n \"brand\": \"Acme Fit\",\n \"platform\": \"Meta\",\n \"daysLive\": 48\n }\n ]\n}"
export default function Media() {
return (
<ProductExample
id="media-search"
question="Find running shoe ads that ran for more than 30 days."
tabs={tabs}
response={response}
specs={[{"label": "Endpoint", "value": "POST /media"}, {"label": "MCP tool", "value": "searchMedia"}, {"label": "Rate limit", "value": "120 requests a minute"}]}
media={{"label": "Returned creatives", "items": [{"brand": "Acme Run", "tone": 3, "caption": "Built for miles.", "meta": "Acme Run, 74 days live"}, {"brand": "Acme Trail", "tone": 2, "caption": "Off the road.", "meta": "Acme Trail, 61 days live"}, {"brand": "Acme Fit", "tone": 4, "caption": "First 5K.", "meta": "Acme Fit, 48 days live"}]}}
/>
)
}<!-- A media search request in three tabs beside its response and the creatives it returned (Acme). -->
<spyglass-product-example prefix="media-search" question="Find running shoe ads that ran for more than 30 days." tabs='[{"id": "mcp", "label": "MCP", "language": "bash", "code": "# Ask your agent\nFind running shoe ads that ran for more than 30 days.\n\n# It calls searchMedia\nsearchMedia({\n \"query\": \"running shoe ads\",\n \"minDaysLive\": 30,\n \"limit\": 3\n})"}, {"id": "rest", "label": "REST", "language": "bash", "code": "curl -X POST https://api.acme.com/v1/media \\\n -H \"Authorization: Bearer $ACME_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"query\": \"running shoe ads\",\n \"minDaysLive\": 30,\n \"limit\": 3\n }'"}, {"id": "python", "label": "Python", "language": "python", "code": "import os\nfrom acme import Acme\n\nclient = Acme(token=os.environ[\"ACME_API_KEY\"])\n\nresult = client.search_media(\n query=\"running shoe ads\",\n min_days_live=30,\n limit=3,\n)"}]' response='{
"count": 3,
"media": [
{
"id": "1001",
"brand": "Acme Run",
"platform": "Instagram",
"daysLive": 74
},
{
"id": "1002",
"brand": "Acme Trail",
"platform": "TikTok",
"daysLive": 61
},
{
"id": "1003",
"brand": "Acme Fit",
"platform": "Meta",
"daysLive": 48
}
]
}' specs='[{"label": "Endpoint", "value": "POST /media"}, {"label": "MCP tool", "value": "searchMedia"}, {"label": "Rate limit", "value": "120 requests a minute"}]' media='{"label": "Returned creatives", "items": [{"brand": "Acme Run", "tone": 3, "caption": "Built for miles.", "meta": "Acme Run, 74 days live"}, {"brand": "Acme Trail", "tone": 2, "caption": "Off the road.", "meta": "Acme Trail, 61 days live"}, {"brand": "Acme Fit", "tone": 4, "caption": "First 5K.", "meta": "Acme Fit, 48 days live"}]}'></spyglass-product-example>Source
import { CodeBlock } from '@/react/components/site/CodeBlock'
import { Code } from '@/react/components/site/Code'
import { CreativeCard, type CreativeItem } from '@/react/components/site/CreativeCard'
import type { CodeTab } from '@/lib/code'
import { cn } from '@/react/lib/cn'
// The site's product example (pages/Products/Example): one request and what comes back. A row of specs (the endpoint,
// the MCP tool, the rate limit: a muted label beside its value in the code face), then the request as the code block
// (MCP, REST, Python tabs and the copy button) beside the response from 1024, the request staying in view as the page
// scrolls: a #262626 panel with the 8px corner, a 56px head ("Response" and the 200 status, muted, in the code face)
// over the JSON scrolling across and fading at its edge. Under it, optionally, the creatives it returned, three across
// at 3:4 with a line each. Nothing moves but the code block's tab line.
export interface ProductExampleSpec { label: string; value: string }
export interface ProductExampleProps {
/** The question the request answers, read by assistive tech in the section's heading. */
question: string
/** The request, one tab each. */
tabs: CodeTab[]
/** The JSON that comes back. */
response: string
specs?: ProductExampleSpec[]
/** The creatives it returned, each with a line under it. */
media?: { label: string; items: (CreativeItem & { meta: string })[] }
heading?: string
codeLabel?: string
responseLabel?: string
status?: string
copy?: { label: string; copiedLabel: string; name: string }
/** Prefix for ids. */
id?: string
className?: string
}
const WRAP = 'mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)'
export function ProductExample({
question,
tabs,
response,
specs = [],
media,
heading = 'Request and response',
codeLabel = 'Request',
responseLabel = 'Response',
status = '200',
copy = { label: 'Copy', copiedLabel: 'Copied', name: 'Copy the request' },
id = 'product',
className,
}: ProductExampleProps) {
return (
<section data-ds="product-example" id={`${id}-example`} aria-labelledby={`${id}-example-heading`} className={cn('pb-(--ds-layout-section) text-fg', className)}>
<div className={WRAP}>
<h2 id={`${id}-example-heading`} className="sr-only">{heading}: {question}</h2>
{specs.length > 0 && (
<dl className="mb-4 flex flex-wrap gap-x-6 gap-y-2">
{specs.map((s) => (
<div key={s.label} className="flex min-w-0 items-baseline gap-2 type-ui">
<dt className="flex-none type-label text-fg-muted">{s.label}</dt>
<dd className="min-w-0 type-code wrap-anywhere">{s.value}</dd>
</div>
))}
</dl>
)}
<div className="grid grid-cols-[minmax(0,1fr)] items-start gap-4 lg:grid-cols-2">
<div className="min-w-0 lg:sticky lg:top-[calc(var(--ds-size-header)+var(--ds-space-2xl))]"><CodeBlock tabs={tabs} label={codeLabel} copy={copy} /></div>
<div className="flex min-w-0 flex-col gap-8">
<div className="flex min-w-0 flex-col rounded-panel bg-surface-raised">
<div className="relative flex h-control-lg flex-none items-center justify-between border-b border-edge-surface px-4 type-ui-strong md:px-6">
<span>{responseLabel}</span>
<span className="type-code font-normal text-fg-muted">{status}</span>
</div>
<div tabIndex={0} role="region" aria-label={responseLabel} className="fade-x min-w-0 overflow-x-auto rounded-b-panel p-4 outline-offset-[-2px] md:p-6">
<div className="w-max pr-12"><Code source={response} language="json" /></div>
</div>
</div>
{media && (
<figure className="m-0 flex flex-col gap-3">
<figcaption className="type-label text-fg-muted">{media.label}</figcaption>
<ul role="list" className="m-0 grid list-none grid-cols-3 gap-4 p-0">
{media.items.map(({ meta, ...c }, i) => (
<li key={`${c.brand ?? ''}-${i}`} className="flex min-w-0 flex-col gap-2">
<CreativeCard {...c} ratio="3/4" className="w-full" />
<span className="type-ui text-pretty text-fg-soft">{meta}</span>
</li>
))}
</ul>
</figure>
)}
</div>
</div>
</div>
</section>
)
}
export default ProductExample// 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 type { ImageFit } from '@/lib/image'
import { html, nothing } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import '@/elements/components/site/code-block'
import '@/elements/components/site/code'
import '@/elements/components/site/creative-card'
import type { CodeTab } from '@/lib/code'
import styles from 'virtual:tw'
// ProductExample.tsx as <spyglass-product-example>: one request and what comes back. The specs row, the request as the
// code block beside the response panel from 1024 (the request staying in view), and optionally the creatives it
// returned. `tabs`, `specs` and `media` ({ label, items: [{ brand, tone, caption, src, meta }] }) as JSON.
export interface ProductExampleSpec { label: string; value: string }
export interface ProductExampleMedia { label: string; items: { brand?: string; tone?: number; caption?: string; src?: string; alt?: string; fit?: ImageFit; position?: string; meta: string }[] }
const WRAP = 'mx-auto w-full max-w-[calc(var(--ds-layout-content)+2*var(--ds-layout-gutter))] px-(--ds-layout-gutter)'
/**
* @summary The product example: the request in tabs beside the response, with the creatives it returned.
*/
export class ProductExample extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="product-example"]'))
static properties = { question: {}, tabs: { type: Array }, response: {}, specs: { type: Array }, media: { type: Object }, heading: {}, codeLabel: { attribute: 'code-label' }, responseLabel: { attribute: 'response-label' }, status: {}, copy: { type: Object }, prefix: {} }
question = ''
tabs: CodeTab[] = []
/** The JSON that comes back. */
response = ''
specs: ProductExampleSpec[] = []
media?: ProductExampleMedia
heading = 'Request and response'
codeLabel = 'Request'
responseLabel = 'Response'
status = '200'
copy = { label: 'Copy', copiedLabel: 'Copied', name: 'Copy the request' }
/** Prefix for ids (React's `id`). */
prefix = 'product'
render() {
const specs = this.specs ?? []
const media = this.media
return html`<section data-ds="product-example" id=${`${this.prefix}-example`} aria-labelledby=${`${this.prefix}-example-heading`} class="pb-(--ds-layout-section) text-fg"><div class=${WRAP}><h2 id=${`${this.prefix}-example-heading`} class="sr-only">${this.heading}: ${this.question}</h2>${specs.length > 0 ? html`<dl class="mb-4 flex flex-wrap gap-x-6 gap-y-2">${specs.map((s) => html`<div class="flex min-w-0 items-baseline gap-2 type-ui"><dt class="flex-none type-label text-fg-muted">${s.label}</dt><dd class="min-w-0 type-code wrap-anywhere">${s.value}</dd></div>`)}</dl>` : nothing}<div class="grid grid-cols-[minmax(0,1fr)] items-start gap-4 lg:grid-cols-2"><div class="min-w-0 lg:sticky lg:top-[calc(var(--ds-size-header)+var(--ds-space-2xl))]"><spyglass-code-block .tabs=${this.tabs ?? []} label=${this.codeLabel} .copy=${this.copy}></spyglass-code-block></div><div class="flex min-w-0 flex-col gap-8"><div class="flex min-w-0 flex-col rounded-panel bg-surface-raised"><div class="relative flex h-control-lg flex-none items-center justify-between border-b border-edge-surface px-4 type-ui-strong md:px-6"><span>${this.responseLabel}</span><span class="type-code font-normal text-fg-muted">${this.status}</span></div><div tabindex="0" role="region" aria-label=${this.responseLabel} class="fade-x min-w-0 overflow-x-auto rounded-b-panel p-4 outline-offset-[-2px] md:p-6"><div class="w-max pr-12"><spyglass-code .source=${this.response} language="json"></spyglass-code></div></div></div>${media ? html`<figure class="m-0 flex flex-col gap-3"><figcaption class="type-label text-fg-muted">${media.label}</figcaption><ul role="list" class="m-0 grid list-none grid-cols-3 gap-4 p-0">${(media.items ?? []).map((c) => html`<li class="flex min-w-0 flex-col gap-2"><spyglass-creative-card brand=${c.brand ?? ''} tone=${c.tone ?? 2} caption=${c.caption ?? ''} src=${c.src ?? ''} alt=${c.alt ?? ''} fit=${ifDefined(c.fit)} position=${ifDefined(c.position)} ratio="3/4" class="w-full"></spyglass-creative-card><span class="type-ui text-pretty text-fg-soft">${c.meta}</span></li>`)}</ul></figure>` : nothing}</div></div></div></section>`
}
}
define('product-example', ProductExample)Reference: Site pages/Products/Example (Products.module.css .specs, .example, .response, .responseHead, .responseBody, .media): specs 8px by 24px apart, t-label over mono values; the code tabs and the response 16px apart, two columns from 1024 with the request sticky at the header plus 32px; the response on --surface with --radius-m, a --control-l head 16px in (24 from 768) over a --line-surface hairline, the status in mono --text-3, the body 16px in (24 from 768) fading over 48px; returned creatives 3:4, three across 16px apart, small --text-2 lines.