Skip to main content
Decoderen
Browse documentation

ItemGrid

Compare short related items such as principles or deliverables, as Material 3 outlined cards whose titles and bodies line up across a row.

2 columns

  • Clarity

    Give each item a clear purpose.

  • Alignment

    Keep related content together.

Show code
Example.astroAstro
---
import ItemGrid from '@dhekode/ui/patterns/ItemGrid.tsx';
---

<ItemGrid columns={2} items={[
  {
    "title": "Clarity",
    "body": "Give each item a clear purpose."
  },
  {
    "title": "Alignment",
    "body": "Keep related content together."
  }
]} />

3 columns

  • Clarity

    Give each item a clear purpose.

  • Alignment

    Keep related content together.

  • Hierarchy

    Show what matters first.

Show code
Example.astroAstro
---
import ItemGrid from '@dhekode/ui/patterns/ItemGrid.tsx';
---

<ItemGrid columns={3} items={[
  {
    "title": "Clarity",
    "body": "Give each item a clear purpose."
  },
  {
    "title": "Alignment",
    "body": "Keep related content together."
  },
  {
    "title": "Hierarchy",
    "body": "Show what matters first."
  }
]} />

4 columns

  • Clarity

    Give each item a clear purpose.

  • Alignment

    Keep related content together.

  • Hierarchy

    Show what matters first.

  • Detail

    Add useful supporting context.

Show code
Example.astroAstro
---
import ItemGrid from '@dhekode/ui/patterns/ItemGrid.tsx';
---

<ItemGrid columns={4} items={[
  {
    "title": "Clarity",
    "body": "Give each item a clear purpose."
  },
  {
    "title": "Alignment",
    "body": "Keep related content together."
  },
  {
    "title": "Hierarchy",
    "body": "Show what matters first."
  },
  {
    "title": "Detail",
    "body": "Add useful supporting context."
  }
]} />

Numbered

  • Clarity

    Give each item a clear purpose.

  • Alignment

    Keep related content together.

  • Hierarchy

    Show what matters first.

Show code
Example.astroAstro
---
import ItemGrid from '@dhekode/ui/patterns/ItemGrid.tsx';
---

<ItemGrid numbered items={[
  {
    "title": "Clarity",
    "body": "Give each item a clear purpose."
  },
  {
    "title": "Alignment",
    "body": "Keep related content together."
  },
  {
    "title": "Hierarchy",
    "body": "Show what matters first."
  }
]} />

Heading level

  • Clarity

    Give each item a clear purpose.

  • Alignment

    Keep related content together.

Show code
Example.astroAstro
---
import ItemGrid from '@dhekode/ui/patterns/ItemGrid.tsx';
---

<ItemGrid columns={2} headingLevel={4} items={[
  {
    "title": "Clarity",
    "body": "Give each item a clear purpose."
  },
  {
    "title": "Alignment",
    "body": "Keep related content together."
  }
]} />
API reference
items

Type: readonly { title: string; body: string }[]

Default: required

Plain text entries.

columns

Type: 2 | 3 | 4

Default: 3

Column count at the widest breakpoint; smaller screens stack or use two columns.

headingLevel

Type: 3 | 4

Default: 3

Item heading level.

numbered

Type: boolean

Default: false

Decorative two-digit indices; not a semantic ordered list.

className

Type: string | undefined

Default: unset

Adds classes to the React component root, after its own utilities. React components take className, not class.

Slots: None.

Use an actual ordered list when sequence conveys essential meaning. Keep text compact; use feature components for richer cards.

Original component source
packages/ui/src/patterns/ItemGrid.tsxAstro
import { classNames } from '@dhekode/utils/class-names';

type Columns = 2 | 3 | 4;

export interface ItemGridProps {
  items: readonly { title: string; body: string }[];
  /** Columns at the widest breakpoint. */
  columns?: Columns | undefined;
  headingLevel?: 3 | 4 | undefined;
  /** Prefix each item with a numeric index (01, 02 …). */
  numbered?: boolean | undefined;
  className?: string | undefined;
}

// Columns follow the grid's own width, not the viewport's, so cards keep room for their titles
// wherever the grid sits, such as the narrower documentation column.
const widest: Record<Columns, string> = {
  2: '',
  3: '@md:grid-cols-3',
  4: '@lg:grid-cols-4',
};

/**
 * Titled items as Material 3 outlined cards in a responsive grid: problems, principles,
 * engagement models. Each card spans two subgrid rows, so titles and bodies line up across a row.
 */
export default function ItemGrid({
  items,
  columns = 3,
  headingLevel = 3,
  numbered = false,
  className,
}: ItemGridProps) {
  const Heading = headingLevel === 4 ? 'h4' : 'h3';
  return (
    <div className={classNames('dk-item-grid-frame @container', className)}>
      <ul
        role="list"
        className={classNames(
          'dk-item-grid grid grid-cols-1 gap-x-gutter gap-y-md @sm:grid-cols-2',
          widest[columns],
        )}
        data-columns={columns}
        data-numbered={numbered ? '' : undefined}
      >
        {items.map((item, i) => (
          <li
            key={item.title}
            className="dk-item-grid__item dk-reveal-item row-span-2 grid min-w-0 grid-rows-subgrid content-start gap-sm rounded-card border-(length:--dk-border-width-hairline) border-solid border-surface-border bg-surface-bg p-lg wrap-anywhere"
          >
            {/* The number is a label above the title: beside a heading this size it floats, and
                its column would squeeze the body. */}
            <div className="grid content-start gap-xs">
              {numbered && (
                <p className="dk-label dk-item-grid__index text-surface-accent" aria-hidden="true">
                  {String(i + 1).padStart(2, '0')}
                </p>
              )}
              <Heading className="dk-item-grid__title min-w-0 text-h3 tracking-heading">
                {item.title}
              </Heading>
            </div>
            <p className="dk-item-grid__body text-body text-surface-muted">{item.body}</p>
          </li>
        ))}
      </ul>
    </div>
  );
}

Best practices

  • Group items of similar importance and keep descriptions parallel.