Skip to content
satin

CSV import

Pro

Brings a CSV file into your records in three steps: upload, map its columns to your fields, review what will be skipped and why.

  1. Upload file
  2. Map columns
  3. Review

Import candidates

Drop your CSV file here, or browse for oneCSV with a header row

Choose a CSV file to continue

Installation

Terminal
npm i @uisatin/ui @uisatin/pro
Import
import '@uisatin/ui/styles.css'
import '@uisatin/pro/styles.css'
import { CsvImport, type CsvImportField } from '@uisatin/pro/csv-import'

Part of Satin Pro, the licensed edition: @uisatin/pro on top of @uisatin/ui at the same version, its stylesheet after Free's. Satin Pro isn't on npm yet.

About 30.1 kB of JavaScript, minified and gzipped, on top of the @uisatin/uicomponents it uses (React aside).

First time with Satin? Set it up once, styles and fonts included, with the installation guide.

API Reference

The CsvImport component (Satin Pro, @uisatin/pro/csv-import) brings a CSV file into your records in three steps, Upload file, Map columns and Review, in one panel whose frame never moves: the steps in a row on top, a step that slides in and scrolls inside, on to the panel's foot, and a footer over it with Back, the reason the primary action is blocked and the primary action: 16px around the buttons on the panel's fill, with a 24px fade above them into the rows scrolling under it. The steps row is drawn here, not with Stepper: the current step on the primary action's fill, done ones with a check, and every other step a button while it can be reached, back or forward as far as Next would go (never while importing or after an import). Upload file starts empty. The drop zone fills the step, and its picture is the file going into your app: a file tile, a dotted arrow that pulses toward the app, and the app's tile (appIcon, a database glyph by default). It takes one CSV by drop or browse; Excel files (.xlsx or old .xls, even renamed .csv), binary files and a wrong type or size are turned away with the reason in an Alert. The file is read as UTF-8 with or without a BOM, UTF-16 by its BOM, else Windows-1250; , ; or tab is sniffed, or taken from Excel's sep= line, and a first row of distinct text is the header row. An added file shows under the zone as an attachment whose bar fills while it is read, and Next opens once it is: nothing moves on by itself. templateHref adds Download template under the zone. Map columns is one card, "Columns in your file → Lead fields": each column's name and first three values, an arrow, and a Select of your fields, each led by its type's icon, plus Don't import, shown muted. Columns auto-match by key, label and aliases, ignoring case, diacritics, spaces, - and _, and show a green check; defaultMapping wins over auto-match. Next stays blocked while a required field has no column (the card says so) or a field has two (both Selects are marked). The card folds with the panel's width: under 480px the arrow goes, under 360px the Select goes under its column. Rows are checked as the mapping changes, by each field's type (email, number as dateLocale writes it, date as dd.mm.yyyy, yyyy-mm-dd or dateFormat, enum against options), required and validate. Review opens with two tabs drawn as tiles, "328 Leads will be imported" and "12 Rows with errors" (a warning mark at its end); the errors tab is selected while there are errors, and each shows its rows, 100 a page: the valid ones, or the invalid ones with each invalid cell in the error colour with its reason. With no errors the errors tab stays, muted, and its table says so. An invalid cell can be fixed in place: Enter, a click or F2 opens a field with its value, Enter or leaving it keeps the fix (switching windows leaves it open), Escape drops it, and neither acts while an IME composes. The rows are checked again; a row that passes moves to the import tab and its count, and focus goes to the next invalid cell. Fixes are kept through mapping changes and dropped with a new file. Rows past maxRows are counted in a line under the tabs and never imported. Nothing is sent before "Import 328 leads": onImport gets only the valid rows, keyed by field and normalised (text trimmed, an enum as its option's value, a number as "1234.5", a date as yyyy-mm-dd). Report progress with onProgress; Review shows "Importing leads" over a Progress bar, and with cancelable Cancel takes Back's place and aborts signal. The result stays on Review. Its title says the outcome ("Import complete", "Import stopped" or "Nothing was imported"), the line under it the counts and, when it stopped, why, then the table (CsvImportResult): Imported and Skipped segments, the Skipped rows with their Reason, and "Download skipped rows" (the original columns plus error). Import another file takes Back's place, and onDone adds Done. A rejected promise, or Cancel after some rows were saved, stops the run: a Not imported segment, and "Retry from row 121" as the primary action. Cancel before any row goes back to Review. Import and Retry send only the rows not yet saved, by the last onProgress count and left out by row, keeping the file and mapping; the result lists exactly the rows sent and not sent; a count reported after Cancel, by a request already in flight, still counts. A file given from the start opens on Map columns once it is read; a new one given later starts on Upload file, as an added one does, and ends an import of the old one. onStepChange says which step is on screen as it changes, not on mount. onBrowse runs in place of the file picker, from Browse files and from a click on the zone, so a demo can drop a sample file; dragging shows the zone's drag-over look. The root is 600px tall and a size container; tables and cards inside take the panel's fill, so put it on a surface (bg-bg-popover). In a Dialog or Sheet give it className="h-auto flex-1" and inDialog: with no dialog header of your own, each step's title and description name the dialog. Parts, for an app that already has the file: CsvImportMapping (the map card: fields, headers, rows, mapping, onMappingChange, autoMapping, noun, appIcon; it folds by its container, so put @container on an ancestor), CsvImportPreview (a summary line, an errors Alert whose links jump to the first invalid cell, Show only errors and the rows; onCellEdit(row, column, value) makes invalid cells editable, with the row's number among the data rows and the source column's index, and you pass the validation checked again), CsvImportProgress and CsvImportResult (fields, mapping, validation, imported, status: "done" | "stopped", reason, onRetry, overLimit, noun, filter/defaultFilter/onFilterChange, headers, fileName, delimiter, with its own heading and a Retry Alert). parseCsv, matchColumns, validateCsv and toCsv come from @uisatin/pro/csv-import-parse (a client entry, not for a Server Component). Its words (csvUploadTitle, csvMapTitle, csvWillImport, csvRowsWithErrors, csvDoneTitle…) are translated with SatinLabels.

PropTypeDefault
fields
CsvImportField[]
—
onImport
(rows: Record<string, string>[], ctx: { signal, onProgress }) => void | Promise<void>
—
noun
{ one: string, other: string }
{ one: "row", other: "rows" }
maxRows
number
—
maxSize
number
—
templateHref
string
—
file
Filenull
—
onFileChange
(file: File | null) => void
—
onStepChange
(step: CsvImportStep) => void
—
mapping
CsvMapping
—
defaultMapping
CsvMapping
—
onMappingChange
(mapping: CsvMapping) => void
—
onDone
() => void
—
cancelable
boolean
false
disabled
boolean
false
appIcon
ReactNode
a database glyph
inDialog
boolean
false
onBrowse
() => void
—
dragging
boolean
false
className
string
—
ref
Ref<HTMLDivElement>
—
...props
ComponentProps<'div'>

Other attributes go to <div>

—

Accessibility

The steps row is an ordered list named "Import steps" (csvSteps in SatinLabels) with aria-current="step" on the current step; a done step adds ", Completed" to its label. Any other step is a button named by its label while it can be reached, back or forward as far as Next would go, and plain text otherwise: never while importing or after an import. Under 480px only the current step shows its label; the others keep theirs for screen readers. When focus is in the panel, entering a step moves it there without scrolling: on Upload file to Browse files; on Map columns to the Select to fix first (a field picked twice, else the first column on Don't import while a required field has no column, else the first Select); on Review to the selected tab, so "12 Rows with errors" is read as one. Review's two tiles are a tablist named "Rows to show" (csvReviewTabs) of two tabs, "328 Leads will be imported" and "12 Rows with errors", the errors tab selected while there are errors; the rows under them are the tabpanel, named by its tab, and the table in it is named "Rows to import" or "Rows with errors". With no errors the errors tab stays, and its table says "No rows with errors". Each mapping Select is named after its column, "Maps to, CSV column Firma" (csvMapsToColumn). An auto-matched column adds ", Auto-matched" to its name, also a Tooltip on the check. A field picked twice marks both Selects as errors and describes each with "Email is already mapped". The field icons, the arrows and the drop zone's picture are hidden. A blocked Next or Import stays focusable with aria-disabled. Its reason is visible text in the footer, read through aria-describedby and shown in a Tooltip; under 400px the text is visually hidden and the other two stay. An invalid cell in the rows is read with its reason (", Not an email address"), also in a Tooltip. On Review it is a button, read as its value, its reason and ", Edit" (csvEditCell); it opens a text field named "Email, row 17" (csvCellLabel). When the fix passes, "Row 17 is ready to import" (csvRowFixed) is read out and focus moves to the next invalid cell, else the one before, else the errors tab; when it still fails, focus returns to the cell, read with its new reason. One polite live region reads out the file being read, the rows read, a read or a check that failed, the import starting, each quarter of its progress and how it ended. While importing, Import keeps focus as a busy button. A file that can't be read moves focus to its Alert. The result's title ("Import complete", "Import stopped", "Nothing was imported") takes focus when it appears; Cancel before any row was saved returns focus to the selected tab. The result's segments (Imported, Skipped, Not imported) are a group named "Rows to show" (csvResultFilter) of radio buttons, each read with its count, and the table under them is named after the segment ("Skipped rows"). The dotted arrow on Upload file pulses in a 1.4s loop, opacity and colour only, with no way to pause it (see Known gaps). Under reduced motion it holds still at a fade toward the app, and the steps don't slide. With inDialog, each step's title and description are the dialog's DialogTitle and DialogDescription, so its name follows the step: on Upload file the drop zone's title ("Import leads") and lines, then "Map CSV columns", "Review rows", "Importing leads" and the outcome.

KeyAction
TabMoves through the steps row's buttons, then the step: on Upload file Browse files, the file's Remove and Download template; on Map columns each Select; on Review the selected tab, its rows table (it scrolls sideways, and each invalid cell is a stop) and the pagination; on the result the segments, Download skipped rows, the table and the pagination. Then Back, Cancel or Import another file, and the primary action in the footer.
EnterorSpaceOn a step in the steps row: goes to it. On Browse files: opens the file picker, or runs onBrowse when it is set (the demo drops its sample file). On Next or Import: moves on, or does nothing while blocked (the reason is read out). On an invalid cell: opens the field to fix it.
F2On an invalid cell: opens the field to fix it, as in a spreadsheet.
EnterIn the field: keeps the fix; the rows are checked again. Leaving the field keeps it too; switching to another window leaves it open. While an IME composes, Enter and Esc go to the IME.
EscIn the field: drops the fix and returns to the cell. In a Dialog, the dialog stays open.
←or→orHomeorEndOn Review's tabs: moves between Will be imported and Rows with errors, and shows its rows.
↑or↓In an open mapping Select: moves between the fields and Don't import, as on Select.
←or→On the result's segments: moves between Imported, Skipped and Not imported, as on Segmented control.