Content.tsx 1.6 KB
Newer Older
P
Peter Pan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * Copyright 2020 Baidu Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17
import React, {FunctionComponent} from 'react';
P
Peter Pan 已提交
18
import {contentHeight, contentMargin, headerHeight, position, transitionProps} from '~/utils/style';
19

20
import BodyLoading from '~/components/BodyLoading';
21
import styled from 'styled-components';
22 23

const Section = styled.section`
P
Peter Pan 已提交
24
    display: flex;
25 26
`;

P
Peter Pan 已提交
27 28 29 30
const Article = styled.article`
    flex: auto;
    margin: ${contentMargin};
    min-height: ${contentHeight};
31 32 33
`;

const Aside = styled.aside`
P
Peter Pan 已提交
34
    flex: none;
P
Peter Pan 已提交
35
    background-color: var(--background-color);
P
Peter Pan 已提交
36 37
    height: ${`calc(100vh - ${headerHeight})`};
    ${position('sticky', headerHeight, 0, null, null)}
P
Peter Pan 已提交
38 39
    overflow-x: hidden;
    overflow-y: auto;
P
Peter Pan 已提交
40
    ${transitionProps('background-color')}
41 42 43 44
`;

type ContentProps = {
    aside?: React.ReactNode;
P
Peter Pan 已提交
45
    loading?: boolean;
46 47
};

P
Peter Pan 已提交
48
const Content: FunctionComponent<ContentProps> = ({children, aside, loading}) => (
49
    <Section>
P
Peter Pan 已提交
50
        <Article>{children}</Article>
51
        {aside && <Aside>{aside}</Aside>}
52
        {loading && <BodyLoading />}
53 54 55 56
    </Section>
);

export default Content;