Skip to content

DimensionPicker

Entity always required; renders what the account demands.
Implemented
Status
Implemented
Family
9 of 13
Registry
@lopifi/dimension-picker
npx shadcn@latest add @lopifi/theme @lopifi/dimension-picker

The component, rendering

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

Preview

The four-layer spec

Entity, department, location, class, project, customer, vendor. Entity always required and always visible. Renders only the dimensions the chosen account requires.

Lifted verbatim from Accounting core (GL). 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/dimension-picker.tsx

Lopifi dependencies · 3
accounting.typescnmoney.types
npm packages
clsxtailwind-merge
Registry entry
/r/dimension-picker.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/dimension-picker.tsx
"use client";

import * as React from "react";
import type { DimensionKey } from "@/lib/ledger/accounting.types";
import { cn } from "@/lib/ledger/cn";

const LABELS: Record<DimensionKey, string> = {
  classId: "Class",
  customerId: "Customer",
  departmentId: "Department",
  entityId: "Entity",
  locationId: "Location",
  productId: "Product",
  projectId: "Project",
  vendorId: "Vendor",
};

const OPTIONS: Record<DimensionKey, string[]> = {
  classId: ["Core", "New product"],
  customerId: ["Contoso", "Fabrikam", "Tailspin"],
  departmentId: ["G&A", "Engineering", "Sales", "Marketing"],
  entityId: ["Northwind Ltd", "Northwind GmbH", "Northwind Inc"],
  locationId: ["London", "Berlin", "New York"],
  productId: ["Platform", "Services"],
  projectId: ["Atlas", "Beacon"],
  vendorId: ["Baker & Co", "Vertex Cloud", "Meridian Legal"],
};

export interface DimensionPickerProps {
  className?: string;
  onValueChange: (value: Partial<Record<DimensionKey, string>>) => void;
  /** Rendered from what the chosen account demands, not a global list. */
  required: DimensionKey[];
  value: Partial<Record<DimensionKey, string>>;
}

/** Entity is always required and always visible. */
export function DimensionPicker({ required, value, onValueChange, className }: DimensionPickerProps) {
  const keys = React.useMemo(() => {
    const set = new Set<DimensionKey>(["entityId", ...required]);
    return [...set];
  }, [required]);

  return (
    <div className={cn("flex flex-wrap gap-1", className)}>
      {keys.map((key) => {
        const missing = !value[key];
        return (
          <label className="block" key={key}>
            <span className="sr-only">{LABELS[key]}</span>
            <select
              aria-invalid={missing}
              className={cn(
                "h-8 rounded-sm border bg-surface px-2 text-caption outline-none focus-visible:border-accent focus-visible:ring-2 focus-visible:ring-accent-subtle",
                missing ? "border-negative text-text-tertiary" : "border-border",
              )}
              onChange={(e) => onValueChange({ ...value, [key]: e.target.value || undefined })}
              value={value[key] ?? ""}
            >
              <option value="">{LABELS[key]}…</option>
              {OPTIONS[key].map((o) => (
                <option key={o} value={o}>
                  {o}
                </option>
              ))}
            </select>
          </label>
        );
      })}
    </div>
  );
}

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 Accounting core (GL)

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 DimensionPicker 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 Accounting core (GL) 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.