Skip to content

Commit 11ccad0

Browse files
committed
add copy to clipboard
1 parent e4e2a61 commit 11ccad0

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"marked": "^2.0.0",
2929
"prop-types": "^15.7.2",
3030
"react": "^16.13.1",
31+
"react-copy-to-clipboard": "^5.0.3",
3132
"react-dom": "^16.13.1",
3233
"react-helmet": "^6.1.0",
3334
"react-scroll": "^1.8.0",

src/components/Preview.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { FireOutlined } from '@ant-design/icons';
1+
import { CopyOutlined, FireOutlined } from '@ant-design/icons';
22
import { faStar } from '@fortawesome/free-solid-svg-icons';
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4-
import { Button, Col, Divider, Grid, Input, Modal, Row, Tooltip, Typography } from 'antd';
4+
import { Button, Col, Divider, Grid, Input, message, Modal, Row, Tooltip, Typography } from 'antd';
55
import marked from 'marked';
66
import React, { MutableRefObject, useContext, useState } from 'react';
7+
import { CopyToClipboard } from 'react-copy-to-clipboard';
78
import { generateSectionTitleMarkdown } from '../components/Section';
89
import { FIELD_TYPES } from '../config/global';
910
import { globalContext } from '../context/GlobalContextProvider';
@@ -120,6 +121,10 @@ export const Preview = ({ scrollRef }: { scrollRef: MutableRefObject<any> }) =>
120121
);
121122
};
122123

124+
const showCopiedSuccessfullyMessage = () => {
125+
message.success('Markdown has been copied to your clipboard.');
126+
};
127+
123128
return (
124129
<div ref={scrollRef}>
125130
<Row justify="space-between">
@@ -141,10 +146,21 @@ export const Preview = ({ scrollRef }: { scrollRef: MutableRefObject<any> }) =>
141146
dangerouslySetInnerHTML={{ __html: generateMarkdown().html }}
142147
/>
143148
<Modal
144-
title="Generated Markdown"
149+
title={
150+
<>
151+
Generated Markdowns{' '}
152+
<CopyToClipboard
153+
text={generateAdvertisedMarkdown(generateMarkdown().markdown)}
154+
onCopy={showCopiedSuccessfullyMessage}
155+
>
156+
<Button type="primary" ghost>
157+
<CopyOutlined /> Copy
158+
</Button>
159+
</CopyToClipboard>
160+
</>
161+
}
145162
width="70vw"
146163
visible={showMarkdown}
147-
onCancel={toggleShowMarkdown}
148164
onOk={toggleShowMarkdown}
149165
>
150166
<h3

0 commit comments

Comments
 (0)