# Changelog

Release notes for a fictional API as a timeline: each version and date in a left column that sticks while you scroll on wide screens, entries grouped under Added, Improved and Fixed `Badge`s with inline `Code`, a breaking-change callout, and a `Field` to get release notes by email.

**Example: Relay API changelog** (`examples/recipes/changelog.tsx`)

```tsx
'use client'

import { Badge, type BadgeTone, Body, Button, Code, Field, Heading, Stack, Text, toastSuccess } from '@blocks/design-system'
import { Rss, TriangleAlert } from 'lucide-react'
import { type FormEvent, type ReactNode, useRef, useState } from 'react'
import styles from './changelog.module.css'

type Kind = 'Added' | 'Improved' | 'Fixed'

interface Release {
  version: string
  date: string
  isoDate: string
  summary: string
  breaking?: ReactNode
  changes: Partial<Record<Kind, ReactNode[]>>
}

const kinds: { kind: Kind; tone: BadgeTone }[] = [
  { kind: 'Added', tone: 'success' },
  { kind: 'Improved', tone: 'info' },
  { kind: 'Fixed', tone: 'neutral' },
]

const releases: Release[] = [
  {
    version: '3.2.0',
    date: 'Nov 24, 2026',
    isoDate: '2026-11-24',
    summary: 'Webhooks you can replay, and faster pagination for large accounts.',
    changes: {
      Added: [
        <>
          Replay any webhook delivery from the last 30 days with <Code>POST /v3/deliveries/:id/replay</Code>.
        </>,
        <>
          A <Code>since</Code> filter on <Code>GET /v3/events</Code>.
        </>,
      ],
      Improved: ['Cursor pagination is up to 4× faster on accounts with more than a million events.'],
      Fixed: [
        <>
          <Code>retry_after</Code> is now in seconds, as documented, instead of milliseconds.
        </>,
        'Deleted endpoints no longer appear in the delivery log filter.',
      ],
    },
  },
  {
    version: '3.1.0',
    date: 'Oct 30, 2026',
    isoDate: '2026-10-30',
    summary: 'Signed payloads for every webhook.',
    changes: {
      Added: [
        <>
          Every delivery carries a <Code>Relay-Signature</Code> header you can verify with your endpoint secret.
        </>,
      ],
      Improved: ['The dashboard shows the last 50 deliveries per endpoint, up from 10.'],
    },
  },
  {
    version: '3.0.0',
    date: 'Sep 15, 2026',
    isoDate: '2026-09-15',
    summary: 'A new major version with consistent naming across the API.',
    breaking: (
      <>
        Fields are now <Code>snake_case</Code> everywhere: <Code>createdAt</Code> becomes <Code>created_at</Code>. Version 2 keeps working
        until March 31, 2027.
      </>
    ),
    changes: {
      Added: ['Idempotency keys on every write endpoint.'],
      Fixed: ['Rate-limit headers are sent on 429 responses too.'],
    },
  },
]

function Subscribe() {
  const [error, setError] = useState('')
  const [subscribed, setSubscribed] = useState('')
  const confirmation = useRef<HTMLParagraphElement>(null)

  function submit(event: FormEvent<HTMLFormElement>) {
    event.preventDefault()
    const email = String(new FormData(event.currentTarget).get('email')).trim()
    const problem = !email
      ? 'Enter your email address.'
      : !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)
        ? 'Enter an email address like name@example.com.'
        : ''
    if (problem) {
      setError(problem)
      return
    }
    setSubscribed(email)
    toastSuccess('Subscribed to release notes')
    requestAnimationFrame(() => confirmation.current?.focus())
  }

  if (subscribed) {
    return (
      <Text as="p" ref={confirmation} tabIndex={-1} fontSize="sm" role="status" margin="none" dangerouslySetClassName={styles.confirmation}>
        Thanks! We’ll email <strong>{subscribed}</strong> when a new version ships.
      </Text>
    )
  }

  return (
    <form className={styles.subscribe} noValidate onSubmit={submit} aria-label="Subscribe to release notes">
      <Field name="email" invalid={Boolean(error)}>
        <Field.Label>Get release notes by email</Field.Label>
        <div className={styles.subscribeRow}>
          <Field.Control type="email" autoComplete="email" placeholder="you@company.com" onValueChange={() => setError('')} />
          <Button type="submit" variant="primary">
            Subscribe
          </Button>
        </div>
        {error && <Field.Error match>{error}</Field.Error>}
      </Field>
    </form>
  )
}

// Release notes as a timeline: each version's heading sticks beside its
// entries on wide screens, and every entry is grouped by kind.
export default function Changelog() {
  return (
    <Stack as="section" gap="xl" aria-labelledby="changelog-title" dangerouslySetClassName={styles.root}>
      <Stack gap="md">
        <Stack direction="row" justify="space-between" align="center" gap="md" wrap="wrap">
          <Heading as="h2" id="changelog-title" fontSize="xxl">
            Relay API changelog
          </Heading>
          <Button as="a" href="#changelog-feed" size="sm" variant="ghost">
            <Rss aria-hidden size={14} />
            RSS feed
          </Button>
        </Stack>
        <Body color="text-muted" margin="none">
          New features, improvements and fixes, newest first.
        </Body>
        <Subscribe />
      </Stack>

      <ol className={styles.timeline}>
        {releases.map((release) => (
          <li key={release.version} className={styles.release}>
            <header className={styles.version}>
              <Heading as="h3" fontSize="lg" id={`changelog-${release.version}`}>
                {release.version}
              </Heading>
              <Text fontSize="sm" color="text-muted">
                <time dateTime={release.isoDate}>{release.date}</time>
              </Text>
            </header>
            <Stack gap="lg" dangerouslySetClassName={styles.entries}>
              <Body fontWeight="medium" margin="none">
                {release.summary}
              </Body>
              {release.breaking && (
                <div className={styles.breaking} role="note" aria-label={`Breaking change in ${release.version}`}>
                  <TriangleAlert aria-hidden size={18} className={styles.breakingIcon} />
                  <Stack gap="xs">
                    <Text fontSize="sm" fontWeight="semibold">
                      Breaking
                    </Text>
                    <Text fontSize="sm">{release.breaking}</Text>
                  </Stack>
                </div>
              )}
              {kinds.map(({ kind, tone }) => {
                const items = release.changes[kind]
                if (!items) return null
                return (
                  <Stack key={kind} gap="sm" as="section" aria-label={`${kind} in ${release.version}`}>
                    <div>
                      <Badge tone={tone}>{kind}</Badge>
                    </div>
                    <ul className={styles.changes}>
                      {items.map((item, index) => (
                        // biome-ignore lint/suspicious/noArrayIndexKey: entries are static and never reorder
                        <li key={index}>{item}</li>
                      ))}
                    </ul>
                  </Stack>
                )
              })}
            </Stack>
          </li>
        ))}
      </ol>
    </Stack>
  )
}
```

## How it works

- The timeline is an ordered list of releases, newest first. The line is each release’s left border and the dot a `::before`; the latest release has a filled dot.
- A container query at 34rem turns each release into two columns and makes the version `position: sticky`, so it stays beside its entries as they scroll by. Narrower, the version sits above its entries.
- The breaking change is a `role="note"` callout with a label naming the release, and it says “Breaking” in words, not only with the warning color.
- The signup validates on submit (`noValidate`, then `invalid` and a `Field.Error`); editing clears the error. On success a confirmation replaces the form and takes focus.

## App-owned CSS

`examples/recipes/changelog.module.css`:

```css
.root {
  container-type: inline-size;
}

.subscribe {
  max-inline-size: 28rem;
}

.confirmation:focus {
  outline: none;
}

.subscribeRow {
  display: flex;
  gap: var(--ds-space-sm);

  & input {
    flex: 1;
    min-inline-size: 0;
  }
}

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
}

.release {
  position: relative;
  display: grid;
  gap: var(--ds-space-md);
  padding: 0 0 var(--ds-space-xl) var(--ds-space-xl);
  border-left: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);

  &:last-child {
    padding-bottom: 0;
    border-left-color: transparent;
  }

  /* The timeline's dot, centered on the line */
  &::before {
    content: '';
    position: absolute;
    top: var(--ds-space-sm);
    left: calc(var(--ds-space-sm) * -1 - var(--ds-border-width-sm) / 2);
    box-sizing: border-box;
    inline-size: var(--ds-space-md);
    block-size: var(--ds-space-md);
    background-color: var(--ds-color-bg);
    border: var(--ds-border-width-md) solid var(--ds-color-accent);
    border-radius: var(--ds-border-radius-circle);
  }

  &:first-child::before {
    background-color: var(--ds-color-accent);
  }
}

.version {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--ds-space-md);
}

.entries {
  min-inline-size: 0;
}

/* Wide: versions in a left column that sticks while its entries scroll by */
@container (width >= 34rem) {
  .release {
    grid-template-columns: 8rem minmax(0, 1fr);
    gap: var(--ds-space-xl);
  }

  .version {
    position: sticky;
    top: var(--ds-space-lg);
    align-self: start;
    flex-direction: column;
    gap: var(--ds-space-xs);
  }
}

.breaking {
  display: flex;
  gap: var(--ds-space-md);
  padding: var(--ds-space-md) var(--ds-space-lg);
  background-color: var(--ds-color-warning-subtle);
  border: var(--ds-border-width-sm) solid color-mix(in srgb, var(--ds-color-warning) 40%, transparent);
  border-radius: var(--ds-border-radius-md);
}

.breakingIcon {
  flex-shrink: 0;
  margin-top: var(--ds-space-xs);
  color: var(--ds-color-warning-text);
}

.changes {
  display: grid;
  gap: var(--ds-space-sm);
  margin: 0;
  padding-left: var(--ds-space-lg);
  font-size: var(--ds-font-size-sm);
  line-height: var(--ds-line-height-body);

  & li::marker {
    color: var(--ds-color-text-muted);
  }
}
```
