Parsers
Parsers are the magic that you need to transform your design data into any company standard output. The parsers can be adjusted to your needs.
Let’s have a look at how they work!
Collect icons from Figma
Let’s pretend we’re a React developer who needs to use icons in a React project. The icons are created as components in Figma and in this example we will use a parser to convert the icons into JSX components.
For the sake of simplicity, we will only focus on a single icon defined as a variant of a Figma component named “chat-alt”.
Store icons in a Specify repository
On the right you can see all of our icons in a Specify repository. Now, let’s pull them into our codebase by using the Specify CLI.
Specify CLI: Raw JSON by default
The Specify CLI is the perfect tool to help you see how Specify transforms your design data.
In this example we would like to have them in JSON first to see the data Specify returns.
The following configuration file filters vector assets from a group named "Icons" and generates an vectors.json file containing our icon in JSON.
Input
.specifyrc.json
After setting the output property in the `to-json` parser and pulling our icon with the `pull` command, we receive the following output: `./output/icons.json` - see the image on the right hand side.
Optimize and transform our SVG with SVGO
By default, Specify returns SVG strings as they are created in Figma. Before using the SVG string inside our final JSX component we need to optimize and transform it.
The svgo parser is based on the famous SVGO package and helps us do just that.
Input
.specifyrc.json
Wrapping our SVG inside a JSX component
Now that we are satisfied with our SVG string let’s generate a JSX component out of it.
Let’s use the svg-to-jsx parser to do this.
Input
.specifyrc.json