diff --git a/src/components/Button.css b/src/components/Button.css index b091aa6..45f285a 100644 --- a/src/components/Button.css +++ b/src/components/Button.css @@ -19,6 +19,10 @@ button:hover { color: white; } +.wrapper { + position: relative; +} + img { width: 70px; height: 70px; @@ -26,6 +30,7 @@ img { opacity: 1; transition: 0.2s; + position: absolute; } .hidden { diff --git a/src/components/Button.js b/src/components/Button.js index f72eaf2..1f1d080 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -5,11 +5,29 @@ If animate on hover is true, the button will show an icon of Koala to the right */ import './Button.css'; -const addKoala = () => { +export default function Button(label, className, animate, eventListener, callback) { + const button = document.createElement('button'); + button.innerHTML = label; + button.classList.add(className); + + button.addEventListener(eventListener, callback); + + const buttonWrapper = document.createElement('div'); + buttonWrapper.classList.add('wrapper'); + buttonWrapper.append(button); + + if (animate) { + const koala = addKoala(button); + buttonWrapper.append(koala); + } + + return buttonWrapper; +} + +const addKoala = (button) => { const koala = document.createElement('img'); koala.src = '/cute_koala.png'; koala.classList.add('koala', 'hidden'); - button.after(koala); button.onmouseover = () => { koala.classList.remove('hidden'); @@ -17,16 +35,5 @@ const addKoala = () => { button.onmouseout = () => { koala.classList.add('hidden'); }; + return koala; }; - -export default function Button(label, className, animate, eventListener, callback) { - const button = document.createElement('button'); - button.innerHTML = label; - button.classList.add(className); - - button.addEventListener(eventListener, callback); - - animate && addKoala(); - - return button; -}