Skip to content
This repository was archived by the owner on Oct 1, 2023. It is now read-only.

Commit eca138f

Browse files
authored
Merge pull request #26 from spawnia/overrideTheme
rename `defaultTheme` to `overrideTheme` and clarify it overrules and ignores prefers-color-scheme
2 parents f12e68a + 4fb8724 commit eca138f

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Change Log
1+
# Changelog
22

3-
[README](README.md) | [CHANGELOG](CHANGELOG.md)
3+
## 2.0.0
4+
5+
- rename `defaultTheme` to `overrideTheme` and clarify it overrules and ignores [prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme)
46

57
## 1.1.2
68

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
# vuepress-theme-default-prefers-color-scheme
22

3-
> add prefers-color-scheme for vuepress default theme
4-
5-
[README](README.md) | [CHANGELOG](CHANGELOG.md)
6-
7-
**This theme for Vuepress 1.x**
3+
This plugin adds support for *prefers-color-scheme* to the Vuepress 1.x default theme.
84

95
[Live Demo and Documentation](https://tolking.github.io/vuepress-theme-default-prefers-color-scheme)
106

11-
---
12-
137
## Installation
148

159
``` sh
@@ -29,23 +23,24 @@ module.exports = {
2923

3024
## Options
3125

32-
### defaultTheme
33-
- Type: `string`, `object`
34-
- Required: `false`
26+
### overrideTheme (optional)
27+
28+
Force users into a specific theme, ignoring [prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme).
29+
30+
Allowed values:
3531

36-
**By default, light or dark themes are displayed by [prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme). You can break it by set `defaultTheme`.**
32+
- `'light' | 'dark'`: Always use the given theme
33+
- `{ light: [beginHours: number, endHours: number], dark: [beginHours: number, endHours: number] }`: Control the time of the day when each theme is used
3734

38-
support `light`, `dark` or `{ theme: [begin hours, end hours] }`
35+
For example:
3936

4037
``` js
4138
module.exports = {
4239
theme: 'default-prefers-color-scheme',
4340
themeConfig: {
44-
defaultTheme: 'dark',
41+
overrideTheme: 'dark',
4542
// or
46-
defaultTheme: { dark: [18, 6] },
47-
// or
48-
defaultTheme: { light: [6, 18], dark: [18, 6] },
43+
overrideTheme: { light: [6, 18], dark: [18, 6] },
4944
}
5045
}
5146
```
@@ -54,10 +49,17 @@ module.exports = {
5449

5550
## Styling
5651

57-
To apply simple color overrides to the styling of the [default preset](https://github.com/tolking/vuepress-theme-default-prefers-color-scheme/blob/master/styles/palette.styl), In your `.vuepress/styles/palette.styl` file. or set CSS Variables in your `.vuepress/styles/index.styl` file.
52+
Apply simple color overrides to the styling of the [default preset](https://github.com/tolking/vuepress-theme-default-prefers-color-scheme/blob/master/styles/palette.styl)
53+
in your `.vuepress/styles/palette.styl` file.
54+
55+
Alternatively, set CSS Variables in your `.vuepress/styles/index.styl` file.
5856

5957
**`$accentColor` and `$accentDarkColor` are best changed together**
6058

59+
## Changelog
60+
61+
This project uses semantic versioning and tracks changes in [CHANGELOG](CHANGELOG.md)
62+
6163
## License
6264

6365
[MIT](http://opensource.org/licenses/MIT)

docs/.vuepress/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports = {
2121
}
2222
},
2323
themeConfig: {
24-
// defaultTheme: { dark: [19, 6] },
2524
repo: 'tolking/vuepress-theme-default-prefers-color-scheme',
2625
docsDir: 'docs',
2726
editLinks: true,

docs/README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,30 @@ module.exports = {
4040

4141
## Options
4242

43-
### defaultTheme
44-
- Type: `string`, `object`
45-
- Required: `false`
43+
### overrideTheme (optional)
4644

47-
::: warning
48-
By default, light or dark themes are displayed by [prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme). You can break it by set `defaultTheme`.
49-
:::
45+
Force users into a specific theme, ignoring [prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme).
46+
47+
Allowed values:
48+
49+
- `'light' | 'dark'`: Always use the given theme
50+
- `{ light: [beginHours: number, endHours: number], dark: [beginHours: number, endHours: number] }`: Control the time of the day when each theme is used
5051

51-
support `light`, `dark` or `{ theme: [begin hours, end hours] }`
52+
For example:
5253

53-
``` js {4,6,8}
54+
``` js
5455
module.exports = {
5556
theme: 'default-prefers-color-scheme',
5657
themeConfig: {
57-
defaultTheme: 'dark',
58-
// or
59-
defaultTheme: { dark: [18, 6] },
58+
overrideTheme: 'dark',
6059
// or
61-
defaultTheme: { light: [6, 18], dark: [18, 6] },
60+
overrideTheme: { light: [6, 18], dark: [18, 6] },
6261
}
6362
}
6463
```
6564

6665
::: danger
67-
After `v1.1.0`, it is no longer necessary to add a postcss plugIn to set `defaulttheme`. It is recommended to remove the relevant content. In the near future, `css-prefers-color-scheme` will be remove from `package.json`
66+
After `v1.1.0`, it is no longer necessary to add a postcss plugIn to set `overrideTheme`. It is recommended to remove the relevant content. In the near future, `css-prefers-color-scheme` will be remove from `package.json`
6867

6968
``` js
7069
module.exports = {

layouts/Layout.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export default {
1010
ParentLayout
1111
},
1212
computed: {
13-
defaultTheme() {
14-
const _defaultTheme = this.$themeConfig.defaultTheme
15-
if (typeof _defaultTheme === 'object') {
13+
overrideTheme() {
14+
const _overrideTheme = this.$themeConfig.overrideTheme
15+
if (typeof _overrideTheme === 'object') {
1616
const hours = new Date().getHours()
1717
let _key = false
18-
for (const key in _defaultTheme) {
19-
const value = _defaultTheme[key]
18+
for (const key in _overrideTheme) {
19+
const value = _overrideTheme[key]
2020
if (value[0] <= value[1]) {
2121
if (value[0] <= hours && hours < value[1]) {
2222
_key = key
@@ -31,13 +31,13 @@ export default {
3131
}
3232
return _key
3333
} else {
34-
return _defaultTheme || false
34+
return _overrideTheme || false
3535
}
3636
}
3737
},
3838
beforeMount() {
39-
if (this.defaultTheme) {
40-
document.getElementsByTagName('html')[0].setAttribute('theme', this.defaultTheme)
39+
if (this.overrideTheme) {
40+
document.getElementsByTagName('html')[0].setAttribute('theme', this.overrideTheme)
4141
}
4242
}
4343
}

0 commit comments

Comments
 (0)