Column Mapper

Checks a spreadsheet column mapping against the actual values, so emails don't land in the phone field and DD/MM dates aren't read as MM/DD.

StopsSpreadsheet imported into wrong fields

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/column-mapper.json

The files land in your project. They're yours to edit.

Usage

column-mapper-usage.tsx
import { ColumnMapper, type ColumnTarget, type MapperColumn, type MapperField } from "@/components/ui/column-mapper"

<ColumnMapper columns={columns} fields={fields} defaultValue={saved} onContinue={(m) => setDone(`Mapped ${m.filter((x) => x.field).length} columns.`)} />

What it catches

  • Values that don't fit the mapped field (an email in Phone)
  • First and last name columns swapped, using a first-name list
  • Day/month order misread, with a readback of what a sample date becomes
  • The same field mapped twice, and required fields left unmapped

Props

ColumnMapper props
PropTypeDefault
columns* (required)

The spreadsheet's columns, each with its heading and a sample of values.

MapperColumn[]—
fields* (required)

The fields you import into. `kind` drives the swap and date checks.

MapperField[]—
value

Controlled mapping, one entry per column.

ColumnTarget[]—
defaultValue

Initial mapping when uncontrolled (e.g. your auto-match or last saved mapping).

ColumnTarget[]—
onValueChange

Called with the mapping on every change.

(value: ColumnTarget[]) => void—
onContinue

Shows a Continue button; receives the mapping with every date order filled in.

(value: ColumnTarget[]) => void—
firstNames

First names used to spot swapped first/last name columns.

string[]COMMON_FIRST_NAMES
messages

Every visible string, for copy changes and translation.

Partial<ColumnMapperMessages>—

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Each column uses a native <select>
  • After a fix, focus moves to the affected select
  • Issues use icons plus text, and each fix and keep action is a button

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Validate types and required fields again on the server during import.

  • Works from the sample rows you pass; problems further down the file are not seen
  • Name-swap detection depends on the firstNames list and can miss uncommon names

What it stops

Spreadsheet imported into wrong fields

Also known as

csv import · excel upload · column mapping · bulk import · spreadsheet · data import · field mapping · xlsx

Field type

Dependencies

Pairs well with