File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ module.exports = {
39
39
'/guide/' ,
40
40
'/guide/class-naming.md' ,
41
41
'/guide/modes.md' ,
42
+ '/guide/events.md' ,
42
43
'/guide/storage.md' ,
43
44
'/guide/meta-theme-color.md' ,
44
45
'/guide/accessibility.md' ,
Original file line number Diff line number Diff line change
1
+ # Events
2
+
3
+ ## change-mode
4
+
5
+ Event fired every color mode change.
6
+
7
+
8
+ | Event | value |
9
+ | -------------- | ------------------------------------------------------------ |
10
+ | ` change-mode ` | color mode token. (` light ` \| ` dark ` \| ` system ` \| ` myCustomMode ` ) |
11
+
12
+ ``` vue
13
+ <VueDarkMode @change-mode="myColorModeHandler">
14
+ <template v-slot="{ mode }">
15
+ Color mode: {{ mode }}
16
+ </template>
17
+ </VueDarkMode>
18
+ ```
19
+
20
+ ``` js
21
+ export default {
22
+ // ...
23
+ methods: {
24
+ myColorModeHandler (mode ) {
25
+ // action here
26
+ }
27
+ }
28
+ }
29
+ ```
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ export default {
62
62
63
63
computed: {
64
64
getPrefersColorScheme () {
65
+ if (this .$isServer ) return false
65
66
const colorSchemeTypes = [' dark' , ' light' ]
66
67
let colorScheme = null
67
68
colorSchemeTypes .forEach (type => {
@@ -120,6 +121,7 @@ export default {
120
121
window [this .storage ].setItem (' colorMode' , this .chosenMode )
121
122
this .handleColorModeClass (' add' )
122
123
if (Object .keys (this .metaThemeColor ).length ) this .setMetaThemeColor (this .metaThemeColor [this .currentMode ] || this .metaThemeColor [this .getPrefersColorScheme ])
124
+ this .$emit (' change-mode' , this .chosenMode )
123
125
},
124
126
125
127
getMediaQueryList (type ) {
@@ -135,6 +137,7 @@ export default {
135
137
},
136
138
137
139
handleColorModeClass (action ) {
140
+ if (this .$isServer ) return
138
141
return document .documentElement .classList [action](` ${ this .className .replace (/ %cm/ g , this .currentMode )} ` )
139
142
},
140
143
You can’t perform that action at this time.
0 commit comments