Components

Card

The brand's card: a #262626 fill on Black with the brand corner, a Funnel Display title, a line of DM Sans and the body, with actions at the foot. No border, no shadow.

Install

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

npx spyglass-ds add card
<script type="module" src="/spyglass-ds/elements/card.js"></script>
Plan

Creator

$10 for your first month, then $20/month

  • AI-powered research across brands, creators, ads, and campaigns
  • Unlimited board swipe files, alerts, and tracked brands
  • Unlimited team seats
Stats

1,240

New Acme creatives this week

38

Brands tracked by the Acme team

6

Boards shared with the agency

Usage

A plan, an offer, a stat or a group of settings set apart from the Black ground. The plan card in the ads is the model.

Never

  • A shadow or a glow around it
  • A border instead of the fill
  • A card on a card

Props

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

<Card>

PropTypeDefault
titleReactNode
descriptionReactNode
actionsReactNode

Buttons or links at the foot.

Examples

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

react/examples/card/Plan.tsx
import { Button } from '@/react/components/ui/Button'
import { Card } from '@/react/components/ui/Card'
// The plan card from the Creator plan ad: the plan, its price, what it includes and the one action.

export default function Plan() {
  return (
    <Card
      className="w-150 max-w-full"
      title="Creator"
      description="$10 for your first month, then $20/month"
      actions={<Button className="w-full">Start Creator for 50% off</Button>}
    >
      <ul className="flex flex-col gap-2 type-ui text-fg">
        <li>AI-powered research across brands, creators, ads, and campaigns</li>
        <li>Unlimited board swipe files, alerts, and tracked brands</li>
        <li>Unlimited team seats</li>
      </ul>
    </Card>
  )
}
elements/examples/card/Plan.html
<!-- The plan card from the Creator plan ad: the plan, its price, what it includes and the one action. -->
<spyglass-card class="w-150 max-w-full" heading="Creator" description="$10 for your first month, then $20/month">
  <ul class="flex flex-col gap-2 type-ui text-fg">
    <li>AI-powered research across brands, creators, ads, and campaigns</li>
    <li>Unlimited board swipe files, alerts, and tracked brands</li>
    <li>Unlimited team seats</li>
  </ul>
  <spyglass-button slot="actions" class="w-full">Start Creator for 50% off</spyglass-button>
</spyglass-card>
react/examples/card/Stats.tsx
import { Card } from '@/react/components/ui/Card'
// Cards for a dashboard: one number each, with what it counts under it.

export default function Stats() {
  return (
    <div className="grid gap-4 sm:grid-cols-3">
      <Card title="1,240" description="New Acme creatives this week" />
      <Card title="38" description="Brands tracked by the Acme team" />
      <Card title="6" description="Boards shared with the agency" />
    </div>
  )
}
elements/examples/card/Stats.html
<!-- Cards for a dashboard: one number each, with what it counts under it. -->
<div class="grid gap-4 sm:grid-cols-3">
  <spyglass-card heading="1,240" description="New Acme creatives this week"></spyglass-card>
  <spyglass-card heading="38" description="Brands tracked by the Acme team"></spyglass-card>
  <spyglass-card heading="6" description="Boards shared with the agency"></spyglass-card>
</div>

Source

react/components/ui/Card.tsx
import type { HTMLAttributes, ReactNode } from 'react'
import { cn } from '@/react/lib/cn'

// The site's card: a #262626 fill on Black with the 4px corner, no border and no shadow, 24px in. `title` is a Funnel
// Display card title (24/28 at 400, as the site's resource cards), `description` a #D4D4D4 line of DM Sans under it, the children the body, and `actions` a row at the foot (a full
// width button in the plan card).
export interface CardProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
  title?: ReactNode
  description?: ReactNode
  /** Buttons or links at the foot. */
  actions?: ReactNode
}

export function Card({ title, description, actions, className, children, ...rest }: CardProps) {
  return (
    <div data-ds="card" {...rest} className={cn('flex flex-col gap-6 rounded-container bg-surface-raised p-6 text-fg', className)}>
      {(title || description) && (
        <div className="flex flex-col gap-2">
          {title && <h3 className="type-heading-3">{title}</h3>}
          {description && <p className="type-body text-fg-soft">{description}</p>}
        </div>
      )}
      {children}
      {actions && <div className="mt-2 flex flex-wrap gap-3">{actions}</div>}
    </div>
  )
}

export default Card
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/ui/card.ts
import { html, nothing } from 'lit'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import styles from 'virtual:tw'

// Card.tsx as <spyglass-card>: a #262626 fill on Black with the 4px corner, no border, no shadow, 24px in. `heading` is the
// Funnel Display card title (React's `title`; `title` is HTML's tooltip), `description` a line under it, the default
// slot the body and the `actions` slot a row at the foot.

/**
 * @summary A card: the brand's #262626 fill, a title, a line and actions.
 * @slot - The body.
 * @slot actions - Buttons or links at the foot.
 */
export class Card extends DsElement {
	static styles = [DsElement.styles, styles]
	// Layout classes on the element (w-150, max-w-full) land on the card, as on the React root.
	protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="card"]'))
	static properties = { heading: {}, description: {} }
	/** The card title (React's `title`). */
	heading?: string
	description?: string

	render() {
		const head = this.heading || this.description
		return html`<div data-ds="card" class="flex flex-col gap-6 rounded-container bg-surface-raised p-6 text-fg">${head ? html`<div class="flex flex-col gap-2">${this.heading ? html`<h3 class="type-heading-3">${this.heading}</h3>` : nothing}${this.description ? html`<p class="type-body text-fg-soft">${this.description}</p>` : nothing}</div>` : nothing}<slot></slot>${this.hasSlot('actions') ? html`<div class="mt-2 flex flex-wrap gap-3"><slot name="actions"></slot></div>` : nothing}</div>`
	}
}

define('card', Card)

Reference: Brand assets (Figma page 8): Card, Creator plan (600x452, #262626, radius 10, 48px in; Creator in Funnel Display 40px at 1.0, DM Sans 24px lines, a 504x56 White button).