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
Showing
8 changed files
with
2,615 additions
and
77 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 |
---|---|---|
|
@@ -4,4 +4,7 @@ yarn-error.log | |
|
||
talk.mdx | ||
draft.mdx | ||
talk | ||
talk | ||
|
||
.docz | ||
/docs |
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,90 @@ | ||
--- | ||
name: CodeSurfer | ||
route: / | ||
--- | ||
|
||
import CodeSurfer from '../../packages/code-surfer/src/code-surfer' | ||
import { Playground, PropsTable } from 'docz' | ||
|
||
|
||
# CodeSurfer | ||
|
||
If you want to use CodeSurfer from a React App you are in the right place. If you want to use it from mdx-deck go to the [CodeSurfer home](https://codesurfer.js.org). | ||
|
||
## Install | ||
|
||
Add `code-surfer` to your dependencies: | ||
|
||
```sh | ||
$ yarn add code-surfer | ||
``` | ||
|
||
Also, if you want to show code directly from a file (and you are using webpack), add `raw-loader` as a dev dependency: | ||
```sh | ||
$ yarn add --dev raw-loader | ||
``` | ||
|
||
## Usage | ||
|
||
```jsx | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import CodeSurfer from "code-surfer"; | ||
|
||
const code = `...`; | ||
|
||
const App = () => ( | ||
<div style={{height: 100}}> | ||
<CodeSurfer code={code} step={{ lines: [1] }} /> | ||
</div> | ||
); | ||
|
||
const rootElement = document.getElementById("root"); | ||
ReactDOM.render(<App />, rootElement); | ||
``` | ||
|
||
Or load the code from a file with webpack: | ||
|
||
```jsx | ||
const App = () => ( | ||
<div style={{height: 100}}> | ||
<CodeSurfer code={require("!raw-loader!./my-code.js")} step={{ lines: [1] }} /> | ||
</div> | ||
); | ||
``` | ||
|
||
## Props | ||
|
||
<PropsTable of={CodeSurfer} /> | ||
|
||
## Playground | ||
|
||
<Playground> | ||
{() => { | ||
const code = [ | ||
"function myFunc() {", | ||
" this.myVar = 0;", | ||
" setTimeout(() => {", | ||
" this.myVar++;", | ||
" console.log(this.myVar) // 1", | ||
" }, 0);", | ||
"}" | ||
].join("\\n"); | ||
|
||
return ( | ||
<div style={{ height: '150px', background: '#222' }}> | ||
<CodeSurfer | ||
code={code} | ||
step={{ | ||
lines: [1, 7], | ||
range: [3, 5], | ||
tokens: { 2: [3, 4, 6] }, | ||
}} | ||
showNumbers | ||
dark | ||
/> | ||
</div> | ||
); | ||
}} | ||
</Playground> | ||
|
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,7 @@ | ||
export default { | ||
title: "CodeSurfer for React", | ||
src: "../..", | ||
files: "fixtures/react-docs/**/*.mdx", | ||
base: "/react-docs/", | ||
dest: "./dist" | ||
}; |
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 @@ | ||
{ | ||
"name": "react-docs-fixture", | ||
"version": "0.4.1", | ||
"author": "pomber", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"start": "docz dev", | ||
"build": "docz build" | ||
}, | ||
"dependencies": { | ||
"code-surfer": "^0.4.1", | ||
"prop-types": "^15.6.2", | ||
"react": "^16.4.2" | ||
}, | ||
"devDependencies": { | ||
"docz": "^0.11.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
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
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
Oops, something went wrong.