aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/export-text-container/export-text-container.component.js
blob: c2546fa9b1d6a9129f786809c6ce34b27fb492e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { Component } = require('react')
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const copyToClipboard = require('copy-to-clipboard')
const { exportAsFile } = require('../../util')

class ExportTextContainer extends Component {
  render () {
    const { text = '', filename = '' } = this.props
    const { t } = this.context

    return (
      h('.export-text-container', [
        h('.export-text-container__text-container', [
          h('.export-text-container__text', text),
        ]),
        h('.export-text-container__buttons-container', [
          h('.export-text-container__button.export-text-container__button--copy', {
            onClick: () => copyToClipboard(text),
          }, [
            h('img', { src: 'images/copy-to-clipboard.svg' }),
            h('.export-text-container__button-text', t('copyToClipboard')),
          ]),
          h('.export-text-container__button', {
            onClick: () => exportAsFile(filename, text),
          }, [
            h('img', { src: 'images/download.svg' }),
            h('.export-text-container__button-text', t('saveAsCsvFile')),
          ]),
        ]),
      ])
    )
  }
}

ExportTextContainer.propTypes = {
  text: PropTypes.string,
  filename: PropTypes.string,
}

ExportTextContainer.contextTypes = {
  t: PropTypes.func,
}

module.exports = ExportTextContainer