Skip to content

Commit

Permalink
light/dark theme fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter committed Feb 27, 2024
1 parent 6ede0cb commit 503369b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 24 deletions.
9 changes: 9 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ import Close from './components/icon/Close.vue'
import Pause from './components/icon/Pause.vue'
import Play from './components/icon/Play.vue'
import PlayNext from './components/icon/PlayNext.vue'
import Sun from './components/icon/Sun.vue'
import Moon from './components/icon/Moon.vue'
import { client } from "./api"
import { themeHandler } from "./theme"
const store = useMainStore()
const storeFilter = useFilterStore()
const table = ref<HTMLElement>()
const settingsDrawer = ref<boolean>(false)
Expand Down Expand Up @@ -466,6 +470,7 @@ const hideColumn = (col: Column) => {
}
onMounted(async () => {
themeHandler.loadTheme()
if (store.demoMode) {
loadDemoMode()
loadAnalytics(true)
Expand Down Expand Up @@ -593,6 +598,10 @@ const updateSampleLine = () => {
Following real-time out of {{ store.receiveCounters?.MessageCount }} entries</button>
<StatusIndicator :status="store.status" />
<button @click="settingsDrawer = true">Settings</button>
<button class="btn" style="padding:0.6em; margin-left:3px;" @click="themeHandler.toggleTheme()">
<Sun v-if="themeHandler.theme.value === 'dark'" />
<Moon v-if="themeHandler.theme.value === 'light'" />
</button>
</div>
</div>
<div class="layout" @mouseup="endDragging">
Expand Down
4 changes: 2 additions & 2 deletions src/components/SettingsDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ hr {
pre {
margin: 6px 0;
background: #1E1E1E;
background: var(--hl-bg2);
padding: 10px;
white-space: pre-wrap;
}
Expand All @@ -555,4 +555,4 @@ hr {
color: rgba(255, 255, 255, .5)
}
}
</style>../moment.lib.ts
</style>
7 changes: 7 additions & 0 deletions src/components/icon/Moon.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M12.2256 2.00253C9.59172 1.94346 6.93894 2.9189 4.92893 4.92891C1.02369 8.83415 1.02369 15.1658 4.92893 19.071C8.83418 22.9763 15.1658 22.9763 19.0711 19.071C21.0811 17.061 22.0565 14.4082 21.9975 11.7743C21.9796 10.9772 21.8669 10.1818 21.6595 9.40643C21.0933 9.9488 20.5078 10.4276 19.9163 10.8425C18.5649 11.7906 17.1826 12.4053 15.9301 12.6837C14.0241 13.1072 12.7156 12.7156 12 12C11.2844 11.2844 10.8928 9.97588 11.3163 8.0699C11.5947 6.81738 12.2094 5.43511 13.1575 4.08368C13.5724 3.49221 14.0512 2.90664 14.5935 2.34046C13.8182 2.13305 13.0228 2.02041 12.2256 2.00253ZM17.6569 17.6568C18.9081 16.4056 19.6582 14.8431 19.9072 13.2186C16.3611 15.2643 12.638 15.4664 10.5858 13.4142C8.53361 11.362 8.73568 7.63895 10.7814 4.09281C9.1569 4.34184 7.59434 5.09193 6.34315 6.34313C3.21895 9.46732 3.21895 14.5326 6.34315 17.6568C9.46734 20.781 14.5327 20.781 17.6569 17.6568Z"
fill="currentColor" />
</svg>
</template>
9 changes: 9 additions & 0 deletions src/components/icon/Sun.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M12 16C14.2091 16 16 14.2091 16 12C16 9.79086 14.2091 8 12 8C9.79086 8 8 9.79086 8 12C8 14.2091 9.79086 16 12 16ZM12 18C15.3137 18 18 15.3137 18 12C18 8.68629 15.3137 6 12 6C8.68629 6 6 8.68629 6 12C6 15.3137 8.68629 18 12 18Z"
fill="currentColor" />
<path fill-rule="evenodd" clip-rule="evenodd"
d="M11 0H13V4.06189C12.6724 4.02104 12.3387 4 12 4C11.6613 4 11.3276 4.02104 11 4.06189V0ZM7.0943 5.68018L4.22173 2.80761L2.80752 4.22183L5.6801 7.09441C6.09071 6.56618 6.56608 6.0908 7.0943 5.68018ZM4.06189 11H0V13H4.06189C4.02104 12.6724 4 12.3387 4 12C4 11.6613 4.02104 11.3276 4.06189 11ZM5.6801 16.9056L2.80751 19.7782L4.22173 21.1924L7.0943 18.3198C6.56608 17.9092 6.09071 17.4338 5.6801 16.9056ZM11 19.9381V24H13V19.9381C12.6724 19.979 12.3387 20 12 20C11.6613 20 11.3276 19.979 11 19.9381ZM16.9056 18.3199L19.7781 21.1924L21.1923 19.7782L18.3198 16.9057C17.9092 17.4339 17.4338 17.9093 16.9056 18.3199ZM19.9381 13H24V11H19.9381C19.979 11.3276 20 11.6613 20 12C20 12.3387 19.979 12.6724 19.9381 13ZM18.3198 7.0943L21.1923 4.22183L19.7781 2.80762L16.9056 5.6801C17.4338 6.09071 17.9092 6.56608 18.3198 7.0943Z"
fill="currentColor" />
</svg></template>
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { createPinia } from 'pinia'
import "./app.scss"
import 'floating-vue/dist/style.css'
import FloatingVue from 'floating-vue'
import { themeHandler } from './theme'

window.moment = moment
window.document.title = 'Logdy'

themeHandler.initTheme()

createApp(App)
.use(VueHighlightJS)
.use(createPinia())
Expand Down
75 changes: 53 additions & 22 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,24 +1,67 @@
:root {
body {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: var(--bg);

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
--danger: #6c2727;
color: var(--font);
background-color: var(--bg);
}

body.dark {
color-scheme: light dark;

--font: #efefef;
--bg: #242424;
--hl-bg: #373737;
--hl-bg2: #3f3f3f;
--hl-bg3: #595959;
--danger: #6c2727;
--bg-btn: #1a1a1a;
}

body.light{
color: #213547;
--font: #303030;
--bg: #f8f8f8;
--hl-bg: #e0e0e0;
--hl-bg2: #9d9d9d;
--hl-bg3: #8c8c8c;
--bg-btn: #c5c5c5;
}

@media (prefers-color-scheme: light) {
body.light {
color-scheme: light;
--font: #303030;
--bg: #f8f8f8;
--hl-bg: #e0e0e0;
--hl-bg2: #9d9d9d;
--hl-bg3: #8c8c8c;
--bg-btn: #c5c5c5;
}

body.dark {
color-scheme: dark;
--font: #efefef;
--bg: #242424;
--hl-bg: #373737;
--hl-bg2: #3f3f3f;
--hl-bg3: #595959;
--bg-btn: #1a1a1a;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}



a {
font-weight: 500;
color: #646cff;
Expand Down Expand Up @@ -58,7 +101,8 @@ button, .btn {
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
color: var(--color);
background-color: var(--bg-btn);
cursor: pointer;
transition: border-color 0.25s;

Expand All @@ -82,17 +126,4 @@ button:focus-visible {
/* max-width: 1280px; */
/* margin: 0 auto; */
/* padding: 1rem; */
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
}
47 changes: 47 additions & 0 deletions src/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ref } from "vue"

const theme = ref<"light" | "dark">()

const loadTheme = () => {
let th = localStorage.getItem('theme')
if (th == 'light') {
theme.value = 'light'
}
if (th == 'dark') {
theme.value = 'dark'
}
}

const initTheme = () => {
let theme = localStorage.getItem('theme')
if (theme) {
document.body.classList.add(theme)
}
}

const toggleTheme = () => {
let th = localStorage.getItem('theme')

if (!th) {
theme.value = 'dark'
localStorage.setItem('theme', 'dark')
document.body.classList.remove('light')
document.body.classList.add('dark')
}

if (th == 'dark') {
theme.value = 'light'
localStorage.setItem('theme', 'light')
document.body.classList.remove('dark')
document.body.classList.add('light')
} else {
theme.value = 'dark'
localStorage.setItem('theme', 'dark')
document.body.classList.remove('light')
document.body.classList.add('dark')
}
}

export const themeHandler = {
theme, loadTheme, toggleTheme, initTheme
}

0 comments on commit 503369b

Please sign in to comment.