-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Add option to upload background image #15
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation + declare |
||
reader.readAsDataURL(file) | ||
reader.onloadend = () => { | ||
setImage(reader.result) | ||
} | ||
}, []) | ||
|
||
const {acceptedFiles, getRootProps, getInputProps} = useDropzone({onDrop}); | ||
|
||
return ( | ||
|
||
<> | ||
<InputBlock> | ||
<div {...getRootProps({className: 'dropzone'})}> | ||
<input {...getInputProps()} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation (you can activate automatic formatting in VS Code in your settings, that will normally apply our eslint formatting to your whole file on each save) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the tip :) I havent been using VS Code but am trying it now - I added the Eslint plugin and checked 'Turns auto fix on save on or off' in settings, but it doesnt seem to fix the formatting on save - have I missed something? |
||
<p>Drag 'n' drop some files here, or click to select files</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes sounds better |
||
</div> | ||
</InputBlock> | ||
</> | ||
) | ||
} | ||
|
||
export default ImageInput |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ImageInput } from "./ImageInput" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import styled from "styled-components" | |
import { ContentInput } from "components/InputWrapper/ContentInput" | ||
import { ColorInput } from "components/InputWrapper/ColorInput" | ||
import { SizeInput } from "components/InputWrapper/SizeInput" | ||
import { ImageInput } from "components/InputWrapper/ImageInput" | ||
|
||
|
||
const Wrapper = styled.div` | ||
display: flex; | ||
|
@@ -35,8 +37,8 @@ const Summary = styled.summary` | |
` | ||
|
||
const InputWrapper = ({ values, setters }) => { | ||
const { bgColor, title, titleSize, titleColor, borderColor, borderSize } = values | ||
const { setBgColor, setTitle, setTitleSize, setTitleColor, setBorderColor, setBorderSize } = setters | ||
const { bgColor, title, titleSize, titleColor, borderColor, borderSize, image } = values | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused |
||
const { setBgColor, setTitle, setTitleSize, setTitleColor, setBorderColor, setBorderSize, setImage } = setters | ||
|
||
return ( | ||
<Wrapper> | ||
|
@@ -56,6 +58,10 @@ const InputWrapper = ({ values, setters }) => { | |
<Summary>Sizes</Summary> | ||
<SizeInput titleSize={titleSize} borderSize={borderSize} setTitleSize={setTitleSize} setBorderSize={setBorderSize} /> | ||
</Detail> | ||
<Detail> | ||
<Summary>Background Image</Summary> | ||
<ImageInput image={image} setImage={setImage}/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since image is not used in this component, remove it as a prop |
||
</Detail> | ||
</Wrapper> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ const Wrapper = styled.div` | |
border: 1px solid #dbdbdb; | ||
border: ${(props) => `${props.borderSize}px solid ${props.borderColor}`}; | ||
box-sizing: border-box; | ||
background-image: url(${(props) => props.image}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of adding: background-repeat: no-repeat;
background-size: cover; ? |
||
|
||
@media (max-width: 1279px) { | ||
width: auto; | ||
|
@@ -26,10 +27,10 @@ const Title = styled.h1` | |
` | ||
|
||
const Output = ({ values }) => { | ||
const { bgColor, title, titleSize, titleColor, borderColor, borderSize } = values | ||
const { bgColor, title, titleSize, titleColor, borderColor, borderSize, image } = values | ||
|
||
return ( | ||
<Wrapper bgColor={bgColor} titleColor={titleColor} borderColor={borderColor} borderSize={borderSize} id="capture"> | ||
<Wrapper bgColor={bgColor} titleColor={titleColor} borderColor={borderColor} borderSize={borderSize} image={image} id="capture"> | ||
<Title size={titleSize}>{title}</Title> | ||
</Wrapper> | ||
) | ||
|
@@ -42,7 +43,8 @@ Output.propTypes = { | |
titleSize: PropTypes.string, | ||
titleColor: PropTypes.string, | ||
borderColor: PropTypes.string, | ||
hasBorder: PropTypes.bool | ||
hasBorder: PropTypes.bool, | ||
image: PropTypes.string | ||
}).isRequired | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
image
prop is unused