diff options
author | Francesco Agosti <francesco.agosti93@gmail.com> | 2018-11-02 04:57:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-02 04:57:29 +0800 |
commit | 0955feb0234bc90b7dcf5ad3a308570c9fa5d490 (patch) | |
tree | 623c55dddb6326cf8998619da25a82c48b87f876 /packages/instant/src/components/animations | |
parent | 44a34ee541f2c350b65005a1430072ed90fbc790 (diff) | |
parent | 935e5da78e14f78685ad9270c19f473fa193d542 (diff) | |
download | dexon-sol-tools-0955feb0234bc90b7dcf5ad3a308570c9fa5d490.tar dexon-sol-tools-0955feb0234bc90b7dcf5ad3a308570c9fa5d490.tar.gz dexon-sol-tools-0955feb0234bc90b7dcf5ad3a308570c9fa5d490.tar.bz2 dexon-sol-tools-0955feb0234bc90b7dcf5ad3a308570c9fa5d490.tar.lz dexon-sol-tools-0955feb0234bc90b7dcf5ad3a308570c9fa5d490.tar.xz dexon-sol-tools-0955feb0234bc90b7dcf5ad3a308570c9fa5d490.tar.zst dexon-sol-tools-0955feb0234bc90b7dcf5ad3a308570c9fa5d490.zip |
Merge pull request #1201 from 0xProject/feature/instant/basic-token-modal
[instant] Add `Select Token` mode, animation abstractions, and basic token selection panel
Diffstat (limited to 'packages/instant/src/components/animations')
3 files changed, 103 insertions, 58 deletions
diff --git a/packages/instant/src/components/animations/position_animation.tsx b/packages/instant/src/components/animations/position_animation.tsx new file mode 100644 index 000000000..4bb21befb --- /dev/null +++ b/packages/instant/src/components/animations/position_animation.tsx @@ -0,0 +1,80 @@ +import { Keyframes } from 'styled-components'; + +import { css, keyframes, styled } from '../../style/theme'; + +export interface TransitionInfo { + from: string; + to: string; +} + +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 = ( + position: string, + top?: TransitionInfo, + bottom?: TransitionInfo, + left?: TransitionInfo, + right?: TransitionInfo, +) => keyframes` + from { + position: ${position}; + ${generateTransitionInfoCss('from', top, bottom, left, right)} + } + + to { + position: ${position}; + ${generateTransitionInfoCss('to', top, bottom, left, right)} + } +`; + +export interface PositionAnimationSettings { + top?: TransitionInfo; + bottom?: TransitionInfo; + left?: TransitionInfo; + right?: TransitionInfo; + timingFunction: string; + duration?: string; +} + +export interface PositionAnimationProps extends PositionAnimationSettings { + position: string; +} + +export const PositionAnimation = + styled.div < + PositionAnimationProps > + ` + animation-name: ${props => + css` + ${slideKeyframeGenerator(props.position, props.top, props.bottom, props.left, props.right)}; + `}; + animation-duration: ${props => props.duration || '0.3s'}; + animation-timing-function: ${props => props.timingFunction}; + animation-delay: 0s; + animation-iteration-count: 1; + animation-fill-mode: forwards; + position: ${props => props.position}; + height: 100%; + width: 100%; +`; + +PositionAnimation.defaultProps = { + position: 'relative', +}; diff --git a/packages/instant/src/components/animations/slide_animation.tsx b/packages/instant/src/components/animations/slide_animation.tsx new file mode 100644 index 000000000..66a314c7f --- /dev/null +++ b/packages/instant/src/components/animations/slide_animation.tsx @@ -0,0 +1,23 @@ +import * as React from 'react'; + +import { PositionAnimation, PositionAnimationSettings } from './position_animation'; + +export type SlideAnimationState = 'slidIn' | 'slidOut' | 'none'; +export interface SlideAnimationProps { + position: string; + animationState: SlideAnimationState; + slideInSettings: PositionAnimationSettings; + slideOutSettings: PositionAnimationSettings; +} + +export const SlideAnimation: React.StatelessComponent<SlideAnimationProps> = props => { + if (props.animationState === 'none') { + return <React.Fragment>{props.children}</React.Fragment>; + } + const propsToUse = props.animationState === 'slidIn' ? props.slideInSettings : props.slideOutSettings; + return ( + <PositionAnimation position={props.position} {...propsToUse}> + {props.children} + </PositionAnimation> + ); +}; diff --git a/packages/instant/src/components/animations/slide_animations.tsx b/packages/instant/src/components/animations/slide_animations.tsx deleted file mode 100644 index 84280372b..000000000 --- a/packages/instant/src/components/animations/slide_animations.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import * as React from 'react'; -import { Keyframes } from 'styled-components'; - -import { css, keyframes, styled } from '../../style/theme'; - -const slideKeyframeGenerator = (fromY: string, toY: string) => keyframes` - from { - position: relative; - top: ${fromY}; - } - - to { - position: relative; - top: ${toY}; - } -`; - -export interface SlideAnimationProps { - keyframes: Keyframes; - animationType: string; - animationDirection?: string; -} - -export const SlideAnimation = - styled.div < - SlideAnimationProps > - ` - animation-name: ${props => - css` - ${props.keyframes}; - `}; - animation-duration: 0.3s; - animation-timing-function: ${props => props.animationType}; - animation-delay: 0s; - animation-iteration-count: 1; - animation-fill-mode: ${props => props.animationDirection || 'none'}; - position: relative; -`; - -export interface SlideAnimationComponentProps { - downY: string; -} - -export const SlideUpAnimation: React.StatelessComponent<SlideAnimationComponentProps> = props => ( - <SlideAnimation animationType="ease-in" keyframes={slideKeyframeGenerator(props.downY, '0px')}> - {props.children} - </SlideAnimation> -); - -export const SlideDownAnimation: React.StatelessComponent<SlideAnimationComponentProps> = props => ( - <SlideAnimation - animationDirection="forwards" - animationType="cubic-bezier(0.25, 0.1, 0.25, 1)" - keyframes={slideKeyframeGenerator('0px', props.downY)} - > - {props.children} - </SlideAnimation> -); |