Content.tsx 1.0 KB
Newer Older
1
import React, {FunctionComponent} from 'react';
P
Peter Pan 已提交
2
import {contentHeight, contentMargin, headerHeight, position, transitionProps} from '~/utils/style';
3

4
import BodyLoading from '~/components/BodyLoading';
5
import styled from 'styled-components';
6 7

const Section = styled.section`
P
Peter Pan 已提交
8
    display: flex;
9 10
`;

P
Peter Pan 已提交
11 12 13 14
const Article = styled.article`
    flex: auto;
    margin: ${contentMargin};
    min-height: ${contentHeight};
15 16 17
`;

const Aside = styled.aside`
P
Peter Pan 已提交
18
    flex: none;
P
Peter Pan 已提交
19
    background-color: var(--background-color);
P
Peter Pan 已提交
20 21
    height: ${`calc(100vh - ${headerHeight})`};
    ${position('sticky', headerHeight, 0, null, null)}
P
Peter Pan 已提交
22 23
    overflow-x: hidden;
    overflow-y: auto;
P
Peter Pan 已提交
24
    ${transitionProps('background-color')}
25 26 27 28
`;

type ContentProps = {
    aside?: React.ReactNode;
P
Peter Pan 已提交
29
    loading?: boolean;
30 31
};

P
Peter Pan 已提交
32
const Content: FunctionComponent<ContentProps> = ({children, aside, loading}) => (
33
    <Section>
P
Peter Pan 已提交
34
        <Article>{children}</Article>
35
        {aside && <Aside>{aside}</Aside>}
36
        {loading && <BodyLoading />}
37 38 39 40
    </Section>
);

export default Content;