Build Design Systems With Penpot Components
Penpot's new component system for building scalable design systems, emphasizing designer-developer collaboration.

medium bookmark / Raindrop.io |
Software Dev | Product Lover | Design Freak
Last week I was developing an internal tool to create a design workflow for my workplace. The process involved creating a style guide for a new project by setting up the branding colours, typefaces, shadows and scrim. All went well until it was required to convert the text layers into symbols so as to generalise them as well.
If you use a text layer in a symbol, you can only override only the text; not any other property including font colour or weight.
This makes the symbol not so customisable. For example, you’d have to create multiple types of alert messages instead of just one where you can change the icon and colour.
Until Sketch releases an update where you override all the properties in a text layer it would be good to convert all your text styles into text symbols and use them in your other symbols.
In this article, I would share some snippets which acted as utils in my project. I kept these methods in a utils.js
file and imported it by adding an import statement on top my main script.
@import ‘utils.js’
First method is generic, where a list and a key is taken as parameters and name
of every element is compared with it. If there is a match, the same item is returned. The other functions are the following:
findLayerByName
takes the artboard as the parameter and iterates over the artboard.layers()
list.findPageByName
the pages
parameter can be fetched from the document by using doc.pages()
.findSymbolByName
list of symbols can be obtained by, again, using the document. The getSymbols(doc
) function looks like this./**
* Get all the symbols for a document.
* @param {MSDocument} doc
* @return {NSArray}
*/
function getSymbols(doc) {
return doc.documentData().allSymbols();
}
createArtboard
function is self explanatory. It creates a new MSArtboardGroup, sets its name, geometry and adds it to the current page. This can be made even more generic by taking the page as a parameter.createPage
functions. First creates a new page and adds it to the document data. Import step is to call doc.loadLayerListPanel()
after you add the page, otherwise the page won’t appear on the left unless you collapse and expand the page list.page.addLayers([layer]);
.If you pass
false
in the third parameter of the call:MSSymbolCreator. createSymbolFromLayers_withName_onSymbolsPage(layers, symbolName, true);
it would be added to the current page.
Frankly, only the third function getBottomSymbol
is the only interesting function in this gist. It compares the position of the symbols and use the compare function to return the appropriate integer. Comments are added to help you out.
I am now planning to release my workflow as a plugin. It essentially would help you out to set a theme for your project. It has inbuilt palette and typeface generator.
AI-driven updates, curated by humans and hand-edited for the Prototypr community