Skip to content

Commit

Permalink
feat: add transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanGmG committed Jul 4, 2024
1 parent 642c64a commit ad325c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<script setup>
import {backgroundColor, textColor} from "@/scripts/color-scheme.js";
import {onMounted} from "vue";
onMounted(() => {
document.getElementById("page").classList.add("transition-colors")
})
</script>

<template>

<div :class="backgroundColor + ' ' + textColor " class = "w-full h-all-page flex flex-col items-center transition-colors">
<div id = "page" :class="backgroundColor + ' ' + textColor " class = "w-full h-all-page flex flex-col items-center">
<router-view/>
</div>

</template>

<style scoped>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Home.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {changeLanguage, languageName} from '@/scripts/i18n.js';
<div class = "flex justify-between">
<h1 class = "text-4xl">{{$t('home.title')}}</h1>
<div :key="darkMode" class = " computer:text-2xl mobile:text-xl flex gap-2.5">
<rounded-button @click="toggleColorTheme">
<rounded-button @click="toggleColorTheme(!darkMode)">
<i v-if="darkMode" class = "pi pi-moon"/>
<i v-else class = "pi pi-sun"/>
</rounded-button>
Expand Down
23 changes: 18 additions & 5 deletions src/scripts/color-scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,32 @@ let backgroundColor = ref("bg-white");
let secondBackgroundColor = ref("bg-gray-200");
let textColor = ref("text-black");

function toggleColorTheme() {
console.log("Toggle color theme")
darkMode.value =!darkMode.value;
function initDarkMode(){

if (localStorage.getItem("dark-mode") === null){
localStorage.setItem("dark-mode", "false");
}else{
toggleColorTheme(Boolean(localStorage.getItem("dark-mode")));
}
}

function toggleColorTheme(colorStatus) {

darkMode.value = colorStatus;
localStorage.setItem("dark-mode", darkMode.value);

if (darkMode.value){
backgroundColor.value = "bg-black";
textColor.value = "text-white";
secondBackgroundColor = "bg-gray-500";
secondBackgroundColor.value = "bg-gray-500";
}else{
backgroundColor.value = "bg-white";
textColor.value = "text-black";
secondBackgroundColor = "bg-gray-200";
secondBackgroundColor.value = "bg-gray-200";
}

}

initDarkMode()

export { darkMode, toggleColorTheme , backgroundColor, secondBackgroundColor, textColor};

0 comments on commit ad325c9

Please sign in to comment.