Skip to content

ColumnManager

Show/hide/reorder with drag.
Implemented
Status
Implemented
Family
5 of 13
Registry
@lopifi/column-manager
npx shadcn@latest add @lopifi/theme @lopifi/column-manager

The component, rendering

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

Preview

The four-layer spec

Show/hide/reorder with drag. Persisted per user per table. Drag uses FLIP + spring.snap; measure once at drag start, never during. Keyboard reorder via Cmd+arrows.

Lifted verbatim from Ledger & tables. 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/column-manager.tsx

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

import { Popover } from "@base-ui-components/react/popover";
import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import { EllipsisVerticalIcon, ViewColumnsIcon } from "@/components/ledger/icons";

export type ManagedColumn = { id: string; label: string; visible: boolean; locked?: boolean };

export interface ColumnManagerProps {
  className?: string;
  columns: ManagedColumn[];
  onChange: (columns: ManagedColumn[]) => void;
}

/**
 * Show / hide / reorder. Persisted per user per table. Keyboard reorder via
 * Cmd+arrows, because drag alone is not an accessible reorder.
 */
export function ColumnManager({ columns, onChange, className }: ColumnManagerProps) {
  const [dragIndex, setDragIndex] = React.useState<number | null>(null);

  const move = (from: number, to: number) => {
    if (to < 0 || to >= columns.length) return;
    const next = [...columns];
    const [item] = next.splice(from, 1);
    next.splice(to, 0, item);
    onChange(next);
  };

  return (
    <Popover.Root>
      <Popover.Trigger
        className={cn(
          "inline-flex h-8 items-center gap-2 rounded-sm border border-border bg-surface px-3 text-label font-medium",
          "transition-colors duration-1 ease-standard hover:bg-surface-hover",
          className,
        )}
      >
        <ViewColumnsIcon aria-hidden="true" className="size-3.5" />
        Columns
      </Popover.Trigger>
      <Popover.Portal>
        <Popover.Positioner align="end" className="z-dropdown" sideOffset={8}>
          <Popover.Popup
            className="w-[260px] rounded-md border border-border bg-surface-raised p-2 shadow-elevation-3"
            style={{ transformOrigin: "var(--transform-origin)" }}
          >
            <ul>
              {columns.map((col, i) => (
                <li
                  className="flex items-center gap-2 rounded-xs px-2 py-1.5 hover:bg-surface-hover"
                  draggable={!col.locked}
                  key={col.id}
                  onDragOver={(e) => e.preventDefault()}
                  onDragStart={() => setDragIndex(i)}
                  onDrop={() => {
                    if (dragIndex !== null) move(dragIndex, i);
                    setDragIndex(null);
                  }}
                >
                  <EllipsisVerticalIcon
                    aria-hidden="true"
                    className={cn("size-3.5 text-text-tertiary", col.locked && "opacity-30")}
                  />
                  <label className="flex flex-1 items-center gap-2 text-body">
                    <input
                      checked={col.visible}
                      className="size-4 accent-[var(--accent)]"
                      disabled={col.locked}
                      onChange={() =>
                        onChange(columns.map((c) => (c.id === col.id ? { ...c, visible: !c.visible } : c)))
                      }
                      type="checkbox"
                    />
                    {col.label}
                  </label>
                  <button
                    aria-label={`Move ${col.label} up`}
                    className="text-caption text-text-tertiary hover:text-text-primary"
                    onClick={() => move(i, i - 1)}
                    onKeyDown={(e) => {
                      if (e.metaKey && e.key === "ArrowUp") move(i, i - 1);
                      if (e.metaKey && e.key === "ArrowDown") move(i, i + 1);
                    }}
                    type="button"
                  >
                    ↑
                  </button>
                  <button
                    aria-label={`Move ${col.label} down`}
                    className="text-caption text-text-tertiary hover:text-text-primary"
                    onClick={() => move(i, i + 1)}
                    type="button"
                  >
                    ↓
                  </button>
                </li>
              ))}
            </ul>
          </Popover.Popup>
        </Popover.Positioner>
      </Popover.Portal>
    </Popover.Root>
  );
}

Also in Ledger & tables

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 ColumnManager 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 Ledger & tables 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.