22 行
564 B
TypeScript
22 行
564 B
TypeScript
import { getCssVariables } from '@/style/tokens';
|
|
|
|
function applyOmniTokens(theme: 'light' | 'dark'): void {
|
|
const vars = getCssVariables(theme);
|
|
const root = document.documentElement;
|
|
Object.entries(vars).forEach(([key, value]) => {
|
|
root.style.setProperty(key, value);
|
|
});
|
|
}
|
|
|
|
function changeTheme(theme: string): void {
|
|
if (theme === 'dark') {
|
|
document.body.setAttribute('arco-theme', 'dark');
|
|
applyOmniTokens('dark');
|
|
return;
|
|
}
|
|
document.body.removeAttribute('arco-theme');
|
|
applyOmniTokens('light');
|
|
}
|
|
|
|
export default changeTheme;
|