Skip to content
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 mobile theme switcher #48

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/assets/scripts/modules/modal.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function initializeModal(modalIdentifier) {
function initializeModal(buttonIdentifier, modalIdentifier) {
const button = document.querySelector(`.${buttonIdentifier}`)
const modal = document.querySelector(`.${modalIdentifier}`)
const button = document.querySelector(`.${modalIdentifier}-button`)
const content = modal.querySelector(`.${modalIdentifier}--content`)
const closeButton = content.querySelector(
`.${modalIdentifier}--close-button`
)
const overlay = modal.querySelector(`.${modalIdentifier}--overlay`)

if (!modal || !button || !content || !closeButton || !overlay) {
if (!button || !modal || !content || !closeButton || !overlay) {
return
}

Expand All @@ -18,8 +18,15 @@ function initializeModal(modalIdentifier) {
}

const closeModal = () => {
content.style.animation = "slideOutToTop 0.4s ease-in forwards"
overlay.style.animation = "hideModal 0.4s ease-in"
const mediaQuery = window.matchMedia("(max-width: 480px)")

if (mediaQuery.matches) {
content.style.animation = "slideOutToBottom 0.4s ease-in forwards"
} else {
content.style.animation = "slideOutToTop 0.4s ease-in forwards"
}

overlay.style.animation = "dissolve 0.4s ease-in"

setTimeout(() => {
modal.style.display = "none"
Expand Down Expand Up @@ -47,4 +54,5 @@ function initializeModal(modalIdentifier) {
})
}

initializeModal("modal-theme-switcher")
initializeModal("theme-switcher-desktop", "modal-theme-switcher")
initializeModal("theme-switcher-mobile", "modal-theme-switcher")
22 changes: 20 additions & 2 deletions src/assets/styles/base/_animation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,25 @@
}
}

@keyframes showModal {
@keyframes slideInFromBottom {
from {
top: 100%;
}
to {
top: 50%;
}
}

@keyframes slideOutToBottom {
from {
top: 50%;
}
to {
top: 150%;
}
}

@keyframes appear {
from {
opacity: 0;
}
Expand All @@ -102,7 +120,7 @@
}
}

@keyframes hideModal {
@keyframes dissolve {
from {
opacity: 1;
}
Expand Down
17 changes: 15 additions & 2 deletions src/assets/styles/components/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
height: 100%;
background-color: var(--overlay);
z-index: 1000;
animation: showModal 0.1s ease-out;
animation: appear 0.1s ease-out;
}

&--content {
Expand All @@ -30,9 +30,17 @@
max-width: 564px;
width: 100%;
z-index: 1001;
animation: slideInFromTop 0.8s cubic-bezier(0.19, 1, 0.22, 1) forwards;
animation: slideInFromTop 0.8s $animation-curve-fast-out-slow-in-alt
forwards;
box-shadow: 0px 1px 20px rgba(0, 0, 0, 0.05),
0px 4px 8px rgba(0, 0, 0, 0.05), 0px 1px 2px rgba(0, 0, 0, 0.25);

@include mq-down(sm) {
height: 100vh;
border-radius: 0px;
animation: slideInFromBottom 0.8s
$animation-curve-fast-out-slow-in-alt forwards;
}
}

&--title {
Expand All @@ -41,6 +49,11 @@
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid var(--border-default);

@include mq-down(sm) {
height: 61px;
}

h2 {
color: var(--text-secondary);
Expand Down
5 changes: 5 additions & 0 deletions src/assets/styles/components/_nav-mobile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
padding-top: 64px;
display: flex;
align-items: center;

.container {
max-width: 960px;
padding: 0px;
}
}

&.is-open {
Expand Down
20 changes: 20 additions & 0 deletions src/assets/styles/components/_theme-switcher.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
align-items: flex-start;
padding: 0px;

@include mq-down(sm) {
flex-direction: column;
gap: 12px;
}

button {
display: flex;
flex-direction: column;
Expand All @@ -19,6 +24,12 @@
border: none;
position: relative;

@include mq-down(sm) {
flex-direction: column;
padding: 24px 24px;
align-items: flex-start;
}

&:hover {
opacity: 0.7;
transition: all 0.2s $animation-curve-default;
Expand Down Expand Up @@ -67,6 +78,15 @@
background: $green-200;
color: $green-950;
border-radius: 12px 12px 0px 0px;
display: flex;
align-items: center;

@include mq-down(sm) {
right: 24px;
bottom: 24px;
border-radius: 12px;
padding: 2px 12px;
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/assets/styles/utils/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ $line-height: 1.4rem;
// Default easing curves, Transitions, etc

$animation-curve-fast-out-slow-in: cubic-bezier(0.4, 0, 0.2, 1);
$animation-curve-linear-out-slow-in: cubic-bezier(0, 0, 0.2, 1);
$animation-curve-fast-out-linear-in: cubic-bezier(0.4, 0, 1, 1);
$animation-curve-fast-out-slow-in-alt: cubic-bezier(0.19, 1, 0.22, 1);
$animation-curve-swoosh: cubic-bezier(0.19, 1, 0.22, 1);
$animation-curve-default: $animation-curve-fast-out-slow-in;

Expand Down
2 changes: 1 addition & 1 deletion src/includes/nav-mobile.njk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</ul>

<button
class="icon-button nav__themebtn js-themeswitcher-toggle-menu nav__mobile-themebtn"
class="icon-button nav__themebtn nav__mobile-themebtn theme-switcher-mobile"
aria-expanded="false"
aria-controls="theme-menu"
data-umami-event="nav-theme-mobile"
Expand Down
2 changes: 1 addition & 1 deletion src/includes/nav.njk
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{%- endfor -%}
<li>
<button
class="icon-button nav__themebtn modal-theme-switcher-button"
class="icon-button nav__themebtn theme-switcher-desktop"
aria-expanded="false"
aria-controls="theme-menu"
data-umami-event="nav-theme"
Expand Down