@@ -79,64 +79,96 @@ import { CSVReader } from 'react-papaparse'
7979const buttonRef = React .createRef ()
8080
8181export default class CSVReader extends Component {
82+ handleOpenDialog = (e ) => {
83+ // Note that the ref is set async, so it might be null at some point
84+ if (buttonRef .current ) {
85+ buttonRef .current .open (e)
86+ }
87+ }
88+
8289 handleOnFileLoad = (data ) => {
83- console .log (' -------------------------------------------------- ' )
90+ console .log (' ---------------------------' )
8491 console .log (data)
85- console .log (' -------------------------------------------------- ' )
92+ console .log (' ---------------------------' )
8693 }
8794
8895 handleOnError = (err , file , inputElem , reason ) => {
8996 console .log (err)
9097 }
9198
92- handleOpenDialog = (e ) => {
93- // Note that the ref is set async, so it might be null at some point
99+ handleOnRemoveFile = (data ) => {
100+ console .log (' ---------------------------' )
101+ console .log (data)
102+ console .log (' ---------------------------' )
103+ }
104+
105+ handleRemoveFile = (e ) => {
106+ // Note that the ref is set async, so it might be null at some point
94107 if (buttonRef .current ) {
95- buttonRef .current .open (e)
108+ buttonRef .current .removeFile (e)
96109 }
97110 }
98111
99112 render () {
100113 return (
101114 < CSVReader
102115 ref= {buttonRef}
103- onFileLoad= {this .handleOnFileLoad }
116+ onFileLoad= {this .handleOnDrop }
104117 onError= {this .handleOnError }
105118 noClick
106119 noDrag
120+ onRemoveFile= {this .handleOnRemoveFile }
107121 >
108- {({file}) => (
109- < aside style= {{display: ' flex' , flexDirection: ' row' , marginBottom: 10 }}>
122+ {({ file }) => (
123+ < aside
124+ style= {{
125+ display: ' flex' ,
126+ flexDirection: ' row' ,
127+ marginBottom: 10
128+ }}
129+ >
110130 < button
111- type= " button"
131+ type= ' button'
112132 onClick= {this .handleOpenDialog }
113133 style= {{
114- width: ' 40%' ,
115134 borderRadius: 0 ,
116135 marginLeft: 0 ,
117136 marginRight: 0 ,
137+ width: ' 40%' ,
118138 paddingLeft: 0 ,
119- paddingRight: 0 ,
139+ paddingRight: 0
120140 }}
121141 >
122142 Browe file
123143 < / button>
124144 < div
125145 style= {{
126- width: ' 60%' ,
127- height: 45 ,
128146 borderWidth: 1 ,
129147 borderStyle: ' solid' ,
130148 borderColor: ' #ccc' ,
149+ height: 45 ,
150+ lineHeight: 2.5 ,
131151 marginTop: 5 ,
132152 marginBottom: 5 ,
133153 paddingLeft: 13 ,
134154 paddingTop: 3 ,
135- lineHeight : 2.5 ,
155+ width : ' 60% '
136156 }}
137157 >
138- {file .name }
158+ {file && file .name }
139159 < / div>
160+ < button
161+ style= {{
162+ borderRadius: 0 ,
163+ marginLeft: 0 ,
164+ marginRight: 0 ,
165+ paddingLeft: 20 ,
166+ paddingRight: 20
167+ }}
168+ onClick= {this .handleRemoveFile }
169+ >
170+ Remove
171+ < / button>
140172 < / aside>
141173 )}
142174 < / CSVReader>
@@ -156,20 +188,28 @@ import { CSVReader } from 'react-papaparse'
156188
157189export default class CSVReader extends Component {
158190 handleOnDrop = (data ) => {
159- console .log (' -------------------------------------------------- ' )
191+ console .log (' ---------------------------' )
160192 console .log (data)
161- console .log (' -------------------------------------------------- ' )
193+ console .log (' ---------------------------' )
162194 }
163195
164196 handleOnError = (err , file , inputElem , reason ) => {
165197 console .log (err)
166198 }
167199
200+ handleOnRemoveFile = (data ) => {
201+ console .log (' ---------------------------' )
202+ console .log (data)
203+ console .log (' ---------------------------' )
204+ }
205+
168206 render () {
169207 return (
170- < CSVReader
208+ < CSVReader
171209 onDrop= {this .handleOnDrop }
172210 onError= {this .handleOnError }
211+ addRemoveButton
212+ onRemoveFile= {this .handleOnRemoveFile }
173213 >
174214 < span> Drop CSV file here or click to upload.< / span>
175215 < / CSVReader>
@@ -189,21 +229,29 @@ import { CSVReader } from 'react-papaparse'
189229
190230export default class CSVReader extends Component {
191231 handleOnDrop = (data ) => {
192- console .log (' -------------------------------------------------- ' )
232+ console .log (' ---------------------------' )
193233 console .log (data)
194- console .log (' -------------------------------------------------- ' )
234+ console .log (' ---------------------------' )
195235 }
196236
197237 handleOnError = (err , file , inputElem , reason ) => {
198238 console .log (err)
199239 }
200240
241+ handleOnRemoveFile = (data ) => {
242+ console .log (' ---------------------------' )
243+ console .log (data)
244+ console .log (' ---------------------------' )
245+ }
246+
201247 render () {
202248 return (
203249 < CSVReader
204250 onDrop= {this .handleOnDrop }
205251 onError= {this .handleOnError }
206252 noClick
253+ addRemoveButton
254+ onRemoveFile= {this .handleOnRemoveFile }
207255 >
208256 < span> Drop CSV file here to upload.< / span>
209257 < / CSVReader>
@@ -223,21 +271,29 @@ import { CSVReader } from 'react-papaparse'
223271
224272export default class CSVReader extends Component {
225273 handleOnDrop = (data ) => {
226- console .log (' -------------------------------------------------- ' )
274+ console .log (' ---------------------------' )
227275 console .log (data)
228- console .log (' -------------------------------------------------- ' )
276+ console .log (' ---------------------------' )
229277 }
230278
231279 handleOnError = (err , file , inputElem , reason ) => {
232280 console .log (err)
233281 }
234282
283+ handleOnRemoveFile = (data ) => {
284+ console .log (' ---------------------------' )
285+ console .log (data)
286+ console .log (' ---------------------------' )
287+ }
288+
235289 render () {
236290 return (
237291 < CSVReader
238292 onDrop= {this .handleOnDrop }
239293 onError= {this .handleOnError }
240294 noDrag
295+ addRemoveButton
296+ onRemoveFile= {this .handleOnRemoveFile }
241297 >
242298 < span> Click to upload.< / span>
243299 < / CSVReader>
0 commit comments