1- import { Fade } from '@mui/material' ;
2- import React from 'react' ;
1+ import { Box , IconButton , Menu , MenuItem , Tooltip } from '@mui/material' ;
2+ import React , { useState } from 'react' ;
33import { FacebookShareButton , LinkedinShareButton , TwitterShareButton } from 'react-share' ;
4- import { ClickAwayListener , IconButton , Paper , Popper , Tooltip } from '../../base' ;
54import { ChainIcon , FacebookIcon , LinkedinIcon , ShareIcon , TwitterIcon } from '../../icons' ;
65import { useTheme } from '../../theme' ;
76import { Pattern } from '../CustomCatalog/CustomCard' ;
7+ import { ErrorBoundary } from '../ErrorBoundary' ;
88import { CopyShareIconWrapper , VisibilityChip } from './style' ;
99
1010interface SocialSharePopperProps {
1111 details : Pattern ;
1212 type : string ;
1313 cardId : string ;
14- handleClick : ( event : React . MouseEvent ) => void ;
1514 title : string ;
16- id : string ;
17- anchorEl : HTMLElement | null ;
18- handleClose : ( ) => void ;
1915 getUrl : ( type : string , id : string ) => string ;
2016 handleCopyUrl : ( type : string , name : string , id : string ) => void ;
2117}
@@ -24,71 +20,105 @@ const SocialSharePopper: React.FC<SocialSharePopperProps> = ({
2420 details,
2521 type,
2622 cardId,
27- handleClick,
2823 title,
29- id,
30- anchorEl,
31- handleClose,
3224 getUrl,
3325 handleCopyUrl
3426} ) => {
35- const cleanedType = type . replace ( 'my-' , '' ) . replace ( / s $ / , '' ) ;
3627 const theme = useTheme ( ) ;
28+ const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
29+ const open = Boolean ( anchorEl ) ;
30+
31+ const handleClick = ( event : React . MouseEvent < HTMLElement > ) => {
32+ setAnchorEl ( event . currentTarget ) ;
33+ } ;
34+
35+ const handleClose = ( ) => {
36+ setAnchorEl ( null ) ;
37+ } ;
38+
39+ const cleanedType = type . replace ( 'my-' , '' ) . replace ( / s $ / , '' ) ;
40+
3741 return (
38- < CopyShareIconWrapper style = { { marginBottom : '2rem' } } >
39- < VisibilityChip
40- style = { {
41- color : theme . palette . text . default
42- } }
43- >
44- { details ?. visibility }
45- </ VisibilityChip >
46- { details ?. visibility !== 'private' && (
47- < Tooltip title = "Copy Link" placement = "top" arrow >
48- < IconButton
49- sx = { { borderRadius : '0.1rem' , padding : '0.5rem' } }
50- onClick = { ( ) => handleCopyUrl ( cleanedType , details ?. name , details ?. id ) }
51- >
52- < ChainIcon height = { '24' } width = { '24' } />
53- </ IconButton >
54- </ Tooltip >
55- ) }
56- { ( details ?. visibility === 'published' || details ?. visibility === 'public' ) && (
57- < >
58- < Tooltip title = { title } placement = "top" arrow >
59- < IconButton sx = { { borderRadius : '0.1rem' , padding : '0.5rem' } } onClick = { handleClick } >
60- < ShareIcon height = { 24 } width = { 22 } />
42+ < ErrorBoundary >
43+ < CopyShareIconWrapper style = { { marginBottom : '2rem' } } >
44+ < VisibilityChip
45+ style = { {
46+ color : theme . palette . text . default
47+ } }
48+ >
49+ { details ?. visibility }
50+ </ VisibilityChip >
51+
52+ { details ?. visibility !== 'private' && (
53+ < Tooltip title = "Copy Link" placement = "top" arrow >
54+ < IconButton
55+ sx = { { borderRadius : '0.1rem' , padding : '0.5rem' } }
56+ onClick = { ( ) => handleCopyUrl ( cleanedType , details ?. name , details ?. id ) }
57+ >
58+ < ChainIcon height = { '24' } width = { '24' } />
6159 </ IconButton >
6260 </ Tooltip >
63- < Popper id = { id } open = { Boolean ( anchorEl ) } anchorEl = { anchorEl } transition >
64- { ( { TransitionProps } ) => (
65- < ClickAwayListener onClickAway = { handleClose } >
66- < Fade { ...TransitionProps } timeout = { 350 } >
67- < Paper >
68- < TwitterShareButton
69- url = { getUrl ( cleanedType , cardId ) }
70- title = "Checkout this awesome design"
71- hashtags = { [ 'opensource' ] }
72- >
73- < TwitterIcon />
74- </ TwitterShareButton >
75- < LinkedinShareButton
76- url = { getUrl ( cleanedType , cardId ) }
77- summary = "Checkout this awesome design"
78- >
79- < LinkedinIcon />
80- </ LinkedinShareButton >
81- < FacebookShareButton url = { getUrl ( cleanedType , cardId ) } hashtag = "#opensource" >
82- < FacebookIcon />
83- </ FacebookShareButton >
84- </ Paper >
85- </ Fade >
86- </ ClickAwayListener >
87- ) }
88- </ Popper >
89- </ >
90- ) }
91- </ CopyShareIconWrapper >
61+ ) }
62+
63+ { ( details ?. visibility === 'published' || details ?. visibility === 'public' ) && (
64+ < >
65+ < Tooltip title = { title } placement = "top" arrow >
66+ < IconButton sx = { { borderRadius : '0.1rem' , padding : '0.5rem' } } onClick = { handleClick } >
67+ < ShareIcon height = { 24 } width = { 22 } />
68+ </ IconButton >
69+ </ Tooltip >
70+
71+ < Menu
72+ anchorEl = { anchorEl }
73+ open = { open }
74+ onClose = { handleClose }
75+ onClick = { handleClose }
76+ PaperProps = { {
77+ sx : {
78+ p : 0 ,
79+ width : 'auto'
80+ }
81+ } }
82+ sx = { {
83+ '& .MuiList-root' : {
84+ paddingBottom : 0
85+ }
86+ } }
87+ transformOrigin = { { horizontal : 'right' , vertical : 'top' } }
88+ anchorOrigin = { { horizontal : 'right' , vertical : 'bottom' } }
89+ >
90+ < MenuItem
91+ sx = { {
92+ backgroundColor : 'transparent' ,
93+ '&:hover' : { backgroundColor : 'transparent' } ,
94+ padding : '0px' ,
95+ cursor : 'default'
96+ } }
97+ >
98+ < Box sx = { { display : 'flex' , gap : 1 } } >
99+ < TwitterShareButton
100+ url = { getUrl ( cleanedType , cardId ) }
101+ title = "Checkout this awesome design"
102+ hashtags = { [ 'opensource' ] }
103+ >
104+ < TwitterIcon />
105+ </ TwitterShareButton >
106+ < LinkedinShareButton
107+ url = { getUrl ( cleanedType , cardId ) }
108+ summary = "Checkout this awesome design"
109+ >
110+ < LinkedinIcon />
111+ </ LinkedinShareButton >
112+ < FacebookShareButton url = { getUrl ( cleanedType , cardId ) } hashtag = "#opensource" >
113+ < FacebookIcon />
114+ </ FacebookShareButton >
115+ </ Box >
116+ </ MenuItem >
117+ </ Menu >
118+ </ >
119+ ) }
120+ </ CopyShareIconWrapper >
121+ </ ErrorBoundary >
92122 ) ;
93123} ;
94124
0 commit comments