diff options
author | August Skare <post@augustskare.no> | 2018-11-16 18:05:30 +0800 |
---|---|---|
committer | August Skare <post@augustskare.no> | 2018-11-16 18:05:30 +0800 |
commit | 54bd7df900316504e4403bc94cffd92930a6c763 (patch) | |
tree | 7b386224e5746be65bfddc094cc5b26f7c018e19 /packages/dev-tools-pages/ts/components/Animations | |
parent | 5afef5fe820674abfbdf58226ed0a6920b5c74f7 (diff) | |
download | dexon-0x-contracts-54bd7df900316504e4403bc94cffd92930a6c763.tar.gz dexon-0x-contracts-54bd7df900316504e4403bc94cffd92930a6c763.tar.zst dexon-0x-contracts-54bd7df900316504e4403bc94cffd92930a6c763.zip |
fix linting + code syntax for statless components
Diffstat (limited to 'packages/dev-tools-pages/ts/components/Animations')
5 files changed, 61 insertions, 64 deletions
diff --git a/packages/dev-tools-pages/ts/components/Animations/Compiler/index.tsx b/packages/dev-tools-pages/ts/components/Animations/Compiler/index.tsx index dbd8a3799..db93ff8a4 100644 --- a/packages/dev-tools-pages/ts/components/Animations/Compiler/index.tsx +++ b/packages/dev-tools-pages/ts/components/Animations/Compiler/index.tsx @@ -1,10 +1,11 @@ import * as React from 'react'; -import Animation from '../index'; +import { BaseAnimation } from '../index'; + import * as animationData from './data.json'; -function AnimationCompiler() { - return <Animation animationData={animationData} width={2150} height={700} />; -} +const CompilerAnimation: React.StatelessComponent<{}> = () => ( + <BaseAnimation animationData={animationData} width={2150} height={700} /> +); -export default AnimationCompiler; +export { CompilerAnimation as Animation }; diff --git a/packages/dev-tools-pages/ts/components/Animations/Cov/index.tsx b/packages/dev-tools-pages/ts/components/Animations/Cov/index.tsx index c14c64ab9..445824717 100644 --- a/packages/dev-tools-pages/ts/components/Animations/Cov/index.tsx +++ b/packages/dev-tools-pages/ts/components/Animations/Cov/index.tsx @@ -1,10 +1,11 @@ import * as React from 'react'; -import Animation from '../index'; +import { BaseAnimation } from '../index'; + import * as animationData from './data.json'; -function AnimationCov() { - return <Animation animationData={animationData} width={1981} height={660} />; -} +const AnimationCov: React.StatelessComponent<{}> = () => ( + <BaseAnimation animationData={animationData} width={1981} height={660} /> +); -export default AnimationCov; +export { AnimationCov as Animation }; diff --git a/packages/dev-tools-pages/ts/components/Animations/Profiler/index.tsx b/packages/dev-tools-pages/ts/components/Animations/Profiler/index.tsx index e767a587f..73a4e9ad6 100644 --- a/packages/dev-tools-pages/ts/components/Animations/Profiler/index.tsx +++ b/packages/dev-tools-pages/ts/components/Animations/Profiler/index.tsx @@ -1,10 +1,11 @@ import * as React from 'react'; -import Animation from '../index'; +import { BaseAnimation } from '../index'; + import * as animationData from './data.json'; -function AnimationProfiler() { - return <Animation animationData={animationData} width={1985} height={657} />; -} +const AnimationProfiler: React.StatelessComponent<{}> = () => ( + <BaseAnimation animationData={animationData} width={1985} height={657} /> +); -export default AnimationProfiler; +export { AnimationProfiler as Animation }; diff --git a/packages/dev-tools-pages/ts/components/Animations/Trace/index.tsx b/packages/dev-tools-pages/ts/components/Animations/Trace/index.tsx index fa421a3bf..10a78ccb7 100644 --- a/packages/dev-tools-pages/ts/components/Animations/Trace/index.tsx +++ b/packages/dev-tools-pages/ts/components/Animations/Trace/index.tsx @@ -1,10 +1,11 @@ import * as React from 'react'; -import Animation from '../index'; +import { BaseAnimation } from '../index'; + import * as animationData from './data.json'; -function AnimationTrace() { - return <Animation animationData={animationData} width={2241} height={610} />; -} +const AnimationTrace: React.StatelessComponent<{}> = () => ( + <BaseAnimation animationData={animationData} width={2241} height={610} /> +); -export default AnimationTrace; +export { AnimationTrace as Animation }; diff --git a/packages/dev-tools-pages/ts/components/Animations/index.tsx b/packages/dev-tools-pages/ts/components/Animations/index.tsx index 3db501dc1..95af4448c 100644 --- a/packages/dev-tools-pages/ts/components/Animations/index.tsx +++ b/packages/dev-tools-pages/ts/components/Animations/index.tsx @@ -11,55 +11,28 @@ interface AnimationProps { } interface AnimationState { - width?: number; - height?: number; + width?: number | undefined; + height?: number | undefined; } -class Animation extends React.PureComponent<AnimationProps, AnimationState> { - timeout = null as any; - constructor(props: AnimationProps) { - super(props); +class BaseAnimation extends React.PureComponent<AnimationProps, AnimationState> { + public state: AnimationState = { + height: undefined, + width: undefined, + }; + private _timeout = null as any; - this.state = { - height: undefined, - width: undefined, - }; - - this.handleResize = this.handleResize.bind(this); - this.updateAnimationSize = this.updateAnimationSize.bind(this); - } - - componentDidMount() { - this.updateAnimationSize(); - window.addEventListener('resize', this.handleResize); - } - - componentWillUnmount() { - window.removeEventListener('resize', this.handleResize); + public componentDidMount(): void { + this._updateAnimationSize(); + window.addEventListener('resize', this._handleResize); } - handleResize() { - clearTimeout(this.timeout); - this.timeout = setTimeout(this.updateAnimationSize, 50); + public componentWillUnmount(): void { + window.removeEventListener('resize', this._handleResize); } - updateAnimationSize() { - const windowWidth = window.innerWidth; - let width = undefined; - let height = undefined; - if (windowWidth <= 1000) { - const maxWidth = windowWidth + 250; - const ratio = maxWidth / this.props.width; - - height = Math.round(this.props.height * ratio); - width = Math.round(this.props.width * ratio); - } - - this.setState({ width, height }); - } - - render() { - let { animationData } = this.props; + public render(): React.ReactNode { + const { animationData } = this.props; const height = this.state.height || this.props.height; const width = this.state.width || this.props.width; @@ -72,13 +45,33 @@ class Animation extends React.PureComponent<AnimationProps, AnimationState> { options={{ loop: true, autoplay: true, - animationData: animationData, + animationData, }} /> </InnerContainer> </Container> ); } + + private readonly _handleResize = () => { + clearTimeout(this._timeout); + this._timeout = setTimeout(this._updateAnimationSize, 50); + }; + + private readonly _updateAnimationSize = () => { + const windowWidth = window.innerWidth; + let width; + let height; + if (windowWidth <= 1000) { + const maxWidth = windowWidth + 250; + const ratio = maxWidth / this.props.width; + + height = Math.round(this.props.height * ratio); + width = Math.round(this.props.width * ratio); + } + + this.setState({ width, height }); + }; } const Container = styled.div` @@ -102,4 +95,4 @@ const InnerContainer = styled.div` transform: translateX(-50%); `; -export default Animation; +export { BaseAnimation }; |