Skip to content

Commit 2df14d6

Browse files
committed
feat(docs): Dark mode docs (Style section and Dark Plugin)
1 parent fc0cf2f commit 2df14d6

File tree

6 files changed

+177
-1
lines changed

6 files changed

+177
-1
lines changed

docs/src/assets/menu.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ const style = [
486486
badge: 'new',
487487
path: 'theme-builder'
488488
},
489+
{
490+
name: 'Dark Mode',
491+
badge: 'new',
492+
path: 'dark-mode'
493+
},
489494
{
490495
name: 'Spacing',
491496
path: 'spacing'
@@ -655,6 +660,11 @@ const plugins = [
655660
name: 'Cookies',
656661
path: 'cookies'
657662
},
663+
{
664+
name: 'Dark',
665+
path: 'dark',
666+
badge: 'new'
667+
},
658668
{
659669
name: 'Dialog',
660670
path: 'dialog'

docs/src/pages/quasar-plugins/app-fullscreen.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ On some phones this will have little effect:
4848
It all depends on the Web Fullscreen API support of the platform the code is running on.
4949
:::
5050

51-
### Watching for fullscreen changes
51+
## Watching for fullscreen changes
5252

5353
``` vue
5454
<template>...</template>

docs/src/pages/quasar-plugins/app-visibility.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,21 @@ import { AppVisibility } from 'quasar'
2020

2121
<doc-example title="AppVisibility" file="AppVisibility/Basic" />
2222

23+
## Watching for status change
24+
25+
``` vue
26+
<template>...</template>
27+
28+
<script>
29+
export default {
30+
watch: {
31+
'$q.appVisibile' (val) {
32+
console.log(val ? 'App became visible' : 'App went in the background')
33+
}
34+
}
35+
}
36+
</script>
37+
```
38+
2339
## AppVisibility API
2440
<doc-api file="AppVisibility" />
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: Dark Plugin
3+
desc: A Quasar plugin to toggle or configure the Dark Mode state of your app.
4+
badge: v1.3+
5+
---
6+
7+
::: tip
8+
For a better understanding of this Quasar plugin, please head to the Style & Identity [Dark Mode](/style/dark-mode) page.
9+
:::
10+
11+
## Installation
12+
This plugin is automatically installed. No need to do anything but directly use it.
13+
14+
## Usage
15+
16+
### Inside of a Vue file
17+
18+
``` js
19+
// get status
20+
console.log(this.$q.dark.isActive)
21+
22+
// set status
23+
this.$q.dark.set(true) // or "false" or "auto"
24+
```
25+
26+
On a **SSR build**, you can set this from a `created` hook from your `/src/App.vue`:
27+
28+
```
29+
export default {
30+
// ...
31+
32+
created () {
33+
this.$q.dark.set(true)
34+
}
35+
}
36+
```
37+
38+
### Outside of a Vue file
39+
40+
``` js
41+
// Warning! This method will not
42+
// work on SSR builds.
43+
44+
import { Dark } from 'quasar'
45+
46+
// get status
47+
console.log(Dark.isActive)
48+
49+
// set status
50+
Dark.set(true) // or "false" or "auto"
51+
```
52+
53+
### Through quasar.conf.js
54+
55+
You can also use `/quasar.conf.js` to set the Dark mode status:
56+
57+
```js
58+
framework: {
59+
config: {
60+
dark: 'auto' // or Boolean true/false
61+
}
62+
}
63+
```
64+
65+
## Note about SSR
66+
67+
When on a SSR build:
68+
* `import { Dark } from 'quasar'` method of using Dark mode will not error out but it will not work (won't do anything). But you can use the other two ways (see previous section). We recommend through quasar.conf.js.
69+
* It's preferred to avoid setting Dark mode to 'auto' for SSR builds. It's because the client dark mode preference cannot be inferred, so SSR will always render in light mode then when the client takes over, it will switch to Dark (if it will be the case). As a result, a quick flicker of the screen will occur.
70+
71+
## Watching for status change
72+
73+
``` vue
74+
<template>...</template>
75+
76+
<script>
77+
export default {
78+
watch: {
79+
'$q.dark.isActive' (val) {
80+
console.log(val ? 'On dark mode' : 'On light mode')
81+
}
82+
}
83+
}
84+
</script>
85+
```
86+
87+
## Dark API
88+
<doc-api file="Dark" />

docs/src/pages/style/dark-mode.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: Dark Mode
3+
desc: Handle dark mode with Quasar.
4+
badge: v1.3+
5+
---
6+
7+
Dark Mode is a supplemental mode that can be used to display mostly dark surfaces on the UI. The design reduces the light emitted by device screens while maintaining the minimum color contrast ratios required for readability.
8+
9+
The advantages of Dark Mode are that:
10+
* it enhances visual ergonomics by reducing eye strain.
11+
* Provides comfort of use at night or in dark environments.
12+
* It conserves battery power mainly if the device screen is OLED or AMOLED, thereby enabling device usage for longer periods without charging.
13+
14+
## What it does
15+
16+
1. It sets a default dark background for the pages (that you can easily override through CSS with the `body.body--dark` selector)
17+
2. All Quasar components with a `dark` property will have it automatically set to `true`. No need to do it manually.
18+
19+
The auto-detection works by looking at `prefers-color-scheme: dark` media query and it's dynamic. If the client browser/platform switches to/from Dark mode while your app is running, it will also update Quasar's Dark mode (if Dark mode is set to `auto`).
20+
21+
## How to use it
22+
23+
You can easily switch between Dark mode and light mode (which is default) through the [Dark Plugin](/quasar-plugins/dark).
24+
25+
## How to style your app
26+
27+
Since your app can be in Dark mode or not, you can easily style it by taking advantage of the `body` tag attached CSS class: `body--light` or `body--dark`. That is if you want to support both modes.
28+
29+
```css
30+
.body--light {
31+
/* ... */
32+
}
33+
34+
.body--dark {
35+
/* ... */
36+
}
37+
```

ui/src/plugins/Dark.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"injection": "$q.dark",
3+
4+
"props": {
5+
"isActive": {
6+
"type": "Boolean",
7+
"desc": "Is Dark mode active?",
8+
"reactive": true
9+
}
10+
},
11+
12+
"methods": {
13+
"set": {
14+
"desc": "Set dark mode status",
15+
"params": {
16+
"status": {
17+
"type": [ "Boolean", "String" ],
18+
"desc": "Dark mode status",
19+
"values": [ true, false, "auto" ],
20+
"required": true
21+
}
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)