File size: 3,273 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import type { PropsWithChildren } from 'react';
import React from 'react';
import { ConfigProvider, Layout, Typography } from 'antd';
import { createStyles } from 'antd-style';
import { FormattedMessage, useRouteMeta } from 'dumi';

import CommonHelmet from '../../common/CommonHelmet';
import EditButton from '../../common/EditButton';
import Footer from '../../slots/Footer';
import { DarkContext } from './../../../hooks/useDark';
import AffixTabs from './AffixTabs';

export type ResourceLayoutProps = PropsWithChildren<NonNullable<any>>;

const resourcePadding = 40;
const articleMaxWidth = 1208;
const resourcePaddingXS = 24;

const useStyle = createStyles(({ token, css }, isDark: boolean) => {
  return {
    resourcePage: css`
      footer {
        margin-top: 176px;
        .rc-footer-container {
          max-width: ${articleMaxWidth}px;
          margin: 0 auto;
          padding-inline-end: 0;
          padding-inline-start: 0;
        }
      }
    `,
    resourceContent: css`
      padding: 0 ${resourcePadding}px;
      max-width: ${articleMaxWidth}px;
      margin: 0 auto;
      box-sizing: content-box;
      min-height: 100vh;

      @media only screen and (max-width: 767.99px) {
        & {
          article {
            padding: 0 ${resourcePaddingXS}px;
          }
          ${token.antCls}-col {
            padding-top: ${token.padding}px !important;
            padding-bottom: ${token.padding}px !important;
          }
        }
      }
    `,
    banner: css`
      padding: 0 ${resourcePadding}px;
      overflow: hidden;
      ${
        isDark
          ? ``
          : `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: ${token.fontSizeLG}px;
        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 isDark = React.use(DarkContext);
  const { styles } = useStyle(isDark);
  const meta = useRouteMeta();
  const node = (
    <Layout>
      <CommonHelmet />
      <div id="resources-page" className={styles.resourcePage}>
        <AffixTabs />
        <div className={styles.banner}>
          <Typography.Title style={{ fontSize: 30 }}>
            {meta.frontmatter?.title}
            <EditButton
              title={<FormattedMessage id="app.content.edit-page" />}
              filename={meta.frontmatter.filename}
            />
          </Typography.Title>
          <section>{meta.frontmatter.description}</section>
        </div>
        <div className={styles.resourceContent}>{children}</div>
        <Footer />
      </div>
    </Layout>
  );

  if (!isDark) {
    return <ConfigProvider theme={{ token: { colorBgLayout: '#fff' } }}>{node}</ConfigProvider>;
  }

  return node;
};

export default ResourceLayout;