Skip to content

Commit 408dcdb

Browse files
AdrieanKhisbetim-lai
authored andcommitted
Rework swagger-api#5259 syntax highlighting with react-syntax-highlight 🌈
1 parent 9e294fb commit 408dcdb

File tree

8 files changed

+248
-191
lines changed

8 files changed

+248
-191
lines changed

package-lock.json

Lines changed: 185 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"react-inspector": "^2.3.0",
7878
"react-motion": "^0.5.2",
7979
"react-redux": "^4.x.x",
80+
"react-syntax-highlighter": "=12.2.1",
8081
"redux": "^3.x.x",
8182
"redux-immutable": "3.1.0",
8283
"remarkable": "^2.0.1",

src/core/components/curl.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from "react"
22
import PropTypes from "prop-types"
33
import curlify from "core/curlify"
4+
import {copyToClipboard} from "core/copy-to-clipboard"
5+
import {SyntaxHighlighter, styles} from "core/syntax-highlighting"
46

57
export default class Curl extends React.Component {
68
static propTypes = {
79
request: PropTypes.object.isRequired
810
}
911

10-
handleFocus(e) {
11-
e.target.select()
12-
document.execCommand("copy")
12+
copy(curlCommand) {
13+
return () => copyToClipboard(curlCommand)
1314
}
1415

1516
render() {
@@ -18,9 +19,9 @@ export default class Curl extends React.Component {
1819

1920
return (
2021
<div>
21-
<h4>Curl</h4>
22-
<div className="copy-paste">
23-
<textarea onFocus={this.handleFocus} readOnly={true} className="curl" value={curl}></textarea>
22+
<h4>Curl <i onClick={this.copy(curl)}>(copyCommand)</i></h4>
23+
<div>
24+
<SyntaxHighlighter language="bash" className="curl" style={styles.agate}>{curl}</SyntaxHighlighter>
2425
</div>
2526
</div>
2627
)

0 commit comments

Comments
 (0)