-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Dark.js #17670
base: dev
Are you sure you want to change the base?
Update Dark.js #17670
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { createReactivePlugin } from '../../utils/private.create/create.js' | ||
|
||
const Plugin = createReactivePlugin({ | ||
isEnabled: false, | ||
isActive: false, | ||
mode: false | ||
}, { | ||
|
@@ -9,11 +10,13 @@ const Plugin = createReactivePlugin({ | |
set (val) { | ||
if (__QUASAR_SSR_SERVER__) return | ||
|
||
const matchMedia = window.matchMedia('(prefers-color-scheme: dark)') | ||
Plugin.mode = val | ||
Plugin.isEnabled = matchMedia.matches | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok i will update this |
||
|
||
if (val === 'auto') { | ||
if (Plugin.__media === void 0) { | ||
Plugin.__media = window.matchMedia('(prefers-color-scheme: dark)') | ||
Plugin.__media = matchMedia | ||
Plugin.__updateMedia = () => { Plugin.set('auto') } | ||
Plugin.__media.addListener(Plugin.__updateMedia) | ||
} | ||
|
@@ -42,15 +45,18 @@ const Plugin = createReactivePlugin({ | |
|
||
if (__QUASAR_SSR_SERVER__) { | ||
this.isActive = dark === true | ||
this.isEnabled = matchMedia.matches | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no matchMedia here, nor can it be. This code runs on the server. It should be defaulted to a value (probably There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noted |
||
|
||
$q.dark = { | ||
isEnabled: false, | ||
isActive: false, | ||
mode: false, | ||
set: val => { | ||
ssrContext._meta.bodyClasses = ssrContext._meta.bodyClasses | ||
.replace(' body--light', '') | ||
.replace(' body--dark', '') + ` body--${ val === true ? 'dark' : 'light' }` | ||
|
||
$q.dark.isEnabled = matchMedia.matches | ||
$q.dark.isActive = val === true | ||
$q.dark.mode = val | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be added to Dark.json too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did that on but i will update it to isPreferred