From 8d3e6f77b751b02bbca72e17ce9c86f54b3fbaac Mon Sep 17 00:00:00 2001 From: August Skare Date: Mon, 19 Nov 2018 15:13:52 +0100 Subject: cleand up code component --- packages/dev-tools-pages/ts/components/Code.tsx | 39 +++++++++++-------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'packages/dev-tools-pages/ts') diff --git a/packages/dev-tools-pages/ts/components/Code.tsx b/packages/dev-tools-pages/ts/components/Code.tsx index 72acc3865..8415f1179 100644 --- a/packages/dev-tools-pages/ts/components/Code.tsx +++ b/packages/dev-tools-pages/ts/components/Code.tsx @@ -68,7 +68,8 @@ const Base = : ``} `; -const StyledCodeDiff = styled(({ gutterLength, children, ...props }: any) => {children})` +const CodeDiff: React.StatelessComponent = ({ gutterLength, ...props }) => ; +const StyledCodeDiff = styled(CodeDiff)` ::before { content: ''; width: calc(0.75rem + ${props => props.gutterLength}ch); @@ -108,9 +109,12 @@ const StyledCodeDiff = styled(({ gutterLength, children, ...props }: any) => + ` margin: 0; - ${(props: { isDiff: boolean }) => + ${props => !props.isDiff ? ` padding: 1.5rem; @@ -129,15 +133,11 @@ const StyledCopyInput = styled.textarea` z-index: -1; `; -const CopyInput = StyledCopyInput as any; - class Code extends React.Component { public state: CodeState = {}; private readonly _code = React.createRef(); public componentDidMount(): void { - /* - * _onMountAsync is only setting state, so no point in handling the promise - */ + // _onMountAsync is only setting state, so no point in handling the promise // tslint:disable-next-line:no-floating-promises this._onMountAsync(); } @@ -145,26 +145,21 @@ class Code extends React.Component { const { language, isLight, isDiff, children, gutterLength, canCopy } = this.props; const { hlCode } = this.state; - let CodeComponent = 'code'; - let codeProps = {}; - if (isDiff) { - codeProps = { gutterLength }; - CodeComponent = StyledCodeDiff as any; - } - return ( - - {hlCode === undefined ? children : null} - + {hlCode === undefined ? ( + {children} + ) : ( + + )} {!('clipboard' in navigator) ? ( -