--- // How it works: an ordered sequence of steps, each a title and a line of // text, optionally with an image — as a vertical list or a row across the // page, numbered or plain. `kind="timeline"` is the dated variant: a date per // item on a vertical rail, optionally alternating left and right of it. import { tv } from 'tailwind-variants' import KitImage from '../_shared/KitImage.astro' import Section from '../_shared/Section.astro' import { instanceId } from '../_shared/instance-id' import { measuredGrid } from '../_shared/measured' import type { MeasuredStyle } from '../_shared/types' import { imageOf, type ImageSource } from '../_shared/image' import { muted } from '../_shared/muted' const steps = tv({ slots: { header: 'mb-10 flex max-w-2xl flex-col gap-3', heading: 'text-3xl [font-weight:var(--font-weight-heading,700)] tracking-tight text-balance md:text-4xl', intro: `text-lg ${muted}`, list: 'grid gap-8 [counter-reset:kit-step]', step: 'flex gap-4 [counter-increment:kit-step]', date: 'text-sm font-semibold tabular-nums text-accent-text', body: 'flex flex-col gap-2', badge: 'shrink-0', media: 'mb-2 overflow-hidden rounded-[var(--radius-image,var(--radius-card))]', title: 'text-lg leading-snug [font-weight:var(--font-weight-heading,600)] text-balance', text: `text-pretty ${muted}`, }, variants: { layout: { list: { list: 'max-w-3xl' }, row: { list: 'sm:grid-cols-2 lg:auto-cols-fr lg:grid-flow-col lg:grid-cols-none', step: 'flex-col' }, // One rail on the inline-start side (the item's own side is the rail's, mirrored in RTL by the logical `ps-`/`border-s`). rail: { list: 'max-w-3xl gap-0', step: 'relative border-s-2 border-line pb-8 ps-6 last:pb-0' }, // Items alternate either side of a centre rail from `md`; the DOM stays chronological, one rail on the start side on phones. alternate: { list: 'gap-0 md:grid-cols-2', step: 'relative border-s-2 border-line pb-8 ps-6 md:[&:nth-child(even)]:col-start-2 md:[&:nth-child(odd)]:col-start-1 md:[&:nth-child(odd)]:border-s-0 md:[&:nth-child(odd)]:border-e-2 md:[&:nth-child(odd)]:pe-6 md:[&:nth-child(odd)]:ps-0 md:[&:nth-child(odd)]:text-end md:[&:nth-child(odd)]:flex-row-reverse md:[&:nth-child(even)]:-ms-px md:[&:nth-child(odd)]:after:start-auto md:[&:nth-child(odd)]:after:-end-[7px]' }, }, // What sits on the rail: the number, a plain dot, or the date (the timeline's own marker). The number marker is `style`'s. marker: { number: {}, dot: { step: 'before:hidden after:absolute after:top-1.5 after:-start-[7px] after:size-3 after:rounded-full after:bg-accent after:content-[""]' } }, connector: { none: {}, line: {}, dashed: { step: 'border-dashed' } }, // The number is drawn from a CSS counter, so the list stays one
    a screen reader counts itself. A number the // source wrote (`01`) is the page's text and is shown as written, hidden from the screen reader that already counts. style: { numbered: { step: "before:flex before:size-10 before:shrink-0 before:items-center before:justify-center before:rounded-full before:bg-accent before:font-semibold before:text-accent-ink before:content-[counter(kit-step)]", badge: 'flex h-10 min-w-10 items-center justify-center self-start rounded-full bg-accent px-2 font-semibold text-accent-ink', }, plain: { step: 'border-s-2 border-accent ps-4', badge: 'font-semibold tabular-nums' }, }, }, defaultVariants: { layout: 'list', marker: 'number', connector: 'line', style: 'numbered' }, }) interface Step { /** The number as the source writes it (`01`, `Step 2`); without it the list counts itself. */ number?: string | undefined title: string text: string /** A timeline's date as the source writes it (`2019`, `Mar 2021`); `datetime` only when it parses as an ISO date or year. */ date?: string | undefined /** Marks the latest item: a visually hidden "Current" is added for readers. */ current?: boolean | undefined /** The image's address. */ image?: ImageSource | undefined imageAlt?: string | undefined } interface Props { heading?: string | undefined intro?: string | undefined items: Step[] /** `steps` numbers a sequence; `timeline` carries a date per item (the rail layouts below). */ kind?: 'steps' | 'timeline' | undefined layout?: 'list' | 'row' | 'rail' | 'alternate' | undefined marker?: 'number' | 'dot' | undefined connector?: 'none' | 'line' | 'dashed' | undefined currentLabel?: string | undefined style?: 'numbered' | 'plain' | undefined /** The source section's measured style (`MeasuredStyle`): frame, padding, fill, background image, columns per width, gap. Absent, the site's tokens; present, it wins over tone and columns. */ measured?: MeasuredStyle | undefined id?: string | undefined /** The page entry this section is built from, without its locale (`services-0`): `data-kit-entry`, the hook a design layer styles this one section by. Absent, none is printed. */ entry?: string | undefined } const { heading, intro, items, kind = 'steps', layout: givenLayout, marker, connector, currentLabel = 'Current', style, measured, id: givenId } = Astro.props // Every section has an id, so a theme or a design layer can address this one: the page's, or `steps`, `steps-2`, … in render order. const id = instanceId(Astro.locals, givenId, 'steps') // A timeline defaults to the rail layout and, without numbers, to the plain dot marker. const layout = givenLayout ?? (kind === 'timeline' ? 'rail' : 'list') const s = steps({ layout, marker: marker ?? (kind === 'timeline' ? 'dot' : 'number'), connector, style }) // A bare year or an ISO date is machine-readable; anything else ("Spring 2021") stays text. const isoDate = (date: string) => /^\d{4}(-\d{2}(-\d{2})?)?$/.test(date.trim()) ? date.trim() : undefined const headingId = heading ? `${id}-title` : undefined // One level under the section heading, or the section's heading when there is none. const StepHeading = heading ? 'h3' : 'h2' --- {items.length > 0 && (
    {(heading || intro) && (
    {heading &&

    {heading}

    } {intro &&

    {intro}

    }
    )}
      {items.map(step => (
    1. {step.number && }
      {kind === 'timeline' && step.date && (isoDate(step.date) ? :

      {step.date}

      )} {step.current && {currentLabel}} {imageOf(step.image, step.imageAlt) &&
      } {step.title}

      {step.text}

    2. ))}
    )}