Site
Creative grid
Creatives in a grid, every cell the same shape: the post's three by three of squares 8px apart with a light tile among them, or the ad's three up in 3/4.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add creative-grid<script type="module" src="/spyglass-ds/elements/creative-grid.js"></script>Usage
A board, the results of a search, or the proof under a hero: many creatives at once, read as a set.
Never
- Cells of different sizes in one grid: use the creative row or the ring
- More than one light tile in nine
- A grid on a card
items takes the creative card's fields; light: true makes a cell a tile of the brand light (seed picks it). Each picture is an image slot (src, alt, fit, position); without src it keeps its placeholder, which carries data-ds-placeholder.
Adds with it: brand-light, creative-card
Props
The web component takes the same as attributes or properties (<spyglass-creative-grid>); title is heading there.
<CreativeGrid>
| Prop | Type | Default |
|---|---|---|
items | CreativeItem[] | |
columns | 2 | 3 | 4 2, 3 or 4 columns (4 falls to 2 on phones). | 3 |
ratio | Exclude<CreativeRatio, 'fill'> Every cell's shape. | '1/1' |
gap | 'sm' | 'md' sm: the post's 8px. md: the ad's wider gutter. | 'sm' |
className | string |
Examples
The same example in React and as web components; both render identically.
import { CreativeGrid } from '@/react/components/site/CreativeGrid'
// The post's grid: nine squares 8px apart, a light tile in the middle.
const items = [
{ brand: 'Acme Skin', tone: 2 as const },
{ brand: 'Acme Studio', tone: 1 as const },
{ brand: 'Acme Drinks', tone: 3 as const },
{ brand: 'Acme Motors', tone: 1 as const },
{ light: true, seed: 0 },
{ brand: 'Acme Drinks', tone: 4 as const },
{ brand: 'Acme Fit', tone: 3 as const },
{ brand: 'Acme Studio', tone: 2 as const },
{ brand: 'Acme Skin', tone: 4 as const },
]
export default function Tiles() {
return <CreativeGrid items={items} className="w-120 max-w-full" />
}<!-- The post's grid: nine squares 8px apart, a light tile in the middle. -->
<spyglass-creative-grid class="w-120 max-w-full" items='[{"brand":"Acme Skin","tone":2},{"brand":"Acme Studio","tone":1},{"brand":"Acme Drinks","tone":3},{"brand":"Acme Motors","tone":1},{"light":true,"seed":0},{"brand":"Acme Drinks","tone":4},{"brand":"Acme Fit","tone":3},{"brand":"Acme Studio","tone":2},{"brand":"Acme Skin","tone":4}]'></spyglass-creative-grid>import { CreativeGrid } from '@/react/components/site/CreativeGrid'
// The ad's three up: 3/4 creatives under the search bar.
const items = [
{ brand: 'Acme Skin', caption: 'Glow in two steps.', tone: 3 as const },
{ brand: 'Acme Skin', caption: 'The travel kit.', tone: 2 as const },
{ brand: 'Acme Skin', caption: 'Night repair.', tone: 4 as const },
]
export default function ThreeUp() {
return <CreativeGrid items={items} ratio="3/4" gap="md" />
}<!-- The ad's three up: 3/4 creatives under the search bar. -->
<spyglass-creative-grid ratio="3/4" gap="md" items='[{"brand":"Acme Skin","caption":"Glow in two steps.","tone":3},{"brand":"Acme Skin","caption":"The travel kit.","tone":2},{"brand":"Acme Skin","caption":"Night repair.","tone":4}]'></spyglass-creative-grid>Source
import { BrandLight } from '@/react/components/visuals/BrandLight'
import { CreativeCard, type CreativeItem, type CreativeRatio } from '@/react/components/site/CreativeCard'
import { cn } from '@/react/lib/cn'
// Creatives in a grid, as the assets set them: the post's three by three of squares 8px apart with a light tile among
// them (Post, Any brand or creator), or the ad's three up in 3/4 (Ad, The only creative search engine). Every cell
// takes the same shape; an item with `light` is a tile of the brand light.
export interface CreativeGridProps {
items: CreativeItem[]
/** 2, 3 or 4 columns (4 falls to 2 on phones). */
columns?: 2 | 3 | 4
/** Every cell's shape. */
ratio?: Exclude<CreativeRatio, 'fill'>
/** sm: the post's 8px. md: the ad's wider gutter. */
gap?: 'sm' | 'md'
className?: string
}
const COLUMNS = { 2: 'grid-cols-2', 3: 'grid-cols-3', 4: 'grid-cols-4 max-sm:grid-cols-2' }
const GAPS = { sm: 'gap-2', md: 'gap-6 max-sm:gap-3' }
export function CreativeGrid({ items, columns = 3, ratio = '1/1', gap = 'sm', className }: CreativeGridProps) {
return (
<div data-ds="creative-grid" className={cn('grid', COLUMNS[columns] ?? COLUMNS[3], GAPS[gap] ?? GAPS.sm, className)}>
{items.map(({ light, seed, ...item }, i) => (
<div key={i} className="min-w-0" style={{ aspectRatio: ratio.replace('/', ' / ') }}>
{light ? <BrandLight variant="tile" seed={seed ?? i} cover className="size-full rounded-container" /> : <CreativeCard {...item} ratio="fill" />}
</div>
))}
</div>
)
}
export default CreativeGrid// 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 } from 'lit'
import { ifDefined } from 'lit/directives/if-defined.js'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import '@/elements/components/site/creative-card'
import '@/elements/components/visuals/brand-light'
import styles from 'virtual:tw'
// CreativeGrid.tsx as <spyglass-creative-grid>: creatives in a grid, every cell the same shape (`ratio`), an item with
// `light` a tile of the brand light. `items` is a list (JSON attribute or property) of creatives.
export interface CreativeItem { src?: string; alt?: string; fit?: ImageFit; position?: string; brand?: string; caption?: string; tone?: 1 | 2 | 3 | 4; href?: string; light?: boolean; seed?: number }
const COLUMNS: Record<number, string> = { 2: 'grid-cols-2', 3: 'grid-cols-3', 4: 'grid-cols-4 max-sm:grid-cols-2' }
const GAPS: Record<string, string> = { sm: 'gap-2', md: 'gap-6 max-sm:gap-3' }
/**
* @summary Creatives in a grid, with light tiles among them.
*/
export class CreativeGrid extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="creative-grid"]'))
static properties = { items: { type: Array }, columns: { type: Number }, ratio: {}, gap: {} }
/** The creatives (light: true for a light tile). */
items: CreativeItem[] = []
/** 2, 3 or 4 columns. */
columns: 2 | 3 | 4 = 3
/** Every cell's shape. */
ratio = '1/1'
/** sm or md. */
gap: 'sm' | 'md' = 'sm'
render() {
const cls = ['grid', COLUMNS[this.columns] ?? COLUMNS[3], GAPS[this.gap] ?? GAPS.sm].join(' ')
return html`<div data-ds="creative-grid" class=${cls}>${(this.items ?? []).map((it, i) => html`<div class="min-w-0" style="aspect-ratio: ${this.ratio.replace('/', ' / ')};">${it.light ? html`<spyglass-brand-light variant="tile" seed=${it.seed ?? i} cover class="size-full rounded-container"></spyglass-brand-light>` : html`<spyglass-creative-card ratio="fill" src=${ifDefined(it.src)} fit=${ifDefined(it.fit)} position=${ifDefined(it.position)} alt=${ifDefined(it.alt)} brand=${ifDefined(it.brand)} caption=${ifDefined(it.caption)} tone=${ifDefined(it.tone)} href=${ifDefined(it.href)}></spyglass-creative-card>`}</div>`)}</div>`
}
}
define('creative-grid', CreativeGrid)Reference: Figma page 8: Post, Any brand or creator (200x200 creatives 8px apart, a Light tile in the middle); Ad, The only creative search engine (three creatives 296x400, 32px apart).