Aside.tsx 1.4 KB
Newer Older
P
Peter Pan 已提交
1
import React, {FunctionComponent} from 'react';
P
Peter Pan 已提交
2
import {WithStyled, asideWidth, rem, size, transitionProps} from '~/utils/style';
P
Peter Pan 已提交
3 4 5 6 7 8 9

import styled from 'styled-components';

export const AsideSection = styled.section`
    margin: ${rem(20)};

    &:not(:last-child) {
P
Peter Pan 已提交
10
        border-bottom: 1px solid var(--border-color);
P
Peter Pan 已提交
11 12
        padding-bottom: ${rem(20)};
        margin-bottom: 0;
P
Peter Pan 已提交
13
        ${transitionProps('border-color')}
P
Peter Pan 已提交
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
    }
`;

const Wrapper = styled.div<{width?: string | number}>`
    ${props => size('100%', props.width == null ? asideWidth : props.width)}
    overflow: hidden;
    display: flex;
    flex-direction: column;

    > .aside-top {
        flex: auto;
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: auto;
        overflow-x: hidden;
        overflow-y: auto;

        > ${AsideSection} {
            flex: none;
        }
    }

    > .aside-bottom {
        flex: none;
        box-shadow: 0 -${rem(5)} ${rem(16)} 0 rgba(0, 0, 0, 0.03);
        padding: ${rem(20)};
    }
`;

type AsideProps = {
    width?: string | number;
    bottom?: React.ReactNode;
};

const Aside: FunctionComponent<AsideProps & WithStyled> = ({width, bottom, className, children}) => {
    return (
        <Wrapper width={width} className={className}>
            <div className="aside-top">{children}</div>
            {bottom && <div className="aside-bottom">{bottom}</div>}
        </Wrapper>
    );
};

export default Aside;