Giter VIP home page Giter VIP logo

Comments (13)

GautierDele avatar GautierDele commented on July 21, 2024 3

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.

nasermirzaei89 avatar nasermirzaei89 commented on July 21, 2024 2

I used this method:

watch: {
    '$colorMode.value': function () {
      this.$vuetify.theme.dark = this.$colorMode.value === 'dark'
    },
  },

from color-mode.

kevinmarrec avatar kevinmarrec commented on July 21, 2024 1

@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.

suppeep avatar suppeep commented on July 21, 2024 1

@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.

Tinoooo avatar Tinoooo commented on July 21, 2024 1

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.

Radiergummi avatar Radiergummi commented on July 21, 2024 1

@nasermirzaei89 It doesn't work on the server that way, tho...

from color-mode.

radudiaconu0 avatar radudiaconu0 commented on July 21, 2024

i want this too but it seems no one answered your issue =(

from color-mode.

GautierDele avatar GautierDele commented on July 21, 2024

@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.

radudiaconu0 avatar radudiaconu0 commented on July 21, 2024

You can use a watcher for $colorMode.value; it works fine on ssr on my setup.

from color-mode.

GautierDele avatar GautierDele commented on July 21, 2024

Just came back on this task.
You can create a plugin with:

export default ({ $vuetify }) => {
  // Your code
}

As simple as that

from color-mode.

ozgurg avatar ozgurg commented on July 21, 2024

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.

Harm-Nullix avatar Harm-Nullix commented on July 21, 2024

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.

aloky avatar aloky commented on July 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.