aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-tools-pages/ts/components
diff options
context:
space:
mode:
authorMegan Pearson <megan.e.pearson@gmail.com>2018-10-24 20:31:07 +0800
committerAugust Skare <post@augustskare.no>2018-10-25 19:13:00 +0800
commit9cf055c1596d8abce854fea8f4e209573d6df7c8 (patch)
tree7b8caf48a0c578358d0f8fe464e836ce5c69b389 /packages/dev-tools-pages/ts/components
parent16b515707823f7f60f641665a3a96b3092d881ee (diff)
downloaddexon-sol-tools-9cf055c1596d8abce854fea8f4e209573d6df7c8.tar
dexon-sol-tools-9cf055c1596d8abce854fea8f4e209573d6df7c8.tar.gz
dexon-sol-tools-9cf055c1596d8abce854fea8f4e209573d6df7c8.tar.bz2
dexon-sol-tools-9cf055c1596d8abce854fea8f4e209573d6df7c8.tar.lz
dexon-sol-tools-9cf055c1596d8abce854fea8f4e209573d6df7c8.tar.xz
dexon-sol-tools-9cf055c1596d8abce854fea8f4e209573d6df7c8.tar.zst
dexon-sol-tools-9cf055c1596d8abce854fea8f4e209573d6df7c8.zip
Add highlighter.js; basic styling for .diff classes; Start of code block in cov
Diffstat (limited to 'packages/dev-tools-pages/ts/components')
-rw-r--r--packages/dev-tools-pages/ts/components/Code.tsx32
1 files changed, 25 insertions, 7 deletions
diff --git a/packages/dev-tools-pages/ts/components/Code.tsx b/packages/dev-tools-pages/ts/components/Code.tsx
index 88cfba7f8..5a03e79ac 100644
--- a/packages/dev-tools-pages/ts/components/Code.tsx
+++ b/packages/dev-tools-pages/ts/components/Code.tsx
@@ -4,6 +4,8 @@ import styled from 'styled-components';
import { colors } from 'ts/variables';
import BaseButton from './Button';
+var highlight = require('highlighter')();
+
interface CodeProps {
children: React.ReactNode;
language?: string;
@@ -28,11 +30,11 @@ const Button = styled(BaseButton)`
const Base =
styled.div <
- CodeProps >
- `
+ CodeProps >
+ `
color: ${props => (props.language === undefined ? colors.white : 'inherit')};
background-color: ${props =>
- props.light ? 'rgba(255,255,255,.15)' : props.language === undefined ? colors.black : colors.lightGray};
+ props.light ? 'rgba(255,255,255,.15)' : props.language === undefined ? colors.black : colors.lightGray};
white-space: ${props => (props.language === undefined ? 'nowrap' : '')};
position: relative;
&:hover ${Button} {
@@ -41,10 +43,25 @@ const Base =
`;
const StyledCode = styled.code`
- padding: 1.5rem;
+ padding-top: 1.5rem;
+ padding-bottom: 1.5rem;
display: block;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
+
+
+ .diff-addition {
+ background-color: #d2e9e0;
+ padding: 0.3125rem;
+ display: inline-block;
+ width: 100%;
+ }
+ .diff-deletion {
+ background-color: #ebdcdc;
+ padding: 0.3125rem;
+ display: inline-block;
+ width: 100%;
+ }
`;
const StyledPre = styled.pre`
@@ -75,7 +92,8 @@ class Code extends React.Component<CodeProps, CodeState> {
if (language !== undefined) {
const { default: hljs } = await System.import(/* webpackChunkName: 'highlightjs' */ 'ts/highlight');
- const { value: hlCode } = hljs.highlight(language, children as string);
+
+ const hlCode = hljs(children as string, language);
this.setState({ hlCode });
}
}
@@ -105,8 +123,8 @@ class Code extends React.Component<CodeProps, CodeState> {
{this.state.hlCode !== undefined ? (
<StyledCode dangerouslySetInnerHTML={{ __html: this.state.hlCode }} />
) : (
- <StyledCode>{this.props.children}</StyledCode>
- )}
+ <StyledCode>{this.props.children}</StyledCode>
+ )}
</StyledPre>
{navigator.userAgent !== 'ReactSnap' ? <Button onClick={this.handleCopy}>Copy</Button> : null}
{!('clipboard' in navigator) ? (