mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
chore: add theme color meta (#31872)
This commit is contained in:
parent
c9bf113b39
commit
bd236a78a1
@ -4,6 +4,7 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#1890ff" />
|
||||
<title>{% if title %}{{ title | safe }}{% else %}{% endif %}</title>
|
||||
{% if meta %}{{ meta | safe }}{% endif %}
|
||||
<link
|
||||
@ -23,6 +24,13 @@
|
||||
<script src="https://b.alicdn.com/s/polyfill.min.js?features=default,es2015,Intl"></script>
|
||||
<link id="darkThemeLink" rel="stylesheet" href="/dark.css" />
|
||||
<script>
|
||||
/* 设置 meta theme-color 的值,默认会设置一个 #1890ff */
|
||||
function setColor(isDarken) {
|
||||
try {
|
||||
const theme = document.getElementsByTagName('meta')['theme-color'];
|
||||
theme.setAttribute('content', isDarken ? 'rgba(0,0,0,0.65)' : '#1890ff');
|
||||
} catch (error) {}
|
||||
}
|
||||
/* -------------------------- 主题相关 -------------------------- */
|
||||
(function () {
|
||||
/* 获取查询参数对象 */
|
||||
@ -58,7 +66,7 @@
|
||||
);
|
||||
// load后卸载
|
||||
window.addEventListener('load', () => darkThemeLinkEl.remove(), { once: true });
|
||||
|
||||
setColor(true);
|
||||
// 清除dark.css中的全部transition 待解析完后恢复
|
||||
var styleElement = document.createElement('style');
|
||||
styleElement.type = 'text/css';
|
||||
@ -71,6 +79,7 @@
|
||||
// 设置系统主题
|
||||
document.documentElement.style.colorScheme = 'dark';
|
||||
} else {
|
||||
setColor(false);
|
||||
document.documentElement.style.colorScheme = 'light';
|
||||
darkThemeLinkEl.remove();
|
||||
}
|
||||
|
@ -320,9 +320,13 @@ class MainContent extends Component {
|
||||
setTheme(theme);
|
||||
if (theme === 'default') {
|
||||
document.documentElement.style.colorScheme = 'light';
|
||||
setColor(false);
|
||||
delete query.theme;
|
||||
} else {
|
||||
if (theme === 'dark') document.documentElement.style.colorScheme = 'dark';
|
||||
if (theme === 'dark') {
|
||||
document.documentElement.style.colorScheme = 'dark';
|
||||
setColor(true);
|
||||
}
|
||||
query.theme = theme;
|
||||
}
|
||||
browserHistory.push({
|
||||
|
Loading…
Reference in New Issue
Block a user