Data Import

CSV import in four steps: upload, match columns, fix rows, see the result.

PROGet Data Import and 168 other Pro components with pro lifetime — Get Pro

Category
Data Tables
Access
Pro
Source
934 lines · one file
States
6 drawn

The decision inside it

An import fails in two places, so it shows both

A row can be wrong in the file, or the server can refuse it afterwards. Most importers only show the first. This one fixes rows before sending, then lists every refused row with its reason and gives you an error report you can fix and import again.

When to use it

Use Data Import for CSV imports: upload, column matching by name and aliases, fixing problem rows in place, an import with progress and cancel, and a result with a downloadable error report.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Data Import for this.
Install it: npx shadcn@latest add @liro/data-import
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/data-import.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/import-customers.tsx
import { DataImport, type ImportField, type ImportRow } from "@/components/ui/data-import";

const fields: ImportField[] = [
  { key: "name", label: "Name", required: true },
  { key: "email", label: "Email", type: "email", required: true, aliases: ["e-mail", "mail"] },
  { key: "plan", label: "Plan", type: "select", options: ["Free", "Team"] },
];

export function ImportCustomers({ create }: { create: (row: ImportRow) => Promise<void> }) {
  return (
    <DataImport
      noun="customer"
      fields={fields}
      onImport={async (rows, { onProgress, signal }) => {
        let done = 0;
        for (const row of rows) {
          if (signal.aborted) break;
          await create(row);
          onProgress(++done);
        }
        return { imported: done };
      }}
    />
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
fieldsImportField[] YesWhat a row can hold. Their order is the order of the review table.
onImport(rows: ImportRow[], context: { onProgress: (done: number) => void; signal: AbortSignal }) => Promise<ImportResult> YesSends the rows. Report progress as a count of rows, honour `signal`, and resolve with what happened.
nounstring | { one: string; other: string } NoWhat is being imported, plural: "contacts". Pass both forms when the singular is irregular. Default "rows".
titleReact.ReactNode | false NoThe heading. Default "Import contacts", from `noun`. Pass `false` to hide it.
maxRowsnumber NoLargest file accepted, in rows. A longer one is refused on upload.
sampleImportFile NoAdds "Use a sample file" to the upload step, so the flow can be tried without one.
defaultFileImportFile NoStart with this file loaded, on the match step. For a file dropped elsewhere in your app.
templateHrefstring NoWhere "Download a template" points. Without it, or `onDownloadTemplate`, a template is built from `fields`.
onDownloadTemplate() => void NoCalled by "Download a template" instead of following a link.
onDone(result: ImportResult) => void NoAdds Done to the result, and is given what the import returned.
onCancel() => void NoAdds Cancel to the upload step.
lookLook NoLayered sets it in a tray, the heading above the card and the status in the strip below. Flat is one card.

Dependencies

npm packages

clsxframer-motionlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-themebadgebuttonfieldinputsegmented-controlselectstatestepperswitch

States

All of them are drawn by the component. None is left for you to design.

  • Upload
  • Matching columns
  • Required field unmatched
  • Fixing rows
  • Importing
  • Done with failures

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances