# Timeline

> A server-component ordered list of events with opposite content, custom markers, tones, disabled items, vertical or horizontal orientation, four alignments and reverse order.

Canonical: https://salmonui.dev/docs/layout/timeline

`Timeline` is an `<ol>` of events. It has list semantics (no APG pattern)
and no client code, so it renders in React Server Components. It lives in
`@salmonui/layout/timeline` with its own stylesheet.

```tsx
import { Timeline } from '@salmonui/layout/timeline';
import '@salmonui/layout/timeline/styles.css';

<Timeline
  aria-label="Order status"
  items={[
    { content: 'Ordered', opposite: '09:00', tone: 'primary' },
    { content: 'Shipped', opposite: '12:00', marker: <TruckIcon /> },
    { content: 'Delivered', disabled: true },
  ]}
/>;
```

### Live demo: Timeline

Live demo: https://salmonui.dev/demos/layout/timeline

An order-status Timeline with opposite times, tones and a disabled step, alternating sides, a reversed release history with custom markers and an item template, a right-to-left Timeline and a horizontal Timeline.

`Demo.tsx`:

```tsx
import { Timeline, type TimelineItemData } from '@salmonui/layout/timeline';

const check = (
  <svg viewBox="0 0 16 16" width="16" height="16">
    <path d="M3 8.5l3 3 7-7" fill="none" stroke="currentColor" strokeWidth="2" />
  </svg>
);

// Newest first: `reverse` flips the DOM order, so screen readers read what is shown.
const HISTORY: TimelineItemData[] = [
  { key: 'v1', content: 'v1.0 released', opposite: 'March', marker: check, tone: 'success' },
  { key: 'v11', content: 'v1.1 adds export', opposite: 'May', marker: check, tone: 'success' },
  { key: 'v2', content: 'v2.0 in review', opposite: 'July', tone: 'warning', className: 'demo-timeline-current' },
];

export default function TimelineDemo() {
  return (
    <div style={{ display: 'grid', gap: 24 }}>
      <Timeline
        aria-label="Order status"
        align="alternate"
        items={[
          { content: 'Ordered', opposite: '09:00', tone: 'primary' },
          { content: 'Packed', opposite: '10:30', tone: 'info' },
          { content: 'Shipped', opposite: '12:00', tone: 'success' },
          { content: 'Delivered', opposite: 'pending', disabled: true },
        ]}
      />
      <Timeline
        aria-label="Release history, newest first"
        reverse
        items={HISTORY}
        renderItem={(item, { first, last }) => (
          <span>
            <strong>{item.content}</strong>
            {last ? ' (latest)' : first ? ' (first release)' : null}
          </span>
        )}
      />
      <div dir="rtl" lang="ar">
        <Timeline aria-label="حالة الطلب" items={[{ content: 'تم الطلب', opposite: '09:00', tone: 'primary' }, { content: 'تم الشحن', opposite: '12:00', tone: 'success' }]} />
      </div>
      <Timeline aria-label="Release" orientation="horizontal" items={[{ content: 'Design', tone: 'success' }, { content: 'Build', tone: 'primary' }, { content: 'Ship' }]} />
    </div>
  );
}
```

## Items

`items` (an array of `{ content, opposite, marker, tone, disabled,
className, key }`) and `Timeline.Item` children (`children`, `opposite`,
`marker`, `tone`, `disabled`, `className`) produce the same markup:

- `opposite` is the content on the other side of the line.
- `marker` replaces the default dot; `tone` colors
  the dot from the theme seeds.
- `disabled` mutes the item and sets `aria-disabled`.
- `renderItem(item, { index, first, last })` renders each `items` entry.
  Per-item logic belongs in `renderItem` or children; there is no
  before-render event.

## Layout

- `orientation`: `'vertical'` (default) or `'horizontal'` (scrolls inline on
  narrow screens).
- `align`: `'end'` (default, content at the inline end of the line),
  `'start'`, `'alternate'`, `'alternateReverse'`.
  Alignment is logical and mirrors with `dir`.
- `reverse` reverses the DOM order, so screen readers read the items in the
  order they are shown.

`className` and `style` reach the `<ol>`; the hooks are `.salmon-timeline`
(`data-orientation`, `data-align`), `.salmon-timeline-item` (`data-tone`),
`.salmon-timeline-opposite`, `.salmon-timeline-marker`,
`.salmon-timeline-dot` and `.salmon-timeline-content`. There is nothing to
persist, and React owns the lifecycle, so there are no lifecycle
events.

The JavaScript is 0.62 KB gzip and the stylesheet 0.79 KB.

API reference: [`@salmonui/layout/timeline`](https://salmonui.dev/docs/reference/layout/timeline).
