aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/sliding_panel.tsx
blob: 7f903704994650edf671de0ea623726ba1a9b1e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
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
59
60
61
62
63
64
65
66
67
import * as React from 'react';

import { ColorOption } from '../style/theme';
import { zIndex } from '../style/z_index';
import { SlideAnimationState } from '../types';

import { PositionAnimationSettings } from './animations/position_animation';
import { SlideAnimation } from './animations/slide_animation';

import { Container } from './ui/container';
import { Flex } from './ui/flex';
import { Icon } from './ui/icon';

export interface PanelProps {
    onClose?: () => void;
}

export const Panel: React.StatelessComponent<PanelProps> = ({ children, onClose }) => (
    <Container backgroundColor={ColorOption.white} width="100%" height="100%" zIndex={zIndex.panel} padding="20px">
        <Flex justify="flex-end">
            <Icon padding="5px" width={12} color={ColorOption.lightGrey} icon="closeX" onClick={onClose} />
        </Flex>
        <Container position="relative" top="-10px" height="100%">
            {children}
        </Container>
    </Container>
);

export interface SlidingPanelProps extends PanelProps {
    animationState: SlideAnimationState;
}

export const SlidingPanel: React.StatelessComponent<SlidingPanelProps> = props => {
    if (props.animationState === 'none') {
        return null;
    }
    const { animationState, ...rest } = props;
    const slideAmount = '100%';
    const slideUpSettings: PositionAnimationSettings = {
        duration: '0.3s',
        timingFunction: 'ease-in-out',
        top: {
            from: slideAmount,
            to: '0px',
        },
        position: 'absolute',
    };
    const slideDownSettings: PositionAnimationSettings = {
        duration: '0.3s',
        timingFunction: 'ease-out',
        top: {
            from: '0px',
            to: slideAmount,
        },
        position: 'absolute',
    };
    return (
        <SlideAnimation
            slideInSettings={slideUpSettings}
            slideOutSettings={slideDownSettings}
            animationState={animationState}
            height="100%"
        >
            <Panel {...rest} />
        </SlideAnimation>
    );
};