Site
Product cards
The site's product cards: products in a grid ruled apart by hairlines, each a link with the name in Funnel Display, one line on what it does and the endpoint in the code face; the #262626 fill under a mouse.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add product-cards<script type="module" src="/spyglass-ds/elements/product-cards.js"></script>- Creator searchFind creators by name, handle or description. Filter by location, language, gender, age and followers.POST /creators
- Media searchSearch ads and organic posts by what is in them, across Meta, Instagram and TikTok.POST /media
- Creator collabsSee which creators a brand has posted with, how often and since when.GET /collabs
Usage
Related products under a product page, or every product on an index, three or four across.
Never
- Pictures or icons in the cards
- Cards that grow or move on hover: the fill changes, nothing moves
- Uneven columns: three or four
Props
The web component takes the same as attributes or properties (<spyglass-product-cards>); title is heading there.
<ProductCards>
| Prop | Type | Default |
|---|---|---|
products | ProductCardItem[] | |
columns | 3 | 4 | 3 |
className | string |
Examples
The same example in React and as web components; both render identically.
import { ProductCards } from '@/react/components/site/ProductCards'
// Three related products, as the site lists them under a product.
export default function Related() {
return (
<div className="w-full max-w-320 px-4 md:px-12">
<ProductCards
products={[
{ name: 'Creator search', line: 'Find creators by name, handle or description. Filter by location, language, gender, age and followers.', endpoint: 'POST /creators', href: '/products/creator-search' },
{ name: 'Media search', line: 'Search ads and organic posts by what is in them, across Meta, Instagram and TikTok.', endpoint: 'POST /media', href: '/products/media-search' },
{ name: 'Creator collabs', line: 'See which creators a brand has posted with, how often and since when.', endpoint: 'GET /collabs', href: '/products/creator-collabs' },
]}
/>
</div>
)
}<!-- Three related products, as the site lists them under a product. -->
<div class="w-full max-w-320 px-4 md:px-12">
<spyglass-product-cards products='[{"name":"Creator search","line":"Find creators by name, handle or description. Filter by location, language, gender, age and followers.","endpoint":"POST /creators","href":"/products/creator-search"},{"name":"Media search","line":"Search ads and organic posts by what is in them, across Meta, Instagram and TikTok.","endpoint":"POST /media","href":"/products/media-search"},{"name":"Creator collabs","line":"See which creators a brand has posted with, how often and since when.","endpoint":"GET /collabs","href":"/products/creator-collabs"}]'></spyglass-product-cards>
</div>Source
import { cn } from '@/react/lib/cn'
// The site's product cards (pages/Products/ProductCards): products in a grid ruled apart by #363636 hairlines, one
// column on phones, two from 768 and three or four from 1024. Each card is a link on Black, 24px in (flush at the sides on
// phones, 32px from 768): the
// name in Funnel Display (20/24, 24/28 from 768), the line in 16/24 #D4D4D4 8px under it and the endpoint in the code
// face, 14/20 #A3A3A3, at the foot. Under a mouse (and while pressed) the card takes the #262626 fill, a color change
// only.
export interface ProductCardItem {
name: string
/** One line on what it does. */
line: string
/** "POST /creators". */
endpoint?: string
href: string
}
export interface ProductCardsProps {
products: ProductCardItem[]
columns?: 3 | 4
className?: string
}
export function ProductCards({ products, columns = 3, className }: ProductCardsProps) {
return (
<ul data-ds="product-cards" role="list" className={cn('m-0 grid list-none grid-cols-[minmax(0,1fr)] gap-px bg-edge p-0 text-fg', columns === 4 ? 'md:grid-cols-2 lg:grid-cols-4' : 'md:grid-cols-2 lg:grid-cols-3', className)}>
{products.map((p) => (
<li key={p.href} className="flex bg-surface">
<a href={p.href} className="flex flex-1 flex-col gap-2 bg-surface py-6 outline-offset-[-4px] transition-[background-color] duration-160 ease-out active:bg-surface-raised pointer-fine:hover:bg-surface-raised md:p-8">
<span className="type-heading-4 md:type-heading-3">{p.name}</span>
<span className="type-body text-pretty text-fg-soft">{p.line}</span>
{p.endpoint && <span className="mt-auto pt-2 type-code wrap-anywhere text-fg-muted">{p.endpoint}</span>}
</a>
</li>
))}
</ul>
)
}
export default ProductCards// 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'
// ProductCards.tsx as <spyglass-product-cards>: products in a hairline-ruled grid of links, the name, the line and the
// endpoint in the code face; the #262626 fill under a mouse. `products` as JSON: [{ name, line, endpoint?, href }].
export interface ProductCardItem { name: string; line: string; endpoint?: string; href: string }
/**
* @summary Product cards: links in a ruled grid with the name, a line and the endpoint.
*/
export class ProductCards extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="product-cards"]'))
static properties = { products: { type: Array }, columns: { type: Number } }
products: ProductCardItem[] = []
/** 3 or 4 columns from 1024 (two from 768). */
columns: 3 | 4 = 3
render() {
return html`<ul data-ds="product-cards" role="list" class=${`m-0 grid list-none grid-cols-[minmax(0,1fr)] gap-px bg-edge p-0 text-fg ${this.columns === 4 ? 'md:grid-cols-2 lg:grid-cols-4' : 'md:grid-cols-2 lg:grid-cols-3'}`}>${(this.products ?? []).map((p) => html`<li class="flex bg-surface"><a href=${p.href} class="flex flex-1 flex-col gap-2 bg-surface py-6 outline-offset-[-4px] transition-[background-color] duration-160 ease-out active:bg-surface-raised pointer-fine:hover:bg-surface-raised md:p-8"><span class="type-heading-4 md:type-heading-3">${p.name}</span><span class="type-body text-pretty text-fg-soft">${p.line}</span>${p.endpoint ? html`<span class="mt-auto pt-2 type-code wrap-anywhere text-fg-muted">${p.endpoint}</span>` : nothing}</a></li>`)}</ul>`
}
}
define('product-cards', ProductCards)Reference: Site pages/Products/ProductCards (Products.module.css .cards, .card, .cardEndpoint): gap --hairline on --line, cards on --bg 24px in (0 at the sides under 768, 32px from 768), one column, two from 768, three or four from 1024 (data-columns), .t-sub names, .text lines (body 16/24 --text-2), the endpoint in --font-mono small --text-3 at the foot; --surface on hover (fine pointers) and on press, --dur-fast.