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

P
Peter Pan 已提交
4
import HashLoader from 'react-spinners/HashLoader';
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;
19
    background-color: ${backgroundColor};
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;
24 25
`;

P
Peter Pan 已提交
26
const Loading = styled.div`
27 28
    ${size('100vh', '100vw')}
    ${position('fixed', 0, 0, 0, 0)}
P
Peter Pan 已提交
29 30 31 32 33 34 35 36
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    overscroll-behavior: none;
    cursor: progress;
`;

37 38
type ContentProps = {
    aside?: React.ReactNode;
P
Peter Pan 已提交
39
    loading?: boolean;
40 41
};

P
Peter Pan 已提交
42
const Content: FunctionComponent<ContentProps> = ({children, aside, loading}) => (
43
    <Section>
P
Peter Pan 已提交
44
        <Article>{children}</Article>
45
        {aside && <Aside>{aside}</Aside>}
P
Peter Pan 已提交
46 47 48 49 50
        {loading && (
            <Loading>
                <HashLoader size="60px" color={primaryColor} />
            </Loading>
        )}
51 52 53 54
    </Section>
);

export default Content;