question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use React SVG components for icons instead of an icon font

See original GitHub issue

This issue is a continuation of the discussion on https://github.com/ant-design/ant-design/issues/7809.

What problem does this feature solve?

The goal is, in one of the future Ant Design minor/bugfix releases, to stop using an icon font by implementing icons as React SVG components instead.

There are multiple articles explaining how SVGs are better than icon fonts:

What does the proposed API look like?

There are two main features to preserve to be able to make the switch without introducing breaking changes:

  • It should be possible to use <Icon />'s style prop to change the icons size and color. In particular, the CSS properties font-size, line-height and color should work as expected. Align SVG Icons to Text and Say Goodbye to Font Icons explains how it’s possible to maintain this behaviour with SVG icons.
  • Passing the correct type prop to the <Icon /> component should be enough to render the correct icon. To keep this working, we would write one React component per existing icon, import them all in <Icon />'s module, and have a switch in <Icon />'s render method to display the right icon based on the type prop. It would slightly increase the JS bundle size but I think it’s worth it as:
    • It would remove today’s fine print of Ant Design icons only working when connected to the Internet without a firewall blocking requests to the chinese http://iconfont.cn/ CDN.
    • The Ant Design team would be able to stop maintaining the local-iconfont package and the related documentation.

In the long term, to make sure only used icons end up in the final application bundle, we could stop using the <Icon type="link" /> component and expose all the icons as separate modules like Material UI does. We could also export all these separate icon modules from a single antd/icons.js and then leverage the existing babel-plugin-import technique to offer the import {Link} from 'antd/icons'; syntax sugar without weighing the final application size down.

What do you think? Can we make the switch without waiting for Ant Design 4?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:25
  • Comments:37 (15 by maintainers)

github_iconTop GitHub Comments

34reactions
yesmeckcommented, May 14, 2018

Here is the summary of our meeting:

  1. We will migrate icon font to SVG (in next one or two minor version).
  2. Our designers are re-making icons of Ant Design (almost finished).

We will start the work when our designers finish the re-making.

26reactions
afc163commented, Sep 2, 2018

Published with 3.9.0!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use SVG Icons in React with React Icons and Font ...
First, let's find an icon. While all Heroicons are available inside react-icons, let's use it as an example since it's easy to find...
Read more >
Icon Library in React: Why Inline SVG Are Better than a Font
One popular method to manage a big set of icons is to use a font. It is quite easy to generate a font...
Read more >
Use React SVG components for icons instead of an icon font
It should be possible to use <Icon /> 's style prop to change the icons size and color. In particular, the CSS properties...
Read more >
Using SVG Icons Components in React - Leapfrog Technology
TL;DR: We create a single SVG component and pass a name prop to it. The component resolves the viewBox and path values associated...
Read more >
How to Use SVG Icons in React with React Icons ... - YouTube
Learn how to use SVG icons right inside of your React app. We'll first walk through installing the React Icons package to instantly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found