Skip to content

Commit

Permalink
feat(components-CopyButton): implement CopyButton component (#771)
Browse files Browse the repository at this point in the history
issue #701
close #762
  • Loading branch information
sabertazimi committed May 2, 2022
1 parent 09e9645 commit 7a1f49b
Show file tree
Hide file tree
Showing 17 changed files with 1,006 additions and 8 deletions.
18 changes: 18 additions & 0 deletions __mocks__/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let navigatorClipboardMocked = false;
const writeTextMock = jest.fn();

const mockNavigatorClipboard = () => {
if (!navigatorClipboardMocked) {
Object.defineProperty(global.navigator, 'clipboard', {
value: {
writeText: writeTextMock,
},
});

navigatorClipboardMocked = true;
}

return { writeTextMock };
};

export { mockNavigatorClipboard };
1 change: 1 addition & 0 deletions components/CodeBlocks/Code.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}

.block {
@apply relative !important;
@apply mb-0 p-5 !important;
}

Expand Down
2 changes: 2 additions & 0 deletions components/CodeBlocks/Code.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CopyButton from '@components/CopyButton';
import { classNames } from '@components/utils';
import type { Language } from 'prism-react-renderer';
import Highlight, { defaultProps } from 'prism-react-renderer';
Expand Down Expand Up @@ -38,6 +39,7 @@ const BlockCode = ({
className={classNames(className, styles.block)}
style={style}
>
<CopyButton code={normalizeCode(children)} />
{tokens.map((line, index) => (
<div key={index} {...getLineProps({ line, key: index })}>
<span className={styles['line-number']}>{index + 1}</span>
Expand Down
Loading

1 comment on commit 7a1f49b

@vercel
Copy link

@vercel vercel bot commented on 7a1f49b May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blog – ./

blog-git-main-sabertaz.vercel.app
blog.tazimi.dev
blog-sabertaz.vercel.app

Please sign in to comment.