Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-dropzone style drop area

I am new to reactjs, trying to create a component that uses react-dropzone. I was wondering, what is the best way to override the default setting to style the drop area.

So far I have inline style, but it looks to me that I am not doing the 'right' thing.

<Row>
    <Jumbotron className="text-center">
        <h4>Create a manual call</h4>
        <Dropzone 
            className=""
            multiple={false}
            onDrop={this.onDrop}
            style={{"width" : "100%", "height" : "20%", "border" : "1px solid black"}}>
                <div>
                    Try dropping some files here, or click to select files to upload.
                </div>
        </Dropzone>
    </Jumbotron>
</Row>

Any help or better suggestion?

Thank you!

like image 985
mikey Avatar asked Mar 20 '17 05:03

mikey


People also ask

What is getRootProps?

Use the getRootProps() fn to get the props required for drag 'n' drop and use them on any element. For click and keydown behavior, use the getInputProps() fn and use the returned props on an <input> . Furthermore, the hook supports folder drag 'n' drop by default.

How do I upload pictures to react dropzone?

js file: import Dropzone from "./Dropzone/Dropzone"; We'd add the component as a child of the div element with class name content : return ( <div> <p className="title">React Drag and Drop Image Upload</p> <div className="content"> <Dropzone /> </div> </div> );


2 Answers

What you are doing is totally fine. If you would prefer you can write your styling in a .css file that you add to your project. Give the component a className and import the css somewhere in your project.

<Dropzone
  className="dropzone"
  multiple={false}
  onDrop={this.onDrop}>
  <div>
    Try dropping some files here, or click to select files to upload.
  </div>
</Dropzone>

/* styles.css */
.dropzone {
  width : 100%;
  height : 20%;
  border : 1px solid black;
}

There are more involved libraries to do css-in-js like styled-components, but there is no 100% correct solution.

like image 113
brookemitchell Avatar answered Nov 09 '22 21:11

brookemitchell


You can create a style object like this

const dropzoneStyle = {
    width  : "100%",
    height : "20%",
    border : "1px solid black"
};

Use the variable in jsx like this

<Dropzone 
  className=""
  multiple={false}
  onDrop={this.onDrop}
  style={dropzoneStyle}
>
  <div>
       Try dropping some files here, or click to select files to upload.
  </div>
</Dropzone>
like image 30
Dhiraj Avatar answered Nov 09 '22 21:11

Dhiraj