Skip to main content
Question

How to get the text styles from our local library

  • January 25, 2023
  • 4 replies
  • 1447 views

Joost_van_Velzen

Hi All,

I’m trying to build a lorem ipsum plugin to be used within my organization. For this I’d like my users to be able to select the text-styles the design system provides in the token library. I could redefine them all in my plugin but this seems like a waste of resources (also no fun when the library itself changes and my plugin does not).

Is there a way to retrieve the tokens text styles programmatically? I can’t seem to find it in the API docs.

Thanks in advance!

This topic has been closed for replies.

4 replies

Gleb
  • Power Member
  • 4710 replies
  • January 25, 2023

Use figma.getLocalTextStyles() (figma | Plugin API) to get the styles in the library file, then save them to client storage, then retrieve these styles in any other file using figma.importStyleByKeyAsync() figma | Plugin API


Joost_van_Velzen

Thanks for your responce @Gleb - I did see the getLocalTextStyles in the docs - when I run this in a file I’d like to place some lorem ipsum I’m getting an empty array back. Just checked in the file where we define the text style (component), here I do get all the proper information back.

I found the importStyleByKeyAsync call in the docs, now I am able to retrieve them one by one, which seems a hassle as I have to create a list of keys and use those (and also - if we introduce a new text style this won’t show up untill I update the plugin, becoming a single point of failure :-))


Gleb
  • Power Member
  • 4710 replies
  • January 25, 2023

Or you can ask the user to update the library manually if you save the keys to the clientstorage instead of hardcoding them into the plugin code.

this is the only way


tank666
  • 4873 replies
  • January 25, 2023

To exclude publishing plugin updates from this path, then you can create a file that lists all the style keys, host it on the web, and then make a network request to it. That is, you will only have to modify the file with the listed keys.


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