Blocks
Testimonial block
One customer as a section: an optional label in capitals over the testimonial, the headshot beside the words or above them, on Black or on the #262626 fill.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add testimonial-block<script type="module" src="/spyglass-ds/elements/testimonial-block.js"></script>From a customer
“We see every launch in our category the day it goes live.”
“This is the only tool that gives me full competitive visibility across every account I manage.”
Usage
A customer's own words on a home, product or pricing page.
Never
- A quote written for a customer, or a real person's name without permission
- Several testimonials in one block
- Stars, ratings or company logos beside the quote
image takes a src or an image slot (src, alt, fit, position).
Adds with it: creative-card, testimonial
Props
The web component takes the same as attributes or properties (<spyglass-testimonial-block>); title is heading there.
<TestimonialBlock>
| 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). | |
label | ReactNode A line in capitals above it. | |
layout | 'side' | 'stacked' side or stacked. | 'side' |
card | boolean On the card fill. | false |
className | string |
Examples
The same example in React and as web components; both render identically.
import { TestimonialBlock } from '@/react/components/blocks/TestimonialBlock'
// An Acme customer, the placeholder headshot beside the words.
export default function Side() {
return <TestimonialBlock label="From a customer" quote="We see every launch in our category the day it goes live." name="Alex Rivera" position="Head of growth, Acme" />
}<!-- An Acme customer, the placeholder headshot beside the words. -->
<spyglass-testimonial-block label="From a customer" quote="We see every launch in our category the day it goes live." name="Alex Rivera" position="Head of growth, Acme"></spyglass-testimonial-block>import { TestimonialBlock } from '@/react/components/blocks/TestimonialBlock'
// The testimonial ad's arrangement on the card fill, without a headshot.
export default function Card() {
return <TestimonialBlock card layout="stacked" image={false} quote="This is the only tool that gives me full competitive visibility across every account I manage." name="Acme customer" position="Head of growth, Acme" />
}<!-- The testimonial ad's arrangement on the card fill, without a headshot. -->
<spyglass-testimonial-block card layout="stacked" image="false" quote="This is the only tool that gives me full competitive visibility across every account I manage." name="Acme customer" position="Head of growth, Acme"></spyglass-testimonial-block>Source
import type { ReactNode } from 'react'
import { Testimonial } from '@/react/components/site/Testimonial'
import type { ImageSlot } from '@/lib/image'
import { cn } from '@/react/lib/cn'
// One customer, as a section: an optional label in capitals, then the testimonial with the headshot beside the words
// (`side`, as a page sets it) or above them (`stacked`, as the ad does). `card` sets it on the #262626 fill. The quote
// is a customer's own words: never write one for them.
export interface TestimonialBlockProps {
/** 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
/** A line in capitals above it. */
label?: ReactNode
/** side or stacked. */
layout?: 'side' | 'stacked'
/** On the card fill. */
card?: boolean
className?: string
}
export function TestimonialBlock({ quote, name, position, image, label, layout = 'side', card = false, className }: TestimonialBlockProps) {
return (
<section data-ds="testimonial-block" className={cn('grid gap-8 text-fg', card && 'rounded-container bg-surface-raised p-12 max-sm:p-6', className)}>
{label && <p className="type-label text-fg-muted">{label}</p>}
<Testimonial quote={quote} name={name} position={position} image={image} layout={layout} />
</section>
)
}
export default TestimonialBlock// 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/testimonial'
import type { ImageSlot } from '@/lib/image'
import styles from 'virtual:tw'
// TestimonialBlock.tsx as <spyglass-testimonial-block>: a `label` in capitals over the testimonial, the headshot
// beside the words (layout="side") or above them (layout="stacked"); `card` sets it on the #262626 fill.
/**
* @summary One customer, as a section.
*/
export class TestimonialBlock extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="testimonial-block"]'))
static properties = { quote: {}, name: {}, position: {}, image: {}, label: {}, arrangement: { attribute: 'layout' }, card: { type: Boolean } }
/** The words, without quote marks. */
quote = ''
name = ''
/** Role and company, shown in capitals. */
position?: string
/** The headshot's src, or "false" for none. */
image?: string | ImageSlot
/** A line in capitals above it. */
label?: string
/** side or stacked (the layout attribute). */
arrangement: 'side' | 'stacked' = 'side'
/** On the card fill. */
card = false
render() {
return html`<section data-ds="testimonial-block" class=${['grid gap-8 text-fg', this.card ? 'rounded-container bg-surface-raised p-12 max-sm:p-6' : ''].filter(Boolean).join(' ')}>${this.label ? html`<p class="type-label text-fg-muted">${this.label}</p>` : nothing}<spyglass-testimonial quote=${this.quote} name=${this.name} .position=${this.position} .image=${this.image} layout=${this.arrangement}></spyglass-testimonial></section>`
}
}
define('testimonial-block', TestimonialBlock)Reference: Built from the library (testimonial); Figma page 8: Ad, Testimonial (the quote, name and role; the Figma's named person and photo are never shipped).