Skip to content

Commit 9cbab6b

Browse files
committed
Rework curl clipboard to be similar to swagger-api#5278 📋
1 parent 65aac3f commit 9cbab6b

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

src/core/components/curl.jsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
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"
4+
import { CopyToClipboard } from "react-copy-to-clipboard"
55
import {SyntaxHighlighter, styles} from "core/syntax-highlighting"
66

77
export default class Curl extends React.Component {
88
static propTypes = {
99
request: PropTypes.object.isRequired
1010
}
1111

12-
copy(curlCommand) {
13-
return () => copyToClipboard(curlCommand)
14-
}
15-
1612
render() {
1713
let { request } = this.props
1814
let curl = curlify(request)
1915

2016
return (
21-
<div>
22-
<h4>Curl <i onClick={this.copy(curl)}>(copyCommand)</i></h4>
17+
<div className="curl-command">
18+
<h4>Curl</h4>
19+
<div className="copy-to-clipboard">
20+
<CopyToClipboard text={curl}><button/></CopyToClipboard>
21+
</div>
2322
<div>
24-
<SyntaxHighlighter language="bash" className="curl" style={styles.agate}>{curl}</SyntaxHighlighter>
23+
<SyntaxHighlighter language="bash" className="curl microlight" style={styles.agate}>{curl}</SyntaxHighlighter>
2524
</div>
2625
</div>
2726
)

src/core/copy-to-clipboard.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/style/_buttons.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,17 @@ button
174174
background: url("data:image/svg+xml, <svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' aria-hidden='true'><path fill='#ffffff' fill-rule='evenodd' d='M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z'></path></svg>") center center no-repeat;
175175
}
176176
}
177+
178+
// overrides for smaller copy button for curl command
179+
.curl-command .copy-to-clipboard
180+
{
181+
bottom: 5px;
182+
right: 10px;
183+
width: 20px;
184+
height: 20px;
185+
button
186+
{
187+
padding-left: 18px;
188+
height: 18px
189+
}
190+
}

src/style/_layout.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,9 @@
664664
min-height: 6em;
665665
}
666666
}
667+
.curl-command {
668+
position: relative;
669+
}
667670

668671
.download-contents {
669672
position: absolute;

0 commit comments

Comments
 (0)