RSI react-spreadsheet-import
A component for importing XLS / XLSX / CSV documents.
Automatic column matching and custom validation rules.
All styles and texts are customisable.
Demo
Figma
We provide full figma designs. You can duplicate the designs
here
Getting started
npm i react-spreadsheet-import
Using the component: (it's up to you when the flow is open and what you do on submit with the imported data)
import { ReactSpreadsheetImport } from "react-spreadsheet-import";
<ReactSpreadsheetImport
isOpen={isOpen}
onClose={onClose}
onSubmit={onSubmit}
fields={fields}
/>
Required Props
isOpen: Boolean
onClose: () => void
onSubmit: (data) => void
Fields
Fields describe what data you are trying to collect.
const fields = [
{
label: "Name",
key: "name",
alternateMatches: ["first name", "first"],
fieldType: {
type: "input",
},
example: "Stephanie",
validations: [
{
rule: "required",
errorMessage: "Name is required",
level: "error",
},
],
},
] as const
Optional Props
Hooks
You can transform and validate data with custom hooks. There are 3 hooks that have different performance tradeoffs:
- initialHook - runs only once after column matching. Operations that should run once should be done here.
- tableHook - runs at the start and on any change. Runs on all rows. Very expensive, but can change rows that depend on other rows.
- rowHook - runs at the start and on any row change. Runs only on the rows changed. Fastest, most validations and transformations should be done here.
Example:
<ReactSpreadsheetImport
rowHook={(data, addError) => {
if (data.name === "John") {
addError("name", { message: "No Johns allowed", level: "info" })
}
return { ...data, name: "Not John" }
}}
/>
Other optional props
allowInvalidSubmit?: boolean
translations?: object
customTheme?: object
maxRecords?: number
maxFileSize?: number
autoMapHeaders?: boolean
autoMapDistance?: number
Customisation
Customising styles (colors, fonts)
Underneath we use Chakra-UI, you can send in a custom theme for us to apply. Read more about themes here
<ReactSpreadsheetImport
customTheme={yourTheme}
/>
You can see all the changable styles here
Changing text (translations)
You can change any text in the flow:
<ReactSpreadsheetImport
translations={{
uploadStep: {
title: "Upload Employees",
},
}}
/>
You can see all the translation keys here
VS other libraries
Flatfile vs react-spreadsheet-import and Dromo vs react-spreadsheet-import:
| RSI | Flatfile | Dromo |
---|
Licence | MIT | Proprietary | Proprietary |
Price | Free | Paid | Paid |
Support | Github Issues | Enterprise | Enterprise |
Self-host | Yes | Paid | Paid |
Hosted solution | In development | Yes | No |
On-prem deployment | N/A | Yes | Yes |
Hooks | Yes | Yes | Yes |
Automatic header matching | Yes | Yes | Yes |
Data validation | Yes | Yes | Yes |
Custom styling | Yes | Yes | Yes |
Translations | Yes | Yes | No |
Trademarked words Data Hooks | No | Yes | No |
React-spreadsheet-import can be used as a free and open-source alternative to Flatfile and Dromo.
Contributing
Feel free to open issues if you have any questions or notice bugs. If you want different component behaviour, consider forking the project.
Credits
Created by Ugnis. Julita Kriauciunaite and Karolis Masiulis. You can contact us at info@ugnis.com