docs: fix res page not work in dark mode (#47697)

This commit is contained in:
二货爱吃白萝卜 2024-03-05 10:57:23 +08:00 committed by GitHub
parent 562567e862
commit 4fafb40147
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 113 additions and 101 deletions

View File

@ -15,7 +15,7 @@ const useStyle = createStyles(({ token, css }) => {
height: 100%; height: 100%;
color: inherit; color: inherit;
list-style: none; list-style: none;
border: 1px solid #e6e6e6; border: 1px solid ${token.colorSplit};
border-radius: 2px; border-radius: 2px;
cursor: pointer; cursor: pointer;
transition: box-shadow 0.3s; transition: box-shadow 0.3s;
@ -47,13 +47,13 @@ const useStyle = createStyles(({ token, css }) => {
`, `,
title: css` title: css`
margin: 16px 20px 8px; margin: 16px 20px 8px;
color: #0d1a26; opacity: 0.85;
font-size: 20px; font-size: 20px;
line-height: 28px; line-height: 28px;
`, `,
description: css` description: css`
margin: 0 20px 20px; margin: 0 20px 20px;
color: #697b8c; opacity: 0.65;
font-size: 14px; font-size: 14px;
line-height: 22px; line-height: 22px;
`, `,

View File

@ -4,6 +4,7 @@ import { ConfigProvider, Layout, Typography } from 'antd';
import { createStyles } from 'antd-style'; import { createStyles } from 'antd-style';
import { FormattedMessage, useRouteMeta } from 'dumi'; import { FormattedMessage, useRouteMeta } from 'dumi';
import useDark from '../../../hooks/useDark';
import CommonHelmet from '../../common/CommonHelmet'; import CommonHelmet from '../../common/CommonHelmet';
import EditButton from '../../common/EditButton'; import EditButton from '../../common/EditButton';
import Footer from '../../slots/Footer'; import Footer from '../../slots/Footer';
@ -15,125 +16,136 @@ const resourcePadding = 40;
const articleMaxWidth = 1208; const articleMaxWidth = 1208;
const resourcePaddingXS = 24; const resourcePaddingXS = 24;
const useStyle = createStyles(({ token, css }) => { const useStyle = () => {
const { antCls } = token; const isRootDark = useDark();
return {
resourcePage: css`
footer {
margin-top: 176px;
.rc-footer-container { return createStyles((config) => {
max-width: ${articleMaxWidth}px; const { token, css } = config;
margin: 0 auto; const { antCls } = token;
padding-right: 0;
padding-left: 0; return {
resourcePage: css`
footer {
margin-top: 176px;
.rc-footer-container {
max-width: ${articleMaxWidth}px;
margin: 0 auto;
padding-right: 0;
padding-left: 0;
}
} }
} `,
`, resourceContent: css`
resourceContent: css` padding: 0 ${resourcePadding}px;
padding: 0 ${resourcePadding}px; max-width: ${articleMaxWidth}px;
max-width: ${articleMaxWidth}px; margin: 0 auto;
margin: 0 auto; box-sizing: content-box;
box-sizing: content-box; min-height: 100vh;
min-height: 100vh;
> .markdown { > .markdown {
> p { > p {
margin-bottom: 56px; margin-bottom: 56px;
} }
h2 { h2 {
margin-top: 124px; margin-top: 124px;
color: #314659; font-weight: lighter;
font-weight: lighter; font-size: 30px;
font-size: 30px; line-height: 38px;
line-height: 38px;
&:first-child { &:first-child {
margin-top: 88px; margin-top: 88px;
}
}
h3 {
margin-top: 56px;
font-weight: 400;
font-size: 24px;
line-height: 32px;
} }
} }
h3 { @media only screen and (max-width: 767.99px) {
margin-top: 56px; & {
font-weight: 400; article {
font-size: 24px; padding: 0 ${resourcePaddingXS}px;
line-height: 32px; }
${antCls}-col {
padding-top: 16px !important;
padding-bottom: 16px !important;
}
}
}
`,
banner: css`
padding: 0 ${resourcePadding}px;
overflow: hidden;
${
isRootDark
? ``
: `background: url('https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*y_r7RogIG1wAAAAAAAAAAABkARQnAQ');`
}
background-size: cover;
h1 {
box-sizing: content-box;
max-width: ${articleMaxWidth}px;
margin: 56px auto 16px;
} }
p { section {
color: #697b8c; max-width: ${articleMaxWidth}px;
margin: 0 auto 56px;
font-weight: 200;
font-size: 16px;
line-height: 24px;
} }
}
@media only screen and (max-width: 767.99px) { @media only screen and (max-width: 767.99px) {
& { & {
article { margin: 0 -${resourcePaddingXS}px;
padding: 0 ${resourcePaddingXS}px; padding: 0 ${resourcePaddingXS}px;
} }
${antCls}-col {
padding-top: 16px !important;
padding-bottom: 16px !important;
}
} }
} `,
`, };
banner: css` })();
padding: 0 ${resourcePadding}px; };
overflow: hidden;
background: url('https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*y_r7RogIG1wAAAAAAAAAAABkARQnAQ');
background-size: cover;
h1 {
box-sizing: content-box;
max-width: ${articleMaxWidth}px;
margin: 56px auto 16px;
}
section {
max-width: ${articleMaxWidth}px;
margin: 0 auto 56px;
font-weight: 200;
font-size: 16px;
line-height: 24px;
}
@media only screen and (max-width: 767.99px) {
& {
margin: 0 -${resourcePaddingXS}px;
padding: 0 ${resourcePaddingXS}px;
}
}
`,
};
});
const ResourceLayout: React.FC<ResourceLayoutProps> = ({ children }) => { const ResourceLayout: React.FC<ResourceLayoutProps> = ({ children }) => {
const { styles } = useStyle(); const { styles } = useStyle();
const meta = useRouteMeta(); const meta = useRouteMeta();
return ( const isRootDark = useDark();
<ConfigProvider theme={{ token: { colorBgLayout: '#fff' } }}>
<Layout> const node = (
<CommonHelmet /> <Layout>
<div id="resources-page" className={styles.resourcePage}> <CommonHelmet />
<AffixTabs /> <div id="resources-page" className={styles.resourcePage}>
<div className={styles.banner}> <AffixTabs />
<Typography.Title style={{ fontSize: 30 }}> <div className={styles.banner}>
{meta.frontmatter?.title} <Typography.Title style={{ fontSize: 30 }}>
<EditButton {meta.frontmatter?.title}
title={<FormattedMessage id="app.content.edit-page" />} <EditButton
filename={meta.frontmatter.filename} title={<FormattedMessage id="app.content.edit-page" />}
/> filename={meta.frontmatter.filename}
</Typography.Title> />
<section>{meta.frontmatter.description}</section> </Typography.Title>
</div> <section>{meta.frontmatter.description}</section>
<div className={styles.resourceContent}>{children}</div>
<Footer />
</div> </div>
</Layout> <div className={styles.resourceContent}>{children}</div>
</ConfigProvider> <Footer />
</div>
</Layout>
); );
if (!isRootDark) {
return <ConfigProvider theme={{ token: { colorBgLayout: '#fff' } }}>{node}</ConfigProvider>;
}
return node;
}; };
export default ResourceLayout; export default ResourceLayout;