diff --git a/src/App.css b/src/App.css index f81776d..0594f72 100644 --- a/src/App.css +++ b/src/App.css @@ -4,6 +4,19 @@ .App-logo { height: 40vmin; +.FrameChooser .frame{ + height: 12vh; + margin: 2vh; + cursor: pointer; + box-shadow: 0 0 0 1vh rgba(255,255,255,0); + transition: transform 0.2s ease; +} +.FrameChooser .frame:hover{ + transform-origin: center center; + transform: scale(1.1); +} +.FrameChooser .frame.choosen{ + box-shadow: 0 0 0 1vh white; } .App-header { diff --git a/src/App.js b/src/App.js index 028066f..6db4a1d 100644 --- a/src/App.js +++ b/src/App.js @@ -1,17 +1,21 @@ import { useState, useEffect, useCallback } from 'react' import './App.css' import download from 'downloadjs' - -import frame_mixed from './frames/ProfileFrame Mixed Bars.png' +import FrameChooser from './FrameChooser.js' import mergeImages from 'merge-images' const frameSize = 1080 function App() { + const [frameURL, setFrameURL] = useState(null) const [photo, setPhoto] = useState(null) const [combinedImage, setCombinedImage] = useState(null) + const handleFrameURL = useCallback(newFrameURL => { + setFrameURL(newFrameURL) + }, [setFrameURL]) + const handleImage = useCallback(files_event => { const reader = new FileReader() reader.onload = reader_event => { @@ -44,10 +48,10 @@ function App() { useEffect(() => { mergeImages([ ...(photo ? [photo] : []), - ...(frame_mixed ? [frame_mixed] : []), + ...(frameURL ? [frameURL] : []), ]) .then(b64 => setCombinedImage(b64)) - }, [photo]) + }, [photo, frameURL]) @@ -61,6 +65,7 @@ return ( + ) } diff --git a/src/FrameChooser.js b/src/FrameChooser.js new file mode 100644 index 0000000..90628cc --- /dev/null +++ b/src/FrameChooser.js @@ -0,0 +1,59 @@ +import { useState, useEffect, useCallback } from 'react' + +function FrameChooser({onFrameChange}) { + const [frames, setFrames] = useState([]) + const [choosenFrame, setChoosenFrame] = useState(null) + + useEffect(() => { + async function loadFrames(){ + Promise.all( + [ + 'ProfileFrame Purple', + 'ProfileFrame Yellow Bars', + 'ProfileFrame Red Bars', + 'ProfileFrame Blue Bars', + 'ProfileFrame Green Bars', + 'ProfileFrame White Bars', + 'ProfileFrame Mixed Bars', + 'ProfileFrame R&Y Bars', + 'ProfileFrame B&G Bars', + ] + .map(async frame_filename => { + return { + name: frame_filename, + src: await import(`./frames/${frame_filename}.png`), + } + }) + ) + .then(new_frames => { + console.log(new_frames) + setFrames(new_frames) + setChoosenFrame(new_frames[0].src.default) + }) + } + loadFrames() + }, []) + + const handleImageChoosing = useCallback(event => { + setChoosenFrame(event.target.dataset.src) + }, [setChoosenFrame]) + + useEffect(() => { + onFrameChange(choosenFrame) + }, [onFrameChange, choosenFrame]) + + return ( +
+

Choose a frame:

+ { + frames.map(frame => { + const frame_src_path = frame.src.default + const isChoosen = choosenFrame === frame_src_path + return {frame.name} + }) + } +
+ ) +} + +export default FrameChooser; diff --git a/src/frames/ProfileFrame B&G Bars.png b/src/frames/ProfileFrame B&G Bars.png new file mode 100644 index 0000000..50475ec Binary files /dev/null and b/src/frames/ProfileFrame B&G Bars.png differ diff --git a/src/frames/ProfileFrame Blue Bars.png b/src/frames/ProfileFrame Blue Bars.png new file mode 100644 index 0000000..a358856 Binary files /dev/null and b/src/frames/ProfileFrame Blue Bars.png differ diff --git a/src/frames/ProfileFrame Green Bars.png b/src/frames/ProfileFrame Green Bars.png new file mode 100644 index 0000000..931523b Binary files /dev/null and b/src/frames/ProfileFrame Green Bars.png differ diff --git a/src/frames/ProfileFrame Purple.png b/src/frames/ProfileFrame Purple.png new file mode 100644 index 0000000..caf7d57 Binary files /dev/null and b/src/frames/ProfileFrame Purple.png differ diff --git a/src/frames/ProfileFrame R&Y Bars.png b/src/frames/ProfileFrame R&Y Bars.png new file mode 100644 index 0000000..9c6bff2 Binary files /dev/null and b/src/frames/ProfileFrame R&Y Bars.png differ diff --git a/src/frames/ProfileFrame Red Bars.png b/src/frames/ProfileFrame Red Bars.png new file mode 100644 index 0000000..9521d1d Binary files /dev/null and b/src/frames/ProfileFrame Red Bars.png differ diff --git a/src/frames/ProfileFrame White Bars.png b/src/frames/ProfileFrame White Bars.png new file mode 100644 index 0000000..436f996 Binary files /dev/null and b/src/frames/ProfileFrame White Bars.png differ diff --git a/src/frames/ProfileFrame Yellow Bars.png b/src/frames/ProfileFrame Yellow Bars.png new file mode 100644 index 0000000..5f93431 Binary files /dev/null and b/src/frames/ProfileFrame Yellow Bars.png differ