Skip to content

Commit 9d29901

Browse files
committed
chore: refactor code button styling and add ClickAwayListener
1 parent aa8ee6a commit 9d29901

File tree

1 file changed

+62
-61
lines changed

1 file changed

+62
-61
lines changed

src/ui/components/CustomButtons/CodeActionButton.tsx

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Popper from '@material-ui/core/Popper';
22
import Paper from '@material-ui/core/Paper';
3+
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
34
import {
45
CheckIcon,
56
ChevronDownIcon,
@@ -9,6 +10,7 @@ import {
910
} from '@primer/octicons-react';
1011
import React, { useState } from 'react';
1112
import { PopperPlacementType } from '@material-ui/core/Popper';
13+
import Button from './Button';
1214

1315
interface CodeActionButtonProps {
1416
cloneURL: string;
@@ -28,30 +30,27 @@ const CodeActionButton: React.FC<CodeActionButtonProps> = ({ cloneURL }) => {
2830
setPlacement(newPlacement);
2931
};
3032

33+
const handleClickAway = () => {
34+
setOpen(false);
35+
};
36+
3137
return (
3238
<>
33-
<div
39+
<Button
40+
color='success'
3441
style={{
35-
background: '#2da44e',
3642
borderRadius: '5px',
37-
color: 'white',
3843
padding: '6px 10px 6px 10px',
3944
fontWeight: 'bold',
40-
cursor: 'pointer',
41-
border: '1px solid rgba(2, 2, 2, 0.1)',
4245
boxSizing: 'border-box',
4346
whiteSpace: 'nowrap',
44-
display: 'inline-flex',
45-
alignItems: 'center',
46-
justifyContent: 'center',
47-
boxShadow: '0 1px 2px 1px rgba(0, 0, 0, 0.2)',
4847
}}
4948
onClick={handleClick('bottom-end')}
5049
>
5150
<CodeIcon size='small' verticalAlign='middle' />{' '}
52-
<span style={{ paddingLeft: '6px', paddingRight: '10px', height: '24px' }}>Code</span>
51+
<span style={{ padding: '4px 10px' }}>Code</span>
5352
<ChevronDownIcon size='small' verticalAlign='text-top' />
54-
</div>
53+
</Button>
5554
<Popper
5655
open={open}
5756
anchorEl={anchorEl}
@@ -64,62 +63,64 @@ const CodeActionButton: React.FC<CodeActionButtonProps> = ({ cloneURL }) => {
6463
zIndex: 99,
6564
}}
6665
>
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
8273
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',
8879
}}
8980
>
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 👍
113119
</span>
114120
</div>
115121
</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>
123124
</Popper>
124125
</>
125126
);

0 commit comments

Comments
 (0)