Last active
October 16, 2020 17:59
-
-
Save daliborgogic/06c603b95bcd8c44036ed47e4d0b699c to your computer and use it in GitHub Desktop.
Vantablack? Nuxt.js simple theme switch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
export default { | |
computed: { | |
theme () { | |
const [color, backgroundColor] = this.$store.state.theme | |
return { | |
'--color': color, | |
'--background-color': backgroundColor | |
} | |
} | |
}, | |
methods: { | |
// https://en.wikipedia.org/wiki/Vantablack | |
vantaBlack () { | |
let [color, backgroundColor] = this.$store.state.theme | |
this.$store.commit('setTheme', [color, backgroundColor] = [backgroundColor, color]) | |
} | |
} | |
} | |
</script> | |
<template> | |
<div> | |
<button @click="vantaBlack">{{ $store.state.theme[1] }}</button> | |
<nuxt :style="theme" /> | |
</div> | |
</template> | |
<style> | |
#__nuxt { | |
transition: all 250ms; | |
background-color: rgb(var(--background-color)); | |
color: rgb(var(--color)); | |
} | |
</style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vuex from 'vuex' | |
const createStore = () => { | |
return new Vuex.Store({ | |
state: () => ({ | |
theme: ['0, 0, 0', '255, 255, 255'] | |
}), | |
mutations: { | |
setTheme: (state, theme) => state.theme = theme | |
} | |
}) | |
} | |
export default createStore |
The dark mode is currently only available on macOS Mojave via prefers-dark-interface CSS media query.
@media (prefers-dark-interface) {
background-color: rgb(var(--background-color));
color: rgb(var(--color));
}
In Safari Technology Preview Release 71 they announced a toggle switch in Safari to make testing easier. I also made a test page to see the browser behaviour.
If you have Safari Technology Preview Release 71 installed you can activate through:
Develop > Experimental Features > Dark Mode CSS Support
Then if you open the test page and open element inspector you have a new icon to toggle Dark/Light mode.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tips
svg
usefill="currentColor"
HEX
, useRGB
value. You might need it for for alpha chanel e.g.rgba(var(--background), 0.5)