Skip to content

RateLine

A rate with its timestamp. Never one without the other.
Implemented
Status
Implemented
Family
4 of 13
Registry
@lopifi/rate-line
npx shadcn@latest add @lopifi/theme @lopifi/rate-line

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

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.

components/ledger/rate-line.tsx
"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

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 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.

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.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.