// @flow
import React from 'react'
import PrintIcon from '@material-ui/icons/Print'
import { defineMessages, FormattedMessage } from 'react-intl'

import ToolbarButton from '../internal/ToolbarButton'

const messages = defineMessages({
  // Button label to print a report
  print: 'Print'
})

type Props = {
  disabled: boolean,
  url: string
}

class PrintButton extends React.Component<Props, State> {

  download () {
    var anchor = document.createElement('a')
    anchor.href = this.url
    anchor.download = 'report.pdf'
    anchor.click()
  }

  render () {
    const { disabled } = this.props

    return (
      <React.Fragment>
        <ToolbarButton onClick={this.download.bind(this)} disabled={disabled}>
          <PrintIcon />
          <FormattedMessage {...messages.print} />
        </ToolbarButton>
      </React.Fragment>
    )
  }
}

export default PrintButton

// @flow
import React from 'react'
import PrintIcon from '@material-ui/icons/Print'
import { defineMessages, FormattedMessage } from 'react-intl'

import ToolbarButton from '../internal/ToolbarButton'

const messages = defineMessages({
  // Button label to print a report
  print: 'Print'
})

type Props = {
  disabled: boolean,
  url: string
}

const PrintButton = ({ url, disabled }: Props) => (
  <React.Fragment>
    <ToolbarButton
      component='a'
      href={url}
      download='report.pdf'
      disabled={disabled}
    >
      <PrintIcon />
      <FormattedMessage {...messages.print} />
    </ToolbarButton>
  </React.Fragment>
)

export default PrintButton

Fix print button (still downloads, does not print)
fix: Fix print button (still downloads, does not print)

PrintButton was using `this.url` instead of `this.props.url`.
However also removed some unnecessary code in this component
