55 lines
2.5 KiB
Plaintext
55 lines
2.5 KiB
Plaintext
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Aurora Admin · ThemeSwitcher</title>
|
|
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
|
|
<link rel="stylesheet" href="./ThemeSwitcher.css" />
|
|
</head>
|
|
<body>
|
|
<div class="aa-page">
|
|
<h2 class="aa-h2">ThemeSwitcher 主题切换</h2>
|
|
<p class="aa-desc">明暗主题 + 品牌色切换,实时预览,可保存偏好。</p>
|
|
|
|
<div class="aa-demo">
|
|
<div class="aa-themesw" id="sw">
|
|
<div class="aa-themesw-opt" role="radio" tabindex="0" data-mode="light"><span class="aa-themesw-dot light"></span>浅色</div>
|
|
<div class="aa-themesw-opt" role="radio" tabindex="0" data-mode="dark"><span class="aa-themesw-dot dark"></span>深色</div>
|
|
<div class="aa-themesw-colors" id="colors"></div>
|
|
<div class="aa-themesw-label" id="label"></div>
|
|
</div>
|
|
<div class="aa-card" style="margin-top:12px">
|
|
<div class="aa-card__body">
|
|
<button class="aa-btn aa-btn--primary">品牌色按钮</button>
|
|
<span style="margin-left:10px">当前主题:<b id="cur"></b></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var brands = ['#2F54EB', '#1677FF', '#722ED1', '#13C2C2', '#FA541C', '#EB2F96'];
|
|
var mode = 'light', brand = '#2F54EB';
|
|
var colorsEl = document.getElementById('colors');
|
|
brands.forEach(function (c) {
|
|
var s = document.createElement('span');
|
|
s.className = 'aa-themesw-color'; s.setAttribute('role','radio'); s.setAttribute('tabindex','0'); s.style.background = c; s.dataset.c = c;
|
|
s.onclick = function () { brand = c; render(); };
|
|
colorsEl.appendChild(s);
|
|
});
|
|
document.querySelectorAll('.aa-themesw-opt').forEach(function (o) {
|
|
o.onclick = function () { mode = o.dataset.mode; render(); };
|
|
});
|
|
function render() {
|
|
document.querySelectorAll('.aa-themesw-opt').forEach(function (o) { o.classList.toggle('is-active', o.dataset.mode === mode); });
|
|
Array.prototype.forEach.call(colorsEl.children, function (c) { c.classList.toggle('is-active', c.dataset.c === brand); });
|
|
document.documentElement.style.setProperty('--brand', brand);
|
|
document.getElementById('cur').textContent = mode === 'light' ? '浅色' : '深色';
|
|
document.getElementById('label').textContent = '品牌色:' + brand + '(点击色块可切换,应用于 CSS 变量 --brand 实时预览)';
|
|
}
|
|
render();
|
|
</script>
|
|
</body>
|
|
</html>
|