-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ef4d421
Showing
26 changed files
with
23,064 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build/ | ||
dist/ | ||
node_modules/ | ||
.snapshots/ | ||
*.min.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"extends": [ | ||
"standard", | ||
"standard-react", | ||
"plugin:prettier/recommended", | ||
"prettier/standard", | ||
"prettier/react", | ||
"plugin:@typescript-eslint/eslint-recommended" | ||
], | ||
"env": { | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"ecmaFeatures": { | ||
"legacyDecorators": true, | ||
"jsx": true | ||
} | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "16" | ||
} | ||
}, | ||
"rules": { | ||
"space-before-function-paren": 0, | ||
"react/prop-types": 0, | ||
"react/jsx-handler-names": 0, | ||
"react/jsx-fragments": 0, | ||
"react/no-unused-prop-types": 0, | ||
"import/export": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# dependencies | ||
node_modules | ||
|
||
# builds | ||
build | ||
dist | ||
.rpt2_cache | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"singleQuote": true, | ||
"jsxSingleQuote": true, | ||
"semi": false, | ||
"tabWidth": 2, | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": false, | ||
"arrowParens": "always", | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 12 | ||
- 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# react-extensible-code-viewer | ||
|
||
> A simple and extensible codeviewer component for react | ||
[](https://www.npmjs.com/package/react-extensible-code-viewer) [](https://standardjs.com) | ||
|
||
## Install | ||
|
||
```bash | ||
npm install --save react-extensible-code-viewer | ||
``` | ||
|
||
## Usage | ||
|
||
```tsx | ||
import React, { Component } from 'react' | ||
|
||
import { CodeViewer } from 'react-extensible-code-viewer' | ||
import 'react-extensible-code-viewer/dist/index.css' | ||
|
||
class Example extends Component { | ||
render() { | ||
return <MyComponent /> | ||
} | ||
} | ||
``` | ||
|
||
## License | ||
|
||
MIT © [JoseRenan](https://github.com/JoseRenan) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This example was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
|
||
It is linked to the react-extensible-code-viewer package in the parent directory for development purposes. | ||
|
||
You can run `yarn install` and then `yarn start` to test your package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "react-extensible-code-viewer-example", | ||
"homepage": "https://JoseRenan.github.io/react-extensible-code-viewer", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"react": "link:../node_modules/react", | ||
"react-dom": "link:../node_modules/react-dom", | ||
"react-extensible-code-viewer": "link:..", | ||
"react-scripts": "link:../node_modules/react-scripts" | ||
}, | ||
"scripts": { | ||
"start": "node ../node_modules/react-scripts/bin/react-scripts.js start", | ||
"build": "node ../node_modules/react-scripts/bin/react-scripts.js build", | ||
"test": "node ../node_modules/react-scripts/bin/react-scripts.js test", | ||
"eject": "node ../node_modules/react-scripts/bin/react-scripts.js eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
], | ||
"devDependencies": { | ||
"tailwindcss": "^1.4.6" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1, shrink-to-fit=no" | ||
/> | ||
<meta name="theme-color" content="#000000" /> | ||
|
||
<!-- | ||
manifest.json provides metadata used when your web app is added to the | ||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
|
||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>react-extensible-code-viewer</title> | ||
</head> | ||
|
||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
|
||
<div id="root"></div> | ||
|
||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"short_name": "react-extensible-code-viewer", | ||
"name": "react-extensible-code-viewer", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import React, { useState } from 'react' | ||
|
||
import { CodeViewer } from 'react-extensible-code-viewer' | ||
import 'react-extensible-code-viewer/dist/index.css' | ||
|
||
const code = `public class Main { | ||
private int c = 5; | ||
public static void main(String args[]) { | ||
int a = 1; | ||
int b = 2; | ||
System.out.println(a + b + c + 1); | ||
Main.sayHello() | ||
} | ||
public static void sayHello() { | ||
System.out.println("Hello 🥺") | ||
} | ||
}` | ||
|
||
const AddCommentButton = ({ onClick }) => ( | ||
<div className='add-comment' onClick={onClick}> | ||
+ | ||
</div> | ||
) | ||
|
||
const CommentInput = () => ( | ||
<div className='comment-input'> | ||
<textarea style={{ width: '100%' }} /> | ||
<div> | ||
<button>Cancel</button> | ||
<button>Comment</button> | ||
</div> | ||
</div> | ||
) | ||
|
||
const CodeLine = ({ lineNumber, children }) => { | ||
const [showAddComment, setShowAddComment] = useState(false) | ||
const [showCommentInput, setShowCommentInput] = useState(false) | ||
return ( | ||
<React.Fragment> | ||
<span | ||
style={{ display: 'flex' }} | ||
onMouseEnter={() => setShowAddComment(true)} | ||
onMouseLeave={() => setShowAddComment(false)} | ||
> | ||
<span className='line-number'>{lineNumber}.</span> | ||
<span style={{ width: '1rem' }}> | ||
{showAddComment ? ( | ||
<AddCommentButton | ||
onClick={() => setShowCommentInput(!showCommentInput)} | ||
/> | ||
) : null} | ||
</span> | ||
{children} | ||
</span> | ||
{showCommentInput ? <CommentInput /> : null} | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
const App = () => { | ||
return ( | ||
<> | ||
<h1>React Extensible Code Viewer Example</h1> | ||
<h3>Result:</h3> | ||
<CodeViewer code={code} language='java' /> | ||
<h3>Code:</h3> | ||
<CodeViewer | ||
code={`import React, { useState } from 'react' | ||
import { CodeViewer } from 'react-extensible-code-viewer' | ||
import 'react-extensible-code-viewer/dist/index.css' | ||
export const App = () => <CodeViewer code={code} language='java' />`} | ||
language='javascript' | ||
/> | ||
|
||
<h1> | ||
Custom example with review comments (hover a code line and click on the | ||
+) | ||
</h1> | ||
<h3>Result:</h3> | ||
<CodeViewer | ||
code={code} | ||
language='java' | ||
line={(props) => <CodeLine {...props} />} | ||
/> | ||
<h3>Code:</h3> | ||
<CodeViewer | ||
code={`import React, { useState } from 'react' | ||
import { CodeViewer } from 'react-extensible-code-viewer' | ||
import 'react-extensible-code-viewer/dist/index.css' | ||
const AddCommentButton = ({ onClick }) => ( | ||
<div className='add-comment' onClick={onClick}> | ||
+ | ||
</div> | ||
) | ||
const CommentInput = () => ( | ||
<div className='comment-input'> | ||
<textarea style={{ width: '100%' }} /> | ||
<div> | ||
<button>Cancel</button> | ||
<button>Comment</button> | ||
</div> | ||
</div> | ||
) | ||
const CodeLine = ({ lineNumber, children }) => { | ||
const [showAddComment, setShowAddComment] = useState(false) | ||
const [showCommentInput, setShowCommentInput] = useState(false) | ||
return ( | ||
<React.Fragment> | ||
<span | ||
style={{ display: 'flex' }} | ||
onMouseEnter={() => setShowAddComment(true)} | ||
onMouseLeave={() => setShowAddComment(false)} | ||
> | ||
<span className='line-number'>{lineNumber}.</span> | ||
<span style={{ width: '1rem' }}> | ||
{showAddComment ? ( | ||
<AddCommentButton | ||
onClick={() => setShowCommentInput(!showCommentInput)} | ||
/> | ||
) : null} | ||
</span> | ||
{children} | ||
</span> | ||
{showCommentInput ? <CommentInput /> : null} | ||
</React.Fragment> | ||
) | ||
} | ||
export const App = () => ( | ||
<CodeViewer | ||
code={code} | ||
language='java' | ||
line={(props) => <CodeLine {...props}/>} | ||
/> | ||
)`} | ||
language='jsx' | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from './App' | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div') | ||
ReactDOM.render(<App />, div) | ||
ReactDOM.unmountComponentAtNode(div) | ||
}) |
Oops, something went wrong.