Gathering detailed insights and metrics for sa-icon
Gathering detailed insights and metrics for sa-icon
Gathering detailed insights and metrics for sa-icon
Gathering detailed insights and metrics for sa-icon
npm install sa-icon
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
2
The Angular Icon Component (sa-icon
) provides an easy way to preview and customize SVG icons in your Angular applications.
Install the component using npm:
1npm install sa-icon
You can use the SaIconComponent
either in an Angular module or as a standalone component.
Note: Please ensure to add your icons before starting the implementation. Go to add new Icons section
1import { NgModule } from "@angular/core"; 2import { BrowserModule } from "@angular/platform-browser"; 3import { AppComponent } from "./app.component"; 4import { SaIconComponent } from "sa-icon"; 5 6@NgModule({ 7 declarations: [AppComponent], 8 imports: [BrowserModule, SaIconComponent], 9 bootstrap: [AppComponent], 10}) 11export class AppModule {}
1import { bootstrapApplication } from "@angular/platform-browser"; 2import { AppComponent } from "./app.component"; 3import { SaIconComponent } from "sa-icon"; 4 5bootstrapApplication(AppComponent, { 6 imports: [SaIconComponent], 7});
Add the sa-icon
component to your HTML template:
1<sa-icon icon="x"></sa-icon>
Input | Type | Default | Description |
---|---|---|---|
icon | string | '' | The ID of the icon to display (e.g., x ). |
path | string | SaIconService.path | Path to the SVG file containing the icons. |
size | number | SaIconService.size | Default size of the icon (width and height). |
width | number | size | Custom width for the icon. |
height | number | size | Custom height for the icon. |
Example:
1<sa-icon path="assets/custom-icons.svg" icon="check" size="30"></sa-icon>
You can set global configurations for the component using Angular providers:
1import { SaIconService } from "sa-icon"; 2import { IconConfig } from "sa-icon"; 3 4@NgModule({ 5 providers: [ 6 { 7 provide: SaIconService, 8 useValue: { 9 config: { 10 path: "assets/custom-icons/icons.svg", 11 size: 32, 12 } as IconConfig, 13 }, 14 }, 15 ], 16}) 17export class AppModule {}
You should have an SVG file containing all your icons. The file should use the <symbol>
tag for each icon.
Example Existing File
1<svg fill="none" xmlns="http://www.w3.org/2000/svg"> 2 <symbol id="x" fill="none" viewBox="0 0 24 24"> 3 <path fill-rule="evenodd" clip-rule="evenodd" d="M2.10964 2.54475C2.2806..." fill="currentColor"></path> 4 </symbol> 5</svg> 6
Suppose you want to add a Facebook icon. Here’s the Facebook SVG:
1<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none"> 2 <path d="M2.5 12C2.5 7.52166 2.5 5.28249 3.89124 3.89124C5.28249 2.5 7.52166 2.5 12 2.5C16.4783 2.5 18.7175 2.5 20.1088 3.89124C21.5 5.28249 21.5 7.52166 21.5 12C21.5 16.4783 21.5 18.7175 20.1088 20.1088C18.7175 21.5 16.4783 21.5 12 21.5C7.52166 21.5 5.28249 21.5 3.89124 20.1088C2.5 18.7175 2.5 16.4783 2.5 12Z" stroke="#ff00ff" stroke-width="1.5" stroke-linejoin="round" /> 3 <path d="M16.9265 8.02637H13.9816C12.9378 8.02637 12.0894 8.86847 12.0817 9.91229L11.9964 21.4268M10.082 14.0017H14.8847" stroke="#ff00ff" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> 4</svg> 5
You need to copy its contents and wrap them in a <symbol>
tag. Replace static colors (#ff00ff)
with currentColor so you can style it using CSS.
Ensure that you have an SVG file containing icons structured with <symbol>
elements. For example:
1<svg fill="none" xmlns="http://www.w3.org/2000/svg"> 2 <symbol id="x" fill="none" viewBox="0 0 24 24"> 3 <path fill-rule="evenodd" clip-rule="evenodd" d="M2.10964 2.54475C2.2806..." fill="currentColor"></path> 4 </symbol> 5</svg>
1<svg fill="none" xmlns="http://www.w3.org/2000/svg"> 2 <symbol id="x" fill="none" viewBox="0 0 24 24"> 3 <path fill-rule="evenodd" clip-rule="evenodd" d="M2.10964 2.54475C2.2806..." fill="currentColor"></path> 4 </symbol> 5 <symbol id="facebook" fill="none" viewBox="0 0 24 24"> 6 <path d="M2.5 12C2.5 7.52166 2.5 5.28249 3.89124 3.89124C5.28249 2.5 7.52166 2.5 12 2.5C16.4783 2.5 18.7175 2.5 20.1088 3.89124C21.5 5.28249 21.5 7.52166 21.5 12C21.5 16.4783 21.5 18.7175 20.1088 20.1088C18.7175 21.5 16.4783 21.5 12 21.5C7.52166 21.5 5.28249 21.5 3.89124 20.1088C2.5 18.7175 2.5 16.4783 2.5 12Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round" /> 7 <path d="M16.9265 8.02637H13.9816C12.9378 8.02637 12.0894 8.86847 12.0817 9.91229L11.9964 21.4268M10.082 14.0017H14.8847" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" /> 8 </symbol> 9</svg> 10
Now, you can use the new facebook icon like this:
1<sa-icon icon="facebook"></sa-icon>
Important Notes:
fill
property on the <symbol>
tag must be none
.currentColor
for fill
or stroke
properties in the icon paths to allow color customization via CSS.This project is licensed under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.