Audit Log Timeline
Security audit log card for admin dashboards: a dense timeline with one row per event, the actor in bold, a right-aligned time, a muted monospace line of IP, key or device detail, and an Export button.
"use client"
import {
Timeline,
TimelineContent,
TimelineIndicator,
TimelineItem,
TimelineLabel,
TimelineTitle,
} from "@/components/timeline/timeline"
import { Button } from "@/components/ui/button"
import {
Card,
CardAction,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
// The copy: change text here, not in the markup.
const COPY = {
title: "Audit log",
body: "Security-relevant events on this workspace.",
cta: "Export",
file: "audit-log.csv",
columns: ["Actor", "Action", "Details", "Time"],
} as const
const EVENTS = [
{
actor: "Pamela Melroy",
action: "changed the billing email",
meta: "pamela@orbcore.dev · 193.0.12.4",
time: "14:02",
},
{
actor: "Alexei Leonov",
action: "created an API key",
meta: "ok_live_…9f2a · 10.4.0.18",
time: "13:47",
},
{
actor: "Megan McArthur",
action: "removed Luca Parmitano from Admins",
meta: "193.0.12.9",
time: "11:20",
},
{
actor: "System",
action: "rotated the signing secret",
meta: "scheduled",
time: "03:00",
},
{
actor: "Raja Chari",
action: "signed in with a new device",
meta: "macOS · Chrome · Lisbon",
time: "Yesterday 22:15",
},
{
actor: "Sian Proctor",
action: "enabled two-factor sign-in",
meta: "193.0.12.2",
time: "Yesterday 09:31",
},
] as const
// Builds a CSV of every event and hands it to the browser as a download.
function exportCsv() {
const quote = (value: string) => `"${value.replaceAll('"', '""')}"`
const lines = [
COPY.columns,
...EVENTS.map((e) => [e.actor, e.action, e.meta, e.time]),
].map((row) => row.map(quote).join(","))
const url = URL.createObjectURL(
new Blob([lines.join("\n")], { type: "text/csv;charset=utf-8" })
)
const link = document.createElement("a")
link.href = url
link.download = COPY.file
link.click()
URL.revokeObjectURL(url)
}
// Dense: one line per event, the detail in a muted mono line under it. The
// actor is the bold name, not a mark; the dot only places the row in time.
export default function AuditLogTimeline01() {
return (
<Card className="mx-auto w-full max-w-md">
<CardHeader>
<CardTitle>{COPY.title}</CardTitle>
<CardDescription>{COPY.body}</CardDescription>
<CardAction>
<Button variant="outline" size="sm" onClick={exportCsv}>
{COPY.cta}
</Button>
</CardAction>
</CardHeader>
<CardContent>
<Timeline className="[--timeline-lh:1.25rem]">
{EVENTS.map((e) => (
<TimelineItem key={e.action + e.time}>
<TimelineIndicator variant="plain" />
<TimelineContent className="pb-5">
<div className="flex items-baseline justify-between gap-3">
<TimelineTitle className="text-sm/5 font-normal">
<span className="font-medium">{e.actor}</span> {e.action}
</TimelineTitle>
<TimelineLabel className="shrink-0 tabular-nums">
{e.time}
</TimelineLabel>
</div>
<p className="mt-0.5 font-mono text-xs text-muted-foreground">
{e.meta}
</p>
</TimelineContent>
</TimelineItem>
))}
</Timeline>
</CardContent>
</Card>
)
}
import type { ComponentProps } from "react"
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cn } from "cn"
/**
* A vertical timeline, as an ordered list. Holds `TimelineItem` entries,
* each with a mark and a line down to the next.
*
* Three CSS variables, set on it through `className` or `style`, tune the
* marks. `--timeline-lh` is the line height of the first line in
* `TimelineContent`, so the mark lines up with it: the default 1rem suits a
* leading `TimelineLabel`; set 1.5rem when a title or body text comes first.
* `--timeline-dot` is the mark's diameter (1rem). `--timeline-nudge` (1px)
* lowers the mark slightly, because a mark centered on a line of text looks
* high.
*/
function Timeline({ className, ...props }: ComponentProps<"ol">) {
return (
<ol
role="list"
data-slot="timeline"
className={cn(
"relative [--timeline-dot:1rem] [--timeline-lh:1rem] [--timeline-nudge:1px]",
"[--timeline-shift:calc((var(--timeline-lh)-var(--timeline-dot))/2+var(--timeline-nudge))]",
className
)}
{...props}
/>
)
}
/**
* One entry, an `li` by default. Put a `TimelineIndicator` and a
* `TimelineContent` inside it. It draws the line from under its mark to the
* next entry's mark; the last entry has none. A `Timeline` nested inside
* `TimelineContent` keeps its own lines.
*/
function TimelineItem({
className,
children,
render,
...props
}: useRender.ComponentProps<"li">) {
return useRender({
defaultTagName: "li",
render,
state: { slot: "timeline-item" },
props: mergeProps<"li">(
{
className: cn(
"group/timeline-item relative flex items-start gap-3",
className
),
children: (
<>
<div
aria-hidden
data-slot="timeline-line"
className={cn(
// Runs from under this mark to the top of the next, never through it. The
// last-item check looks at the direct parent only, so a Timeline nested in
// TimelineContent keeps its own rails.
"pointer-events-none absolute top-[calc(var(--timeline-shift)+var(--timeline-dot))]",
"left-[calc(var(--timeline-dot)/2)] w-px -translate-x-1/2",
"h-[calc(100%-var(--timeline-dot))]",
// A 1px rail can't get thinner, so it is lighter than the type.
"bg-muted-foreground/45 [[data-slot=timeline-item]:last-child>&]:hidden"
)}
/>
{children}
</>
),
},
props
),
})
}
const indicatorVariants = {
default: { ring: "", dot: "bg-foreground" },
muted: { ring: "border-border", dot: "bg-muted-foreground/60" },
plain: { ring: "border-0", dot: "bg-muted-foreground/60" },
faint: { ring: "border-0", dot: "bg-border" },
line: { ring: "border-border", dot: "bg-border" },
empty: { ring: "border-border bg-transparent", dot: "hidden" },
solid: { ring: "border-0 bg-muted-foreground/60", dot: "hidden" },
inverted: { ring: "border-0 bg-foreground", dot: "bg-background" },
primary: { ring: "border-primary", dot: "bg-primary" },
}
/**
* The mark beside an entry. With no children it shows a small dot in a ring.
* Pass an element, such as an icon, to show your own mark instead; the ring
* and fill are then removed. Bare text and `false` are not supported.
*
* `variant` picks how the default mark looks, so a finished, current or
* upcoming entry can read differently without overriding the dot:
* `default` is a foreground ring and dot (the current entry); `muted` a
* soft ring with a muted dot; `plain` a muted dot with no ring; `faint` a
* pale dot with no ring; `line` a soft ring with a pale dot; `empty` an
* empty soft ring (upcoming); `solid` a filled muted disc; `inverted` a
* foreground disc with a background-colored dot; `primary` a primary ring
* and dot. It has no effect on a custom child.
*/
function TimelineIndicator({
className,
children,
variant = "default",
...props
}: ComponentProps<"div"> & {
/** Which look the default mark takes. See the part's description. */
variant?: keyof typeof indicatorVariants
}) {
const look = indicatorVariants[variant]
return (
<div
data-slot="timeline-indicator"
data-variant={variant}
className={cn(
"relative z-10 mt-(--timeline-shift) flex shrink-0",
"size-(--timeline-dot) items-center justify-center rounded-full",
// No children: the default dot in its ring. An element child: your mark,
// no ring. false, [] and bare text are not supported forms.
"border-[1.5px] border-foreground bg-background",
"has-[*:not([data-slot=timeline-dot])]:border-0",
"has-[*:not([data-slot=timeline-dot])]:bg-transparent",
look.ring,
className
)}
{...props}
>
{children ?? (
<div
data-slot="timeline-dot"
className={cn("size-1.5 rounded-full", look.dot)}
/>
)}
</div>
)
}
/**
* The text of an entry, beside its mark. It leaves 32px of space before the
* next entry, and none after the last.
*/
function TimelineContent({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="timeline-content"
className={cn(
"min-w-0 flex-1 pb-8 [[data-slot=timeline-item]:last-child>&]:pb-0",
className
)}
{...props}
/>
)
}
/** The entry's title, in medium weight. It renders a `div`, not a heading. */
function TimelineTitle({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="timeline-title"
className={cn("font-medium", className)}
{...props}
/>
)
}
/** Supporting text for an entry, small and muted, under the title. */
function TimelineDescription({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="timeline-description"
className={cn("mt-1 text-sm text-muted-foreground", className)}
{...props}
/>
)
}
/**
* A small muted line for an entry, such as a date. Its line height matches
* the default `--timeline-lh`, so a label that comes first lines up with the
* mark.
*/
function TimelineLabel({ className, ...props }: ComponentProps<"p">) {
return (
<p
data-slot="timeline-label"
className={cn("text-xs/4 text-muted-foreground", className)}
{...props}
/>
)
}
export {
Timeline,
TimelineItem,
TimelineIndicator,
TimelineContent,
TimelineTitle,
TimelineDescription,
TimelineLabel,
}
Installation
npx shadcn@latest add @01orbital/audit-log-timeline-01Make it yours
- Its words are in
COPYat the top ofcomponents/blocks/timeline/audit-log-timeline-01/index.tsx: change them there, not in the markup. EVENTS, also at the top of the file, holds its lists and settings.
Built from
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
- Button
- Card
font-geist-mono- App Timeline
The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.
Last updated on