1- import React from 'react' ;
2- import classnames from 'classnames' ;
3- import { Paper , IconButton , Menu , MenuItem , withStyles } from "@material-ui/core" ;
4- import { MoreVert as MoreIcon } from '@material-ui/icons' ;
1+ import React from "react" ;
2+ import classnames from "classnames" ;
3+ import {
4+ Paper ,
5+ IconButton ,
6+ Menu ,
7+ MenuItem ,
8+ withStyles
9+ } from "@material-ui/core" ;
10+ import { MoreVert as MoreIcon } from "@material-ui/icons" ;
511import Typography from "@material-ui/core/es/Typography/Typography" ;
612
7- const Widget = ( { classes, children, title, noBodyPadding, bodyClass, className, disableWidgetMenu, ...props } ) => (
13+ const Widget = ( {
14+ classes,
15+ children,
16+ title,
17+ noBodyPadding,
18+ bodyClass,
19+ className,
20+ disableWidgetMenu,
21+ ...props
22+ } ) => (
823 < div className = { classes . widgetWrapper } >
924 < Paper className = { classes . paper } classes = { { root : classes . widgetRoot } } >
1025 < div className = { classes . widgetHeader } >
11- < Typography variant = "headline" color = "textSecondary" > { title } </ Typography >
12- { ! disableWidgetMenu && (
13- < IconButton
14- color = "primary"
15- classes = { { root : classes . moreButton } }
16- aria-owns = "widget-menu"
17- aria-haspopup = "true"
18- onClick = { ( ) => props . setMoreMenuOpen ( true ) }
19- buttonRef = { props . setMoreButtonRef }
20- >
21- < MoreIcon />
22- </ IconButton >
26+ { props . header ? (
27+ props . header
28+ ) : (
29+ < React . Fragment >
30+ < Typography variant = "headline" color = "textSecondary" >
31+ { title }
32+ </ Typography >
33+ { ! disableWidgetMenu && (
34+ < IconButton
35+ color = "primary"
36+ classes = { { root : classes . moreButton } }
37+ aria-owns = "widget-menu"
38+ aria-haspopup = "true"
39+ onClick = { ( ) => props . setMoreMenuOpen ( true ) }
40+ buttonRef = { props . setMoreButtonRef }
41+ >
42+ < MoreIcon />
43+ </ IconButton >
44+ ) }
45+ </ React . Fragment >
2346 ) }
2447 </ div >
25- < div className = { classnames ( classes . widgetBody , { [ classes . noPadding ] : noBodyPadding , [ bodyClass ] : bodyClass } ) } >
48+ < div
49+ className = { classnames ( classes . widgetBody , {
50+ [ classes . noPadding ] : noBodyPadding ,
51+ [ bodyClass ] : bodyClass
52+ } ) }
53+ >
2654 { children }
2755 </ div >
2856 </ Paper >
@@ -33,54 +61,62 @@ const Widget = ({ classes, children, title, noBodyPadding, bodyClass, className,
3361 onClose = { ( ) => props . setMoreMenuOpen ( false ) }
3462 disableAutoFocusItem
3563 >
36- < MenuItem > < Typography > Edit</ Typography > </ MenuItem >
37- < MenuItem > < Typography > Copy</ Typography > </ MenuItem >
38- < MenuItem > < Typography > Delete</ Typography > </ MenuItem >
39- < MenuItem > < Typography > Print</ Typography > </ MenuItem >
64+ < MenuItem >
65+ < Typography > Edit</ Typography >
66+ </ MenuItem >
67+ < MenuItem >
68+ < Typography > Copy</ Typography >
69+ </ MenuItem >
70+ < MenuItem >
71+ < Typography > Delete</ Typography >
72+ </ MenuItem >
73+ < MenuItem >
74+ < Typography > Print</ Typography >
75+ </ MenuItem >
4076 </ Menu >
4177 </ div >
4278) ;
4379
4480const styles = theme => ( {
4581 widgetWrapper : {
46- display : ' flex' ,
47- minHeight : ' 100%' ,
82+ display : " flex" ,
83+ minHeight : " 100%"
4884 } ,
4985 widgetHeader : {
5086 padding : theme . spacing . unit * 3 ,
5187 paddingBottom : theme . spacing . unit ,
52- display : ' flex' ,
53- justifyContent : ' space-between' ,
54- alignItems : ' center' ,
88+ display : " flex" ,
89+ justifyContent : " space-between" ,
90+ alignItems : " center"
5591 } ,
5692 widgetRoot : {
57- boxShadow : theme . customShadows . widget ,
93+ boxShadow : theme . customShadows . widget
5894 } ,
5995 widgetBody : {
6096 paddingBottom : theme . spacing . unit * 3 ,
6197 paddingRight : theme . spacing . unit * 3 ,
62- paddingLeft : theme . spacing . unit * 3 ,
98+ paddingLeft : theme . spacing . unit * 3
6399 } ,
64100 noPadding : {
65- padding : 0 ,
101+ padding : 0
66102 } ,
67103 paper : {
68- display : ' flex' ,
69- flexDirection : ' column' ,
104+ display : " flex" ,
105+ flexDirection : " column" ,
70106 flexGrow : 1 ,
71- overflow : ' hidden' ,
107+ overflow : " hidden"
72108 } ,
73109 moreButton : {
74110 margin : - theme . spacing . unit ,
75111 padding : 0 ,
76112 width : 40 ,
77113 height : 40 ,
78114 color : theme . palette . text . hint ,
79- ' &:hover' : {
115+ " &:hover" : {
80116 backgroundColor : theme . palette . primary . main ,
81- color : ' rgba(255, 255, 255, 0.35)' ,
82- } ,
83- } ,
117+ color : " rgba(255, 255, 255, 0.35)"
118+ }
119+ }
84120} ) ;
85121
86122export default withStyles ( styles , { withTheme : true } ) ( Widget ) ;
0 commit comments