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
|
import * as React from 'react';
import { Keyframes } from 'styled-components';
import { css, keyframes, styled } from '../../style/theme';
const generateTransitionInfoCss = (
key: keyof TransitionInfo,
top?: TransitionInfo,
bottom?: TransitionInfo,
left?: TransitionInfo,
right?: TransitionInfo,
): string => {
const topStringIfExists = top ? `top: ${top[key]};` : '';
const bottomStringIfExists = bottom ? `bottom: ${bottom[key]};` : '';
const leftStringIfExists = left ? `left: ${left[key]};` : '';
const rightStringIfExists = right ? `right: ${right[key]};` : '';
return `
${topStringIfExists}
${bottomStringIfExists}
${leftStringIfExists}
${rightStringIfExists}
`;
};
const slideKeyframeGenerator = (
top?: TransitionInfo,
bottom?: TransitionInfo,
left?: TransitionInfo,
right?: TransitionInfo,
) => keyframes`
from {
position: relative;
${generateTransitionInfoCss('from', top, bottom, left, right)}
}
to {
position: relative;
${generateTransitionInfoCss('to', top, bottom, left, right)}
}
`;
export interface TransitionInfo {
from: string;
to: string;
}
export interface PositionAnimationProps {
top?: TransitionInfo;
bottom?: TransitionInfo;
left?: TransitionInfo;
right?: TransitionInfo;
timingFunction: string;
direction?: string;
}
export const PositionAnimation =
styled.div <
PositionAnimationProps >
`
animation-name: ${props =>
css`
${slideKeyframeGenerator(props.top, props.bottom, props.left, props.right)};
`};
animation-duration: 0.3s;
animation-timing-function: ${props => props.timingFunction};
animation-delay: 0s;
animation-iteration-count: 1;
animation-fill-mode: ${props => props.direction || 'none'};
position: relative;
`;
|