Skip to content

Commit

Permalink
added popout animation for input letters
Browse files Browse the repository at this point in the history
  • Loading branch information
LooLzzz committed Aug 31, 2024
1 parent dee65c6 commit 5e43d80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/components/WordsGuesser/Guess/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ $reveal-anim-duration-ms: 500;
$reveal-anim-duration: #{$reveal-anim-duration-ms}ms;
$reveal-anim-timing-function: ease-in-out;

$popout-anim-duration-ms: 150;
$popout-anim-duration: #{$popout-anim-duration-ms}ms;
$popout-anim-timing-function: ease;

@keyframes reveal-anim {
0% {
transform: scaleY(1);
Expand All @@ -16,6 +20,16 @@ $reveal-anim-timing-function: ease-in-out;
}
}

@keyframes popout-anim {
0% {
transform: scale(1.15);
}

100% {
transform: scale(1);
}
}

@for $i from 1 through 6 {
.lettersContainer .reveal:nth-child(#{$i}n) {
animation-delay: #{($i - 1) * $reveal-anim-duration-ms}ms;
Expand Down Expand Up @@ -76,6 +90,9 @@ $reveal-anim-timing-function: ease-in-out;

&.guessedLetter {
border-color: var(--color-letter-filled-border);
animation: popout-anim $popout-anim-duration;
animation-iteration-count: 1;
animation-timing-function: $popout-anim-timing-function;
}

&.selected {
Expand Down
12 changes: 10 additions & 2 deletions src/components/WordsGuesser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,16 @@ const WordsGuesser = () => {
&& e.key.length === 1
&& e.key.match(/[a-z]/i)
) {
addLetterToCurrentGuess(e.key, selectedIdx)
setSelectedIdx(undefined)
if (selectedIdx !== undefined) {
removeLetterFromCurrentGuess(selectedIdx)
setTimeout(() => {
addLetterToCurrentGuess(e.key, selectedIdx)
}, 10)
setSelectedIdx(undefined)
} else {
addLetterToCurrentGuess(e.key, selectedIdx)
setSelectedIdx(undefined)
}
}
}
}, [lastGuess, currentGuess, currentGuessString, numberOfEmptyLetters, selectedIdx, wordsSet])
Expand Down

0 comments on commit 5e43d80

Please sign in to comment.