# Onboarding checklist

A “Get started” card for a new workspace: a progress ring and the time left, five tasks that each open to a short how-to and a call to action, and a done state once the last one lands. `Card`, `Stack`, `Heading`, `Button`, `Link` and `toastSuccess` compose it; the ring and task rows are app-owned.

**Example: Set up Harbor** (`examples/recipes/onboarding-checklist.tsx`)

```tsx
'use client'

import { Body, BodySmall, Box, Button, Card, Heading, Link, Stack, Text, toastSuccess } from '@blocks/design-system'
import { ChevronDown, Circle, CircleCheck, PartyPopper, X } from 'lucide-react'
import { useEffect, useId, useRef, useState } from 'react'
import styles from './onboarding-checklist.module.css'

interface Task {
  id: string
  title: string
  minutes: number
  howTo: string
  action: string
  done: string
}

const tasks: Task[] = [
  {
    id: 'profile',
    title: 'Name your workspace',
    minutes: 1,
    howTo: 'Pick the name your team will see in invites and on shared dashboards. You can change it later.',
    action: 'Name workspace',
    done: 'Workspace named “Fernhill Labs”',
  },
  {
    id: 'invite',
    title: 'Invite your teammates',
    minutes: 2,
    howTo: 'Send invites by email or share a join link. New members start as viewers until you promote them.',
    action: 'Invite teammates',
    done: 'Invites sent to 3 teammates',
  },
  {
    id: 'connect',
    title: 'Connect a data source',
    minutes: 3,
    howTo: 'Harbor reads from Postgres, BigQuery or a CSV upload. Credentials stay encrypted in your region.',
    action: 'Connect source',
    done: 'Connected “orders-prod”',
  },
  {
    id: 'dashboard',
    title: 'Build your first dashboard',
    minutes: 4,
    howTo: 'Start from the Revenue template or a blank canvas, then drag in charts from your new source.',
    action: 'Open the builder',
    done: 'Created “Weekly revenue”',
  },
  {
    id: 'alerts',
    title: 'Turn on an alert',
    minutes: 1,
    howTo: 'Get a message when a metric crosses a threshold, so the dashboard comes to you.',
    action: 'Create alert',
    done: 'Alert set for refunds over 2%',
  },
]

// Twelve decorative pieces; the module CSS gives each its color, lane and delay.
const confetti = Array.from({ length: 12 }, (_, index) => `piece-${index}`)

// A "Get started" card: a progress ring, one task open at a time, and a
// celebratory state once everything is done.
export default function OnboardingChecklist() {
  const [completed, setCompleted] = useState<string[]>(['profile'])
  const [open, setOpen] = useState<string | null>('invite')
  const [dismissed, setDismissed] = useState(false)
  const id = useId()
  const heading = useRef<HTMLHeadingElement>(null)
  const showAgain = useRef<HTMLButtonElement>(null)
  const wasDismissed = useRef(false)

  const doneCount = completed.length
  const allDone = doneCount === tasks.length
  const minutesLeft = tasks.filter((task) => !completed.includes(task.id)).reduce((sum, task) => sum + task.minutes, 0)

  // Keep focus with the content that replaced the control the reader used.
  useEffect(() => {
    if (allDone) heading.current?.focus()
  }, [allDone])
  useEffect(() => {
    if (dismissed) {
      wasDismissed.current = true
      showAgain.current?.focus()
    } else if (wasDismissed.current) {
      heading.current?.focus()
    }
  }, [dismissed])

  function complete(task: Task) {
    const next = [...completed, task.id]
    setCompleted(next)
    setOpen(tasks.find((candidate) => !next.includes(candidate.id))?.id ?? null)
    toastSuccess(task.done)
  }

  function reopen(task: Task) {
    setCompleted(completed.filter((taskId) => taskId !== task.id))
  }

  if (dismissed) {
    return (
      <Card as="aside" aria-label="Get started" padding="md" backgroundColor="bg-subtle">
        <Stack direction="row" align="center" justify="space-between" gap="sm" wrap="wrap">
          <BodySmall margin="none" color="text-muted">
            Checklist hidden · {doneCount} of {tasks.length} done
          </BodySmall>
          <Button ref={showAgain} type="button" size="sm" variant="ghost" onClick={() => setDismissed(false)}>
            Show checklist
          </Button>
        </Stack>
      </Card>
    )
  }

  return (
    <Card as="section" aria-labelledby={`${id}-title`} padding="none" dangerouslySetClassName={styles.card}>
      <div className={styles.header}>
        <ProgressRing done={doneCount} total={tasks.length} />
        <Stack gap="xs" flex="1">
          <Heading as="h3" id={`${id}-title`} ref={heading} tabIndex={-1} fontSize="lg">
            {allDone ? 'You’re all set' : 'Set up Harbor'}
          </Heading>
          <BodySmall margin="none" color="text-muted">
            {allDone ? (
              'Every setup task is done.'
            ) : (
              <>
                {tasks.length - doneCount} tasks left · <span className={styles.nowrap}>about {minutesLeft} min</span>
              </>
            )}
          </BodySmall>
        </Stack>
        <button type="button" aria-label="Dismiss checklist" className={styles.close} onClick={() => setDismissed(true)}>
          <X aria-hidden size={18} />
        </button>
      </div>

      {allDone ? (
        <Stack align="center" gap="sm" padding="xl" textAlign="center" dangerouslySetClassName={styles.celebration}>
          <span className={styles.confetti} aria-hidden>
            {confetti.map((piece) => (
              <i key={piece} />
            ))}
          </span>
          <Box padding="md" backgroundColor="accent-subtle" color="accent-text" dangerouslySetClassName={styles.badge}>
            <PartyPopper aria-hidden size={28} />
          </Box>
          <Body margin="none">Your team can start exploring. Templates are a good next stop.</Body>
          <Link href="#onboarding-templates" fontWeight="semibold">
            Browse templates
          </Link>
        </Stack>
      ) : (
        <ol className={styles.tasks}>
          {tasks.map((task) => {
            const isDone = completed.includes(task.id)
            const isOpen = open === task.id
            const panelId = `${id}-${task.id}`
            return (
              <li key={task.id} className={styles.task} data-open={isOpen || undefined}>
                <button
                  type="button"
                  className={styles.toggle}
                  aria-expanded={isOpen}
                  aria-controls={panelId}
                  onClick={() => setOpen(isOpen ? null : task.id)}
                >
                  {isDone ? (
                    <CircleCheck aria-hidden size={20} className={styles.status} data-done />
                  ) : (
                    <Circle aria-hidden size={20} className={styles.status} />
                  )}
                  <Text fontWeight="medium" dangerouslySetClassName={isDone ? styles.doneTitle : undefined}>
                    {task.title}
                    <span className={styles.visuallyHidden}>{isDone ? ', done' : ', to do'}</span>
                  </Text>
                  <Text fontSize="xs" color="text-muted" dangerouslySetClassName={styles.minutes}>
                    {task.minutes} min
                  </Text>
                  <ChevronDown aria-hidden size={16} className={styles.chevron} />
                </button>
                <div id={panelId} hidden={!isOpen} className={styles.panel}>
                  <BodySmall margin="none" color="text-muted">
                    {isDone ? task.done : task.howTo}
                  </BodySmall>
                  {isDone ? (
                    <Button type="button" size="sm" variant="ghost" onClick={() => reopen(task)}>
                      Mark as not done
                    </Button>
                  ) : (
                    <Button type="button" size="sm" variant="primary" onClick={() => complete(task)}>
                      {task.action}
                    </Button>
                  )}
                </div>
              </li>
            )
          })}
        </ol>
      )}
    </Card>
  )
}

// The ring is decoration for the progressbar's text, which says the same thing.
function ProgressRing({ done, total }: { done: number; total: number }) {
  const percent = (done / total) * 100
  return (
    <div
      role="progressbar"
      aria-label="Setup progress"
      aria-valuemin={0}
      aria-valuemax={total}
      aria-valuenow={done}
      aria-valuetext={`${done} of ${total} tasks done`}
      className={styles.ring}
    >
      <svg viewBox="0 0 36 36" aria-hidden>
        <circle cx="18" cy="18" r="15.5" pathLength={100} className={styles.track} />
        <circle
          cx="18"
          cy="18"
          r="15.5"
          pathLength={100}
          strokeDasharray={`${percent} 100`}
          className={styles.fill}
        />
      </svg>
      <span className={styles.fraction}>
        {done}/{total}
      </span>
    </div>
  )
}
```

## How it works

- The ring is a `progressbar` with an `aria-valuetext` (“2 of 5 tasks done”); the SVG arc beside the visible fraction is decoration, drawn with `pathLength="100"` so the dash length is the percentage.
- Each task is a disclosure: a native button with `aria-expanded` and `aria-controls` over a panel. One task is open at a time, and finishing one opens the next task still to do. Done tasks carry “done” in their accessible name, not only a green check and a strikethrough.
- When the content under the reader’s focus is replaced (finishing the last task, dismissing the card, bringing it back) focus moves to the new heading or button rather than falling to the page.
- The confetti only plays without `prefers-reduced-motion`, and it is `aria-hidden`.

## App-owned CSS

`examples/recipes/onboarding-checklist.module.css`:

```css
.card {
  container-type: inline-size;
  overflow: hidden;
  background-color: var(--ds-color-bg);
  box-shadow: var(--ds-shadow-sm);
}

/* Header: the ring, the title and a quiet close button aligned to the title's top. */
.header {
  display: flex;
  align-items: center;
  gap: var(--ds-space-lg);
  padding: var(--ds-space-lg);
}

.nowrap {
  white-space: nowrap;
}

.close {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  align-self: start;
  width: var(--ds-control-height-sm);
  height: var(--ds-control-height-sm);
  padding: 0;
  color: var(--ds-color-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--ds-border-radius-md);
  cursor: pointer;

  &:hover {
    color: var(--ds-color-text);
    background-color: var(--ds-color-surface-hover);
  }

  &:focus-visible {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
  }
}

/* Progress ring: a track and an arc drawn with pathLength="100". */
.ring {
  position: relative;
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: calc(var(--ds-space-xl) * 1.75);
  aspect-ratio: 1;
}

.ring svg {
  position: absolute;
  inset: 0;
  rotate: -90deg;
}

.track,
.fill {
  fill: none;
  stroke-width: 3;
}

.track {
  stroke: var(--ds-color-surface-active);
}

.fill {
  stroke: var(--ds-color-success);
  stroke-linecap: round;
  transition: stroke-dasharray var(--ds-duration-slow) var(--ds-easing-emphasized);
}

.fraction {
  font-size: var(--ds-font-size-sm);
  font-weight: var(--ds-font-weight-semibold);
  font-variant-numeric: tabular-nums;
}

@container (max-width: 26rem) {
  .header {
    gap: var(--ds-space-md);
    padding: var(--ds-space-md) var(--ds-space-md) var(--ds-space-md) var(--ds-space-lg);
  }

  .ring {
    width: calc(var(--ds-space-xl) + var(--ds-space-sm));
  }

  .fraction {
    font-size: var(--ds-font-size-xxs);
  }
}

/* Tasks */
.tasks {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
}

.task + .task {
  border-top: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
}

.task[data-open] {
  background-color: var(--ds-color-bg-subtle);
}

.toggle {
  --first-line: calc(var(--ds-font-size-md) * var(--ds-line-height-body));

  display: flex;
  align-items: start;
  gap: var(--ds-space-md);
  width: 100%;
  padding: calc(var(--ds-space-md) + var(--ds-space-sm)) var(--ds-space-lg);
  font: inherit;
  color: var(--ds-color-text);
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;

  &:hover {
    background-color: var(--ds-color-surface-hover);
  }

  &:focus-visible {
    outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
    outline-offset: calc(var(--ds-border-width-md) * -1);
  }

  & > :nth-child(2) {
    flex: 1;
  }
}

.status {
  flex-shrink: 0;
  margin-top: calc((var(--first-line) - var(--ds-icon-size-md)) / 2);
  color: var(--ds-color-border);
  transition: color var(--ds-duration-normal) var(--ds-easing-standard);

  &[data-done] {
    color: var(--ds-color-success);
  }
}

.doneTitle {
  color: var(--ds-color-text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--ds-color-border-strong);
}

.minutes {
  flex-shrink: 0;
  margin-top: calc((var(--first-line) - var(--ds-font-size-xs) * var(--ds-line-height-body)) / 2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chevron {
  flex-shrink: 0;
  margin-top: calc((var(--first-line) - var(--ds-icon-size-sm)) / 2);
  color: var(--ds-color-text-muted);
  transition: rotate var(--ds-duration-normal) var(--ds-easing-standard);
}

.toggle[aria-expanded="true"] .chevron {
  rotate: 180deg;
}

.panel:not([hidden]) {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: var(--ds-space-md);
  padding: 0 var(--ds-space-lg) var(--ds-space-lg) calc(var(--ds-space-lg) + var(--ds-icon-size-md) + var(--ds-space-md));
}

.visuallyHidden {
  position: absolute;
  width: var(--ds-space-xxs);
  height: var(--ds-space-xxs);
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Done state */
.celebration {
  position: relative;
  overflow: hidden;
  border-top: var(--ds-border-width-sm) solid var(--ds-color-border-subtle);
  background: radial-gradient(circle at 50% 0%, var(--ds-color-accent-subtle), transparent 70%);
}

.badge {
  display: grid;
  place-items: center;
  border-radius: var(--ds-border-radius-circle);
  animation: pop var(--ds-duration-slow) var(--ds-easing-emphasized) both;
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -5%;
  left: calc(var(--x) * 1%);
  width: var(--ds-space-md);
  height: calc(var(--ds-space-sm) + var(--ds-space-xs));
  border-radius: var(--ds-border-radius-sm);
  background-color: var(--piece);
  opacity: 0;
  animation: fall calc(var(--ds-duration-slow) * 6) var(--ds-easing-standard) calc(var(--delay) * var(--ds-duration-fast)) both;
}

.confetti i:nth-child(4n + 1) {
  --piece: var(--ds-color-accent);
}

.confetti i:nth-child(4n + 2) {
  --piece: var(--ds-color-success);
}

.confetti i:nth-child(4n + 3) {
  --piece: var(--ds-color-warning);
}

.confetti i:nth-child(4n + 4) {
  --piece: var(--ds-color-info);
}

.confetti i:nth-child(1) { --x: 8; --delay: 0; }
.confetti i:nth-child(2) { --x: 17; --delay: 3; }
.confetti i:nth-child(3) { --x: 26; --delay: 1; }
.confetti i:nth-child(4) { --x: 35; --delay: 4; }
.confetti i:nth-child(5) { --x: 44; --delay: 2; }
.confetti i:nth-child(6) { --x: 53; --delay: 5; }
.confetti i:nth-child(7) { --x: 62; --delay: 1; }
.confetti i:nth-child(8) { --x: 71; --delay: 3; }
.confetti i:nth-child(9) { --x: 80; --delay: 0; }
.confetti i:nth-child(10) { --x: 89; --delay: 4; }
.confetti i:nth-child(11) { --x: 13; --delay: 6; }
.confetti i:nth-child(12) { --x: 76; --delay: 6; }

@keyframes fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0turn);
  }

  100% {
    opacity: 0;
    transform: translateY(calc(var(--ds-space-xxxl) * 1.75)) rotate(1.5turn);
  }
}

@keyframes pop {
  from {
    scale: 0.6;
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .confetti {
    display: none;
  }

  .badge,
  .fill,
  .status,
  .chevron {
    animation: none;
    transition: none;
  }
}
```
