Site
Creative ring
Twelve tiles around the middle of a square in the post's exact places: eight creatives, four tiles of the brand light, and the lockup inside.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add creative-ring<script type="module" src="/spyglass-ds/elements/creative-ring.js"></script>Usage
A cover, a social post or the center of a section that says everything is in one place. The middle holds the lockup, nothing else.
Never
- A headline or a paragraph in the middle: only the lockup
- Tiles moved off the post's places, or spun
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-ring>); title is heading there.
<CreativeRing>
| Prop | Type | Default |
|---|---|---|
items | CreativeItem[] Up to eight creatives, clockwise from the top (fewer repeat). | |
seed | number The first light tile's seed; the others follow it. | 0 |
children | ReactNode What sits in the middle (the lockup). | |
className | string |
Examples
The same example in React and as web components; both render identically.
import { CreativeRing } from '@/react/components/site/CreativeRing'
import { Logo } from '@/react/components/visuals/Logo'
// The post's ring around the lockup.
const items = [
{ brand: 'Acme Skin', tone: 4 as const },
{ brand: 'Acme Studio', tone: 2 as const },
{ brand: 'Acme Motors', tone: 3 as const },
{ brand: 'Acme Fit', tone: 1 as const },
{ brand: 'Acme Drinks', tone: 3 as const },
{ brand: 'Acme Drinks', tone: 4 as const },
{ brand: 'Acme Motors', tone: 2 as const },
{ brand: 'Acme Fit', tone: 3 as const },
]
export default function Ring() {
return (
<CreativeRing items={items} className="w-140 max-w-full">
<Logo height={20} />
</CreativeRing>
)
}<!-- The post's ring around the lockup. -->
<spyglass-creative-ring class="w-140 max-w-full" items='[{"brand":"Acme Skin","tone":4},{"brand":"Acme Studio","tone":2},{"brand":"Acme Motors","tone":3},{"brand":"Acme Fit","tone":1},{"brand":"Acme Drinks","tone":3},{"brand":"Acme Drinks","tone":4},{"brand":"Acme Motors","tone":2},{"brand":"Acme Fit","tone":3}]'>
<spyglass-logo height="20"></spyglass-logo>
</spyglass-creative-ring>Source
import type { ReactNode } from 'react'
import { BrandLight } from '@/react/components/visuals/BrandLight'
import { CreativeCard, type CreativeItem } from '@/react/components/site/CreativeCard'
import { RING_FRAME, RING_SLOTS, placeAt } from '@/lib/creative-layouts'
import { cn } from '@/react/lib/cn'
// The creative ring (Post, Creative ring): twelve tiles around the middle of a square, clockwise from the top, in the
// post's exact places and sizes; eight are creatives (squares, 7/5 and tall) and four are tiles of the brand light.
// The children sit in the middle: the lockup, as the post has it. The ring scales with its width.
export interface CreativeRingProps {
/** Up to eight creatives, clockwise from the top (fewer repeat). */
items: CreativeItem[]
/** The first light tile's seed; the others follow it. */
seed?: number
/** What sits in the middle (the lockup). */
children?: ReactNode
className?: string
}
export function CreativeRing({ items, seed = 0, children, className }: CreativeRingProps) {
let n = 0
let lights = 0
return (
<div data-ds="creative-ring" className={cn('relative aspect-square', className)}>
{RING_SLOTS.map((slot, i) => {
const at = placeAt(slot, RING_FRAME, RING_FRAME)
if (slot.light) return (
<div key={i} className="absolute" style={at}>
<BrandLight variant="tile" seed={seed + lights++} cover className="size-full rounded-container" />
</div>
)
const { light: _light, seed: _seed, ...item } = items.length ? items[n++ % items.length] : ({} as CreativeItem)
return (
<div key={i} className="absolute" style={at}>
<CreativeCard {...item} ratio="fill" />
</div>
)
})}
{children && <div className="absolute inset-0 flex items-center justify-center">{children}</div>}
</div>
)
}
export default CreativeRing// 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 { styleMap } from 'lit/directives/style-map.js'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { RING_FRAME, RING_SLOTS, placeAt } from '@/lib/creative-layouts'
import '@/elements/components/site/creative-card'
import '@/elements/components/visuals/brand-light'
import styles from 'virtual:tw'
// CreativeRing.tsx as <spyglass-creative-ring>: twelve tiles around a square in the post's places, eight creatives
// (`items`, clockwise from the top) and four light tiles (from `seed`). The default slot sits in the middle.
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 }
/**
* @summary The creative ring: creatives and light tiles around the lockup.
* @slot - What sits in the middle (the lockup).
*/
export class CreativeRing extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="creative-ring"]'))
static properties = { items: { type: Array }, seed: { type: Number } }
/** Up to eight creatives, clockwise from the top. */
items: CreativeItem[] = []
/** The first light tile's seed. */
seed = 0
render() {
const items = this.items ?? []
let n = 0
let lights = 0
return html`<div data-ds="creative-ring" class="relative aspect-square">${RING_SLOTS.map((slot) => {
const at = styleMap(placeAt(slot, RING_FRAME, RING_FRAME))
if (slot.light) return html`<div class="absolute" style=${at}><spyglass-brand-light variant="tile" seed=${this.seed + lights++} cover class="size-full rounded-container"></spyglass-brand-light></div>`
const it: CreativeItem = items.length ? items[n++ % items.length] : {}
return html`<div class="absolute" style=${at}><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>`
})}${this.hasSlot() ? html`<div class="absolute inset-0 flex items-center justify-center"><slot></slot></div>` : nothing}</div>`
}
}
define('creative-ring', CreativeRing)Reference: Figma page 8: Post, Creative ring (1080x1080; creatives 128x128, 112x146 and 160x114; Light tile 112x145 and 128x128; Spyglass lockup 261x40 in the middle).