Content.tsx 1.8 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 {WithStyled, 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
const Article = styled.article`
    flex: auto;
P
Peter Pan 已提交
29
    min-width: 0;
P
Peter Pan 已提交
30 31
    margin: ${contentMargin};
    min-height: ${contentHeight};
32 33 34
`;

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

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

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

export default Content;