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
- ProPro · unlocked
- 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
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.
| Type | Notes | ||
|---|---|---|---|
fields | ImportField[] | Yes | What 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> | Yes | Sends the rows. Report progress as a count of rows, honour `signal`, and resolve with what happened. |
noun | string | { one: string; other: string } | No | What is being imported, plural: "contacts". Pass both forms when the singular is irregular. Default "rows". |
title | React.ReactNode | false | No | The heading. Default "Import contacts", from `noun`. Pass `false` to hide it. |
maxRows | number | No | Largest file accepted, in rows. A longer one is refused on upload. |
sample | ImportFile | No | Adds "Use a sample file" to the upload step, so the flow can be tried without one. |
defaultFile | ImportFile | No | Start with this file loaded, on the match step. For a file dropped elsewhere in your app. |
templateHref | string | No | Where "Download a template" points. Without it, or `onDownloadTemplate`, a template is built from `fields`. |
onDownloadTemplate | () => void | No | Called by "Download a template" instead of following a link. |
onDone | (result: ImportResult) => void | No | Adds Done to the result, and is given what the import returned. |
onCancel | () => void | No | Adds Cancel to the upload step. |
look | Look | No | Layered 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-mergeLiro foundations, installed alongside it
liro-themebadgebuttonfieldinputsegmented-controlselectstatestepperswitchStates
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