AnomalyCard
- Status
- Implemented
- Family
- 2 of 13
- Registry
- @lopifi/anomaly-card
npx shadcn@latest add @lopifi/theme @lopifi/anomaly-cardThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
A flagged deviation, with the comparison that triggered it and one clear action (approve / flag / create rule). Never a bare alert — an anomaly without its baseline is noise.
Lifted verbatim from Cards. The doc and this page are the same paragraphs, so they cannot disagree.
What lands in your repository
One component is never one file. Everything below is copied into your project, where you own it.
- Files
components/ledger/anomaly-card.tsx
- npm packages
- @base-ui-components/reactclass-variance-authorityclsxtailwind-merge
- Registry entry
- /r/anomaly-card.json
The whole component
No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.
"use client";
import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import type { MoneyValue, Polarity } from "@/lib/ledger/money.types";
import { Button } from "@/components/ledger/button";
import { Card } from "@/components/ledger/card";
import { Delta } from "@/components/ledger/delta";
import { ExclamationTriangleIcon } from "@/components/ledger/icons";
import { Money } from "@/components/ledger/money";
import { Tooltip } from "@/components/ledger/tooltip";
export interface AnomalyCardProps extends React.ComponentPropsWithoutRef<"div"> {
baseline: MoneyValue;
baselineLabel: string;
delta: MoneyValue;
explanation: string;
/** The comparison that triggered the flag. An anomaly without its baseline is noise. */
observed: MoneyValue;
onApprove?: () => void;
onCreateRule?: () => void;
onFlag?: () => void;
polarity?: Polarity;
title: string;
}
export const AnomalyCard = React.forwardRef<HTMLDivElement, AnomalyCardProps>(
(
{
className,
title,
observed,
baseline,
baselineLabel,
delta,
polarity = "inverted",
explanation,
onApprove,
onFlag,
onCreateRule,
...props
},
ref,
) => (
<Card className={cn("flex flex-col gap-4", className)} ref={ref} {...props}>
<div className="flex items-start gap-3">
<div className="grid size-8 shrink-0 place-items-center rounded-sm bg-warning-subtle">
<ExclamationTriangleIcon aria-hidden="true" className="size-4 text-warning" />
</div>
<div className="min-w-0">
<p className="text-body font-medium">{title}</p>
{/* The explanation is the card's substance, so it stays on the card —
but capped at two lines. A five-line paragraph pushes the figures
it exists to explain below the fold of a dashboard tile. */}
<Tooltip content={explanation} display="block">
<p className="mt-1 line-clamp-2 text-caption text-text-secondary">{explanation}</p>
</Tooltip>
</div>
</div>
<div className="grid grid-cols-2 gap-4 rounded-md bg-surface-sunken p-3">
<div>
<span className="block text-caption text-text-secondary">This period</span>
<Money className="mt-0.5" size="md" value={observed} />
</div>
<div>
<span className="block text-caption text-text-secondary">{baselineLabel}</span>
<Money className="mt-0.5" size="md" tone="secondary" value={baseline} />
</div>
<div className="col-span-2">
{/* The baseline is the column header two inches away; repeating it
inline is the third mention. It rides on hover instead. */}
<Delta basisTooltip={`vs. ${baselineLabel.toLowerCase()}`} polarity={polarity} value={delta} />
</div>
</div>
<div className="flex flex-wrap gap-2">
<Button onClick={onApprove} size="sm" variant="primary">
Approve
</Button>
<Button onClick={onFlag} size="sm" variant="secondary">
Flag for review
</Button>
<Button onClick={onCreateRule} size="sm" variant="ghost">
Create a rule
</Button>
</div>
</Card>
),
);
AnomalyCard.displayName = "AnomalyCard";
Also in Cards
- BalanceCardThe hero: one trusted number.
- KpiCardMetric + delta + optional sparkline.
- AccountCardBank account with available vs. current.
- PaymentMethodCardThe physical card object. 3D flip, pointer tilt.
- RunwayCardMonths of runway with a burn line.
- InvoiceCardInvoice summary with aging state.
- SubscriptionCardRecurring charge with next-billing.
- GoalCardTarget vs. actual with a progress rule.
- StatCardThe minimal label+value card.Spec
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
Elsewhere in the system
Where AnomalyCard sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.
- AnomalyCard, runningThe cards showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Benford & round numbersTwo cheap tests over a pasted column. Neither proves anything; both tell you where to look.Tool
- CardsAll cards: 24px radius, 24px inset, --surface on --canvas, 1px --border, no resting shadow. Specs for 10 React components: BalanceCard, KpiCard, AccountCard, PaymentMethodCard and 6 more.Doc
Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.
Told when Cards changes
Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.