Skip to main content
Joost_van_Velzen
January 25, 2023
Question

How to get the text styles from our local library

  • January 25, 2023
  • 4 replies
  • 1708 views

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
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
January 25, 2023

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
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
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.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank