# Data import

Drop a spreadsheet, then see exactly what was read: rows, columns with sample values, and any rows that couldn't be read and why. Nothing is mapped or loaded at this step.

- Registry name: `data-import` (`@candor/data-import`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/data-import

## Install

```bash
npx candor-ui add data-import
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/data-import`.
It brings in: button, data, locale, utils.
npm packages: lucide-react@^1.67.0.

## Example

```tsx
"use client"

import * as React from "react"
import { DataImport, type ImportRead } from "@/components/data-import"

// What your parser returns for a file; here, a fixed sample stands in for parsing.
const sample = (name: string, size: number): ImportRead => ({
  file: { name, size },
  rows: 214,
  columns: [
    { header: "Flag", samples: ["new-billing-page", "dark-mode", "fast-search"] },
    { header: "Repo", samples: ["acme/web", "acme/web", "acme/api"] },
    { header: "Owner Email", samples: ["dana@acme.example", "jonas@acme", "mei@acme.example"] },
    { header: "Rollout %", samples: ["25", "100", "n/a"] },
  ],
  skipped: [{ count: 2, reason: "the row was empty" }],
})

export default function Example() {
  const [read, setRead] = React.useState<ImportRead | null>(null)
  const [reading, setReading] = React.useState(false)
  return (
    <DataImport
      className="max-w-2xl"
      read={read}
      reading={reading}
      onFile={(file) => {
        setReading(true)
        setTimeout(() => {
          setRead(sample(file.name, file.size))
          setReading(false)
        }, 600)
      }}
    />
  )
}
```

## <DataImport>

Props:

- `read: ImportRead | null`: What was read from the file. null shows the drop zone.
- `onFile: (file: File) => void`: Called with the file a person dropped or chose.
- `reading?: boolean | undefined` (default `false`): The file is being read; the drop zone says so and the button is disabled.
- `accept?: string | undefined` (default `".csv,.xlsx,.xls,.tsv"`): File types the picker offers, as in the input accept attribute.
- `className?: string | undefined`

## Strings (`dataImport`)

The fixed words, English by default. Override any of them under `dataImport` in `<LocaleProvider strings={{ dataImport: { … } }}>`; the table is exported as `dataImportStrings`.

- `reading`: Reading…
- `drop`: Drop a CSV or Excel file
- `firstRow`: The first row should be column names.
- `chooseFile`: Choose file
- `whatWasRead`: What was read
- `rows`: { one: "{count} row", other: "{count} rows" }
- `columns`: { one: "{count} column", other: "{count} columns" }
- `notRead`: { one: "{count} row not read", other: "{count} rows not read" }
- `skippedRows`: { one: "{count} row: {reason}", other: "{count} rows: {reason}" }

## Types

### ImportRead

```ts
{ file: { name: string; size: number } rows: number columns: ImportColumn[] /** Rows that couldn't be read at all, grouped by reason. */ skipped: { count: number; reason: string }[] }
```

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
