Skip to content

Commit 9d1a58a

Browse files
committed
feat: add copy sandbox link on Sandbox Card from Dashboard
1 parent 5ccffbd commit 9d1a58a

File tree

1 file changed

+27
-0
lines changed
  • packages/app/src/app/pages/Dashboard/Content/SandboxCard

1 file changed

+27
-0
lines changed

packages/app/src/app/pages/Dashboard/Content/SandboxCard/index.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ type State = {
8181
export const DELETE_SANDBOX_DROP_KEY = 'delete';
8282
export const MAKE_TEMPLATE_DROP_KEY = 'makeTemplate';
8383

84+
const copyToClipboard = (str: string) => {
85+
const el = document.createElement('textarea');
86+
el.value = str;
87+
el.setAttribute('readonly', '');
88+
el.style.position = 'absolute';
89+
el.style.left = '-9999px';
90+
document.body.appendChild(el);
91+
el.select();
92+
document.execCommand('copy');
93+
document.body.removeChild(el);
94+
};
95+
8496
class SandboxItemComponent extends React.PureComponent<Props, State> {
8597
el: HTMLDivElement;
8698
screenshotTimeout: number;
@@ -290,6 +302,13 @@ class SandboxItemComponent extends React.PureComponent<Props, State> {
290302
return true;
291303
},
292304
},
305+
{
306+
title: 'Copy Sandbox Link',
307+
action: () => {
308+
this.copySandboxURL();
309+
return true;
310+
},
311+
},
293312
{
294313
title: 'Fork Sandbox',
295314
action: () => {
@@ -383,6 +402,14 @@ class SandboxItemComponent extends React.PureComponent<Props, State> {
383402
return true;
384403
};
385404

405+
copySandboxURL = () => {
406+
const url = sandboxUrl({ id: this.props.id, alias: this.props.alias });
407+
408+
copyToClipboard(`https://codesandbox.io${url}`);
409+
410+
return true;
411+
};
412+
386413
handleMouseDown = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
387414
e.stopPropagation();
388415

0 commit comments

Comments
 (0)