ant-design/site/theme/template/IconSet/CopyableIcon.jsx

33 lines
802 B
React
Raw Normal View History

2016-03-31 17:46:35 +08:00
import React from 'react';
import CopyToClipboard from 'react-copy-to-clipboard';
2016-04-11 10:12:48 +08:00
import { Icon } from 'antd';
2016-03-31 17:46:35 +08:00
export default class CopyableIcon extends React.Component {
constructor(props) {
super(props);
this.state = {
2016-05-11 09:32:33 +08:00
justCopied: false,
2016-03-31 17:46:35 +08:00
};
}
onCopied = () => {
this.setState({ justCopied: true }, () => {
setTimeout(() => {
this.setState({ justCopied: false });
2017-03-10 18:04:14 +08:00
}, 2000);
2016-03-31 17:46:35 +08:00
});
}
render() {
const text = `<Icon type="${this.props.type}" />`;
return (
<CopyToClipboard text={text} onCopy={this.onCopied}>
<li className={this.state.justCopied ? 'copied' : ''}>
<Icon type={this.props.type} />
<span className="anticon-class">{this.props.type}</span>
</li>
</CopyToClipboard>
);
}
}