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

Using property menu to call the function

Example output for string variable


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.

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.

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.

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'})