Building a Design Systems Library with Figma & Scripter

栏目: IT技术 · 发布时间: 4年前

内容简介:Over the past few months, I’ve been helping Lyft build the initial version of our Figma design systems library, which contains all of the colors, text styles, and components used by designers across the company. As we worked on the project, we began to not

Over the past few months, I’ve been helping Lyft build the initial version of our Figma design systems library, which contains all of the colors, text styles, and components used by designers across the company. As we worked on the project, we began to notice patterns of time-consuming tasks, some examples being:

  • Generating helpful descriptions for our 500+ color styles.
  • Optimizing each of the 900+ icons in our icon library.
  • Finding and deleting private components that were no longer being used.

Eventually we became curious as to whether we could automate some of these processes. We discovered a Figma plugin called Scripter that allowed us to write quick-and-dirty scripts in TypeScript using the Figma Plugin API . It has significantly sped up our workflows ever since.

Building a Design Systems Library with Figma & Scripter

figma.com/c/plugin/757836922707087381/Scripter

In this blog post, I want to share a few examples of how we’ve used Scripter to help build our design systems library in Figma and automate tasks that would have otherwise taken hours or even days to complete.

Generating descriptions for color styles

Figma allows users to add descriptions to their styles that show up as tooltips when designers hover over them in the style picker. One thing we wanted to do was update the description of each of our color styles to be the color’s RGB hex code, making it easily accessible for designers.

Building a Design Systems Library with Figma & Scripter

Editing and displaying color style descriptions in Figma.

These descriptions are easy to add and edit in Figma: simply right click the style, select ‘Edit Style,’ and update the description. However, our design system consists of over 500 color styles, and updating each individually would have taken hours.

One of the first scripts we wrote was designed to automatically generate these tooltips. For each color style, the script analyzed the style’s color, generated its corresponding RGB hex color code, and set it as the style’s description.

A script that generates descriptions for each color style in the current Figma file.

Flattening icons

Like many design tools, Figma allows one to optimize icons by ‘flattening’ them into a single layer. We’ve found it to be good practice to flatten icons before publishing them for a few reasons:

  • Flattened icons result in less noise in the layers panel.
  • Icons that contain less layers are more efficient to render in Figma, especially in mocks that are heavily dependent on our icon library.
  • Flattening icons after they have been published breaks overrides that designers have applied.

Building a Design Systems Library with Figma & Scripter

Flattening a multi-layered bike icon into a single layer.

That said, our icon library currently consists of over 900 icons, so flattening each one independently through the Figma UI was unrealistic. Fortunately, the Figma Plugin API provides the figma.flatten() function that can help automate the process!

A script that flattens the children nodes of each component in a file.

Note that this script makes a few important assumptions to be aware of. Specifically, it assumes that (1) every component in the file is an icon, (2) each icon contains a single color, and (3) the icons don’t use masks. The figma.flatten() function may not work as one expects if one of these conditions aren’t met.

Deleting unused private components

Most of the components in our design systems library are created using atomic building block components . For example, each of our button components share the same internal background component, which is private to the file and makes our buttons easier to update and maintain. When Auto Layout was released , we rebuilt several of our components from scratch and many of these building block components became outdated and were no longer necessary.

Unfortunately, Figma doesn’t provide a built-in mechanism for searching for local instances of a given master component, which made it difficult for us to confirm whether or not some of these components were still being used in the file. To solve this problem, we wrote a script! It allows us to select a component to delete and takes care of removing the component if it’s private and unused in the file.

A script that deletes the selected component if it is private and unused in the file.

Other scripts we’ve written

These are just a few of many scripts we’ve written to build our Figma design systems library. Here are some other examples:

  • Generating color styles. We wrote a script that parses a JSON file containing all of the colors in our color spectrum and created a corresponding Figma color style for each using figma.createPaintStyle() . This saved us hours of work that would have otherwise been spent manually creating hundreds of color styles through the Figma UI.
  • Searching for layers that aren’t using our color styles. We want all of our components to make use of our color spectrum styles rather than hardcoded hex colors. To verify that this is the case, we wrote a script that searches files for color usages that are not linked to a Figma color style. We determine if a layer has a fill color by analyzing its fills property, then verifying the fill color is linked to a Figma color style by checking that the layer’s fillStyleId property is non-empty. Check out this script for an example.
  • Building custom selections. Figma provides numerous tools for selecting multiple layers at once. However, sometimes we want to create a selection satisfying our own custom set of criteria (e.g. selecting all instances of the currently selected master component). Fortunately, building selections is relatively easy to automate in a script. We do this by traversing the current page’s layer hierarchy, creating a list of layers you want to select, and assigning that list to the figma.currentPage.selection property.
  • Cleaning up layer names. Every once in a while we run a script that cleans up our layer names by removing trailing whitespace, fixing capitalization mistakes, adding missing spaces before and after ‘/’ characters, etc. This has significantly reduced the number of accidental typos we’ve made, and has ensured that naming remains consistent across our libraries.

Final thoughts

Writing scripts has been essential for accelerating up the development of our Figma design systems library, and has also made working on the project a lot more fun! We’d love to hear ideas and stories about how others automate their workflows in the comments below! And if you’d like to work with me, or any of our amazing designers and engineers here at Lyft —we’re hiring!


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

编程人生

编程人生

Peter Seibel / 图灵俱乐部 / 人民邮电出版社 / 2011-1-1 / 79.00元

界顶尖的程序员是怎么走上编程道路的? 他们的编程工作创造和改变了人类历史,在这一过程中都有哪些经验和教训? 他们对计算机软件行业的过去、现在和未来有什么独到的看法和见解? 他们对培养、发现、选拔、面试优秀的程序员有什么建议? 放下手头的工作,听听这些软件先驱们的故事和建议,眼界可以更开阔,思路可以更清晰,方向可以更明确,人生可以更精彩。 作者Peter Seibel采......一起来看看 《编程人生》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具