forked from christopherkade/banner-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add option to upload background image
Using react-dropzone and FileReader to allow user to upload image from computer onto background-image of the banner christopherkade#5
- Loading branch information
1 parent
3e9a764
commit e43c348
Showing
9 changed files
with
13,147 additions
and
38 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, {useCallback} from 'react'; | ||
import styled from "styled-components" | ||
import {useDropzone} from 'react-dropzone'; | ||
|
||
|
||
const InputBlock = styled.div` | ||
position: relative; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
border: 2px dashed; | ||
border-radius: 20px; | ||
width: 480px; | ||
font-family: sans-serif; | ||
margin: 40px auto; | ||
padding: 20px; | ||
` | ||
|
||
const ImageInput = ({ image, setImage }) => { | ||
const onDrop = useCallback(acceptedFiles => { | ||
const file = acceptedFiles[0] | ||
let reader = new FileReader(); | ||
reader.readAsDataURL(file) | ||
reader.onloadend = () => { | ||
setImage(reader.result) | ||
} | ||
}, []) | ||
|
||
const {acceptedFiles, getRootProps, getInputProps} = useDropzone({onDrop}); | ||
|
||
return ( | ||
|
||
<> | ||
<InputBlock> | ||
<div {...getRootProps({className: 'dropzone'})}> | ||
<input {...getInputProps()} /> | ||
<p>Drag 'n' drop some files here, or click to select files</p> | ||
</div> | ||
</InputBlock> | ||
</> | ||
) | ||
} | ||
|
||
export default ImageInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ImageInput } from "./ImageInput" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.