Documentation menuReact viewer
React viewer
Show the audit log to your customers' admins.
import { AuditLog } from "@sweberdev/logarithm-react"
import "@sweberdev/logarithm-react/styles.css"
<AuditLog
endpoint="/api/audit"
locale="de-CH"
nouns={{ project: "Projekt", member: "Mitglied" }}
actions={[
{ value: "project.*", label: "Projekte" },
{ value: "member.*", label: "Mitglieder" },
]}
fieldLabels={{ "billing.plan": "Abo" }}
/>
The view shows entries grouped by day, with a sentence such as "Anna Muster hat Projekt „Website“ geändert", the time and the action. Details opens the field changes, the request context and metadata.
Props
| Prop | Default | Meaning |
|---|---|---|
endpoint | – | URL of a createAuditHandler route |
fetchPage | – | Load a page yourself instead, e.g. a server action |
scope | – | Fixed filters, e.g. { targetId: project.id } for a project's history tab |
pageSize | 25 | Entries per page |
locale | en | Dates and built-in labels; English, German, French and Italian are included |
labels | – | Override single labels |
nouns | – | Display names for resource types |
actions | – | Choices for the action filter; hidden when empty |
filters | true | Show search, action and date filters |
describe | – | Your own sentence per event |
fieldLabels | – | Readable names for changed fields |
refreshKey | – | Change it to reload |
theme | system | light or dark |
headingLevel | 3 | Level of the day headings (2 to 5), so they follow your page's headings |
Styling
The stylesheet uses custom properties on .lg-root. Override them to match your app, or leave the stylesheet out and style the lg-* classes yourself:
.lg-root {
--lg-accent: #0f766e;
--lg-radius: 2px;
--lg-font: "Inter", sans-serif;
}
Dark mode follows prefers-color-scheme; force a scheme with theme="light" or theme="dark".
Accessibility
Filters have visible labels, the details button announces its state with aria-expanded, the result count is a polite live region, the changes table has a caption and header cells, and focus is always visible.
Languages
English, German, French and Italian labels and sentences are built in and chosen by locale, e.g. de-CH, fr-CH or it-CH. Pass resource names with nouns. In French and Italian, include the article, because it depends on the noun:
<AuditLog endpoint="/api/audit" locale="fr-CH" nouns={{ project: "le projet", member: "le membre" }} />
// Anna Muster a modifié le projet « Website »
For other languages, pass your own labels and a describe function.
Activity feed
<ActivityFeed> is a compact list of the latest events for a dashboard or a side panel. It uses the same endpoint and stylesheet as <AuditLog>, shows relative times ("5 minutes ago", in German "vor 5 Minuten") and links to the full log.
<ActivityFeed endpoint="/api/audit" limit={5} href="/settings/activity" locale="de-CH" />
Pass scope={{ targetId: project.id }} to show the activity of one object, e.g. on a project page, and title={null} to hide the heading. For the history of one object with a diff per change, use <ObjectHistory>. The other props match <AuditLog>: fetchPage, init, labels, nouns, describe, refreshKey, theme, headingLevel (for its title) and className.
History of one object
<ObjectHistory> shows every recorded change to one object, newest first, with who made it, when, and the before and after value of each field. A filter narrows it to the changes of a single field, which answers "who changed the plan, and when" in one click. It uses the same endpoint and stylesheet as <AuditLog>.
<ObjectHistory endpoint="/api/audit" targetType="project" targetId={project.id}
fieldLabels={{ "billing.plan": "Plan" }} locale="de-CH" />
Props: targetType and targetId (required), scope for further fixed filters, pageSize (default 20), fieldLabels, nouns, describe, labels, locale, title (null hides it), headingLevel, theme, refreshKey, fetchPage, init and className. The endpoint has to be a createAuditHandler that is allowed to read the object's tenant.
Failed and denied events are marked with text and a symbol, not colour alone, in <AuditLog> and <ObjectHistory>. <AuditLog> also has a filter for the result and shows the correlation id under "Details".
Your own layout
useAuditLog({ endpoint, query }) returns events, loading, error, hasMore, loadMore() and reload(). describeAction(event, { locale }) from the core package builds the sentence.
Accessibility and theming
The default stylesheet meets WCAG 2.2 AA text contrast (4.5:1) in the light and the dark theme for every pair of text and background colour, which the test suite checks on every release. Expanding a row uses a button with aria-expanded and aria-controls, filters sit in a labelled search landmark, result counts are announced through a polite live region, and errors use role="alert". All controls are reachable by keyboard and show a focus ring.
Before each release that changes the viewer we run axe-core in Chromium against the rendered viewer (WCAG 2.0, 2.1 and 2.2 level A and AA plus best practices) in the light theme, the dark theme and German, and tab through every control. The current result is 0 violations in all four runs, and Enter and Space open and close the details. The day headings default to h3; if your page has an h1 and no h2 above the viewer, pass headingLevel={2}, otherwise axe reports a skipped heading level. The date fields are the browser's native datetime-local inputs, which have several tab stops each; that is browser behaviour. The audit harness is in audits/a11y of the repository. Automated tools find about half of all accessibility problems, so please also test with your screen reader and tell us what you find.
Colours, radius and fonts are CSS custom properties on .lg-root (--lg-bg, --lg-fg, --lg-muted, --lg-border, --lg-surface, --lg-accent, --lg-removed, --lg-added, --lg-radius, --lg-font, --lg-mono). Dark mode follows prefers-color-scheme; force a theme with data-theme="light" or data-theme="dark" on the root element. If you change the colours, keep the 4.5:1 contrast between text and its background.