@@ -81,6 +81,18 @@ type State = {
8181export const DELETE_SANDBOX_DROP_KEY = 'delete' ;
8282export 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+
8496class 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