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 = {
3939 '/guide/' ,
4040 '/guide/class-naming.md' ,
4141 '/guide/modes.md' ,
42+ '/guide/events.md' ,
4243 '/guide/storage.md' ,
4344 '/guide/meta-theme-color.md' ,
4445 '/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 {
6262
6363 computed: {
6464 getPrefersColorScheme () {
65+ if (this .$isServer ) return false
6566 const colorSchemeTypes = [' dark' , ' light' ]
6667 let colorScheme = null
6768 colorSchemeTypes .forEach (type => {
@@ -120,6 +121,7 @@ export default {
120121 window [this .storage ].setItem (' colorMode' , this .chosenMode )
121122 this .handleColorModeClass (' add' )
122123 if (Object .keys (this .metaThemeColor ).length ) this .setMetaThemeColor (this .metaThemeColor [this .currentMode ] || this .metaThemeColor [this .getPrefersColorScheme ])
124+ this .$emit (' change-mode' , this .chosenMode )
123125 },
124126
125127 getMediaQueryList (type ) {
@@ -135,6 +137,7 @@ export default {
135137 },
136138
137139 handleColorModeClass (action ) {
140+ if (this .$isServer ) return
138141 return document .documentElement .classList [action](` ${ this .className .replace (/ %cm/ g , this .currentMode )} ` )
139142 },
140143
You can’t perform that action at this time.
0 commit comments