{
  "name": "audit-log",
  "type": "registry:ui",
  "framework": "react",
  "title": "Audit Log",
  "description": "A list of who changed what and when, with entries that open to show each change.",
  "registryDependencies": [
    "@newtui/avatar"
  ],
  "files": [
    {
      "path": "ui/audit-log.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Avatar } from \"@/registry/bases/newt/ui/avatar\"\n\n/*\n * A record of who changed what, newest first, as an ordered list. Pass\n * `aria-label` to name it.\n */\nconst AuditLog = React.forwardRef<HTMLOListElement, React.ComponentProps<\"ol\">>(\n  ({ className, ...props }, ref) => (\n    <ol\n      ref={ref}\n      className={cn(\"m-0 flex w-full list-none flex-col gap-2 p-0\", className)}\n      {...props}\n    />\n  )\n)\nAuditLog.displayName = \"AuditLog\"\n\nexport type AuditLogKind = \"create\" | \"update\" | \"delete\"\n\n/* One shape per kind, so three colours are never the only difference. */\nconst KIND = {\n  create: {\n    className: \"text-newt-online\",\n    label: \"Added\",\n    path: \"M8 2a1 1 0 0 1 1 1v4h4a1 1 0 1 1 0 2H9v4a1 1 0 1 1-2 0V9H3a1 1 0 0 1 0-2h4V3a1 1 0 0 1 1-1Z\",\n  },\n  update: {\n    className: \"text-newt-idle\",\n    label: \"Updated\",\n    path: \"M8 2.75a5.25 5.25 0 1 0 0 10.5 5.25 5.25 0 0 0 0-10.5Zm0 2.5a2.75 2.75 0 1 1 0 5.5 2.75 2.75 0 0 1 0-5.5Z\",\n  },\n  delete: {\n    className: \"text-newt-danger\",\n    label: \"Removed\",\n    path: \"M3 7h10a1 1 0 1 1 0 2H3a1 1 0 0 1 0-2Z\",\n  },\n} as const\n\nexport interface AuditLogEntryProps extends Omit<\n  React.ComponentProps<\"li\">,\n  \"children\"\n> {\n  /** Who did it. The first letter is the avatar's fallback. */\n  actor: string\n  /** What they did, as the middle of a sentence: \"updated the role\". */\n  action: string\n  /** What they did it to. */\n  target?: string\n  kind?: AuditLogKind\n  /** The time as the reader should see it. */\n  time: string\n  /** The same moment in machine form, for the `<time>` element. */\n  dateTime?: string\n  /** Replaces the default initial avatar, for one with an image. */\n  avatar?: React.ReactNode\n  /** Read by a screen reader in place of the kind's shape. */\n  kindLabel?: string\n  /** Start with the changes showing. */\n  defaultOpen?: boolean\n  /** `AuditLogChange` rows. With none, the entry does not open. */\n  children?: React.ReactNode\n}\n\nconst summaryClassName =\n  \"flex list-none items-center gap-2.5 px-3 py-2.5 text-sm leading-5 text-newt-text-secondary [&::-webkit-details-marker]:hidden\"\n\n/*\n * An entry with changes is a native `<details>`, so it opens with Enter or\n * Space and needs no script; one without is a plain row.\n */\nconst AuditLogEntry = React.forwardRef<HTMLLIElement, AuditLogEntryProps>(\n  (\n    {\n      className,\n      actor,\n      action,\n      target,\n      kind = \"update\",\n      time,\n      dateTime,\n      avatar,\n      kindLabel,\n      defaultOpen = false,\n      children,\n      ...props\n    },\n    ref\n  ) => {\n    const mark = KIND[kind]\n    const line = (\n      <>\n        <span className={cn(\"inline-flex shrink-0\", mark.className)}>\n          <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className=\"h-4 w-4\">\n            <path fill=\"currentColor\" fillRule=\"evenodd\" d={mark.path} />\n          </svg>\n          <span className=\"sr-only\">{kindLabel ?? mark.label}</span>\n        </span>\n        {avatar ?? <Avatar size=\"sm\">{actor.slice(0, 1).toUpperCase()}</Avatar>}\n        <span className=\"min-w-0 flex-1\">\n          <strong className=\"font-semibold text-newt-text-primary\">\n            {actor}\n          </strong>{\" \"}\n          {action}\n          {target === undefined ? null : (\n            <>\n              {\" \"}\n              <strong className=\"font-semibold text-newt-text-primary\">\n                {target}\n              </strong>\n            </>\n          )}\n        </span>\n        <time\n          dateTime={dateTime}\n          className=\"shrink-0 text-xs text-newt-text-muted\"\n        >\n          {time}\n        </time>\n      </>\n    )\n    /* `toArray` drops `null` and `false`, so `{cond && <Change />}` counts as none. */\n    const expandable = React.Children.toArray(children).length > 0\n    return (\n      <li\n        ref={ref}\n        data-kind={kind}\n        className={cn(\n          \"overflow-hidden rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-surface\",\n          className\n        )}\n        {...props}\n      >\n        {expandable ? (\n          <details open={defaultOpen || undefined} className=\"group\">\n            <summary\n              className={cn(\n                summaryClassName,\n                \"cursor-pointer hover:bg-newt-bg-hover focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-newt-text-link\"\n              )}\n            >\n              {line}\n              <svg\n                viewBox=\"0 0 16 16\"\n                aria-hidden=\"true\"\n                className=\"h-3.5 w-3.5 shrink-0 text-newt-text-muted group-open:rotate-90 rtl:-scale-x-100 rtl:group-open:scale-x-100\"\n              >\n                <path\n                  fill=\"currentColor\"\n                  d=\"M5.3 3.3a1 1 0 0 1 1.4 0l4 4a1 1 0 0 1 0 1.4l-4 4a1 1 0 0 1-1.4-1.4L8.6 8 5.3 4.7a1 1 0 0 1 0-1.4Z\"\n                />\n              </svg>\n            </summary>\n            <ol className=\"m-0 flex flex-col gap-1 pb-3 pe-3 ps-12 pt-1 text-[13px] leading-[18px] text-newt-text-secondary [list-style:decimal-leading-zero_inside]\">\n              {children}\n            </ol>\n          </details>\n        ) : (\n          <div className={summaryClassName}>{line}</div>\n        )}\n      </li>\n    )\n  }\n)\nAuditLogEntry.displayName = \"AuditLogEntry\"\n\n/** One numbered line under an entry. Wrap the value that changed in `<strong>`. */\nconst AuditLogChange = React.forwardRef<\n  HTMLLIElement,\n  React.ComponentProps<\"li\">\n>(({ className, children, ...props }, ref) => (\n  <li\n    ref={ref}\n    className={cn(\n      \"marker:font-[family-name:var(--newt-font-mono)] marker:text-xs marker:text-newt-text-muted [&_strong]:font-semibold [&_strong]:text-newt-text-primary\",\n      className\n    )}\n    {...props}\n  >\n    {children}\n  </li>\n))\nAuditLogChange.displayName = \"AuditLogChange\"\n\nexport { AuditLog, AuditLogEntry, AuditLogChange }\n",
      "type": "registry:ui"
    }
  ]
}