-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update synthax highlight and remove package
- Loading branch information
Showing
8 changed files
with
610 additions
and
171 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import '../../register' | ||
import '@kadira/storybook/addons' | ||
import '@kadira/storybook-addon-options/register' | ||
import '../../register' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ | |
}, | ||
"dependencies": { | ||
"jsx-to-string": "^1.1.0", | ||
"prismjs": "^1.6.0", | ||
"react-copy-to-clipboard": "^4.3.1" | ||
} | ||
} |
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,60 @@ | ||
import React, { Component } from 'react' | ||
import Prism from './prism.min' | ||
|
||
import globalStyle from './css' | ||
|
||
const prismStyle = document.createElement('style') | ||
prismStyle.innerHTML = globalStyle | ||
document.body.appendChild(prismStyle) | ||
|
||
export default class JSX extends Component { | ||
constructor(props, ...args) { | ||
super(props, ...args) | ||
props.ob({ | ||
next: type => | ||
(type === 'jsx' | ||
? this.onAddJSX.bind(this) | ||
: this.setCurrent.bind(this)), | ||
}) | ||
|
||
this.state = {} | ||
this.stopListeningOnStory = () => this.setState({}) | ||
} | ||
|
||
setCurrent(kind, story) { | ||
this.setState({ current: { kind, story } }) | ||
} | ||
|
||
onAddJSX(kind, story, jsx) { | ||
const state = this.state | ||
|
||
if (typeof state[kind] === 'undefined') { | ||
state[kind] = {} | ||
} | ||
state[kind][story] = jsx | ||
this.setState(state) | ||
} | ||
render() { | ||
if ( | ||
typeof this.state.current !== 'undefined' && | ||
typeof this.state[this.state.current.kind] !== 'undefined' | ||
) { | ||
const current = this.state.current | ||
const code = this.state[current.kind][current.story] | ||
const jsx = code ? Prism.highlight(code, Prism.languages.jsx) : '' | ||
|
||
return ( | ||
<pre style={styles.pre} dangerouslySetInnerHTML={{ __html: jsx }} /> | ||
) | ||
} else { | ||
return <pre style={styles.pre} /> | ||
} | ||
} | ||
} | ||
|
||
const styles = { | ||
pre: { | ||
flex: 1, | ||
padding: '5px 15px', | ||
}, | ||
} |
Oops, something went wrong.