From 54bd7df900316504e4403bc94cffd92930a6c763 Mon Sep 17 00:00:00 2001 From: August Skare Date: Fri, 16 Nov 2018 11:05:30 +0100 Subject: fix linting + code syntax for statless components --- .../ts/components/Animations/Compiler/index.tsx | 11 +- .../ts/components/Animations/Cov/index.tsx | 11 +- .../ts/components/Animations/Profiler/index.tsx | 11 +- .../ts/components/Animations/Trace/index.tsx | 11 +- .../ts/components/Animations/index.tsx | 81 ++++---- packages/dev-tools-pages/ts/components/Base.tsx | 33 ++-- .../dev-tools-pages/ts/components/Breakout.tsx | 2 +- packages/dev-tools-pages/ts/components/Button.tsx | 16 +- packages/dev-tools-pages/ts/components/Code.tsx | 122 ++++++------ .../dev-tools-pages/ts/components/Compiler.tsx | 45 +++-- .../dev-tools-pages/ts/components/Container.tsx | 4 +- packages/dev-tools-pages/ts/components/Content.tsx | 16 +- .../dev-tools-pages/ts/components/ContentBlock.tsx | 15 +- packages/dev-tools-pages/ts/components/Footer.tsx | 90 +++++---- packages/dev-tools-pages/ts/components/Header.tsx | 46 ++--- packages/dev-tools-pages/ts/components/Hero.tsx | 27 ++- .../dev-tools-pages/ts/components/InlineCode.tsx | 9 +- packages/dev-tools-pages/ts/components/Intro.tsx | 48 +++-- packages/dev-tools-pages/ts/components/List.tsx | 27 ++- packages/dev-tools-pages/ts/components/Tabs.tsx | 51 +++--- packages/dev-tools-pages/ts/components/Trace.tsx | 204 +++++++++++---------- .../dev-tools-pages/ts/components/Typography.tsx | 1 + .../dev-tools-pages/ts/components/withContext.tsx | 23 --- packages/dev-tools-pages/ts/context/compiler.tsx | 2 +- packages/dev-tools-pages/ts/context/cov.tsx | 2 +- packages/dev-tools-pages/ts/context/index.tsx | 11 +- packages/dev-tools-pages/ts/context/profiler.tsx | 2 +- packages/dev-tools-pages/ts/context/trace.tsx | 2 +- packages/dev-tools-pages/ts/globalStyles.tsx | 21 +-- packages/dev-tools-pages/ts/globals.d.ts | 4 +- packages/dev-tools-pages/ts/highlight.tsx | 46 ++--- packages/dev-tools-pages/ts/pages/Compiler.tsx | 177 +++++++++--------- packages/dev-tools-pages/ts/pages/Cov.tsx | 186 +++++++++---------- packages/dev-tools-pages/ts/pages/Profiler.tsx | 181 +++++++++--------- packages/dev-tools-pages/ts/pages/Trace.tsx | 148 +++++++-------- packages/dev-tools-pages/ts/variables.tsx | 1 - 36 files changed, 844 insertions(+), 843 deletions(-) delete mode 100644 packages/dev-tools-pages/ts/components/withContext.tsx 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 ; -} +const CompilerAnimation: React.StatelessComponent<{}> = () => ( + +); -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 ; -} +const AnimationCov: React.StatelessComponent<{}> = () => ( + +); -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 ; -} +const AnimationProfiler: React.StatelessComponent<{}> = () => ( + +); -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 ; -} +const AnimationTrace: React.StatelessComponent<{}> = () => ( + +); -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 { - timeout = null as any; - constructor(props: AnimationProps) { - super(props); +class BaseAnimation extends React.PureComponent { + 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 { options={{ loop: true, autoplay: true, - animationData: animationData, + animationData, }} /> ); } + + 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 }; diff --git a/packages/dev-tools-pages/ts/components/Base.tsx b/packages/dev-tools-pages/ts/components/Base.tsx index 54340c9de..a1b066d85 100644 --- a/packages/dev-tools-pages/ts/components/Base.tsx +++ b/packages/dev-tools-pages/ts/components/Base.tsx @@ -1,24 +1,27 @@ import * as React from 'react'; +import { ThemeProvider } from 'styled-components'; -import ThemeContext from 'ts/context'; -import GlobalStyles from 'ts/globalStyles'; -import Header from 'ts/components/Header'; -import Footer from 'ts/components/Footer'; +import { Footer } from 'ts/components/Footer'; +import { Header } from 'ts/components/Header'; +import { ThemeContext } from 'ts/context'; +import { GlobalStyles } from 'ts/globalStyles'; interface BaseProps { context: any; children: React.ReactNode; } -function Base(props: BaseProps) { - return ( - - -
- {props.children} -