Skip to content

Item ​

One row in a list of things: a leading media slot, a title and a description, trailing actions. Settings rows, search results, members of a team and files in an upload list are all this shape, and building each by hand is how one product ends up with four different vertical rhythms.

ItemContent is min-w-0, so it shrinks to the room left: a long title wraps and a description clamps to two lines, instead of pushing the actions off the row — the most common bug in a flex row built by hand. Every part but Item is a plain styled <div>, so they nest as values, with no () =>.

sh
ream nebula:add item

Molecule · molecules/Item.ts · no dependencies

Usage ​

ts
import { html } from '@c9up/aurora'
import { Button, Item, ItemActions, ItemContent, ItemDescription, ItemTitle } from '@c9up/nebula'

Item({
  variant: 'outline',
  children: html`
    ${ItemContent({ children: html`
      ${ItemTitle({ children: 'Two-factor authentication' })}
      ${ItemDescription({ children: 'Ask for a code from your phone at every sign-in.' })}
    ` })}
    ${ItemActions({ children: Button({ variant: 'outline', size: 'sm', children: 'Enable' }) })}
  `,
})

Examples ​

Variants and sizes ​

ts
Item({ children: 'No border, no background' })              // default
Item({ variant: 'outline', children: 'A border of its own' })
Item({ variant: 'muted', children: 'A tinted background' })
Item({ size: 'sm', children: 'Tighter padding and gap' })

Media ​

ItemMedia holds an icon — sized to 16 px unless it carries its own size-* class — an avatar or a thumbnail, and never shrinks:

ts
import { Avatar, AvatarFallback, AvatarImage, ItemMedia, SearchIcon } from '@c9up/nebula'

Item({
  variant: 'outline',
  size: 'sm',
  children: html`
    ${ItemMedia({ children: SearchIcon() })}
    ${ItemContent({ children: ItemTitle({ children: 'Saved search: open invoices' }) })}
  `,
})

Item({
  children: html`
    ${ItemMedia({ children: Avatar({ children: () => html`
      ${AvatarImage({ src: user.avatarUrl, alt: user.name })}
      ${AvatarFallback({ children: user.initials })}
    ` }) })}
    ${ItemContent({ children: html`
      ${ItemTitle({ children: user.name })}
      ${ItemDescription({ children: user.email })}
    ` })}
  `,
})

The Avatar takes its parts in a thunk because it provides context; the Item parts around it do not.

A list that follows a signal ​

ItemGroup stacks rows; ItemSeparator draws the rule between two of them. Its children is an accessor, so the list follows people:

ts
import { ItemGroup, ItemSeparator } from '@c9up/nebula'

ItemGroup({
  children: () => people().map((person, index) => html`
    ${index > 0 ? ItemSeparator() : null}
    ${Item({ children: html`
      ${ItemContent({ children: html`
        ${ItemTitle({ children: person.name })}
        ${ItemDescription({ children: person.role })}
      ` })}
      ${ItemActions({ children: Button({ variant: 'ghost', size: 'sm', children: 'Remove', onClick: () => remove(person.id) }) })}
    ` })}
  `),
})

Item always renders a <div>. For a row that navigates, put itemVariants on an <a> yourself — the variants already carry a hover background and a focus ring for exactly that case:

ts
import { ChevronRightIcon, itemVariants } from '@c9up/nebula'

html`<a href="/settings/billing" class="${itemVariants({ variant: 'outline', size: 'sm' })}">
  ${ItemContent({ children: ItemTitle({ children: 'Billing' }) })}
  ${ItemActions({ children: ChevronRightIcon() })}
</a>`

API ​

Item ​

PropTypeDefaultDescription
childrenSlot—The parts: media, content, actions.
variantReactive<ItemVariants['variant']>'default''default' (transparent), 'outline' (bordered) or 'muted' (tinted).
sizeReactive<ItemVariants['size']>'default''default' or 'sm', which tightens padding and gap.
classReactive<string>—Merged last, so a conflicting utility wins.

ItemGroup ​

PropTypeDefaultDescription
childrenSlot—The rows, stacked in a column.
classReactive<string>—Merged last.
idstring—The element's id.

ItemMedia ​

PropTypeDefaultDescription
childrenSlot—An icon, an avatar or an image, at the start of the row.
classReactive<string>—Merged last.
idstring—The element's id.

ItemContent ​

PropTypeDefaultDescription
childrenSlot—The title and description. Takes the free width; a second ItemContent in the same row keeps its own size.
classReactive<string>—Merged last.
idstring—The element's id.

ItemTitle ​

PropTypeDefaultDescription
childrenSlot—The row's name, in medium weight; an icon or a badge can sit beside it.
classReactive<string>—Merged last.
idstring—The element's id.

ItemDescription ​

PropTypeDefaultDescription
childrenSlot—A muted line under the title, clamped to two lines.
classReactive<string>—Merged last.
idstring—The element's id.

ItemActions ​

PropTypeDefaultDescription
childrenSlot—Buttons or an icon, at the end of the row.
classReactive<string>—Merged last.
idstring—The element's id.

ItemSeparator ​

PropTypeDefaultDescription
childrenSlot—Leave it empty: the separator is a 1 px rule, and content would spill out of it.
classReactive<string>—Merged last.
idstring—The element's id.

itemVariants ​

itemVariants({ variant?, size?, class? }): string — the class list an Item would carry, for a row that has to be another element, such as a link. ItemVariants is the type of its options.

Accessibility ​

An item is a <div> with no role, and it handles no key. The focus ring on :focus-visible shows only on a row that can take focus — the link form above. ItemGroup is not announced as a list and ItemSeparator is a drawn line, not a Separator: for a screen reader to hear "list, 12 items", render the rows inside a <ul> with one <li> each.