22import React from 'react'
33import PrintIcon from '@material-ui/icons/Print'
44import Button from '@material-ui/core/Button'
5- import Dialog from '@material-ui/core/Dialog'
6- import DialogActions from '@material-ui/core/DialogActions'
7- import DialogContent from '@material-ui/core/DialogContent'
8- import DialogTitle from '@material-ui/core/DialogTitle'
95import InputLabel from '@material-ui/core/InputLabel'
106import Input from '@material-ui/core/Input'
117import FormControl from '@material-ui/core/FormControl'
@@ -33,15 +29,7 @@ type Props = {
3329 paperSize : PaperSize
3430}
3531
36- type State = {
37- dialogOpen : boolean
38- }
39-
4032class PrintButton extends React . Component < Props , State > {
41- state = {
42- dialogOpen : false
43- }
44-
4533 handleKeyDown = ( event : SyntheticKeyboardEvent < HTMLElement > ) => {
4634 if ( ! ( event . key === 'p' && event . metaKey ) ) return
4735 event . preventDefault ( )
@@ -50,70 +38,22 @@ class PrintButton extends React.Component<Props, State> {
5038
5139 handleKeyUp = ( event : SyntheticKeyboardEvent < HTMLElement > ) => {
5240 window. removeEventListener ( 'keyup' , this . handleKeyUp )
53- if ( this . state . dialogOpen ) {
54- this . props . requestPrint ( )
55- } else {
56- this. openDialog ( )
57- }
41+ this . props . requestPrint ( )
5842 }
5943
60- openDialog = ( ) => this . setState ( { dialogOpen : true } )
61-
62- closeDialog = ( ) => this . setState ( { dialogOpen : false } )
63-
6444 handleChangePaperSize = ( e : SyntheticInputEvent < HTMLSelectElement > ) => {
6545 // $FlowFixMe - Flow doesn't recognize value being one of options
6646 const value : PaperSize = e . currentTarget . value
6747 this . props . changePaperSize ( value )
6848 }
6949
7050 render ( ) {
71- const { requestPrint , paperSize } = this . props
72- const { dialogOpen } = this . state
7351 return (
7452 < React . Fragment >
7553 < ToolbarButton onClick = { this . openDialog } >
7654 < PrintIcon />
7755 < FormattedMessage { ...messages . print } />
7856 </ ToolbarButton >
79- < Dialog
80- open = { dialogOpen }
81- onClose = { this . closeDialog }
82- fullWidth
83- maxWidth = "xs"
84- className = "d-print-none" >
85- < DialogTitle >
86- < FormattedMessage { ...messages . dialogTitle } />
87- </ DialogTitle >
88- < DialogContent >
89- < FormControl >
90- < InputLabel htmlFor = "paper-size" >
91- < FormattedMessage { ...messages . paperSize } />
92- </ InputLabel >
93- < Select
94- native
95- value = { paperSize }
96- onChange = { this . handleChangePaperSize }
97- input = { < Input id = "paper-size" /> } >
98- < option value = "a4" > A4 (210mm x 297mm)</ option >
99- < option value = "letter" > Letter (8.5" x 11")</ option >
100- </ Select >
101- </ FormControl >
102- </ DialogContent >
103- < DialogActions >
104- < Button onClick = { this . closeDialog } color = "primary" >
105- < FormattedMessage { ...messages . close } />
106- </ Button >
107- < Button
108- onClick = { ( ) => {
109- this . closeDialog ( )
110- requestPrint ( )
111- } }
112- color = "primary" >
113- < FormattedMessage { ...messages . print } />
114- </ Button >
115- </ DialogActions >
116- </ Dialog >
11757 </ React . Fragment >
11858 )
11959 }
0 commit comments