This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from readmeio/enhancement/copy-code-button
Add a button to copy code samples
- Loading branch information
Showing
9 changed files
with
9,528 additions
and
982 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const { CopyToClipboard } = require('react-copy-to-clipboard'); | ||
|
||
class CopyCode extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
copied: false, | ||
}; | ||
|
||
this.onCopy = this.onCopy.bind(this); | ||
} | ||
|
||
onCopy() { | ||
this.setState({ copied: true }); | ||
setTimeout(() => { | ||
this.setState({ copied: false }); | ||
}, 1000); | ||
} | ||
|
||
render() { | ||
return ( | ||
<CopyToClipboard text={this.props.code} onCopy={this.onCopy}> | ||
<button className="copy-code-button main_background"> | ||
{this.state.copied ? <span>Copied</span> : <span>Copy</span>} | ||
</button> | ||
</CopyToClipboard> | ||
); | ||
} | ||
} | ||
|
||
module.exports = CopyCode; | ||
|
||
CopyCode.propTypes = { | ||
code: PropTypes.string.isRequired, | ||
}; |
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