Skip to main content
Question

Copy String to clipboard or Trigger download modal from Figma Widget?

  • February 10, 2023
  • 4 replies
  • 1578 views

Carter_Xiao

Using property menu to call the function

Example output for string variable

Fruit
  Blue
   Blueberry
  Red
   Apple
    Fuji
  Yellow
   Banana
This topic has been closed for replies.

4 replies

tank666
  • 4873 replies
  • February 11, 2023

To copy something to the clipboard or bring up the download window, you need to open the UI, send a message to the UI, and then call the copy to clipboard or download file function.


Carter_Xiao
  • Author
  • 3 replies
  • February 12, 2023

Thanks @tank666, I tried but seems it only works with elements inside the widget not the property menu item? If there’s a similar thing to navigator or via 3rd party library import which I could click to copy, that will be great, but probably doesn’t support yet.


tank666
  • 4873 replies
  • February 12, 2023

It doesn’t matter. You can call showUI from both the widget UI and the properties menu. You are probably missing something.
If you can share the code it will help identify the issue.

navigator.clipboard doesn’t seem to be available, but you can use document.execCommand(). As for third-party libraries, I can’t help with that, so try looking for them yourself on GitHub.


Carter_Xiao
  • Author
  • 3 replies
  • February 14, 2023

Thanks, I eventually solved it, the issue was I forgot to return a promise directly to the anonymous function, so this code works for me. exportMindmap() returns an HTML in string format without using a separate ui.html file

({propertyName, propertyValue}) => {  
    if (propertyName === 'Export') {
      return new Promise((resolve) => {
        figma.showUI(exportMindmap(), {title: 'Copy to clipbord'})
      })
    }
}

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings