Components

Empty

What shows where a list has nothing in it yet: a dashed hairline with the brand corner, a Lucide icon in a #262626 tile, a Funnel Display title, one muted line and the actions that fill it.

Install

React apps get the React files; every other stack gets the web component.

npx spyglass-ds add empty
<script type="module" src="/spyglass-ds/elements/empty.js"></script>
An empty board

No creatives saved yet.

Search for ads, product shots and UGC, then save the ones that work to this board.

No results

Nothing matches that search.

Try fewer words, or search a format instead of a brand.

Usage

A new board, a search with no results, a list before the first item.

Never

  • Illustrations or the brand light inside it
  • An empty state with no way forward
  • A spectrum color for the icon

Props

The web component takes the same as attributes or properties (<spyglass-empty>); title is heading there.

<Empty>

PropTypeDefault
titlestring

What is missing, in Funnel Display.

descriptionstring

One muted line on how to fill it.

iconReactNode

A 20px Lucide icon.

Examples

The same example in React and as web components; both render identically.

react/examples/empty/Board.tsx
import { Bookmark, Search } from 'lucide-react'
import { Button } from '@/react/components/ui/Button'
import { Empty } from '@/react/components/ui/Empty'
// A new board with nothing saved yet, and the way to fill it.

export default function Board() {
  return (
    <Empty className="max-w-160" icon={<Bookmark size={20} strokeWidth={1.5} />} title="No creatives saved yet." description="Search for ads, product shots and UGC, then save the ones that work to this board.">
      <Button><Search size={16} strokeWidth={1.5} aria-hidden="true" />Search creatives</Button>
      <Button variant="secondary">Import from a link</Button>
    </Empty>
  )
}
elements/examples/empty/Board.html
<!-- A new board with nothing saved yet, and the way to fill it. -->
<spyglass-empty class="max-w-160" heading="No creatives saved yet." description="Search for ads, product shots and UGC, then save the ones that work to this board.">
  <i data-lucide="bookmark" data-size="20" data-stroke-width="1.5" slot="icon"></i>
  <spyglass-button><i data-lucide="search" data-size="16" data-stroke-width="1.5" aria-hidden="true"></i>Search creatives</spyglass-button>
  <spyglass-button variant="secondary">Import from a link</spyglass-button>
</spyglass-empty>
react/examples/empty/Search.tsx
import { Button } from '@/react/components/ui/Button'
import { Empty } from '@/react/components/ui/Empty'
// A search with no results, without an icon: what to try instead.

export default function Search() {
  return (
    <Empty className="max-w-160" title="Nothing matches that search." description="Try fewer words, or search a format instead of a brand.">
      <Button variant="secondary">Clear filters</Button>
    </Empty>
  )
}
elements/examples/empty/Search.html
<!-- A search with no results, without an icon: what to try instead. -->
<spyglass-empty class="max-w-160" heading="Nothing matches that search." description="Try fewer words, or search a format instead of a brand.">
  <spyglass-button variant="secondary">Clear filters</spyglass-button>
</spyglass-empty>

Source

react/components/ui/Empty.tsx
import type { HTMLAttributes, ReactNode } from 'react'
import { cn } from '@/react/lib/cn'

// shadcn's empty in the brand: what shows where a list has nothing in it yet. A dashed #666666 hairline with the brand
// corner on Black, a 20px Lucide icon in a #262626 tile, a Funnel Display title, one muted line on what is missing and
// the actions that fill it. No illustrations, and never without a way forward.
export interface EmptyProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
  /** What is missing, in Funnel Display. */
  title: string
  /** One muted line on how to fill it. */
  description?: string
  /** A 20px Lucide icon. */
  icon?: ReactNode
}

export function Empty({ title, description, icon, className, children, ...rest }: EmptyProps) {
  return (
    <div data-ds="empty" className={cn('flex w-full flex-col items-center gap-2 rounded-container border border-dashed border-edge-strong px-6 py-12 text-center', className)} {...rest}>
      {icon && <span className="mb-2 flex size-10 items-center justify-center rounded-control bg-surface-raised text-fg" aria-hidden="true">{icon}</span>}
      <p className="type-heading-4 text-fg">{title}</p>
      {description && <p className="max-w-sm type-ui text-fg-muted">{description}</p>}
      {children && <div className="mt-4 flex flex-wrap justify-center gap-3">{children}</div>}
    </div>
  )
}

export default Empty
react/lib/cn.ts
// 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(' ')
}
elements/components/ui/empty.ts
import { html, nothing } from 'lit'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import styles from 'virtual:tw'

// Empty.tsx as <spyglass-empty>: what shows where a list has nothing in it yet. A dashed #666666 hairline with the
// brand corner on Black, a 20px Lucide icon in a #262626 tile (the `icon` slot), a Funnel Display title (`heading`,
// React's `title`), one muted line on what is missing and the actions that fill it (the default slot).

/**
 * @summary What shows where a list is empty: an icon, a title, a line and the actions that fill it.
 * @slot - The actions (buttons).
 * @slot icon - A 20px Lucide icon.
 */
export class Empty extends DsElement {
	static styles = [DsElement.styles, styles]
	protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="empty"]'))
	static properties = { heading: {}, description: {} }

	/** What is missing (React's `title`; `title` is HTML's tooltip attribute). */
	heading = ''
	/** One muted line on how to fill it. */
	description?: string

	render() {
		return html`<div data-ds="empty" class="flex w-full flex-col items-center gap-2 rounded-container border border-dashed border-edge-strong px-6 py-12 text-center">${this.hasSlot('icon') ? html`<span class="mb-2 flex size-10 items-center justify-center rounded-control bg-surface-raised text-fg" aria-hidden="true"><slot name="icon"></slot></span>` : nothing}<p class="type-heading-4 text-fg">${this.heading}</p>${this.description ? html`<p class="max-w-sm type-ui text-fg-muted">${this.description}</p>` : nothing}${this.hasSlot() ? html`<div class="mt-4 flex flex-wrap justify-center gap-3"><slot></slot></div>` : nothing}</div>`
	}
}

define('empty', Empty)

Reference: Derived from the guidelines: Funnel Display titles, DM Sans muted lines, the #262626 card fill, neutral hairlines and the brand's voice (short declarative sentences ending with a period). shadcn's empty for anatomy..