mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-06 12:17:13 +08:00
Merge remote-tracking branch 'upstream/develop' into develop
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
This commit is contained in:
commit
ce4a10a882
@ -1,4 +1,8 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
## 1.3.3 (2020-06-03)
|
||||||
|
### Features
|
||||||
|
- Add `$NOs.theme` to get the current theme of the OS.
|
||||||
|
|
||||||
## 1.3.2 (2020-06-02)
|
## 1.3.2 (2020-06-02)
|
||||||
### Fixes
|
### Fixes
|
||||||
- Fix the problem that `n-log`'s loading indicator uses monospace font.
|
- Fix the problem that `n-log`'s loading indicator uses monospace font.
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
## 1.3.3 (2020-06-03)
|
||||||
|
### Features
|
||||||
|
- 增加了 `$NOs.theme` 来获取当前操作系统的主题
|
||||||
|
|
||||||
## 1.3.2 (2020-06-02)
|
## 1.3.2 (2020-06-02)
|
||||||
### Fixes
|
### Fixes
|
||||||
- 修正了 `n-log` 的加载器显示等宽字体的问题
|
- 修正了 `n-log` 的加载器显示等宽字体的问题
|
||||||
|
@ -6,6 +6,7 @@ theme
|
|||||||
namespace
|
namespace
|
||||||
inherit-theme
|
inherit-theme
|
||||||
theme-environment
|
theme-environment
|
||||||
|
os-theme
|
||||||
language
|
language
|
||||||
transparent
|
transparent
|
||||||
```
|
```
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
# Use OS Theme
|
||||||
|
Naive-ui provides `$NOs.theme` property to get the current theme of your OS.
|
||||||
|
```html
|
||||||
|
<n-config-provider :theme="$NOs.theme">
|
||||||
|
<n-card>
|
||||||
|
Your current system theme is {{ JSON.stringify($NOs.theme) }}.
|
||||||
|
</n-card>
|
||||||
|
</n-config-provider>
|
||||||
|
```
|
@ -6,6 +6,7 @@ theme
|
|||||||
namespace
|
namespace
|
||||||
inherit-theme
|
inherit-theme
|
||||||
theme-environment
|
theme-environment
|
||||||
|
os-theme
|
||||||
language
|
language
|
||||||
transparent
|
transparent
|
||||||
```
|
```
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
# 使用操作系统主题
|
||||||
|
Naive-ui 提供 `$NOs.theme` 属性来获取当前操作系统的主题。
|
||||||
|
```html
|
||||||
|
<n-config-provider :theme="$NOs.theme">
|
||||||
|
<n-card>
|
||||||
|
当前操作系统的主题是 {{ JSON.stringify($NOs.theme) }}。
|
||||||
|
</n-card>
|
||||||
|
</n-config-provider>
|
||||||
|
```
|
@ -96,7 +96,11 @@ export default {
|
|||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
get () {
|
get () {
|
||||||
return this.$route.params.theme === 'light' ? 'light' : 'dark'
|
switch (this.$route.params.theme) {
|
||||||
|
case 'os-theme': return this.$NOs.theme
|
||||||
|
case 'dark': return 'dark'
|
||||||
|
default: return 'light'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
set (theme) {
|
set (theme) {
|
||||||
this.$router.push(changeThemeInPath(this.$route.fullPath, theme))
|
this.$router.push(changeThemeInPath(this.$route.fullPath, theme))
|
||||||
|
@ -170,6 +170,6 @@ export const routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/*',
|
path: '/*',
|
||||||
redirect: '/zh-CN/light'
|
redirect: '/zh-CN/os-theme'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
/* istanbul ignore file */
|
/* istanbul ignore file */
|
||||||
import ConfigProvider from './src/main.vue'
|
import ConfigProvider from './src/main.vue'
|
||||||
|
import installOsProperty from './src/installOsProperty'
|
||||||
|
|
||||||
ConfigProvider.install = function (Vue) {
|
ConfigProvider.install = function (Vue) {
|
||||||
Vue.component(ConfigProvider.name, ConfigProvider)
|
Vue.component(ConfigProvider.name, ConfigProvider)
|
||||||
Vue.component('NApp', ConfigProvider)
|
Vue.component('NApp', ConfigProvider)
|
||||||
|
installOsProperty(Vue)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ConfigProvider
|
export default ConfigProvider
|
||||||
|
47
src/ConfigProvider/src/installOsProperty.js
Normal file
47
src/ConfigProvider/src/installOsProperty.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
export default function installOsProperty (Vue) {
|
||||||
|
let osTheme = null
|
||||||
|
// Mql means media query list
|
||||||
|
let darkMql = null
|
||||||
|
let lightMql = null
|
||||||
|
function handleDarkMqlChange (e) {
|
||||||
|
if (e.matches) {
|
||||||
|
os.theme = 'dark'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function handleLightMqlChange (e) {
|
||||||
|
if (e.matches) {
|
||||||
|
os.theme = 'light'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (window.matchMedia) {
|
||||||
|
darkMql = window.matchMedia('(prefers-color-scheme: dark)')
|
||||||
|
lightMql = window.matchMedia('(prefers-color-scheme: light)')
|
||||||
|
if (darkMql.matches) {
|
||||||
|
osTheme = 'dark'
|
||||||
|
} else if (lightMql.matches) {
|
||||||
|
osTheme = 'light'
|
||||||
|
}
|
||||||
|
if (darkMql.addEventListener) {
|
||||||
|
darkMql.addEventListener('change', handleDarkMqlChange)
|
||||||
|
lightMql.addEventListener('change', handleLightMqlChange)
|
||||||
|
} else if (darkMql.addListener) {
|
||||||
|
darkMql.addListener(handleDarkMqlChange)
|
||||||
|
lightMql.addListener(handleLightMqlChange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const os = Vue.observable({
|
||||||
|
theme: osTheme
|
||||||
|
})
|
||||||
|
Vue.prototype.$NOs = os
|
||||||
|
return () => {
|
||||||
|
if (window.matchMedia) {
|
||||||
|
if (darkMql.removeEventListener) {
|
||||||
|
darkMql.removeEventListener('change', handleDarkMqlChange)
|
||||||
|
lightMql.removeEventListener('change', handleLightMqlChange)
|
||||||
|
} else if (darkMql.removeListener) {
|
||||||
|
darkMql.removeListener(handleDarkMqlChange)
|
||||||
|
lightMql.removeListener(handleLightMqlChange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user