aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/sliding_error.tsx
blob: b59e2a905c3a14c4a49733fe6402f84102f93a0d (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as React from 'react';

import { ScreenSpecification } from '../style/media';
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 { Text } from './ui/text';

export interface ErrorProps {
    icon: string;
    message: string;
}

export const Error: React.StatelessComponent<ErrorProps> = props => (
    <Container
        padding="10px"
        border={`1px solid ${ColorOption.darkOrange}`}
        backgroundColor={ColorOption.lightOrange}
        width="100%"
        borderRadius="6px"
        marginTop="10px"
        marginBottom="10px"
    >
        <Flex justify="flex-start">
            <Container marginRight="5px" display="inline" top="3px" position="relative">
                <Text fontSize="20px">{props.icon}</Text>
            </Container>
            <Text fontWeight="500" fontColor={ColorOption.darkOrange}>
                {props.message}
            </Text>
        </Flex>
    </Container>
);

export interface SlidingErrorProps extends ErrorProps {
    animationState: SlideAnimationState;
}
export const SlidingError: React.StatelessComponent<SlidingErrorProps> = props => {
    const slideAmount = '120px';

    const desktopSlideIn: PositionAnimationSettings = {
        timingFunction: 'ease-in',
        top: {
            from: slideAmount,
            to: '0px',
        },
        position: 'relative',
    };
    const desktopSlideOut: PositionAnimationSettings = {
        timingFunction: 'cubic-bezier(0.25, 0.1, 0.25, 1)',
        top: {
            from: '0px',
            to: slideAmount,
        },
        position: 'relative',
    };

    const mobileSlideIn: PositionAnimationSettings = {
        duration: '0.5s',
        timingFunction: 'ease-in',
        top: { from: '-120px', to: '0px' },
        position: 'fixed',
    };
    const moblieSlideOut: PositionAnimationSettings = {
        duration: '0.5s',
        timingFunction: 'ease-in',
        top: { from: '0px', to: '-120px' },
        position: 'fixed',
    };

    const slideUpSettings: ScreenSpecification<PositionAnimationSettings> = {
        default: desktopSlideIn,
        sm: mobileSlideIn,
    };
    const slideOutSettings: ScreenSpecification<PositionAnimationSettings> = {
        default: desktopSlideOut,
        sm: moblieSlideOut,
    };

    return (
        <SlideAnimation
            slideInSettings={slideUpSettings}
            slideOutSettings={slideOutSettings}
            zIndex={{ sm: zIndex.errorPopup, default: zIndex.errorPopBehind }}
            animationState={props.animationState}
        >
            <Error icon={props.icon} message={props.message} />
        </SlideAnimation>
    );
};