- Notifications
You must be signed in to change notification settings - Fork116
The open-source CSV importer, maintained by@tableflowhq
License
tableflowhq/csv-import
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Embed the CSV Importer in your app with theReactorJavaScript SDK
- Define the columns your users can import (via the
template
parameter) - Your users import their files in your app
- Retrieve the imported data from the
onComplete
event
Use NPM or Yarn to install the SDK forReactorJavaScript.
NPM
npm install csv-import-react# ornpm install csv-import-js
Yarn
yarn add csv-import-react# oryarn add csv-import-js
import{CSVImporter}from"csv-import-react";import{useState}from"react";functionMyComponent(){const[isOpen,setIsOpen]=useState(false);return(<><buttononClick={()=>setIsOpen(true)}>Open CSV Importer</button><CSVImportermodalIsOpen={isOpen}modalOnCloseTriggered={()=>setIsOpen(false)}darkMode={true}onComplete={(data)=>console.log(data)}template={{columns:[{name:"First Name",key:"first_name",required:true,description:"The first name of the user",suggested_mappings:["First","Name"],},{name:"Age",data_type:"number",},],}}/></>);}
<head><scriptsrc="https://unpkg.com/csv-import-js@latest/index.js"></script></head><body><buttonid="uploadButton">Open CSV Importer</button><divid="app"></div><script>constimporter=CSVImporter.createCSVImporter({domElement:document.getElementById("app"),modalOnCloseTriggered:()=>importer?.closeModal(),onComplete:(data)=>console.log(data),darkMode:true,template:{columns:[{name:"First Name",key:"first_name",required:true,description:"The first name of the user",suggested_mappings:["First","Name"],},{name:"Age",data_type:"number",},],},});constuploadButton=document.getElementById("uploadButton");uploadButton.addEventListener("click",()=>{importer?.showModal();});</script></body>
When set totrue
(default value), the importer will behave as a modal with its open state controlled bymodalIsOpen
. When set tofalse
, the importer will be embedded directly in your page.
Only used whenisModal
istrue
: Controls the importer modal being open or closed.
React SDK Only: For the JavaScript SDK, use.showModal()
and.closeModal()
to operate the modal.
Only used whenisModal
istrue
: A function called when the user clicks the close button or clicks outside of (when used withmodalCloseOnOutsideClick
) the importer.useState
can be used to control the importer modal opening and closing.
const[isOpen,setIsOpen]=useState(false);
<buttononClick={()=>setIsOpen(true)}>Open CSV Importer</button><CSVImportermodalIsOpen={isOpen}modalOnCloseTriggered={()=>setIsOpen(false)} .../>
Only used whenisModal
istrue
: Clicking outside the modal will call themodalOnCloseTriggered
function.
Configure the columns used for the import.
template={{columns:[{name:"First Name",key:"first_name",required:true,description:"The first name of the user",suggested_mappings:["First","Name"],},{name:"Age",data_type:"number",},],}}
Callback function that fires when a user completes an import. It returnsdata
, an object that contains the row data, column definitions, and other information about the import.
onComplete={(data)=>console.log(data)}
Exampledata
:
{"num_rows":2,"num_columns":3,"columns": [ {"key":"age","name":"Age" }, {"key":"email","name":"Email" }, {"key":"first_name","name":"First Name" } ],"rows": [ {"index":0,"values": {"age":23,"email":"maria@example.com","first_name":"Maria" } }, {"index":1,"values": {"age":32,"email":"robert@example.com","first_name":"Robert" } } ]}
Toggle between dark mode (true
) and light mode (false
).
Specifies the primary color for the importer in hex format. UsecustomStyles
to customize the UI in more detail.
primaryColor="#7A5EF8"
Apply custom styles to the importer with an object containing CSS properties and values. Note that custom style properties will overrideprimaryColor
and any default styles fromdarkMode
.Available options:
customStyles={{"font-family":"cursive","font-size":"15px","base-spacing":"2rem","border-radius":"8px","color-primary":"salmon","color-primary-hover":"crimson","color-secondary":"indianRed","color-secondary-hover":"crimson","color-tertiary":"indianRed","color-tertiary-hover":"crimson","color-border":"lightCoral","color-text":"brown","color-text-soft":"rgba(165, 42, 42, .5)","color-text-on-primary":"#fff","color-text-on-secondary":"#ffffff","color-background":"bisque","color-background-modal":"blanchedAlmond","color-input-background":"blanchedAlmond","color-input-background-soft":"white","color-background-menu-hover":"bisque","color-importer-link":"indigo","color-progress-bar":"darkGreen"}}
- Out-of-the-box support for various languages.
- Common languages are available through the language prop (i.e.,
language="fr"
for French). - Available predefined languages:
- en
- es
- fr
- Language keys can be exported and overridden.
- Labels and messages can be customized to any text.
- Translations key examples can be found in
src/i18n/es.ts
// Set up custom translationsconstcustomTranslations={jp:{Upload:"アップロード","Browse files":"ファイルを参照",},pt:{Upload:"Carregar","Browse files":"Procurar arquivos",},};return(<CSVImporterlanguage="jp"customTranslations={customTranslations}...props/>)
When set tofalse
, hide the Download Template button on the first screen of the importer.
When set totrue
, the importer will not display and skip the Header Row Selection step and always choose the first row in the file as the header.
To set up the project locally, follow these steps:
- Clone the repository
git clone https://github.com/tableflowhq/csv-import.gitcd csv-import
- Install dependencies
yarn install
- Build the project
yarn build
To run Storybook locally, follow these steps:
- Start Storybook
yarn storybook
- Open Storybook in your browser:Storybook should automatically open in your default browser. If it doesn't, navigate tohttp://localhost:6006.
The project includes a demo app that you can use to test your changes. The demo app has its ownREADME.md
file with detailed instructions on how to set it up and run it.
- Make your changes in the codebase.
- Follow the instructions in the demo app's
README.md
to set up and run the demo app. This will help you verify that your changes work as expected in a real application. - Commit your changes and push them to your forked repository.
- Create a pull request to the main repository.
Let us know your feedback or feature requests! Submit a GitHubissuehere.
About
The open-source CSV importer, maintained by@tableflowhq
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.