Skip to content
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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ui/src/plugins/dark/Dark.js
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,
Copy link
Member

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.

Copy link
Contributor Author

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

isActive: false,
mode: false
}, {
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isPreferred would be better otherwise it is confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
}
Expand Down Expand Up @@ -42,15 +45,18 @@ const Plugin = createReactivePlugin({

if (__QUASAR_SSR_SERVER__) {
this.isActive = dark === true
this.isEnabled = matchMedia.matches
Copy link
Member

Choose a reason for hiding this comment

The 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 false) and updated only on client takeover, otherwise there will be hydration errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
},
Expand Down
Loading