Table of Contents
Introduction
In our platform, Karelics Cloud, we strive to automate repetitive tasks and improve interactions with robots through our robotic fleet management capabilities. As part of our efforts, we often incorporate custom icons into our platform, particularly for construction site photo documentation UI. To achieve this, we have developed a process for creating and extending a custom icon. In this article, we will outline the algorithm we follow to create a custom icon font that can be applied to various JavaScript projects.
Creation and Installation
We use Material Symbols as our main icon font, but there are times when we need custom icons. To meet this need, we have created our own icon font.
Below is the alghotithm for creating/extending our own icon font:
- To start, export the desired icons in SVG format from design tools such as Figma. After exporting, clean up the icons by removing unnecessary attributes like “fill” and adjusting their sizes using Online SVG code editor service.
Example of SVG code for the “device.svg” icon:
device.svg
- Open IcoMoon and click the “IcoMoon App“ button. As written on their website “The IcoMoon app is free to use. Code files (HTML, CSS, JS) generated by IcoMoon are MIT licensed.”
- Create a new empty set:
- Import our icons:
- Select all icons and click the “Generate Font“ button:
- On the next page you can set the names of the icons (file names by default). Click on the gear to open font settings:
- Here are the settings we use for our icon font:
- Download the generated font files and put them into your JavaScript project:
Make necessary adjustments to the font paths in your project’s CSS file. Additionally, if required, update/add the font import styles in your project’s HTML file using the element.
...
Usage
Here is an example of using custom icons:
Custom icons
Using custom icons in the Karelics robots fleet management platform Karelics Cloud:
Usage in Angular
We use the MatIcon module to embed icons into our application. By default, expects the Material icons font. Example:
To use our icons, we register the kc
alias through the MatIconRegistry service during application initialization:
@Injectable({
providedIn: 'root',
})
export class KcIconsService {
private readonly matIconRegistry = inject(MatIconRegistry);
initializeKcIcons(): Promise {
return new Promise((res) => {
this.matIconRegistry.registerFontClassAlias('kc', 'kc-icon');
res();
});
}
}
Usage in a template (you just need to add the fontSet
attribute with the registered alias):
Conclusion
In conclusion, this article has provided a comprehensive guide to creating a custom icon font for JavaScript projects. Whether you are developing a robotic fleet management system or any other project, incorporating custom icons can greatly enhance the user interface and overall user experience. By following the outlined steps, you can create a unique icon font that adds a personal touch and improves visual appeal.