Skip to content

Commit

Permalink
Merge pull request #1200 from survivant/feature/-feature/1198-copy-to…
Browse files Browse the repository at this point in the history
…-clipboard-codegen-main

Add copy to clipboard icon
  • Loading branch information
helloanoop authored Dec 14, 2023
2 parents 8ddec6b + f8ff305 commit ee2d7a1
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 20 deletions.
139 changes: 126 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/bruno-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"qs": "^6.11.0",
"query-string": "^7.0.1",
"react": "18.2.0",
"react-copy-to-clipboard": "^5.1.0",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import styled from 'styled-components';

const StyledWrapper = styled.div`
position: relative;
.copy-to-clipboard {
position: absolute;
cursor: pointer;
top: 0px;
right: 0px;
z-index: 10;
opacity: 0.5;
&:hover {
opacity: 1;
}
}
`;

export default StyledWrapper;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import CodeEditor from 'components/CodeEditor/index';
import get from 'lodash/get';
import { HTTPSnippet } from 'httpsnippet';
import { useTheme } from 'providers/Theme/index';
import StyledWrapper from './StyledWrapper';
import { buildHarRequest } from 'utils/codegenerator/har';
import { useSelector } from 'react-redux';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import toast from 'react-hot-toast';
import { IconCopy } from '@tabler/icons';

const CodeView = ({ language, item }) => {
const { storedTheme } = useTheme();
Expand All @@ -20,13 +24,24 @@ const CodeView = ({ language, item }) => {
}

return (
<CodeEditor
readOnly
value={snippet}
font={get(preferences, 'font.codeFont', 'default')}
theme={storedTheme}
mode={lang}
/>
<>
<StyledWrapper>
<CopyToClipboard
className="copy-to-clipboard"
text={snippet}
onCopy={() => toast.success('Copied to clipboard!')}
>
<IconCopy size={25} strokeWidth={1.5} />
</CopyToClipboard>
<CodeEditor
readOnly
value={snippet}
font={get(preferences, 'font.codeFont', 'default')}
theme={storedTheme}
mode={lang}
/>
</StyledWrapper>
</>
);
};

Expand Down

0 comments on commit ee2d7a1

Please sign in to comment.