Skip to content

Commit 1229ea7

Browse files
committed
implement copy url
1 parent e566938 commit 1229ea7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

packages/app/src/app/pages/common/Modals/ShareModal2/elements.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ export const Button = styled.button(
157157
backgroundColor: 'blues.600',
158158
borderColor: 'blues.500',
159159
},
160-
161-
textDecoration: 'line-through',
162160
})
163161
);
164162

packages/app/src/app/pages/common/Modals/ShareModal2/index.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/** TODO:
2+
- convert to typescript
3+
- add default module to show
4+
- check what initial path does
5+
- visual polish
6+
- overflow-x
7+
- multiline
8+
- style more info in brackets
9+
- total height of the container is beyond preview
10+
- add postMessage to embed for smoother embed modal
11+
- include darkMode in settings
12+
*/
13+
114
import React from 'react';
215
import queryString from 'query-string';
316
import { ThemeProvider } from 'styled-components';
@@ -80,6 +93,7 @@ function getUrl(settings, darkMode) {
8093
encode: false,
8194
skipNull: true,
8295
});
96+
8397
const url =
8498
`https://codesandbox.io/embed/dark-magic-variant-5pj49?` + stringified;
8599

@@ -107,6 +121,18 @@ function ShareSheet() {
107121
setSettings({ ...settings, preset: name, ...presets[name] });
108122
};
109123

124+
/** Copy Embed code */
125+
const urlContainer = React.createRef();
126+
const [copied, setCopied] = React.useState(false);
127+
128+
const copyEmbedCode = () => {
129+
const copyText = urlContainer.current;
130+
copyText.select();
131+
document.execCommand('copy');
132+
setCopied(true);
133+
window.setTimeout(() => setCopied(false), 2000);
134+
};
135+
110136
return (
111137
<ThemeProvider theme={theme}>
112138
<Container>
@@ -235,11 +261,18 @@ function ShareSheet() {
235261
rows="5"
236262
readOnly
237263
value={getUrl(settings, darkMode)}
264+
ref={urlContainer}
238265
/>
239-
<Button>Copy Embed Code</Button>
266+
<Button onClick={copyEmbedCode}>
267+
{copied ? 'Copied!' : 'Copy Embed Code'}
268+
</Button>
240269
<Option multiline>
241270
Editor url (also works on Medium)
242-
<Input code readOnly value="https://codesandbox.io/s/xoj79" />
271+
<Input
272+
code
273+
readOnly
274+
value={getUrl(settings, darkMode).replace('embed', 's')}
275+
/>
243276
</Option>
244277
</Section.Body>
245278
</Sidebar>

0 commit comments

Comments
 (0)