Skip to content

Commit 0363e41

Browse files
authored
docs: support docs dark in iframe color (ant-design#54252)
1 parent 1bbbe49 commit 0363e41

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

.dumi/theme/SiteThemeProvider.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { theme as antdTheme, ConfigProvider } from 'antd';
33
import type { ThemeConfig } from 'antd';
44
import type { ThemeProviderProps } from 'antd-style';
55
import { ThemeProvider } from 'antd-style';
6+
import { updateCSS } from 'rc-util/lib/Dom/dynamicCSS';
67

78
import SiteContext from './slots/SiteContext';
89

@@ -41,6 +42,24 @@ const SiteThemeProvider: React.FC<ThemeProviderProps<any>> = ({ children, theme,
4142
ConfigProvider.config({ theme: theme as ThemeConfig });
4243
}, [theme]);
4344

45+
React.useEffect(() => {
46+
// iframe demo 生效
47+
if (window.parent !== window) {
48+
updateCSS(
49+
`
50+
[data-prefers-color='dark'] {
51+
color-scheme: dark !important;
52+
}
53+
54+
[data-prefers-color='light'] {
55+
color-scheme: light !important;
56+
}
57+
`,
58+
'color-scheme',
59+
);
60+
}
61+
}, [theme]);
62+
4463
return (
4564
<ThemeProvider<NewToken>
4665
{...rest}
@@ -51,7 +70,7 @@ const SiteThemeProvider: React.FC<ThemeProviderProps<any>> = ({ children, theme,
5170
menuItemBorder: 2,
5271
mobileMaxWidth: 767.99,
5372
siteMarkdownCodeBg: token.colorFillTertiary,
54-
siteMarkdownCodeBgDark: "#000",
73+
siteMarkdownCodeBgDark: '#000',
5574
antCls: `.${rootPrefixCls}`,
5675
iconCls: `.${iconPrefixCls}`,
5776
/** 56 */

.dumi/theme/common/BrowserFrame.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const useStyle = createStyles(({ token, css }) => ({
3636
& > * {
3737
display: block;
3838
}
39+
[data-prefers-color='dark'] & {
40+
border-top: 2em solid rgba(80, 80, 80, 0.7);
41+
box-shadow: 0 0.1em 0.5em 0 rgba(0, 0, 0, 0.6);
42+
background-color: #000; /* 可选 */
43+
44+
&::after {
45+
background-color: #333;
46+
}
47+
}
3948
`,
4049
}));
4150

0 commit comments

Comments
 (0)