Skip to content

Commit

Permalink
add CodeReviewCard and corresponding story
Browse files Browse the repository at this point in the history
  • Loading branch information
glenwid committed Mar 29, 2021
1 parent 8ef6b69 commit 8aa200c
Show file tree
Hide file tree
Showing 19 changed files with 716 additions and 460 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@types/node": "^12.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"antd": "^4.15.0",
"less": "^4.1.1",
"prism-react-renderer": "^1.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
43 changes: 5 additions & 38 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,5 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.code {
padding: 200px;
display: flex;
justify-content: center;
}
9 changes: 0 additions & 9 deletions src/App.test.tsx

This file was deleted.

15 changes: 13 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import React from 'react';
import './App.css';
import Basic from "./components/Basic";
import CodeReviewCard from "./components/CodeReviewCard";

const exampleCode = `
(function someDemo() {
var test = "Hello World!";
console.log(test);
})();
return () => <App />;
`.trim();

function App() {
return (
<Basic />
<div className={"code"}>
<CodeReviewCard code={exampleCode} language={"jsx"}/>
</div>
);
}

Expand Down
31 changes: 0 additions & 31 deletions src/components/Basic.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions src/components/CodeReview.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.codeReview {
display: flex;
justify-content: center;
width: 80%;
}
67 changes: 67 additions & 0 deletions src/components/CodeReview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, {FunctionComponent} from "react";
import { Pre, Line, LineNo, LineContent } from "./styles"
import Highlight, { defaultProps } from "prism-react-renderer";
import theme from "prism-react-renderer/themes/nightOwl";
import "./CodeReview.less";

type Language =
| "markup"
| "bash"
| "clike"
| "c"
| "cpp"
| "css"
| "javascript"
| "jsx"
| "coffeescript"
| "actionscript"
| "css-extr"
| "diff"
| "git"
| "go"
| "graphql"
| "handlebars"
| "json"
| "less"
| "makefile"
| "markdown"
| "objectivec"
| "ocaml"
| "python"
| "reason"
| "sass"
| "scss"
| "sql"
| "stylus"
| "tsx"
| "typescript"
| "wasm"
| "yaml";

type CodeReviewProps = {
code: string
language: Language
}

export const CodeReview: FunctionComponent<CodeReviewProps> = ({ code, language }) => {
return (
<Highlight {...defaultProps} theme={theme} code={code} language={language}>
{({ className, style, tokens, getLineProps, getTokenProps }) => (
<Pre className={className} style={style}>
{tokens.map((line, i) => (
<Line key={i} {...getLineProps({ line, key: i })}>
<LineNo>{i + 1}</LineNo>
<LineContent>
{line.map((token, key) => (
<span key={key} {...getTokenProps({ token, key })} />
))}
</LineContent>
</Line>
))}
</Pre>
)}
</Highlight>
)
}

export default CodeReview;
51 changes: 51 additions & 0 deletions src/components/CodeReviewCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from "react";
import {Card} from "antd";
import CodeReview from "./CodeReview";

type Language =
| "markup"
| "bash"
| "clike"
| "c"
| "cpp"
| "css"
| "javascript"
| "jsx"
| "coffeescript"
| "actionscript"
| "css-extr"
| "diff"
| "git"
| "go"
| "graphql"
| "handlebars"
| "json"
| "less"
| "makefile"
| "markdown"
| "objectivec"
| "ocaml"
| "python"
| "reason"
| "sass"
| "scss"
| "sql"
| "stylus"
| "tsx"
| "typescript"
| "wasm"
| "yaml";

export interface CodeReviewCardProps {
code: string;
language: Language;
}
export const CodeReviewCard: React.FC<CodeReviewCardProps> = ({ code, language }) => {
return (
<Card style={{ width: 500 }}>
<CodeReview code={code} language={language}/>
</Card>
)
}

export default CodeReviewCard;
38 changes: 0 additions & 38 deletions src/stories/Button.stories.tsx

This file was deleted.

48 changes: 0 additions & 48 deletions src/stories/Button.tsx

This file was deleted.

26 changes: 26 additions & 0 deletions src/stories/CodeReviewCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import {CodeReviewCard, CodeReviewCardProps} from "../components/CodeReviewCard";
import { Story, Meta } from '@storybook/react/types-6-0';


export default {
componenet: CodeReviewCard,
title: 'CodeReviewCard'
} as Meta;

const Template: Story<CodeReviewCardProps> = (args) => <CodeReviewCard {...args} />;

const jsxCode = `
(function someDemo() {
var test = "Hello World!";
console.log(test);
})();
return () => <App />;
`.trim();

export const Default = Template.bind({});
Default.args = {
code: jsxCode,
language: "jsx"
}
20 changes: 0 additions & 20 deletions src/stories/Header.stories.tsx

This file was deleted.

Loading

0 comments on commit 8aa200c

Please sign in to comment.