Timeline

Two composable patches for vertical event timelines. Apply timeline to the <ol> or <ul> container. Apply timelineItem to each <li> — it creates a 2-column grid with a colored dot (::before) and a vertical connector line (::after). Set active to highlight the dot, and last to suppress the connector on the final item.

timeline

No props. Resets list styles and arranges children in a column.

timelineItem

PropTypeDefault
activeValueOrState<boolean>false
lastbooleanfalse
colorThemeColor"neutral"
accentColorThemeColor"primary"
Customization

Must see the source of patch at the bottom of each patch page to understand the structure then code it still code as html native element.

There are four levels of customization, in increasing order of effort:

  1. Patch props. Each patch exposes a small, stable set of props—typically fewer than five. Lowest friction.
  2. Context attributes. Use dataTone, dataSize, and dataDensity on a container to shift tone, size, or density for an entire subtree without touching individual elements.
  3. Inline override. Native-wins merge strategy: any property set directly on the element overrides the patch value.
  4. Create a variant. Clone a similar patch and edit it. Use this only when you need a reusable custom version.
Formulas

Unit - U = fontSize / 4 - convert final values with themeSpacing(n).

Size - n = intrinsic text lines, w = wrapping level, d = density factor:

height        = (n * 6 + 2 * d * w) * U
paddingBlock  = d * w * U
paddingInline = ceil(3 / w) * d * w * U
radius        = d * w * U

Base density d = 1.5:

Uw=0w=1w=2w=3
height (n = 1)691215
paddingBlock01.534.5
paddingInline34.564.5
radius01.534.5

Tone - K = N / 2 where N is the palette length. For N = 18, K = 9.

RoleShiftn=0
Backgroundparent +/- n0
Textbg + K6
Borderbg + K/23
Hoverbg + 2K/34
Selected / Focusabove +/- K/32-4

State shift range: K/3 <= delta <= 2K/3.

<div class="blocks">
<div class="block active" data-tab="0">
import { type PartialElement, toState, type ValueOrState } from "@domphy/core";
import {
  type ThemeColor,
  themeColor,
  themeDensity,
  themeSpacing,
} from "@domphy/theme";

/**
 * Container for a vertical timeline. Sets list reset styles. Apply to `<ol>` or `<ul>`.
 *
 * @example { ol: [...], $: [timeline()] }
 */
function timeline(): PartialElement {
  return {
    style: {
      listStyle: "none",
      margin: 0,
      padding: 0,
      display: "flex",
      flexDirection: "column",
    },
  };
}

/**
 * A single event row in a `timeline`. Uses a 2-column grid: the left column holds
 * a dot (`::before`) and optional connector line (`::after`); the right column holds
 * the user's content. Apply to `<li>`.
 *
 * @param props.active - Full-opacity dot (accent color). `ValueOrState<boolean>`, defaults to `false`.
 * @param props.last - Suppress the vertical connector below this item. `boolean`, defaults to `false`.
 * @param props.color - Dot/connector color tone. `ThemeColor`, defaults to `"neutral"`.
 * @param props.accentColor - Active dot color tone. `ThemeColor`, defaults to `"primary"`.
 * @example { li: [{ b: "2024" }, { p: "Event" }], $: [timelineItem({ active: true })] }
 */
function timelineItem(
  props: {
    active?: ValueOrState<boolean>;
    last?: boolean;
    color?: ThemeColor;
    accentColor?: ThemeColor;
  } = {},
): PartialElement {
  const { last = false } = props;
  const color = props.color ?? "neutral";
  const accentColor = props.accentColor ?? "primary";
  const activeState = toState(props.active ?? false);

  return {
    style: {
      display: "grid",
      gridTemplateColumns: "2rem 1fr",
      columnGap: (listener) => themeSpacing(themeDensity(listener) * 2),
      paddingBottom: (listener) =>
        last ? "0" : themeSpacing(themeDensity(listener) * 4),
      position: "relative",

      // Dot
      "&::before": {
        content: '""',
        display: "block",
        width: "0.75rem",
        height: "0.75rem",
        borderRadius: "50%",
        justifySelf: "center",
        marginTop: "0.25em",
        transition: "background-color 200ms ease, opacity 200ms ease",
        backgroundColor: (listener) =>
          themeColor(
            listener,
            "shift-8",
            activeState.get(listener) ? accentColor : color,
          ),
        opacity: (listener) => (activeState.get(listener) ? "1" : "0.4"),
      },

      // Vertical connector to the next item
      ...(last
        ? {}
        : {
            "&::after": {
              content: '""',
              position: "absolute",
              left: "calc(1rem - 1px)",
              top: "1.25rem",
              bottom: (listener) =>
                `-${themeSpacing(themeDensity(listener) * 4)}`,
              width: "2px",
              backgroundColor: (listener) =>
                themeColor(listener, "shift-3", color),
            },
          }),
    },
  };
}

export { timeline, timelineItem };
</div>
</div>