@@ -8,12 +8,16 @@ import CloseIcon from '@material-ui/icons/Close';
88import TextField from '@material-ui/core/TextField' ;
99import GetAppIcon from '@material-ui/icons/GetApp' ;
1010import FilterNoneOutlinedIcon from '@material-ui/icons/FilterNoneOutlined' ;
11+ import Menu from '@material-ui/core/Menu' ;
12+ import MenuItem from '@material-ui/core/MenuItem' ;
1113import useClipboard from "react-use-clipboard" ;
1214import { 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" ;
1417import Alert from "@material-ui/lab/Alert" ;
1518import DialogContentText from '@material-ui/core/DialogContentText' ;
1619import moment from "moment" ;
20+ import { saveSvgAsPng } from "save-svg-png-ext" ;
1721
1822export const DialogBox = ( { params = "" } ) => {
1923 const [ showNotice , setShowNotice ] = React . useState ( false ) ;
@@ -48,6 +52,15 @@ export const DialogBox = ({ params = "" }) => {
4852 const [ , setCopy ] = useClipboard ( `${ SHARE_BASE_URL } ${ params } ` , { successDuration : 3000 } ) ;
4953 const embedCode = `<iframe style={{ width: "100%", height: "auto" , minWidth: "600px", minHeight: "1000px" }} src="${ SHARE_BASE_URL } ${ params } " frameBorder="0"></iframe>`
5054 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+ } ;
5164
5265 const SearchButton = ( ) => (
5366 < Button
@@ -85,17 +98,34 @@ export const DialogBox = ({ params = "" }) => {
8598 } }
8699 >
87100 < Button
101+ aria-controls = "save-image-menu"
102+ aria-haspopup = "true"
88103 className = { classes . color }
89104 size = "small"
90- value = "image"
91105 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 } >
97107 Image
98108 </ 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 >
99129 < Button
100130 className = { classes . color }
101131 variant = "outlined"
@@ -124,7 +154,7 @@ export const DialogBox = ({ params = "" }) => {
124154 className = { classes . root }
125155 size = "small"
126156 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 > }
128158 onClick = { ( ) => {
129159 handleShareToTwitterClick ( params ) ;
130160 } }
0 commit comments