Components
Item
A row: media, a title in DM Sans Medium with a muted line under it, and actions at the end. No fill, a hairline box or the card's #262626 fill. ItemGroup puts a hairline between rows.
Install
React apps get the React files; every other stack gets the web component.
npx spyglass-ds add item<script type="module" src="/spyglass-ds/elements/item.js"></script>Usage
A board, a tracked brand, a setting or a notification as one row; a list of them in a card. With href the whole row is a link.
Never
- Buttons inside a row that is a link
- A chevron or arrow that moves on hover
- A row of rows for many columns: use Table
- A shadow under an outlined row
Adds with it: packages lucide-react
Props
The web component takes the same as attributes or properties (<spyglass-item>); title is heading there.
<Item>
| Prop | Type | Default |
|---|---|---|
title | string The title. | |
description | string A muted line under the title (two lines at most). | |
variant | ItemVariant default (no fill), outline (a hairline box) or muted (the card's fill). | 'default' |
size | ItemSize default or sm (tighter). | 'default' |
href | string The whole row opens this. | |
arrow | boolean A chevron at the end of a link row. | |
media | ReactNode Before the title: an icon, a logo, a thumbnail. | |
actions | ReactNode At the end, on a row without href: buttons, a tag, a time. | |
className | string | |
children | ReactNode The title, in place of `title`. |
<ItemGroup>
| Prop | Type | Default |
|---|
Examples
The same example in React and as web components; both render identically.
import { Bookmark, Sparkles } from 'lucide-react'
import { Button } from '@/react/components/ui/Button'
import { Item } from '@/react/components/ui/Item'
// A board in a hairline box with its action, a tighter row on the card's fill, and a plain row.
export default function Variants() {
return (
<div className="flex w-full max-w-md flex-col gap-4">
<Item variant="outline" title="Acme hooks" description="48 creatives from 12 brands, updated today." media={<Bookmark size={20} strokeWidth={1.5} aria-hidden="true" />} actions={<Button variant="secondary" size="sm">Open</Button>} />
<Item variant="muted" size="sm" title="New creatives found" description="12 since your last visit." media={<Sparkles size={16} strokeWidth={1.5} aria-hidden="true" />} actions={<Button variant="ghost" size="sm">Review</Button>} />
<Item title="Weekly digest" description="Every Monday, the ads your rivals started running." actions={<Button variant="secondary" size="sm">Turn on</Button>} />
</div>
)
}<!-- A board in a hairline box with its action, a tighter row on the card's fill, and a plain row. -->
<div class="flex w-full max-w-md flex-col gap-4">
<spyglass-item variant="outline" heading="Acme hooks" description="48 creatives from 12 brands, updated today.">
<i data-lucide="bookmark" slot="media" data-size="20" data-stroke-width="1.5" aria-hidden="true"></i>
<spyglass-button slot="actions" variant="secondary" size="sm">Open</spyglass-button>
</spyglass-item>
<spyglass-item variant="muted" size="sm" heading="New creatives found" description="12 since your last visit.">
<i data-lucide="sparkles" slot="media" data-size="16" data-stroke-width="1.5" aria-hidden="true"></i>
<spyglass-button slot="actions" variant="ghost" size="sm">Review</spyglass-button>
</spyglass-item>
<spyglass-item heading="Weekly digest" description="Every Monday, the ads your rivals started running.">
<spyglass-button slot="actions" variant="secondary" size="sm">Turn on</spyglass-button>
</spyglass-item>
</div>import { Item } from '@/react/components/ui/Item'
import { ItemGroup } from '@/react/components/ui/ItemGroup'
// Boards in a card, each row a link with a chevron, a hairline between them.
const BOARDS = [
{ name: 'Acme hooks', count: '48 creatives' },
{ name: 'Acme summer launch', count: '112 creatives' },
{ name: 'UGC openers', count: '36 creatives' },
]
export default function Boards() {
return (
<div className="w-full max-w-md rounded-container bg-surface-raised p-2">
<ItemGroup>
{BOARDS.map((b) => (
<li key={b.name}><Item href="#boards" arrow size="sm" title={b.name} description={b.count} /></li>
))}
</ItemGroup>
</div>
)
}<!-- Boards in a card, each row a link with a chevron, a hairline between them. -->
<div class="w-full max-w-md rounded-container bg-surface-raised p-2">
<spyglass-item-group>
<li><spyglass-item href="#boards" arrow size="sm" heading="Acme hooks" description="48 creatives"></spyglass-item></li>
<li><spyglass-item href="#boards" arrow size="sm" heading="Acme summer launch" description="112 creatives"></spyglass-item></li>
<li><spyglass-item href="#boards" arrow size="sm" heading="UGC openers" description="36 creatives"></spyglass-item></li>
</spyglass-item-group>
</div>Source
import { ChevronRight } from 'lucide-react'
import type { ReactNode } from 'react'
import { cn } from '@/react/lib/cn'
// A row: media, a title in DM Sans Medium with a muted line under it, and what goes at the end. `variant` default has
// no fill (rows in a list, split by ItemGroup's hairlines), outline a #363636 hairline box, muted the card's #262626
// fill; both boxes take the brand corner. `size` sm is tighter. With `href` the whole row is one link that takes the
// ghost fill under the pointer (160ms), and `arrow` adds a chevron that brightens with it and never moves. A link holds
// no buttons: `actions` only show on a row without `href`.
export type ItemVariant = 'default' | 'outline' | 'muted'
export type ItemSize = 'default' | 'sm'
const VARIANTS: Record<ItemVariant, string> = {
default: 'bg-transparent',
outline: 'rounded-container border border-edge',
muted: 'rounded-container bg-surface-raised',
}
const SIZES: Record<ItemSize, string> = { default: 'gap-4 p-4', sm: 'gap-3 px-4 py-3' }
export interface ItemProps {
/** The title. */
title?: string
/** A muted line under the title (two lines at most). */
description?: string
/** default (no fill), outline (a hairline box) or muted (the card's fill). */
variant?: ItemVariant
/** default or sm (tighter). */
size?: ItemSize
/** The whole row opens this. */
href?: string
/** A chevron at the end of a link row. */
arrow?: boolean
/** Before the title: an icon, a logo, a thumbnail. */
media?: ReactNode
/** At the end, on a row without href: buttons, a tag, a time. */
actions?: ReactNode
className?: string
/** The title, in place of `title`. */
children?: ReactNode
}
export function Item({ title, description, variant = 'default', size = 'default', href, arrow, media, actions, className, children }: ItemProps) {
const classes = cn('group/item flex min-w-0 items-center', VARIANTS[variant] ?? VARIANTS.default, SIZES[size] ?? SIZES.default)
const body = (
<>
{media && <span className="flex shrink-0 items-center justify-center text-fg-soft">{media}</span>}
<span className="flex min-w-0 flex-1 flex-col gap-1">
<span className="truncate type-ui-strong text-fg">{children ?? title}</span>
{description && <span className="line-clamp-2 type-ui text-fg-muted">{description}</span>}
</span>
</>
)
if (href) {
return (
<a data-ds="item" href={href} className={cn(classes, 'cursor-pointer rounded-container transition-[background-color] duration-160 ease-standard hover:bg-action-ghost-hover', className)}>
{body}
{arrow && <ChevronRight size={16} strokeWidth={1.5} className="shrink-0 text-fg-muted transition-[color] duration-160 ease-standard group-hover/item:text-fg" aria-hidden="true" />}
</a>
)
}
return (
<div data-ds="item" className={cn(classes, className)}>
{body}
{actions && <span className="flex shrink-0 items-center gap-2">{actions}</span>}
</div>
)
}
export default Itemimport type { HTMLAttributes } from 'react'
import { cn } from '@/react/lib/cn'
// Rows of one list, a #363636 hairline between each. Put Item rows in it, one per <li>.
export type ItemGroupProps = HTMLAttributes<HTMLUListElement>
export function ItemGroup({ className, children, ...rest }: ItemGroupProps) {
return <ul data-ds="item-group" className={cn('flex flex-col [&>*+*]:border-t [&>*+*]:border-edge', className)} {...rest}>{children}</ul>
}
export default ItemGroup// 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 { ChevronRight } from 'lucide'
import { DsElement, define, HostLayoutController } from '@/elements/lib/element'
import { icon } from '@/elements/lib/icon'
import styles from 'virtual:tw'
// Item.tsx as <spyglass-item>: a row with media, a title in DM Sans Medium with a muted line under it, and actions at
// the end. `variant` default (no fill), outline (a hairline box) or muted (the card's fill); `size` sm is tighter. With
// `href` the whole row is one link that takes the ghost fill under the pointer; `arrow` adds a chevron that brightens
// with it and never moves. A link holds no buttons: the actions slot only shows on a row without href.
const VARIANTS = {
default: 'bg-transparent',
outline: 'rounded-container border border-edge',
muted: 'rounded-container bg-surface-raised',
} as const
const SIZES = { default: 'gap-4 p-4', sm: 'gap-3 px-4 py-3' } as const
/**
* @summary A row: media, a title and a muted line, and actions; with href, the whole row is a link.
* @slot - The title, in place of `heading`.
* @slot media - Before the title: an icon, a logo, a thumbnail.
* @slot actions - At the end, on a row without href only.
*/
export class Item extends DsElement {
static styles = [DsElement.styles, styles]
protected readonly layout = new HostLayoutController(this, () => this.renderRoot.querySelector<HTMLElement>('[data-ds="item"]'))
static properties = { heading: {}, description: {}, variant: { reflect: true }, size: { reflect: true }, href: {}, arrow: { type: Boolean } }
/** The title (React's `title`; `title` is HTML's tooltip attribute). */
heading?: string
/** A muted line under the title. */
description?: string
/** default, outline or muted. */
variant: keyof typeof VARIANTS = 'default'
/** default or sm. */
size: keyof typeof SIZES = 'default'
/** The whole row opens this. */
href?: string
/** A chevron at the end of a link row. */
arrow = false
render() {
const classes = ['group/item flex min-w-0 items-center', VARIANTS[this.variant] ?? VARIANTS.default, SIZES[this.size] ?? SIZES.default].join(' ')
const body = html`${this.hasSlot('media') ? html`<span class="flex shrink-0 items-center justify-center text-fg-soft"><slot name="media"></slot></span>` : nothing}<span class="flex min-w-0 flex-1 flex-col gap-1"><span class="truncate type-ui-strong text-fg"><slot></slot>${this.hasSlot() ? nothing : this.heading}</span>${this.description ? html`<span class="line-clamp-2 type-ui text-fg-muted">${this.description}</span>` : nothing}</span>`
if (this.href) {
return html`<a data-ds="item" href=${this.href} class=${`${classes} cursor-pointer rounded-container transition-[background-color] duration-160 ease-standard hover:bg-action-ghost-hover`}>${body}${this.arrow ? icon(ChevronRight, 'chevron-right', { size: 16, strokeWidth: 1.5, class: 'shrink-0 text-fg-muted transition-[color] duration-160 ease-standard group-hover/item:text-fg', attrs: { 'aria-hidden': 'true' } }) : nothing}</a>`
}
return html`<div data-ds="item" class=${classes}>${body}${this.hasSlot('actions') ? html`<span class="flex shrink-0 items-center gap-2"><slot name="actions"></slot></span>` : nothing}</div>`
}
}
define('item', Item)import { html } from 'lit'
import { DsElement, define } from '@/elements/lib/element'
import styles from 'virtual:tw'
// ItemGroup.tsx as <spyglass-item-group>: rows of one list, a #363636 hairline between each. The host is the list's
// box, so a class on the element lands on it; the <ul> inside keeps the list's meaning and lays out nothing. The rows
// are the page's <li>s, each holding a <spyglass-item>.
/**
* @summary Rows of one list, a hairline between each.
* @slot - <li> elements, each holding a <spyglass-item>.
*/
export class ItemGroup extends DsElement {
static styles = [DsElement.styles, styles]
render() {
return html`<ul class="contents"><slot></slot></ul>`
}
}
define('item-group', ItemGroup)/* The host is the list's box (ItemGroup.tsx's <ul>). The hairline between rows is set on the slotted <li>s, important
because the page's reset (no border on any element) outranks ::slotted. */
:host { display: flex; flex-direction: column; }
::slotted(:not(:first-child)) { border-top: var(--ds-border-hairline) solid var(--ds-color-edge) !important; }Reference: Derived from the brand guidelines (no list row in the brand assets): the plan card's fill and corner, DM Sans Medium for titles, the neutral steps for the hairline and the muted line.