When attempting to create custom icons, I experimented with various methods and found that the simplest and most effective approach was using the component
property of the antd Icon
component. By providing a functional component that returns the desired image, you can easily implement custom icons:
<Icon component={() => (<img src="/image.svg" />)} />
While this method works well within menu items and submenus, it may not align perfectly with the menu text like the default icons. To address this issue, I had to apply transform: translateY(-3px)
in the CSS to adjust the positioning (this adjustment may vary depending on the image used).
Alternatively, the official recommendation (specifically for SVG images) suggests utilizing the @svgr/webpack plugin to convert the SVG file into a component. This approach could offer benefits in terms of layout and coloring, as antd icons appear to favor actual <svg>
elements over <img>
elements with SVG files. However, I did not personally explore this option.