Skip to content

Commit

Permalink
feat: adds pause button
Browse files Browse the repository at this point in the history
  • Loading branch information
sirPixieJerry committed Feb 10, 2024
1 parent 36d5a35 commit 8a21500
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 3 deletions.
60 changes: 60 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ body {
width: 300px;
height: 300px;
background-color: rgb(53, 45, 106);
transform: translateX(30px);
}

svg {
Expand Down Expand Up @@ -125,3 +126,62 @@ path {
transform: translate(-45px, -45px);
background-color: yellow;
}

button {
width: 40px;
height: 40px;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
margin-bottom: 4px;
border: none;
background-color: white;
position: relative;
overflow: hidden;
}

button:hover {
background-color: rgb(242, 242, 242);
}

img {
height: 25px;
width: 25px;
}

#menu {
display: flex;
flex-direction: column;
transform: translate(40px, -150px);
}

button span {
position: absolute;
border-radius: 8px;
background-color: rgba(0, 0, 0, 0.2);
width: 40px;
height: 40px;
animation: ripple 1s;
opacity: 0;
}

@keyframes ripple {
from {
opacity: 1;
transform: scale(0);
}
to {
opacity: 0;
transform: scale(10);
}
}

.active {
background-color: rgb(236, 236, 236);
}

.active:hover {
background-color: rgb(226, 226, 226);
}
13 changes: 13 additions & 0 deletions src/icons/square-arrow-left-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/icons/square-arrow-right-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/icons/square-pause-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
</div>
</div>
</div>
<div id="menu">
<button id="pause">
<img src="./icons/square-pause-svgrepo-com.svg" alt="pause" />
</button>
</div>
<script type="module" src="ts/index.ts"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions src/modules/addRippleEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const addRippleEffect = (button: HTMLButtonElement): void => {
const ripple = document.createElement('span');
ripple.classList.add('ripple');
button.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
};
16 changes: 16 additions & 0 deletions src/modules/handleMenuButtons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { addRippleEffect } from './addRippleEffect';
import { setPauseRewind } from './rewindColors';

export const handleMenuButtons = (): void => {
document.querySelectorAll('button').forEach((button) => {
button.addEventListener('click', (evt) => {
const button = evt.currentTarget as HTMLButtonElement;
addRippleEffect(button);

if (button.id === 'pause') {
button.classList.toggle('active');
setPauseRewind();
}
});
});
};
1 change: 1 addition & 0 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './colorSVG';
export * from './colorReflection';
export * from './handleClickableElement';
export * from './recordColorChange';
export * from './handleMenuButtons';
9 changes: 7 additions & 2 deletions src/modules/rewindColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const TIMEOUT = 5000;
let idleTime: NodeJS.Timeout;
let interval: NodeJS.Timeout;
let stopRewind = true;
let pauseRewind = false;
let initialDelay: number;

const rewind = (): void => {
const removeStep = (): void => {
if (stopRewind) return;
if (stopRewind || pauseRewind) return;
if (steps.length > 0) {
console.log(steps.length);
const removedStep = steps.pop();
Expand All @@ -29,8 +30,12 @@ export const setStopRewind = (arg: boolean): void => {
stopRewind = arg;
};

export const setPauseRewind = (): void => {
pauseRewind = !pauseRewind;
};

export const resetTimer = (): void => {
if (stopRewind) return;
if (stopRewind || pauseRewind) return;
clearTimeout(idleTime);
clearTimeout(interval);
initialDelay = DELAY;
Expand Down
3 changes: 2 additions & 1 deletion src/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleClickableElement } from '../modules';
import { handleClickableElement, handleMenuButtons } from '../modules';

((): void => {
handleClickableElement();
handleMenuButtons();
})();

0 comments on commit 8a21500

Please sign in to comment.