{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "update-feed",
  "type": "registry:ui",
  "title": "Update Feed",
  "description": "What is new, newest first: a product's changelog, a publication's latest pieces, a team's releases. Entries are grouped under their day or month, each with a kind (\"Release\", \"Article\"), a title that links to the thing itself and a line on what it is. Pass…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "blog",
    "pattern"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/patterns/update-feed.tsx",
      "target": "components/ui/patterns/update-feed.tsx",
      "type": "registry:ui",
      "content": "import * as React from 'react';\n\n// @interlace/update-feed v1.0.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/update-feed\n// What changed since: https://ds.interlace.tools/c/update-feed#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — UpdateFeed\n *\n * What is new, newest first: a product's changelog, a publication's latest\n * pieces, a team's releases. Entries are grouped under their day or month,\n * each with a kind (\"Release\", \"Article\"), a title that links to the thing\n * itself and a line on what it is. Pass `since`, the moment the reader last\n * looked, and the entries that arrived after it carry a \"New\" tag and the\n * feed opens with how many there are: a reason to come back, said once.\n *\n * ## Anatomy\n *\n *   UpdateFeed                      (div — data-slot=\"update-feed\", @container)\n *     ├─ p                          (data-slot=\"update-feed-summary\": \"3 new since your last visit\", only with new entries)\n *     ├─ section × groups           (data-slot=\"update-feed-group\", labelled by its heading)\n *     │   ├─ h2                     (data-slot=\"update-feed-date\": a real <time>)\n *     │   └─ ol                     (data-slot=\"update-feed-list\")\n *     │       └─ li                 (data-slot=\"update-feed-entry\", data-new when new)\n *     │           ├─ p              (data-slot=\"update-feed-kind\": kind + \"New\" tag)\n *     │           ├─ h3 > a         (data-slot=\"update-feed-title\")\n *     │           └─ p              (data-slot=\"update-feed-description\")\n *     └─ p                          (data-slot=\"update-feed-empty\", only with no entries)\n *\n * ## Layout\n *\n * In a narrow column the date heads its group. Once the feed itself is\n * 42rem wide (a container query, so it works in a sidebar too) the date\n * moves to a rail on the start side and the entries read beside it.\n *\n * ## Links\n *\n * Titles are plain `<a href>`. A framework router passes `renderLink`, which\n * gets the href, the class and the children, and returns its own link.\n *\n * ## Dates and the server\n *\n * Dates format through `Intl.DateTimeFormat` in UTC, so a day key reads as\n * the same day on the server and in every time zone. `since` usually lives\n * in the browser (local storage), so a server render passes none and the\n * client adds the tags after it reads it: the entries never move, only the\n * tags appear.\n *\n * ## MIN_VIEWPORT — 320\n *\n * | Rule | Concept                   | Where in this file                                     |\n * | ---- | ------------------------- | ------------------------------------------------------ |\n * | R4   | Extends native el         | `React.ComponentProps<'div'>`                          |\n * | R6   | data-slot per part        | update-feed / -summary / -group / -date / -list / -entry / -kind / -title / -description / -empty |\n * | R7   | cn + ...rest              | `cn(…, className)` + `{...props}`                      |\n * | R14  | Declares min viewport     | `data-min-viewport` + exported const                   |\n * | R19  | Tokens only               | primary, border, muted-foreground, foreground, ring    |\n * | R26  | A11y                      | groups labelled by real <time> headings; \"New\" in words, not colour |\n */\n\nimport { cn } from '@/lib/utils';\nimport { groupUpdates, isNewSince, type UpdateFeedEntry } from '@/components/ui/patterns/update-feed-model';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ninterface UpdateFeedItem extends UpdateFeedEntry {\n  title: React.ReactNode;\n  href?: string;\n  /** A short label for what kind of update it is. */\n  kind?: React.ReactNode;\n  description?: React.ReactNode;\n}\n\ninterface UpdateFeedLinkProps {\n  href: string;\n  className: string;\n  children: React.ReactNode;\n  'data-slot': string;\n}\n\ninterface UpdateFeedLabels {\n  /** @default 'New' */\n  new?: string;\n  /** @default n => `${n} new since your last visit` (n is formatted) */\n  newSince?: (n: string, count: number) => string;\n  /** @default 'Nothing here yet.' */\n  empty?: string;\n}\n\ntype UpdateFeedProps = Omit<React.ComponentProps<'div'>, 'children'> & {\n  entries: readonly UpdateFeedItem[];\n  /** Group under each day or each month. @default 'day' */\n  groupBy?: 'day' | 'month';\n  /** When the reader last looked (ISO string or day key). Entries after it are tagged new. */\n  since?: string | null;\n  /** The level of the date headings; entry titles sit one below. @default 2 */\n  headingLevel?: 2 | 3;\n  renderLink?: (props: UpdateFeedLinkProps) => React.ReactNode;\n  locale?: string;\n  labels?: UpdateFeedLabels;\n};\n\nconst toDate = (key: string) => new Date(`${key.length === 7 ? `${key}-01` : key}T00:00:00Z`);\n\nfunction UpdateFeed({\n  entries,\n  groupBy = 'day',\n  since,\n  headingLevel = 2,\n  renderLink,\n  locale,\n  labels,\n  className,\n  ...props\n}: UpdateFeedProps) {\n  const groups = React.useMemo(() => groupUpdates(entries, groupBy), [entries, groupBy]);\n  const baseId = React.useId();\n  const nf = new Intl.NumberFormat(locale);\n  const dateFormat = new Intl.DateTimeFormat(\n    locale,\n    groupBy === 'day'\n      ? { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' }\n      : { year: 'numeric', month: 'long', timeZone: 'UTC' },\n  );\n  const newCount = entries.reduce((n, e) => n + (isNewSince(e, since) ? 1 : 0), 0);\n  const words = {\n    new: labels?.new ?? 'New',\n    newSince: labels?.newSince ?? ((n: string) => `${n} new since your last visit`),\n    empty: labels?.empty ?? 'Nothing here yet.',\n  };\n  const GroupHeading = `h${headingLevel}` as 'h2' | 'h3';\n  const EntryHeading = `h${headingLevel + 1}` as 'h3' | 'h4';\n  const titleClass =\n    'focus-visible:outline-ring rounded-sm underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-offset-2';\n\n  return (\n    <div\n      data-slot=\"update-feed\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('@container grid gap-10', className)}\n      {...props}\n    >\n      {newCount > 0 ? (\n        <p data-slot=\"update-feed-summary\" className=\"text-primary text-sm font-semibold\">\n          {words.newSince(nf.format(newCount), newCount)}\n        </p>\n      ) : null}\n      {groups.map((group) => {\n        const headingId = `${baseId}-${group.key}`;\n        return (\n          <section\n            key={group.key}\n            data-slot=\"update-feed-group\"\n            aria-labelledby={headingId}\n            className=\"grid gap-4 @2xl:grid-cols-[11rem_1fr] @2xl:gap-8\"\n          >\n            <GroupHeading\n              id={headingId}\n              data-slot=\"update-feed-date\"\n              className=\"text-muted-foreground text-sm font-medium @2xl:pt-1\"\n            >\n              <time dateTime={group.key}>{dateFormat.format(toDate(group.key))}</time>\n            </GroupHeading>\n            <ol data-slot=\"update-feed-list\" className=\"divide-border grid divide-y\">\n              {group.entries.map((entry) => {\n                const isNew = isNewSince(entry, since);\n                return (\n                  <li\n                    key={entry.id}\n                    data-slot=\"update-feed-entry\"\n                    data-new={isNew ? '' : undefined}\n                    className=\"grid gap-1 py-4 first:pt-0 last:pb-0\"\n                  >\n                    {entry.kind || isNew ? (\n                      <p\n                        data-slot=\"update-feed-kind\"\n                        className=\"text-muted-foreground flex flex-wrap items-center gap-x-2 gap-y-1 text-xs font-medium\"\n                      >\n                        {entry.kind ? <span>{entry.kind}</span> : null}\n                        {isNew ? (\n                          <span className=\"text-primary inline-flex items-center gap-1 font-semibold\">\n                            <span aria-hidden className=\"bg-primary size-1.5 rounded-full\" />\n                            {words.new}\n                          </span>\n                        ) : null}\n                      </p>\n                    ) : null}\n                    <EntryHeading className=\"font-heading text-lg leading-snug font-semibold text-balance\">\n                      {entry.href ? (\n                        renderLink ? (\n                          renderLink({\n                            href: entry.href,\n                            className: titleClass,\n                            children: entry.title,\n                            'data-slot': 'update-feed-title',\n                          })\n                        ) : (\n                          <a href={entry.href} data-slot=\"update-feed-title\" className={titleClass}>\n                            {entry.title}\n                          </a>\n                        )\n                      ) : (\n                        <span data-slot=\"update-feed-title\">{entry.title}</span>\n                      )}\n                    </EntryHeading>\n                    {entry.description ? (\n                      <p data-slot=\"update-feed-description\" className=\"text-muted-foreground text-sm leading-relaxed\">\n                        {entry.description}\n                      </p>\n                    ) : null}\n                  </li>\n                );\n              })}\n            </ol>\n          </section>\n        );\n      })}\n      {groups.length === 0 ? (\n        <p data-slot=\"update-feed-empty\" className=\"text-muted-foreground text-sm\">\n          {words.empty}\n        </p>\n      ) : null}\n    </div>\n  );\n}\nUpdateFeed.displayName = 'UpdateFeed';\n\nexport { UpdateFeed };\nexport type { UpdateFeedProps, UpdateFeedItem, UpdateFeedLabels, UpdateFeedLinkProps };\n"
    },
    {
      "path": "registry/interlace-ui/patterns/update-feed-model.ts",
      "target": "components/ui/patterns/update-feed-model.ts",
      "type": "registry:ui",
      "content": "export interface UpdateFeedEntry {\n  /** Stable id: a key, and the tie-break for entries with the same date. */\n  id: string;\n  /** ISO date or timestamp. */\n  date: string;\n}\n\nexport interface UpdateGroup<T extends UpdateFeedEntry> {\n  /** `YYYY-MM-DD` for a day, `YYYY-MM` for a month. */\n  key: string;\n  entries: T[];\n}\n\nconst ISO_DAY = /^\\d{4}-\\d{2}-\\d{2}/;\n\n/** Newest first, ties by id. Entries without a readable date go last. */\nexport function sortUpdates<T extends UpdateFeedEntry>(entries: readonly T[]): T[] {\n  return entries\n    .slice()\n    .sort((a, b) => {\n      const ra = ISO_DAY.test(a.date);\n      const rb = ISO_DAY.test(b.date);\n      if (ra !== rb) return ra ? -1 : 1;\n      return a.date < b.date ? 1 : a.date > b.date ? -1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;\n    });\n}\n\n/** Newest group first; inside a group, newest entry first. */\nexport function groupUpdates<T extends UpdateFeedEntry>(\n  entries: readonly T[],\n  by: 'day' | 'month' = 'day',\n): UpdateGroup<T>[] {\n  const groups: UpdateGroup<T>[] = [];\n  for (const entry of sortUpdates(entries)) {\n    if (!ISO_DAY.test(entry.date)) continue;\n    const key = entry.date.slice(0, by === 'day' ? 10 : 7);\n    const last = groups.at(-1);\n    if (last?.key === key) last.entries.push(entry);\n    else groups.push({ key, entries: [entry] });\n  }\n  return groups;\n}\n\n/** True when `entry` arrived after `since`. False on a first visit (no `since`). */\nexport function isNewSince(entry: UpdateFeedEntry, since: string | null | undefined): boolean {\n  if (!since || !ISO_DAY.test(since) || !ISO_DAY.test(entry.date)) return false;\n  return entry.date > since;\n}\n\n/** How many entries arrived after `since`: the number for a badge. */\nexport function countNewSince(\n  entries: readonly UpdateFeedEntry[],\n  since: string | null | undefined,\n): number {\n  return entries.reduce((n, e) => n + (isNewSince(e, since) ? 1 : 0), 0);\n}\n\n/**\n * @interlace/ui — patterns/update-feed-model\n *\n * The arithmetic under an `UpdateFeed`: newest first, grouped by day or by\n * month, and which entries arrived since the reader last looked. Pure, so a\n * server can build the same groups, an RSS file can use the same order, and\n * an app badge can count the same \"new\" the page marks.\n *\n * ## Dates\n *\n * An entry's `date` is an ISO calendar date, `\"2026-11-24\"`, or a full ISO\n * timestamp. Grouping reads the first ten characters, so it never shifts a\n * day with the reader's time zone. Order is by the full string, then by\n * `id`, so two entries on one day keep a stable order on every device.\n *\n * ## New since\n *\n * `since` is the moment the reader last saw the feed, as an ISO string or a\n * day key. An entry is new when its `date` sorts after `since`. With no\n * `since` (a first visit) nothing is marked: everything is new, which says\n * nothing.\n */\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": false,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/update-feed\n\nInstalled to `components/ui/patterns/update-feed.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/update-feed';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/update-feed\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
