{
  "$schema": "https://zoblocks.design/schema/registry-item.json",
  "name": "timeline",
  "type": "zoblocks:component",
  "title": "Timeline",
  "description": "An ordered list with a rail. The API matches Ant Design v6 exactly, including the v5 names it still accepts, and takes no dependency on it. Adds a required accessible name and drops the current-step behaviour a chronology has no use for.",
  "categories": [
    "data-display",
    "primitives"
  ],
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "registryDependencies": [
    "utils",
    "tokens",
    "timeline-core"
  ],
  "files": [
    {
      "path": "registry/zoblocks/timeline/timeline.tsx",
      "type": "zoblocks:component",
      "target": "components/zoblocks/timeline.tsx",
      "content": "\"use client\";\n\n/**\n * Timeline — Ant Design v6's Timeline, with the accessibility it does not have.\n *\n * The API is antd's, prop for prop, including the v6 spellings (`title`,\n * `content`, `icon`, `placement`) and the v5 names it still accepts. An\n * existing antd call site migrates by changing one import. There is no\n * dependency on antd: `Timeline` is an ordered list with a rail, and taking a\n * dependency for that would put antd into every consumer of a primitive and\n * end copy-as-source distribution for the whole family.\n *\n * Three divergences, each deliberate and each in `limitations`.\n *\n *   1. **No `current`, and no equivalent.** antd's Timeline is a thin adapter\n *      over `Steps` and hardcodes `current: items.length - 1`, which marks the\n *      last rendered item `process` — and antd's own timeline stylesheet gives\n *      that state a *dotted rail*. On a wizard \"the step you are on, and it\n *      continues\" is right. On a chronology it is a mark of incompleteness\n *      applied to whichever event happened to be last, and with `reverse` it\n *      lands on the oldest event in the chart. A history has no current step,\n *      so this one does not have the prop.\n *\n *   2. **An accessible name is required**, in the type. antd exposes no way to\n *      name the list — `@rc-component/steps` emits no `role`, no\n *      `aria-current`, no `aria-label` at all — so a page with a care timeline\n *      and an access-history timeline gives a screen-reader user two unnamed\n *      lists.\n *\n *   3. **`role=\"list\"` is stated explicitly.** Safari drops list semantics from\n *      any list with `list-style: none`, and VoiceOver then announces neither\n *      the list nor its item count. The redundant role is the accepted fix;\n *      the HTML validator's complaint about it is wrong here.\n *\n * Styling lives in `styles/zoblocks-timeline.css`, installed alongside.\n */\n\nimport * as React from \"react\";\nimport { cn } from \"@/lib/utils\";\n\n/** antd v5 accepted physical sides; v6 renamed them to logical ones. */\nexport type TimelineItemPosition = \"left\" | \"right\" | \"start\" | \"end\";\nexport type TimelineItemPlacement = \"start\" | \"end\";\nexport type TimelineMode = TimelineItemPosition | \"alternate\";\nexport type TimelineOrientation = \"horizontal\" | \"vertical\";\nexport type TimelineVariant = \"filled\" | \"outlined\";\n\n/** antd's four presets, plus any CSS colour. */\nexport type TimelineColor = \"blue\" | \"red\" | \"green\" | \"gray\" | (string & {});\n\n/**\n * The parts of the rendered tree a caller may reach, matching Ant Design v6's\n * semantic DOM keys exactly. Same names, same nesting, so a `classNames` object\n * written for antd keeps working.\n */\nexport type TimelineSlot =\n  | \"root\"\n  | \"item\"\n  | \"itemWrapper\"\n  | \"itemIcon\"\n  | \"itemSection\"\n  | \"itemHeader\"\n  | \"itemTitle\"\n  | \"itemContent\"\n  | \"itemRail\";\n\nexport interface TimelineItemType {\n  key?: React.Key;\n  /** v6 name for the node's heading. */\n  title?: React.ReactNode;\n  /** v6 name for the node's body. */\n  content?: React.ReactNode;\n  /** v6 name for the node mark. */\n  icon?: React.ReactNode;\n  color?: TimelineColor;\n  loading?: boolean;\n  /** Which side, in `mode=\"alternate\"`. v6 name. */\n  placement?: TimelineItemPlacement;\n  className?: string;\n  style?: React.CSSProperties;\n  classNames?: Partial<Record<TimelineSlot, string>>;\n  styles?: Partial<Record<TimelineSlot, React.CSSProperties>>;\n\n  /** @deprecated Ant Design v6 renamed this to `title`. Accepted for parity. */\n  label?: React.ReactNode;\n  /** @deprecated Ant Design v6 renamed this to `content`. Accepted for parity. */\n  children?: React.ReactNode;\n  /** @deprecated Ant Design v6 renamed this to `icon`. Accepted for parity. */\n  dot?: React.ReactNode;\n  /** @deprecated Ant Design v6 renamed this to `placement`. Accepted for parity. */\n  position?: TimelineItemPosition;\n}\n\ninterface TimelineOwnProps extends Omit<\n  React.HTMLAttributes<HTMLOListElement>,\n  \"className\" | \"style\" | \"children\"\n> {\n  /**\n   * The events, in order. Ant Design's `items` API exactly — the difference is what this\n   * component refuses to infer from them.\n   */\n  items?: readonly TimelineItemType[];\n  /** `<Timeline.Item>` children, as antd v5 wrote them. Accepted for parity. */\n  children?: React.ReactNode;\n  /** Ant Design v6 resolves an unset value to `start`. So does this. */\n  mode?: TimelineMode;\n  /** Horizontal or vertical. Ant Design's `tabPlacement`-style rename in v6. */\n  orientation?: TimelineOrientation;\n  /**\n   * Rail treatment. Never used to imply a state: antd's Timeline dots a rail for whatever it\n   * decides is `current`, and on a clinical chronology a dotted rail reads as a data claim\n   * nobody authored.\n   */\n  variant?: TimelineVariant;\n  /** Distance to the centre of the node. A number is a ratio; a string is a length. */\n  titleSpan?: string | number;\n  /**\n   * Newest first. Reverses the rendered order only — it does not change which item is treated\n   * as current, which is the bug this component exists not to reproduce.\n   */\n  reverse?: boolean;\n  /** Ant Design's class prefix. Accepted for parity with an existing antd theme. */\n  prefixCls?: string;\n  /** Applied to the root element, alongside the generated classes. */\n  rootClassName?: string;\n  /** Applied to the list element. */\n  className?: string;\n  /** Inline styles on the list element. */\n  style?: React.CSSProperties;\n  /** Per-slot class names — rail, node, content, label. Ant Design v6's semantic-DOM API. */\n  classNames?: Partial<Record<TimelineSlot, string>>;\n  /** Per-slot inline styles. The counterpart to `classNames`. */\n  styles?: Partial<Record<TimelineSlot, React.CSSProperties>>;\n\n  /**\n   * A trailing \"in progress\" entry, as antd v5 wrote it.\n   *\n   * @deprecated Ant Design v6 takes a pending item in `items`. Accepted for parity.\n   */\n  pending?: React.ReactNode;\n  /**\n   * The icon for the pending entry, as antd v5 wrote it.\n   *\n   * @deprecated Ant Design v6 takes `items[].icon`. Accepted for parity.\n   */\n  pendingDot?: React.ReactNode;\n}\n\n/**\n * One of the two has to be present.\n *\n * Expressed in the type rather than checked at runtime, because an unnamed\n * list is invisible in review, invisible in a rendering test, and obvious to\n * exactly one group of people.\n */\nexport type TimelineProps = TimelineOwnProps &\n  ({ \"aria-label\": string } | { \"aria-labelledby\": string });\n\n/**\n * The class names this component renders, spelled out.\n *\n * A literal table rather than interpolation at the call site, for the reason\n * `@zoblocks/no-dynamic-class-name` exists: a class assembled from a variable\n * is invisible to anything that resolves classes by scanning source text, and\n * an unstyled element is a defect that renders perfectly.\n *\n * `prefixCls` is Ant Design's escape hatch and it has to keep working, so\n * `partsFor` rebuilds the table for a caller who supplies one. A caller who\n * changes the prefix is supplying their own stylesheet by definition — the\n * names below are the ones `timeline.css` defines, and they are static there.\n */\nconst PARTS = {\n  root: \"zb-timeline\",\n  item: \"zb-timeline__item\",\n  rail: \"zb-timeline__rail\",\n  node: \"zb-timeline__node\",\n  line: \"zb-timeline__line\",\n  body: \"zb-timeline__body\",\n  section: \"zb-timeline__section\",\n  header: \"zb-timeline__header\",\n  title: \"zb-timeline__title\",\n  content: \"zb-timeline__content\",\n  itemStart: \"zb-timeline__item--start\",\n  itemEnd: \"zb-timeline__item--end\",\n  modeStart: \"zb-timeline--start\",\n  modeEnd: \"zb-timeline--end\",\n  modeAlternate: \"zb-timeline--alternate\",\n  vertical: \"zb-timeline--vertical\",\n  horizontal: \"zb-timeline--horizontal\",\n  outlined: \"zb-timeline--outlined\",\n  filled: \"zb-timeline--filled\",\n} as const;\n\nconst DEFAULT_PREFIX = \"zb-timeline\";\n\ntype Parts = typeof PARTS;\n\nfunction partsFor(prefixCls: string): Parts {\n  if (prefixCls === DEFAULT_PREFIX) return PARTS;\n  const swap = (value: string) => prefixCls + value.slice(DEFAULT_PREFIX.length);\n  return Object.fromEntries(\n    Object.entries(PARTS).map(([key, value]) => [key, swap(value)]),\n  ) as Parts;\n}\n\nconst PRESET_COLOR: Readonly<Record<string, string>> = {\n  blue: \"var(--zb-accent)\",\n  red: \"var(--zb-status-critical)\",\n  green: \"var(--zb-status-normal)\",\n  gray: \"var(--zb-text-subtle)\",\n};\n\n/** antd v5's physical sides mean the same thing as v6's logical ones. */\nfunction normalizeMode(mode: TimelineMode | undefined): \"start\" | \"end\" | \"alternate\" {\n  if (mode === \"left\") return \"start\";\n  if (mode === \"right\") return \"end\";\n  if (mode === \"start\" || mode === \"end\" || mode === \"alternate\") return mode;\n  return \"start\";\n}\n\nfunction normalizePlacement(item: TimelineItemType): TimelineItemPlacement | undefined {\n  if (item.placement) return item.placement;\n  if (item.position === \"left\" || item.position === \"start\") return \"start\";\n  if (item.position === \"right\" || item.position === \"end\") return \"end\";\n  return undefined;\n}\n\n/**\n * `<Timeline.Item>` children, read into the `items` shape.\n *\n * antd's own `Timeline.Item` is a no-op function whose props are harvested by\n * the parent; this does the same thing, so children and `items` produce an\n * identical tree.\n */\nfunction itemsFromChildren(children: React.ReactNode): TimelineItemType[] {\n  const collected: TimelineItemType[] = [];\n  React.Children.forEach(children, (child, index) => {\n    if (!React.isValidElement(child)) return;\n    const props = child.props as TimelineItemType;\n    collected.push({ ...props, key: child.key ?? props.key ?? index });\n  });\n  return collected;\n}\n\n/**\n * A node with nothing else to show. Not a status: purely the default mark.\n */\nfunction DefaultIcon() {\n  return (\n    <span\n      aria-hidden=\"true\"\n      style={{\n        inlineSize: \"0.4375rem\",\n        blockSize: \"0.4375rem\",\n        borderRadius: \"var(--zb-radius-full)\",\n        background: \"currentColor\",\n        display: \"block\",\n      }}\n    />\n  );\n}\n\n/**\n * The item type. Renders nothing itself — its props are harvested by the\n * parent, exactly as Ant Design's own `Timeline.Item` works.\n */\nconst TimelineItem: React.FC<TimelineItemType> = () => null;\nTimelineItem.displayName = \"Timeline.Item\";\n\nfunction TimelineRoot({\n  ref,\n  ...props\n}: TimelineProps & {\n  /** The `<ol>` the timeline renders. It is a list, not a `<ul>` — antd's own docs say otherwise and its source does this. */\n  ref?: React.Ref<HTMLOListElement>;\n}) {\n  const {\n    items,\n    children,\n    mode,\n    orientation = \"vertical\",\n    variant = \"outlined\",\n    titleSpan,\n    reverse = false,\n    prefixCls = \"zb-timeline\",\n    rootClassName,\n    className,\n    style,\n    classNames: slotClassNames,\n    styles: slotStyles,\n    pending,\n    pendingDot,\n    ...rest\n  } = props;\n\n  const resolvedMode = normalizeMode(mode);\n  const parts = partsFor(prefixCls);\n\n  const resolved = React.useMemo(() => {\n    const base = items && items.length > 0 ? [...items] : itemsFromChildren(children);\n    if (pending !== undefined && pending !== false) {\n      base.push({\n        key: \"__pending__\",\n        content: pending === true ? undefined : pending,\n        icon: pendingDot,\n        loading: true,\n      });\n    }\n    return reverse ? base.reverse() : base;\n  }, [items, children, pending, pendingDot, reverse]);\n\n  const rootStyle: React.CSSProperties = { ...slotStyles?.root, ...style };\n  if (titleSpan !== undefined) {\n    (rootStyle as Record<string, string | number>)[\"--zb-timeline-title-span\"] =\n      typeof titleSpan === \"number\" ? `${titleSpan}` : titleSpan;\n  }\n\n  return (\n    <ol\n      {...rest}\n      ref={ref}\n      role=\"list\"\n      data-zb-timeline=\"\"\n      data-zb-mode={resolvedMode}\n      data-zb-orientation={orientation}\n      data-zb-variant={variant}\n      className={cn(\n        parts.root,\n        resolvedMode === \"alternate\"\n          ? parts.modeAlternate\n          : resolvedMode === \"end\"\n            ? parts.modeEnd\n            : parts.modeStart,\n        orientation === \"horizontal\" ? parts.horizontal : parts.vertical,\n        variant === \"filled\" ? parts.filled : parts.outlined,\n        slotClassNames?.root,\n        rootClassName,\n        className,\n      )}\n      style={rootStyle}\n    >\n      {resolved.map((item, index) => {\n        const placement =\n          normalizePlacement(item) ??\n          (resolvedMode === \"alternate\" && index % 2 === 1 ? \"start\" : \"end\");\n        const title = item.title ?? item.label;\n        const content = item.content ?? item.children;\n        const icon = item.icon ?? item.dot;\n        const color = item.color ? (PRESET_COLOR[item.color] ?? item.color) : undefined;\n\n        return (\n          <li\n            key={item.key ?? index}\n            className={cn(\n              parts.item,\n              placement === \"start\" ? parts.itemStart : parts.itemEnd,\n              slotClassNames?.item,\n              item.classNames?.item,\n              item.className,\n            )}\n            style={{ ...slotStyles?.item, ...item.styles?.item, ...item.style }}\n          >\n            <span\n              className={cn(parts.rail, slotClassNames?.itemRail, item.classNames?.itemRail)}\n              style={{ ...slotStyles?.itemRail, ...item.styles?.itemRail }}\n            >\n              <span\n                className={cn(parts.node, slotClassNames?.itemIcon, item.classNames?.itemIcon)}\n                style={{\n                  ...slotStyles?.itemIcon,\n                  ...item.styles?.itemIcon,\n                  ...(color ? { color, borderColor: color } : undefined),\n                }}\n                data-loading={item.loading ? \"\" : undefined}\n              >\n                {icon ?? <DefaultIcon />}\n              </span>\n              <span className={parts.line} />\n            </span>\n\n            <div\n              className={cn(parts.body, slotClassNames?.itemWrapper, item.classNames?.itemWrapper)}\n              style={{ ...slotStyles?.itemWrapper, ...item.styles?.itemWrapper }}\n            >\n              <div\n                className={cn(\n                  parts.section,\n                  slotClassNames?.itemSection,\n                  item.classNames?.itemSection,\n                )}\n                style={{ ...slotStyles?.itemSection, ...item.styles?.itemSection }}\n              >\n                {title === undefined ? null : (\n                  <div\n                    className={cn(\n                      parts.header,\n                      slotClassNames?.itemHeader,\n                      item.classNames?.itemHeader,\n                    )}\n                    style={{ ...slotStyles?.itemHeader, ...item.styles?.itemHeader }}\n                  >\n                    <div\n                      className={cn(\n                        parts.title,\n                        slotClassNames?.itemTitle,\n                        item.classNames?.itemTitle,\n                      )}\n                      style={{ ...slotStyles?.itemTitle, ...item.styles?.itemTitle }}\n                    >\n                      {title}\n                    </div>\n                  </div>\n                )}\n                {content === undefined ? null : (\n                  <div\n                    className={cn(\n                      parts.content,\n                      slotClassNames?.itemContent,\n                      item.classNames?.itemContent,\n                    )}\n                    style={{ ...slotStyles?.itemContent, ...item.styles?.itemContent }}\n                  >\n                    {content}\n                  </div>\n                )}\n              </div>\n            </div>\n          </li>\n        );\n      })}\n    </ol>\n  );\n}\n\nTimelineRoot.displayName = \"Timeline\";\n\nexport const Timeline = Object.assign(TimelineRoot, { Item: TimelineItem });\n"
    }
  ]
}
