Skip to content

Reference

Copyable transaction/account ID with disambiguated glyphs.
Implemented
Status
Implemented
Family
1 of 13
Registry
@lopifi/reference
npx shadcn@latest add @lopifi/theme @lopifi/reference

The component, rendering

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

Preview

The four-layer spec

Transaction and account IDs. "zero" 1, "ss02" 1 so 0/O and 1/l/I are unambiguous — these get transcribed by humans into other systems. Click to copy; copies the raw value. Truncates in the middle (txn_8a2…f091), never at the end, because the tail is the discriminating part.

Lifted verbatim from Primitives. 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/reference.tsx

Lopifi dependencies · 3
cniconstooltip
npm packages
@base-ui-components/reactclsxtailwind-merge
Registry entry
/r/reference.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/reference.tsx
"use client";

import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import { CheckIcon, DocumentDuplicateIcon } from "@/components/ledger/icons";
import { Tooltip } from "@/components/ledger/tooltip";

export interface ReferenceProps extends React.ComponentPropsWithoutRef<"span"> {
  copyable?: boolean;
  label?: string;
  /** Truncate in the middle; the tail is the discriminating part. */
  truncate?: boolean;
  value: string;
}

/**
 * Transaction and account IDs — the strings humans transcribe into other
 * systems. `zero` slashes the 0 and `ss02` separates 1 / l / I, so nobody
 * mistypes an IBAN. Copy takes the raw value.
 */
export const Reference = React.forwardRef<HTMLSpanElement, ReferenceProps>(
  ({ className, value, truncate = true, copyable = true, label = "Reference", ...props }, ref) => {
    const [copied, setCopied] = React.useState(false);
    const shown = truncate && value.length > 18 ? `${value.slice(0, 8)}…${value.slice(-4)}` : value;

    const copy = React.useCallback(() => {
      navigator.clipboard?.writeText(value).then(
        () => {
          setCopied(true);
          setTimeout(() => setCopied(false), 1600);
        },
        () => setCopied(false),
      );
    }, [value]);

    return (
      <span className={cn("inline-flex items-center gap-1", className)} ref={ref} {...props}>
        <Tooltip content={shown === value ? null : value}>
          <span className="reference-numeric text-caption text-text-secondary">{shown}</span>
        </Tooltip>
        {copyable ? (
          <button
            aria-label={copied ? `${label} copied` : `Copy ${label.toLowerCase()} ${value}`}
            className={cn(
              "press grid size-6 place-items-center rounded-xs text-text-tertiary",
              "hover:bg-surface-hover",
            )}
            onClick={copy}
            type="button"
          >
            {copied ? (
              <CheckIcon aria-hidden="true" className="size-3 text-positive" />
            ) : (
              <DocumentDuplicateIcon aria-hidden="true" className="size-3" />
            )}
          </button>
        ) : null}
      </span>
    );
  },
);
Reference.displayName = "Reference";

/** Account numbers show last 4 only; the mask is aria-hidden. */
export function MaskedAccount({ last4, className }: { last4: string; className?: string }) {
  return (
    <span className={cn("reference-numeric relative text-caption text-text-secondary", className)}>
      <span aria-hidden="true">•••• {last4}</span>
      <span className="sr-only select-none">account ending {last4}</span>
    </span>
  );
}

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 Primitives

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