Manual Reference Source

basic/CopyToClipboardButton.js

  1. /**
  2. * Created by jakubniezgoda on 25/05/2018.
  3. */
  4.  
  5. import PropTypes from 'prop-types';
  6. import { Component } from 'react';
  7. import { CopyToClipboard } from 'react-copy-to-clipboard';
  8. import { Button, Icon } from 'semantic-ui-react';
  9.  
  10. /**
  11. * CopyToClipboardButton component shows a simple copy icon and on click action it copies prop - text to clipboard
  12. *
  13. * ## Access
  14. * `Stage.Basic.CopyToClipboardButton`
  15. *
  16. * ## Usage
  17. *
  18. * ![CopyToClipboardButton](manual/asset/CopyToClipboardButton_0.png)
  19. * ```
  20. * <CopyToClipboardButton text='Text to copy' content='Copy ID' />
  21. *```
  22. */
  23. export default class CopyToClipboardButton extends Component {
  24. constructor(props, context) {
  25. super(props, context);
  26. }
  27.  
  28. /**
  29. * @property {string} [text=''] Text to be copied to clipboard
  30. * @property {string} [content=''] Button label
  31. * @property {string} [className=''] Class name to be added to button component
  32. */
  33. static propTypes = {
  34. text: PropTypes.string,
  35. content: PropTypes.string,
  36. className: PropTypes.string
  37. };
  38.  
  39. static defaultProps = {
  40. text: '',
  41. content: '',
  42. className: ''
  43. };
  44.  
  45. render() {
  46. return (
  47. <CopyToClipboard text={this.props.text}>
  48. {this.props.content ? (
  49. <Button
  50. animated="vertical"
  51. basic
  52. className={this.props.className}
  53. onClick={event => event.stopPropagation()}
  54. >
  55. <Button.Content visible>{this.props.content}</Button.Content>
  56. <Button.Content hidden>
  57. <Icon name="copy" />
  58. </Button.Content>
  59. </Button>
  60. ) : (
  61. <Button
  62. basic
  63. compact
  64. icon="copy"
  65. className={this.props.className}
  66. onClick={event => event.stopPropagation()}
  67. />
  68. )}
  69. </CopyToClipboard>
  70. );
  71. }
  72. }