mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-17 23:57:15 +00:00
fix(frontend): preserve theme body classes (#6157)
* fix(storybook): preserve preview body classes * fix(frontend): retain theme body classes * fix(storybook): mirror panel theme attributes * test(storybook): cover theme switches * test(storybook): strengthen theme DOM coverage * fix(frontend): preserve message container classes --------- Co-authored-by: PathGao <gaoyanbo@gaoyanbodeMacBook-Air.local>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useLayoutEffect } from 'react';
|
||||
import type { Decorator, Preview } from '@storybook/react-vite';
|
||||
import { ConfigProvider } from 'antd';
|
||||
import i18next from 'i18next';
|
||||
@@ -17,11 +17,12 @@ if (!i18next.isInitialized) {
|
||||
});
|
||||
}
|
||||
|
||||
const withTheme: Decorator = (Story, context) => {
|
||||
export const withTheme: Decorator = (Story, context) => {
|
||||
const dark = context.globals.theme === 'dark';
|
||||
useEffect(() => {
|
||||
document.body.setAttribute('class', dark ? 'dark' : 'light');
|
||||
document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light');
|
||||
useLayoutEffect(() => {
|
||||
document.body.classList.remove('dark', 'light');
|
||||
document.body.classList.add(dark ? 'dark' : 'light');
|
||||
document.documentElement.removeAttribute('data-theme');
|
||||
}, [dark]);
|
||||
return (
|
||||
<ConfigProvider theme={buildAntdThemeConfig(dark, false)}>
|
||||
|
||||
Reference in New Issue
Block a user