Icons Library
Icons are getting added (more or less) automatically by extracting them from Figma Icons Library.
What is the icons flow?
- Icons are fetched as SVG files from an API.
- The information about the new icons are stored in two data files:
icons-svg.lock
contains API information, so we are able to compare it next time the API is called.icons-meta.json
contains additional information such as the category it belongs to.
- They are then optimized with SVGO and stored in
/assets/icons/
. Each size in a different SVG. - During build (
yarn build
) the SVG files get converted to JSX based React components and stored in/src/icons
. Also several index files and fallbacks are automatically generated.
How to sync new icons?
To fetch new icons from the Figma Icons Library file, you have to:
-
Re-branch
main
, and name iticons/{your-branch-name}
(it needs to include icons in the name):git pull origin maingit checkout -b icons/{your-branch-name} && git push -u origin -
After the CI/CD process has finished it should have made a commit back to the branch including the new optimized icons.
-
With that commit, make a PR back to
main
, review, and (squash) merge it.
Notes:
- The PR or commit needs a appropriate title e.g.
feat(Icons): add [icon names]
orfix(Icon): fix cropped [icon name]
. You can either give the commit a good title during the squash merge of the PR or you may pull and rebase interactivegit pull && git rebase -i
or amend. - Depending on the situation, you may have to pull the changes down locally, and run all tests, to eventually update broken visual snapshots. But ideally, all of that should be handled during the CI/CD process.
How to fix icons?
If you need to re-fetch one or several icons that got updated or changed in the Figma Icons Library you can force the icons to get re-processed before the cache timeout of 30 days:
- Find the icon in the
icons-svg.lock
file and change theupdated
field to0
. - Commit the change – but ensure the git branch name starts with
icon/
(more details above). - You may consider to run
yarn workspace @dnb/eufemia figma:reset
– it will delete everything and refetch the icons.
How to convert icons only?
During development of the conversion script convertSvgToJsx
you may consider to run yarn workspace @dnb/eufemia dev:icons
. Its the same process, when calling yarn build
. It will convert SVGs to JSXs and create all the needed index files in watch mode.
Icons CI/CD process description
This is a description of what happens during adding new icons to the icons library.
Icons are getting added (more or less) automatically by extracting them from Figma. Following is how the process is tied together.
- The connection happens on CI.
- Checks if a new Figma Icons library version is available.
- Download the Figma file (JSON) by a stream basis, and cache that.
- Store the new version, in a version file.
- Parse the JSON Figma file for valid icon IDs.
- For PDF only: unpack the existing zip file with icons.
- Checks if an icon file (SVG or PDF) exists in the repo.
- If no, download it.
- Details about the icon file are getting stored in a "lock" file, so we can compare it next time against.
- For PDF only: pack the icon files to a zip (tar) and delete the files.
- For SVG only: store a meta data file, so the portal can display more relevant data about the icons.
- For SVG only: optimize the SVG file for a lower size.
- For SVG only: Create a JSX component.
- For SVG only: run integration and visual tests.
- Commit the extracted / generated files back to the repo.
Access denied
If you get an access denied request from the Figma API – while streaming down by the GET image endpoint, you may reset the URLs from inside the icons.lock file by running this command: yarn figma:reset
and commit the re-generated files. Image URL's expires after 30 days.