Site
Testimonial
The testimonial ad: a 4/5 headshot in the brand corner, the quote in Funnel Display in curly quotes, the name in DM Sans and the role and company in capitals.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add testimonial<script type="module" src="/spyglass-ds/elements/testimonial.js"></script>“We see every launch in our category the day it goes live.”
“Our Monday brief takes ten minutes now. It used to take a morning.”
Usage
One customer's words on a page or in an ad, with their real name, role and photo. Stacked as the ad sets it, or side by side on a wide page.
Never
- A made-up quote presented as a real customer's
- Stars, logos or a card around it
- More than one testimonial in view at once
The examples are Acme placeholders: put a real customer's quote, name, position and headshot (image) in their place. image={false} (React) or image="false" leaves the headshot out. image takes a src or an image slot (src, alt, fit, position); the placeholder headshot carries data-ds-placeholder.
Adds with it: creative-card
Props
The web component takes the same as attributes or properties (<spyglass-testimonial>); title is heading there.
<Testimonial>
| Prop | Type | Default |
|---|---|---|
quote | string The words, without quote marks. | |
name | string | |
position | string Role and company, shown in capitals. | |
image | string | ImageSlot | false The headshot (a src, or { src, alt, fit, position }), the placeholder (undefined) or none (false). | |
layout | 'stacked' | 'side' stacked (the ad) or side. | 'stacked' |
className | string |
Examples
The same example in React and as web components; both render identically.
import { Testimonial } from '@/react/components/site/Testimonial'
// As the ad sets it: the headshot above the quote.
export default function Stacked() {
return <Testimonial className="w-160 max-w-full" quote="We see every launch in our category the day it goes live." name="Alex Rivera" position="Head of growth, Acme" />
}<!-- As the ad sets it: the headshot above the quote. -->
<spyglass-testimonial class="w-160 max-w-full" quote="We see every launch in our category the day it goes live." name="Alex Rivera" position="Head of growth, Acme"></spyglass-testimonial>import { Testimonial } from '@/react/components/site/Testimonial'
// On a wide page: the headshot beside the words.
export default function Side() {
return <Testimonial layout="side" quote="Our Monday brief takes ten minutes now. It used to take a morning." name="Sam Okafor" position="Creative director, Acme Studio" />
}<!-- On a wide page: the headshot beside the words. -->
<spyglass-testimonial layout="side" quote="Our Monday brief takes ten minutes now. It used to take a morning." name="Sam Okafor" position="Creative director, Acme Studio"></spyglass-testimonial>Source
import { CreativeCard } from '@/react/components/site/CreativeCard'
import { cn } from '@/react/lib/cn'
import { toSlot, type ImageSlot } from '@/lib/image'
// The testimonial ad (Ad, Testimonial): a 4/5 headshot in the brand corner, the quote in Funnel Display (40px on the
// canvas, 28px here) in curly quotes, the name in DM Sans and the position (role and company) in capitals under it. `stacked` is the ad (the
// headshot half the width above the quote); `side` puts the headshot beside the words, for a page. Without `image`
// the headshot is the neutral placeholder, and with `image={false}` there is none. `image` is a src or an image slot
// ({ src, alt, fit, position }); the alt defaults to the name.
export interface TestimonialProps {
/** The words, without quote marks. */
quote: string
name: string
/** Role and company, shown in capitals. */
position?: string
/** The headshot (a src, or { src, alt, fit, position }), the placeholder (undefined) or none (false). */
image?: string | ImageSlot | false
/** stacked (the ad) or side. */
layout?: 'stacked' | 'side'
className?: string
}
export function Testimonial({ quote, name, position, image, layout = 'stacked', className }: TestimonialProps) {
const side = layout === 'side'
const shot = toSlot(image || undefined)
return (
<figure data-ds="testimonial" className={cn('m-0 grid text-fg', side ? 'grid-cols-5 items-center gap-12 max-md:grid-cols-1 max-md:gap-8' : 'gap-10 max-sm:gap-8', className)}>
{image !== false && (
<div className={side ? 'col-span-2 max-md:col-span-1 max-md:w-1/2' : 'w-1/2'}>
<CreativeCard src={shot.src || undefined} alt={shot.src ? shot.alt ?? name : `${name}, headshot`} fit={shot.fit} position={shot.position} tone={3} ratio="4/5" />
</div>
)}
<div className={cn('grid gap-6', side && 'col-span-3 max-md:col-span-1')}>
<blockquote className="m-0 type-heading-2 leading-(--ds-text-display-leading)">
<p>{`“${quote}”`}</p>
</blockquote>
<figcaption className="grid gap-1">
<span className="type-body text-fg">{name}</span>
{position && <span className="type-label text-fg-muted">{position}</span>}
</figcaption>
</div>
</figure>
)
}
export default Testimonial// 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 '@/elements/components/site/creative-card'
import { toSlot, type ImageSlot } from '@/lib/image'
import styles from 'virtual:tw'
// Testimonial.tsx as <spyglass-testimonial>: a 4/5 headshot, the quote in Funnel Display in curly quotes, the name and
// the position in capitals (not `role`, which is the host's ARIA role). `layout` stacked (the ad) or side. `image` is the headshot's src; without it the placeholder,
// and image="false" draws none. As a property, `image` also takes { src, alt, fit, position }.
/**
* @summary A testimonial: headshot, quote, name and role.
*/
export class Testimonial extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="testimonial"]'))
static properties = { quote: {}, name: {}, position: {}, image: {}, arrangement: { attribute: 'layout' } }
/** The words, without quote marks. */
quote = ''
name = ''
/** Role and company, shown in capitals. */
position?: string
/** The headshot's src (or, as a property, { src, alt, fit, position }), or "false" for none. */
image?: string | ImageSlot
/** stacked or side (the layout attribute). */
arrangement: 'stacked' | 'side' = 'stacked'
render() {
const side = this.arrangement === 'side'
const none = this.image === 'false'
const shot = none ? {} : toSlot(this.image)
const src = shot.src || undefined
return html`<figure data-ds="testimonial" class=${['m-0 grid text-fg', side ? 'grid-cols-5 items-center gap-12 max-md:grid-cols-1 max-md:gap-8' : 'gap-10 max-sm:gap-8'].join(' ')}>${none ? nothing : html`<div class=${side ? 'col-span-2 max-md:col-span-1 max-md:w-1/2' : 'w-1/2'}><spyglass-creative-card .src=${src} alt=${src ? shot.alt ?? this.name : `${this.name}, headshot`} .fit=${shot.fit} .position=${shot.position} tone="3" ratio="4/5"></spyglass-creative-card></div>`}<div class=${['grid gap-6', side ? 'col-span-3 max-md:col-span-1' : ''].filter(Boolean).join(' ')}><blockquote class="m-0 type-heading-2 leading-(--ds-text-display-leading)"><p>${`“${this.quote}”`}</p></blockquote><figcaption class="grid gap-1"><span class="type-body text-fg">${this.name}</span>${this.position ? html`<span class="type-label text-fg-muted">${this.position}</span>` : nothing}</figcaption></div></figure>`
}
}
define('testimonial', Testimonial)Reference: Figma page 8: Ad, Testimonial (Headshot 464x580 at 64,160; the quote 920 wide at 812; the name at 1010; the role in capitals at 1050).