1
1
import Popper from '@material-ui/core/Popper' ;
2
2
import Paper from '@material-ui/core/Paper' ;
3
+ import ClickAwayListener from '@material-ui/core/ClickAwayListener' ;
3
4
import {
4
5
CheckIcon ,
5
6
ChevronDownIcon ,
@@ -9,6 +10,7 @@ import {
9
10
} from '@primer/octicons-react' ;
10
11
import React , { useState } from 'react' ;
11
12
import { PopperPlacementType } from '@material-ui/core/Popper' ;
13
+ import Button from './Button' ;
12
14
13
15
interface CodeActionButtonProps {
14
16
cloneURL : string ;
@@ -28,30 +30,27 @@ const CodeActionButton: React.FC<CodeActionButtonProps> = ({ cloneURL }) => {
28
30
setPlacement ( newPlacement ) ;
29
31
} ;
30
32
33
+ const handleClickAway = ( ) => {
34
+ setOpen ( false ) ;
35
+ } ;
36
+
31
37
return (
32
38
< >
33
- < div
39
+ < Button
40
+ color = 'success'
34
41
style = { {
35
- background : '#2da44e' ,
36
42
borderRadius : '5px' ,
37
- color : 'white' ,
38
43
padding : '6px 10px 6px 10px' ,
39
44
fontWeight : 'bold' ,
40
- cursor : 'pointer' ,
41
- border : '1px solid rgba(2, 2, 2, 0.1)' ,
42
45
boxSizing : 'border-box' ,
43
46
whiteSpace : 'nowrap' ,
44
- display : 'inline-flex' ,
45
- alignItems : 'center' ,
46
- justifyContent : 'center' ,
47
- boxShadow : '0 1px 2px 1px rgba(0, 0, 0, 0.2)' ,
48
47
} }
49
48
onClick = { handleClick ( 'bottom-end' ) }
50
49
>
51
50
< CodeIcon size = 'small' verticalAlign = 'middle' /> { ' ' }
52
- < span style = { { paddingLeft : '6px' , paddingRight : ' 10px' , height : '24px ' } } > Code</ span >
51
+ < span style = { { padding : '4px 10px' } } > Code</ span >
53
52
< ChevronDownIcon size = 'small' verticalAlign = 'text-top' />
54
- </ div >
53
+ </ Button >
55
54
< Popper
56
55
open = { open }
57
56
anchorEl = { anchorEl }
@@ -64,62 +63,64 @@ const CodeActionButton: React.FC<CodeActionButtonProps> = ({ cloneURL }) => {
64
63
zIndex : 99 ,
65
64
} }
66
65
>
67
- < Paper >
68
- < div style = { { padding : '15px' , gap : '5px' } } >
69
- < TerminalIcon size = 'small' verticalAlign = 'middle' /> { ' ' }
70
- < span style = { { paddingLeft : '5px' , fontSize : '14px' , fontWeight : 'bold' } } > Clone</ span >
71
- < div style = { { marginTop : '5px' , maxWidth : '299px' } } >
72
- < div
73
- style = { {
74
- padding : '3px 8px 3px 8px' ,
75
- border : '1px solid gray' ,
76
- borderRadius : '5px' ,
77
- fontSize : '12px' ,
78
- minHeight : '22px' ,
79
- } }
80
- >
81
- < span
66
+ < ClickAwayListener onClickAway = { handleClickAway } >
67
+ < Paper >
68
+ < div style = { { padding : '15px' , gap : '5px' } } >
69
+ < TerminalIcon size = 'small' verticalAlign = 'middle' /> { ' ' }
70
+ < span style = { { paddingLeft : '5px' , fontSize : '14px' , fontWeight : 'bold' } } > Clone</ span >
71
+ < div style = { { marginTop : '5px' , maxWidth : '299px' } } >
72
+ < div
82
73
style = { {
83
- float : 'left ' ,
84
- overflow : 'hidden ' ,
85
- textOverflow : 'ellipsis ' ,
86
- whiteSpace : 'nowrap ' ,
87
- width : '90% ' ,
74
+ padding : '3px 8px 3px 8px ' ,
75
+ border : '1px solid gray ' ,
76
+ borderRadius : '5px ' ,
77
+ fontSize : '12px ' ,
78
+ minHeight : '22px ' ,
88
79
} }
89
80
>
90
- { cloneURL }
91
- </ span >
92
- < span
93
- style = { {
94
- float : 'right' ,
95
- } }
96
- >
97
- { ! isCopied && (
98
- < span
99
- style = { { cursor : 'pointer' } }
100
- onClick = { ( ) => {
101
- navigator . clipboard . writeText ( `git clone ${ cloneURL } ` ) ;
102
- setIsCopied ( true ) ;
103
- } }
104
- >
105
- < CopyIcon />
106
- </ span >
107
- ) }
108
- { isCopied && (
109
- < span style = { { color : 'green' } } >
110
- < CheckIcon />
111
- </ span >
112
- ) }
81
+ < span
82
+ style = { {
83
+ float : 'left' ,
84
+ overflow : 'hidden' ,
85
+ textOverflow : 'ellipsis' ,
86
+ whiteSpace : 'nowrap' ,
87
+ width : '90%' ,
88
+ } }
89
+ >
90
+ { cloneURL }
91
+ </ span >
92
+ < span
93
+ style = { {
94
+ float : 'right' ,
95
+ } }
96
+ >
97
+ { ! isCopied && (
98
+ < span
99
+ style = { { cursor : 'pointer' } }
100
+ onClick = { ( ) => {
101
+ navigator . clipboard . writeText ( `git clone ${ cloneURL } ` ) ;
102
+ setIsCopied ( true ) ;
103
+ } }
104
+ >
105
+ < CopyIcon />
106
+ </ span >
107
+ ) }
108
+ { isCopied && (
109
+ < span style = { { color : 'green' } } >
110
+ < CheckIcon />
111
+ </ span >
112
+ ) }
113
+ </ span >
114
+ </ div >
115
+ </ div >
116
+ < div style = { { marginTop : '5px' } } >
117
+ < span style = { { fontWeight : 'lighter' , fontSize : '12px' , opacity : 0.9 } } >
118
+ Use Git and run this command in your IDE or Terminal 👍
113
119
</ span >
114
120
</ div >
115
121
</ div >
116
- < div style = { { marginTop : '5px' } } >
117
- < span style = { { fontWeight : 'lighter' , fontSize : '12px' , opacity : 0.9 } } >
118
- Use Git and run this command in your IDE or Terminal 👍
119
- </ span >
120
- </ div >
121
- </ div >
122
- </ Paper >
122
+ </ Paper >
123
+ </ ClickAwayListener >
123
124
</ Popper >
124
125
</ >
125
126
) ;
0 commit comments