|
| 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 | + |
1 | 14 | import React from 'react'; |
2 | 15 | import queryString from 'query-string'; |
3 | 16 | import { ThemeProvider } from 'styled-components'; |
@@ -80,6 +93,7 @@ function getUrl(settings, darkMode) { |
80 | 93 | encode: false, |
81 | 94 | skipNull: true, |
82 | 95 | }); |
| 96 | + |
83 | 97 | const url = |
84 | 98 | `https://codesandbox.io/embed/dark-magic-variant-5pj49?` + stringified; |
85 | 99 |
|
@@ -107,6 +121,18 @@ function ShareSheet() { |
107 | 121 | setSettings({ ...settings, preset: name, ...presets[name] }); |
108 | 122 | }; |
109 | 123 |
|
| 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 | + |
110 | 136 | return ( |
111 | 137 | <ThemeProvider theme={theme}> |
112 | 138 | <Container> |
@@ -235,11 +261,18 @@ function ShareSheet() { |
235 | 261 | rows="5" |
236 | 262 | readOnly |
237 | 263 | value={getUrl(settings, darkMode)} |
| 264 | + ref={urlContainer} |
238 | 265 | /> |
239 | | - <Button>Copy Embed Code</Button> |
| 266 | + <Button onClick={copyEmbedCode}> |
| 267 | + {copied ? 'Copied!' : 'Copy Embed Code'} |
| 268 | + </Button> |
240 | 269 | <Option multiline> |
241 | 270 | 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 | + /> |
243 | 276 | </Option> |
244 | 277 | </Section.Body> |
245 | 278 | </Sidebar> |
|
0 commit comments