Comments (13)
Thanks for the feedback, using a watcher is a great idea but on my side I want to load it the earliest time possible. One solution is the plugin directory but since vuetify is a nuxt module i don't think we can access it from there
@suppeep it could fix your white screen flash this way
from color-mode.
I used this method:
watch: {
'$colorMode.value': function () {
this.$vuetify.theme.dark = this.$colorMode.value === 'dark'
},
},
from color-mode.
@GautierDele @radudiaconu0 @suppeep
What are you guys missing with what already provide Vuetify ?
See : https://vuetifyjs.com/en/customization/theme
Vuetify provides dark mode & theme feature which can be changed at runtime :
Dark/Light mode
this.$vuetify.theme.dark = true // Set dark mode
this.$vuetify.theme.dark = false // Set light mode
this.$vuetify.theme.dark = !this.$vuetify.theme.dark // Toggle mode
Theming
this.$vuetify.theme.themes.dark.primary = true // Change primary color of dark theme
this.$vuetify.theme.themes.light.primary = true // Change primary color of light theme
Still, it's your job storing in a cookie the user preference.
from color-mode.
@GautierDele I also had my problems with the vuetify darkmode. But since a few weeks I am good with it. My only problem is that if the darkmode is on and I reload the page I still see a white screen at the beginning, maybe because it doesnt work correctly on ssr
from color-mode.
If you use vuetify and color mode as modules you can create a plugin to avoid flickering.
export default ({ $vuetify, $colorMode }) => {
$vuetify.theme.dark = $colorMode.preference === 'dark';
};
from color-mode.
@nasermirzaei89 It doesn't work on the server that way, tho...
from color-mode.
i want this too but it seems no one answered your issue =(
from color-mode.
@kevinmarrec yes thanks i know the vuetify documentation
The user preference is already stored in the cookies as you can read in the README
The only examples we have are not progammatically as the code you gave.
I thought that it would be interesting to provide a much easier way to make it accessible.
Actually i'm doing this without this extension in the store and I don't like the idea. I would prefer going with a file in the plugins directory but vuetify is not accessible from their if i'm right.
I might be missing something but I don't think it's actually possible
from color-mode.
You can use a watcher for $colorMode.value; it works fine on ssr on my setup.
from color-mode.
Just came back on this task.
You can create a plugin with:
export default ({ $vuetify }) => {
// Your code
}
As simple as that
from color-mode.
If you use vuetify and color mode as modules you can create a plugin to avoid flickering.
export default ({ $vuetify, $colorMode }) => { $vuetify.theme.dark = $colorMode.preference === 'dark'; };
Use value
instead of preference
for "system" setting:
$vuetify.theme.dark = $colorMode.value === "dark";
from color-mode.
I used the following, so when prefrence is system, check the value.
Else maybe the user has already altered his preference and it could be something else.
export default ({ $vuetify, $colorMode }) => {
if ($colorMode.preference === 'system') {
$vuetify.theme.dark = $colorMode.value === 'dark'
} else {
$vuetify.theme.dark = $colorMode.preference === 'dark'
}
}
Then I have this toggle to switch mode:
<v-switch
v-model="$vuetify.theme.dark"
prepend-icon="mdi-weather-sunny"
append-icon="mdi-weather-night"
hide-details
/>
And watch that so that when it changes, I also change the preference of the colormode:
watch: {
'$vuetify.theme.dark' () {
this.$colorMode.preference = this.$vuetify.theme.dark ? 'dark' : 'light'
}
}
from color-mode.
If you use vuetify and color mode as modules you can create a plugin to avoid flickering.
export default ({ $vuetify, $colorMode }) => { $vuetify.theme.dark = $colorMode.preference === 'dark'; };
Can you more details show
from color-mode.
Related Issues (20)
- Throws Error about accessing `preference` of `undefined` HOT 4
- Dark theme cannot be loaded
- allow disabling css transitions while changing color scheme
- Get color-theme while server render HOT 2
- Forced color mode incorrect timing
- Adding class "theme-red" to <html> breaks color-mode
- Load color-mode already in spa template
- helper.getColorScheme is not a function error when trying to use the module HOT 7
- Can I use only data value?
- Selected Color dosn't save on LocalStorage
- Question about demo asset regarding license HOT 2
- On light mode background-color is transparent HOT 1
- Document how to force color mode dynamically (e.g. from a useFetch response) HOT 6
- Color of element stuck in 1 color.
- Reactive `useColorMode()` value HOT 1
- tailwind module integration breaks dark mode HOT 7
- Support set html attribute HOT 1
- Why is my nuxt app color mode configuration not working with the "prefrence : light" ? HOT 3
- Should there be a way to force a color mode in the root of the app?
- How to set a theme in arc design
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from color-mode.