diff --git a/README.md b/README.md index 7fe6521..d683559 100644 --- a/README.md +++ b/README.md @@ -63,53 +63,48 @@ To learn how to use react-papaparse: ![basic-upload](https://react-papaparse.github.io/static/images/csvreader1.png) -```javascript -import React, { CSSProperties } from 'react'; +```typescript +import React from 'react'; import { useCSVReader } from 'react-papaparse'; -const styles = { +const styles: Record = { csvReader: { display: 'flex', flexDirection: 'row', marginBottom: 10, - } as CSSProperties, + }, browseFile: { width: '20%', - } as CSSProperties, + }, acceptedFile: { border: '1px solid #ccc', height: 45, lineHeight: 2.5, paddingLeft: 10, width: '80%', - } as CSSProperties, + }, remove: { borderRadius: 0, padding: '0 20px', - } as CSSProperties, + }, progressBarBackgroundColor: { backgroundColor: 'red', - } as CSSProperties, + }, }; export default function CSVReader() { - const { CSVReader } = useCSVReader(); + const { CSVReader } = useCSVReader(); return ( { + onUploadAccepted={(results) => { console.log('---------------------------'); console.log(results); console.log('---------------------------'); }} > - {({ - getRootProps, - acceptedFile, - ProgressBar, - getRemoveFileProps, - }: any) => ( + {({ getRootProps, acceptedFile, ProgressBar, getRemoveFileProps }) => ( <>
             
-              {`import React, { useState, CSSProperties } from 'react';
+              {`import React, { useState } from 'react';
 
 import {
   useCSVReader,
@@ -152,7 +152,7 @@ const REMOVE_HOVER_COLOR_LIGHT = lightenDarkenColor(
 );
 const GREY_DIM = '#686868';
 
-const styles = {
+const styles: Record = {
   zone: {
     alignItems: 'center',
     borderWidth: 2,
@@ -164,7 +164,7 @@ const styles = {
     height: '100%',
     justifyContent: 'center',
     padding: 20,
-  } as CSSProperties,
+  },
   file: {
     background: 'linear-gradient(to bottom, #EEE, #DDD)',
     borderRadius: 20,
@@ -175,47 +175,47 @@ const styles = {
     zIndex: 10,
     flexDirection: 'column',
     justifyContent: 'center',
-  } as CSSProperties,
+  },
   info: {
     alignItems: 'center',
     display: 'flex',
     flexDirection: 'column',
     paddingLeft: 10,
     paddingRight: 10,
-  } as CSSProperties,
+  },
   size: {
     backgroundColor: GREY_LIGHT,
     borderRadius: 3,
     marginBottom: '0.5em',
     justifyContent: 'center',
     display: 'flex',
-  } as CSSProperties,
+  },
   name: {
     backgroundColor: GREY_LIGHT,
     borderRadius: 3,
     fontSize: 12,
     marginBottom: '0.5em',
-  } as CSSProperties,
+  },
   progressBar: {
     bottom: 14,
     position: 'absolute',
     width: '100%',
     paddingLeft: 10,
     paddingRight: 10,
-  } as CSSProperties,
+  },
   zoneHover: {
     borderColor: GREY_DIM,
-  } as CSSProperties,
+  },
   default: {
     borderColor: GREY,
-  } as CSSProperties,
+  },
   remove: {
     height: 23,
     position: 'absolute',
     right: 6,
     top: 6,
     width: 23,
-  } as CSSProperties,
+  },
 };
 
 export default function CSVReader() {
@@ -227,17 +227,17 @@ export default function CSVReader() {
 
   return (
      {
+      onUploadAccepted={(results) => {
         console.log('---------------------------');
         console.log(results);
         console.log('---------------------------');
         setZoneHover(false);
       }}
-      onDragOver={(event: DragEvent) => {
+      onDragOver={(event) => {
         event.preventDefault();
         setZoneHover(true);
       }}
-      onDragLeave={(event: DragEvent) => {
+      onDragLeave={(event) => {
         event.preventDefault();
         setZoneHover(false);
       }}
@@ -248,7 +248,7 @@ export default function CSVReader() {
         ProgressBar,
         getRemoveFileProps,
         Remove,
-      }: any) => (
+      }) => (
         <>
           
{ + onMouseOver={(event) => { event.preventDefault(); setRemoveHoverColor(REMOVE_HOVER_COLOR_LIGHT); }} - onMouseOut={(event: Event) => { + onMouseOut={(event) => { event.preventDefault(); setRemoveHoverColor(DEFAULT_REMOVE_HOVER_COLOR); }} @@ -325,7 +325,7 @@ export default function CSVReader() {
             
-              {`import React, { useState, CSSProperties } from 'react';
+              {`import React, { useState } from 'react';
 
 import {
   useCSVReader,
@@ -342,7 +342,7 @@ const REMOVE_HOVER_COLOR_LIGHT = lightenDarkenColor(
 );
 const GREY_DIM = '#686868';
 
-const styles = {
+const styles: Record = {
   zone: {
     alignItems: 'center',
     borderWidth: 2,
@@ -354,7 +354,7 @@ const styles = {
     height: '100%',
     justifyContent: 'center',
     padding: 20,
-  } as CSSProperties,
+  },
   file: {
     background: 'linear-gradient(to bottom, #EEE, #DDD)',
     borderRadius: 20,
@@ -365,47 +365,47 @@ const styles = {
     zIndex: 10,
     flexDirection: 'column',
     justifyContent: 'center',
-  } as CSSProperties,
+  },
   info: {
     alignItems: 'center',
     display: 'flex',
     flexDirection: 'column',
     paddingLeft: 10,
     paddingRight: 10,
-  } as CSSProperties,
+  },
   size: {
     backgroundColor: GREY_LIGHT,
     borderRadius: 3,
     marginBottom: '0.5em',
     justifyContent: 'center',
     display: 'flex',
-  } as CSSProperties,
+  },
   name: {
     backgroundColor: GREY_LIGHT,
     borderRadius: 3,
     fontSize: 12,
     marginBottom: '0.5em',
-  } as CSSProperties,
+  },
   progressBar: {
     bottom: 14,
     position: 'absolute',
     width: '100%',
     paddingLeft: 10,
     paddingRight: 10,
-  } as CSSProperties,
+  },
   zoneHover: {
     borderColor: GREY_DIM,
-  } as CSSProperties,
+  },
   default: {
     borderColor: GREY,
-  } as CSSProperties,
+  },
   remove: {
     height: 23,
     position: 'absolute',
     right: 6,
     top: 6,
     width: 23,
-  } as CSSProperties,
+  },
 };
 
 export default function CSVReader() {
@@ -417,17 +417,17 @@ export default function CSVReader() {
 
   return (
      {
+      onUploadAccepted={(results) => {
         console.log('---------------------------');
         console.log(results);
         console.log('---------------------------');
         setZoneHover(false);
       }}
-      onDragOver={(event: DragEvent) => {
+      onDragOver={(event) => {
         event.preventDefault();
         setZoneHover(true);
       }}
-      onDragLeave={(event: DragEvent) => {
+      onDragLeave={(event) => {
         event.preventDefault();
         setZoneHover(false);
       }}
@@ -439,7 +439,7 @@ export default function CSVReader() {
         ProgressBar,
         getRemoveFileProps,
         Remove,
-      }: any) => (
+      }) => (
         <>
           
{ + onMouseOver={(event) => { event.preventDefault(); setRemoveHoverColor(REMOVE_HOVER_COLOR_LIGHT); }} - onMouseOut={(event: Event) => { + onMouseOut={(event) => { event.preventDefault(); setRemoveHoverColor(DEFAULT_REMOVE_HOVER_COLOR); }} @@ -516,7 +516,7 @@ export default function CSVReader() {
             
-              {`import React, { useState, CSSProperties } from 'react';
+              {`import React, { useState } from 'react';
 
 import {
   useCSVReader,
@@ -533,7 +533,7 @@ const REMOVE_HOVER_COLOR_LIGHT = lightenDarkenColor(
 );
 const GREY_DIM = '#686868';
 
-const styles = {
+const styles: Record = {
   zone: {
     alignItems: 'center',
     borderWidth: 2,
@@ -545,7 +545,7 @@ const styles = {
     height: '100%',
     justifyContent: 'center',
     padding: 20,
-  } as CSSProperties,
+  },
   file: {
     background: 'linear-gradient(to bottom, #EEE, #DDD)',
     borderRadius: 20,
@@ -556,47 +556,47 @@ const styles = {
     zIndex: 10,
     flexDirection: 'column',
     justifyContent: 'center',
-  } as CSSProperties,
+  },
   info: {
     alignItems: 'center',
     display: 'flex',
     flexDirection: 'column',
     paddingLeft: 10,
     paddingRight: 10,
-  } as CSSProperties,
+  },
   size: {
     backgroundColor: GREY_LIGHT,
     borderRadius: 3,
     marginBottom: '0.5em',
     justifyContent: 'center',
     display: 'flex',
-  } as CSSProperties,
+  },
   name: {
     backgroundColor: GREY_LIGHT,
     borderRadius: 3,
     fontSize: 12,
     marginBottom: '0.5em',
-  } as CSSProperties,
+  },
   progressBar: {
     bottom: 14,
     position: 'absolute',
     width: '100%',
     paddingLeft: 10,
     paddingRight: 10,
-  } as CSSProperties,
+  },
   zoneHover: {
     borderColor: GREY_DIM,
-  } as CSSProperties,
+  },
   default: {
     borderColor: GREY,
-  } as CSSProperties,
+  },
   remove: {
     height: 23,
     position: 'absolute',
     right: 6,
     top: 6,
     width: 23,
-  } as CSSProperties,
+  },
 };
 
 export default function CSVReader() {
@@ -608,17 +608,17 @@ export default function CSVReader() {
 
   return (
      {
+      onUploadAccepted={(results) => {
         console.log('---------------------------');
         console.log(results);
         console.log('---------------------------');
         setZoneHover(false);
       }}
-      onDragOver={(event: DragEvent) => {
+      onDragOver={(event) => {
         event.preventDefault();
         setZoneHover(true);
       }}
-      onDragLeave={(event: DragEvent) => {
+      onDragLeave={(event) => {
         event.preventDefault();
         setZoneHover(false);
       }}
@@ -630,7 +630,7 @@ export default function CSVReader() {
         ProgressBar,
         getRemoveFileProps,
         Remove,
-      }: any) => (
+      }) => (
         <>
           
{ + onMouseOver={(event) => { event.preventDefault(); setRemoveHoverColor(REMOVE_HOVER_COLOR_LIGHT); }} - onMouseOut={(event: Event) => { + onMouseOut={(event) => { event.preventDefault(); setRemoveHoverColor(DEFAULT_REMOVE_HOVER_COLOR); }} diff --git a/examples/CSVReaderBasicUpload.tsx b/examples/CSVReaderBasicUpload.tsx index d791f7b..4231be0 100644 --- a/examples/CSVReaderBasicUpload.tsx +++ b/examples/CSVReaderBasicUpload.tsx @@ -1,49 +1,44 @@ -import React, { CSSProperties } from 'react'; +import React from 'react'; import { useCSVReader } from 'react-papaparse'; -const styles = { +const styles: Record = { csvReader: { display: 'flex', flexDirection: 'row', marginBottom: 10, - } as CSSProperties, + }, browseFile: { width: '20%', - } as CSSProperties, + }, acceptedFile: { border: '1px solid #ccc', height: 45, lineHeight: 2.5, paddingLeft: 10, width: '80%', - } as CSSProperties, + }, remove: { borderRadius: 0, padding: '0 20px', - } as CSSProperties, + }, progressBarBackgroundColor: { backgroundColor: 'red', - } as CSSProperties, + }, }; export default function CSVReader() { - const { CSVReader } = useCSVReader(); + const { CSVReader } = useCSVReader(); return ( { + onUploadAccepted={(results) => { console.log('---------------------------'); console.log(results); console.log('---------------------------'); }} > - {({ - getRootProps, - acceptedFile, - ProgressBar, - getRemoveFileProps, - }: any) => ( + {({ getRootProps, acceptedFile, ProgressBar, getRemoveFileProps }) => ( <>
-
- {acceptedFile && acceptedFile.name} -
- +
{acceptedFile && acceptedFile.name}
+
diff --git a/test/__snapshots__/CSVReader.spec.tsx.snap b/test/__snapshots__/CSVReader.spec.tsx.snap index 4abb796..ff27024 100644 --- a/test/__snapshots__/CSVReader.spec.tsx.snap +++ b/test/__snapshots__/CSVReader.spec.tsx.snap @@ -27,7 +27,7 @@ Array [ onDrop={[Function]} onFocus={[Function]} onKeyDown={[Function]} - type="button" + type='button' > Chargez votre offre