@@ -8,12 +8,16 @@ import CloseIcon from '@material-ui/icons/Close';
8
8
import TextField from '@material-ui/core/TextField' ;
9
9
import GetAppIcon from '@material-ui/icons/GetApp' ;
10
10
import FilterNoneOutlinedIcon from '@material-ui/icons/FilterNoneOutlined' ;
11
+ import Menu from '@material-ui/core/Menu' ;
12
+ import MenuItem from '@material-ui/core/MenuItem' ;
11
13
import useClipboard from "react-use-clipboard" ;
12
14
import { handleShareToTwitterClick } from "../../utils" ;
13
- import { Snackbar , makeStyles } from "@material-ui/core" ;
15
+ import Snackbar from '@material-ui/core/Snackbar' ;
16
+ import { makeStyles } from "@material-ui/core/styles" ;
14
17
import Alert from "@material-ui/lab/Alert" ;
15
18
import DialogContentText from '@material-ui/core/DialogContentText' ;
16
19
import moment from "moment" ;
20
+ import { saveSvgAsPng } from "save-svg-png-ext" ;
17
21
18
22
export const DialogBox = ( { params = "" } ) => {
19
23
const [ showNotice , setShowNotice ] = React . useState ( false ) ;
@@ -48,6 +52,15 @@ export const DialogBox = ({ params = "" }) => {
48
52
const [ , setCopy ] = useClipboard ( `${ SHARE_BASE_URL } ${ params } ` , { successDuration : 3000 } ) ;
49
53
const embedCode = `<iframe style={{ width: "100%", height: "auto" , minWidth: "600px", minHeight: "1000px" }} src="${ SHARE_BASE_URL } ${ params } " frameBorder="0"></iframe>`
50
54
const [ , setEmbedcopy ] = useClipboard ( embedCode , { successDuration : 3000 } )
55
+ const [ anchorEl , setAnchorEl ] = React . useState ( null ) ;
56
+
57
+ const handleClick = ( event ) => {
58
+ setAnchorEl ( event . currentTarget ) ;
59
+ } ;
60
+
61
+ const handleClose = ( ) => {
62
+ setAnchorEl ( null ) ;
63
+ } ;
51
64
52
65
const SearchButton = ( ) => (
53
66
< Button
@@ -85,17 +98,34 @@ export const DialogBox = ({ params = "" }) => {
85
98
} }
86
99
>
87
100
< Button
101
+ aria-controls = "save-image-menu"
102
+ aria-haspopup = "true"
88
103
className = { classes . color }
89
104
size = "small"
90
- value = "image"
91
105
startIcon = { < GetAppIcon /> }
92
- onClick = { ( ) => {
93
- const date = moment ( new Date ( ) ) . format ( 'YYYYMMDD' ) ;
94
- saveAs ( `https://contributor-overtime-api.apiseven.com/contributors-svg${ params } ` , `github-contributor-over-time-${ date } .svg` )
95
- } }
96
- >
106
+ onClick = { handleClick } >
97
107
Image
98
108
</ Button >
109
+ < Menu
110
+ id = "save-image-menu"
111
+ anchorEl = { anchorEl }
112
+ keepMounted
113
+ open = { Boolean ( anchorEl ) }
114
+ onClose = { handleClose }
115
+ >
116
+ < MenuItem onClick = { ( ) => {
117
+ const date = moment ( new Date ( ) ) . format ( 'YYYYMMDD' ) ;
118
+ saveAs ( `https://contributor-overtime-api.apiseven.com/contributors-svg${ params } ` , `github-contributor-over-time-${ date } .svg` )
119
+ } } >
120
+ Save as SVG
121
+ </ MenuItem >
122
+ < MenuItem onClick = { ( ) => {
123
+ const date = moment ( new Date ( ) ) . format ( 'YYYYMMDD' ) ;
124
+ saveSvgAsPng ( document . querySelector ( "div.echarts-for-react svg" ) , `github-contributor-over-time-${ date } .png` ) ;
125
+ } } >
126
+ Save as PNG
127
+ </ MenuItem >
128
+ </ Menu >
99
129
< Button
100
130
className = { classes . color }
101
131
variant = "outlined"
@@ -124,7 +154,7 @@ export const DialogBox = ({ params = "" }) => {
124
154
className = { classes . root }
125
155
size = "small"
126
156
value = "Share on twtter"
127
- startIcon = { < svg stroke = "currentColor" fill = "currentColor" stroke-width = "0" viewBox = "0 0 512 512" height = "0.9em" width = "0.9em" xmlns = "http://www.w3.org/2000/svg" > < path width = '1.8em' height = '1.8em' d = "M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z" > </ path > </ svg > }
157
+ startIcon = { < svg stroke = "currentColor" fill = "currentColor" strokeWidth = "0" viewBox = "0 0 512 512" height = "0.9em" width = "0.9em" xmlns = "http://www.w3.org/2000/svg" > < path width = '1.8em' height = '1.8em' d = "M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z" > </ path > </ svg > }
128
158
onClick = { ( ) => {
129
159
handleShareToTwitterClick ( params ) ;
130
160
} }
0 commit comments