Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from i3thuan5/khoh鈕仔愛換逝
Browse files Browse the repository at this point in the history
Khoh鈕仔愛換逝
  • Loading branch information
Wenli Tsai authored May 30, 2019
2 parents 423ffea + 5abf548 commit 57e4288
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo/Demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Demo extends React.Component {

<section>
<h3>CopyButton</h3>
<p><CopyButton 複製內容="Hello copied!"/>按我複製</p>
<p><CopyButton 複製內容={"Hello world~\ncopied!"}/>按我複製</p>
</section>

<section>
Expand Down
15 changes: 9 additions & 6 deletions src/component/CopyButton.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import React from 'react';
import PropTypes from 'prop-types';

class CopyButton extends React.Component {
class CopyButton extends React.PureComponent {

copy() {
const { 複製內容 } = this.props;
const textField = document.createElement("textarea");
textField.innerText = 複製內容;//.toString().replace(/ --/g, "--");
textField.value = 複製內容;
document.body.appendChild(textField);
textField.select();
document.execCommand("copy");
textField.remove();
}

render() {
const { 按鈕名 } = this.props;
return (
<button onClick={this.copy.bind(this)}
className='ui icon button'>
<i className='icon-docs'></i>
{按鈕名}
className={this.props.css}>
<i className='icon-docs'/>
{this.props.按鈕名}
</button>
);
}
}

CopyButton.defaultProps = {
css: 'ui icon button',
按鈕名: ''
}

CopyButton.propTypes = {
複製內容: PropTypes.string.isRequired,
Expand Down

0 comments on commit 57e4288

Please sign in to comment.