RateLine
- Status
- Implemented
- Family
- 4 of 13
- Registry
- @lopifi/rate-line
npx shadcn@latest add @lopifi/theme @lopifi/rate-lineThe component, rendering
Real data, the shipped component. Switch the theme to check the claims the spec makes below.
The four-layer spec
<RateLine from="USD" to="EUR" rate={0.91842} asOf={t} />
// 1 USD = 0.91842 EUR · 12s ago
5 significant figures, tnum. The timestamp is not optional — the component has no variant without it.
Live variant flashes on update (value flash), throttled to one flash per 400ms.
Lifted verbatim from Swaps & FX. 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/rate-line.tsx
- Lopifi dependencies · 8
- as-ofcnfiscal-periodformat-moneymoney.typestooltipuse-live-valueuse-shared-now
- npm packages
- @base-ui-components/reactclsxtailwind-merge
- Registry entry
- /r/rate-line.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 { useValueFlash } from "@/hooks/ledger/use-live-value";
import { cn } from "@/lib/ledger/cn";
import { formatRate } from "@/lib/ledger/format-money";
import { AsOf } from "@/components/ledger/as-of";
export interface RateLineProps extends React.ComponentPropsWithoutRef<"div"> {
/** Not optional. The component has no variant without it. */
asOf: Date;
from: string;
live?: boolean;
locked?: boolean;
rate: number;
to: string;
}
/* Lives in ../lib/format-money so Server Components can call it; re-exported
here for anything that already imports it from this module. */
export { formatRate } from "@/lib/ledger/format-money";
export const RateLine = React.forwardRef<HTMLDivElement, RateLineProps>(
({ className, from, to, rate, asOf, live = false, locked = false, ...props }, ref) => {
const { flash, key } = useValueFlash(live ? rate : undefined);
return (
<div className={cn("flex flex-wrap items-center gap-2 text-caption", className)} ref={ref} {...props}>
<span
className={cn(
"numeric rounded-xs px-1 text-body text-text-primary",
flash === "positive" && "ledger-flash-positive",
flash === "negative" && "ledger-flash-negative",
)}
key={key}
>
1 {from} = {formatRate(rate)} {to}
</span>
<span aria-hidden="true" className="text-text-tertiary">
·
</span>
<AsOf date={asOf} />
{locked ? (
<span className="rounded-xs bg-accent-subtle px-1.5 py-0.5 text-caption font-medium text-accent">
Locked
</span>
) : null}
</div>
);
},
);
RateLine.displayName = "RateLine";
The accounting it encodes
Concepts this component renders. Each one is defined once, in the lexicon, and used identically in the code and the copy.
Also in Swaps & FX
- SwapWidgetFrom/to with the flip. The signature component.
- RateLockLocked rate with a countdown and expiry behavior.
- ConversionBreakdownAmount → fee → rate → recipient gets. Every line.
- CurrencyPairChartRate history with a period selector.
- RateTickerLive multi-pair ticker with value flash.
- SlippageControlTolerance setting with an explicit worst case.
- SwapRouteMulti-hop path visualization.
- FxExposurePosition by currency with unrealized gain/loss.
See also
A component is specified in one place, defined in another, and running in a third. All three, from here.
- Swaps & FX — the family specThe four-layer specification this component was built against, before it was written.Doc
- FX, swaps and rate componentsThe family running, with real figures in it, in both themes and at every density.Live
- CatalogAll 179 components, specified before they are written.Doc
- As atThe point-in-time label for a balance sheetTerm
Elsewhere in the system
Where RateLine 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.
- RateLine, runningThe swaps showcase — live, with theme, density, greyscale and reduced-motion switches.Live
- Effective vs nominal rate12% compounded monthly is 12.68%. That difference is the covenant you either pass or fail.Tool
- Swaps & FXThe governing rule for this entire family: A rate is a perishable fact. It never appears without a timestamp, and it is never transacted on without a lock. Specs for 9 React components: SwapWidget, RateLine, RateLock, ConversionBreakdown and 5 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 Swaps & FX 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.