All Projects â†’ ngneat â†’ Svg Icon

ngneat / Svg Icon

Licence: mit
👻 A lightweight library that makes it easier to use SVG icons in your Angular Application

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Svg Icon

Bytesize Icons
Tiny style-controlled SVG iconset (101 icons, 12kb)
Stars: ✭ 3,662 (+3169.64%)
Mutual labels:  svg, icons, svg-icons
Browser Logos
🗂 High resolution web browser logos
Stars: ✭ 5,538 (+4844.64%)
Mutual labels:  svg, icons, svg-icons
Jam
Jam icons is a set of SVG icons designed for web projects, illustrations, print projects, etc. Licensed under MIT
Stars: ✭ 398 (+255.36%)
Mutual labels:  svg, icons, svg-icons
React Kawaii
Cute SVG React Components
Stars: ✭ 2,709 (+2318.75%)
Mutual labels:  svg, icons, svg-icons
Icons
The premium icon font for @uiwjs Component Library. https://uiwjs.github.io/icons
Stars: ✭ 99 (-11.61%)
Mutual labels:  svg, icons, svg-icons
Vectorlogozone
3,000+ gorgeous SVG logos, perfect for your README or credits page
Stars: ✭ 239 (+113.39%)
Mutual labels:  svg, icons, svg-icons
Icons
All SVG icons available on http://game-icons.net
Stars: ✭ 598 (+433.93%)
Mutual labels:  svg, icons, svg-icons
Feathericon
simply generic vector icon collection - including sketch file, svg files, and font files.
Stars: ✭ 178 (+58.93%)
Mutual labels:  svg, icons, svg-icons
Phosphor React
A flexible icon family for React
Stars: ✭ 97 (-13.39%)
Mutual labels:  svg, icons, svg-icons
Mono Icons
Stars: ✭ 899 (+702.68%)
Mutual labels:  svg, icons, svg-icons
Svgsprit.es
Public endpoint to generate SVG Sprites
Stars: ✭ 73 (-34.82%)
Mutual labels:  svg, icons, svg-icons
Boxicons
High Quality web friendly icons
Stars: ✭ 1,104 (+885.71%)
Mutual labels:  svg, icons, svg-icons
Small N Flat
svg icons on a 24px grid
Stars: ✭ 205 (+83.04%)
Mutual labels:  svg, icons, svg-icons
Grayshift
A lightweight front-end component library for developing fast and powerful web interfaces.
Stars: ✭ 304 (+171.43%)
Mutual labels:  svg, icons, svg-icons
Vue Eva Icons
Is a pack of more than 480 beautiful open source Eva icons as Vue components
Stars: ✭ 189 (+68.75%)
Mutual labels:  svg, icons, svg-icons
Evil Icons
Simple and clean SVG icon pack with the code to support Rails, Sprockets, Node.js, Gulp, Grunt and CDN
Stars: ✭ 4,944 (+4314.29%)
Mutual labels:  svg, icons, svg-icons
Materialdesign Svg
@mdi/svg Dist for Material Design Icons.
Stars: ✭ 166 (+48.21%)
Mutual labels:  svg, icons, svg-icons
File Icon Vectors
A collection of file type icons in SVG format
Stars: ✭ 171 (+52.68%)
Mutual labels:  svg, icons, svg-icons
Vue Unicons
1000+ Pixel-perfect svg icons for your next project as Vue components
Stars: ✭ 828 (+639.29%)
Mutual labels:  svg, icons, svg-icons
React Icomoon
It allows you to simply view the icons in the selection.json file provided by Icomoon.
Stars: ✭ 48 (-57.14%)
Mutual labels:  svg, icons, svg-icons


A lightweight library that makes it easier to use SVG icons in your Angular Application

MIT commitizen PRs styled with prettier All Contributors ngneat spectator

The svg-icon library enables using the <svg-icon> tag to directly display SVG icons in the DOM. This approach offers an advantage over using an <img> tag or via the CSS background-image property, because it allows styling and animating the SVG with CSS.

For example, if the fill or stroke properties of elements in the svg are set to currentColor, they will have the color defined for the containing DOM element. So the color can easily be changed by changing the color style on the svg-icon element.

Installation

ng add @ngneat/svg-icon

Icons Preparation

  • Add the icons to src/assets/svg
  • Add an alias to the tsconfig file:
{
  ...
  "paths": {
    "@app/svg/*": ["src/app/svg/*"]
  }
},
  • Use @ngneat/svg-generator to clean and extract the icons content:
{
  "scripts": {
    "generate-icons": "svgGenerator"
  },
  "svgGenerator": {
    "outputPath": "./src/app/svg",
    "prefix": "app",
    "srcPath": "./src/assets/svg",
    "svgoConfig": {
      "plugins": [
        {
          "removeDimensions": true,
          "cleanupAttrs": true
        }
      ]
    }
  }
}
  • Run npm run generate-icons

Icons Rendering

Import the SvgIconsModule in your AppModule, and register the icons:

import { SvgIconsModule } from '@ngneat/svg-icon';
import { settingsIcon } from '@app/svg/settings';

@NgModule({
  imports: [
    SvgIconsModule.forRoot({
      icons: [settingsIcon],
    }),
  ]
})
export class AppModule {}

Now we can use the svg-icon component:

<svg-icon key="settings"></svg-icon> 
<svg-icon key="settings" color="hotpink" fontSize="40px"></svg-icon>

Lazy Loaded Modules

In lazy load modules, we can use the forChild method:

import { dashboardIcon } from '@app/svg/dashboard';
import { userIcon } from '@app/svg/user';
import { SvgIconsModule } from '@ngneat/svg-icon';

@NgModule({
  declarations: [DashboardComponent],
  imports: [ 
    DashboardRoutingModule, 
    SvgIconsModule.forChild([userIcon])
  ],
})
export class DashboardModule {}

Note that we're NOT using a barrel file (i.e index.ts). This will make sure we only load the SVG files we use in the current module.

Webpack Plugin

To make the process more seamless, the library provides a Webpack plugin you can use to automate the extracting process:

const { SvgGeneratorWebpackPlugin } = require('@ngneat/svg-generator/webpack-plugin');

{
 plugins: [
  new SvgGeneratorWebpackPlugin({
    watch: !isProd,
    srcPath: './src/assets/svg',
    outputPath: './src/app/svg',
    svgoConfig: {
      plugins: [
        {
          removeDimensions: true,
          cleanupAttrs: true,
        },
      ],
    },
  }),
 ];
}

Group Icons

There are cases where we want to group multiple SVG icons. For example, we might have a notifications feature, and we need to load SVG icons such as Slack, Email, etc.

In such cases, create a unique directory, and put the related icons inside it. For example:

home.svg
user.svg
/notifications
 - slack.svg
 - email.svg

This will create a notifications folder with a barrel file that export the SVG icons inside the folder under a const named ${folderName}Icons:

import { notificationsIcons } from '@app/svg/notifications';

@NgModule({
  imports: [SvgIconsModule.forChild(notificationsIcons)],
})
export class NotificationsModule {}

Icon Sizing

To control the SVG size, we use the font-size property as described in this article. You also have the option to pass fixed sizes and use them across the application:

@NgModule({
  imports: [
    SvgIconsModule.forRoot({
      sizes: {
        xs: '10px',
        sm: '12px',
        md: '16px',
        lg: '20px',
        xl: '25px',
        xxl: '30px'
      },
      defaultSize: 'md'
      icons
    })
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

They are used in the size input:

<svg-icon key="settings" size="lg"></svg-icon>

Inputs

@Input() key: string;
@Input() size: string;
@Input() fontSize: string;
@Input() color: string;
@Input() width: string | number;
@Input() height: string | number;

SvgIconRegistry

You can inject the SvgIconRegistry, and get existing SVG icons or register new ones:

import { SvgIconRegistry } from '@ngneat/svg-icon';

interface Icon {
  name: string;
  data: string;
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  constructor(private registry: SvgIconRegistry) {
    registry.register([Icon, Icon, Icon]);
    registry.register(Icon);
    registry.get(name);
    registry.getAll();
  }
}

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Netanel Basal

💻 📖 🤔

Inbal Sinai

📖

Shahar Kazaz

💻 🤔

Artur Androsovych

💻

Vlad Tansky

💻

This project follows the all-contributors specification. Contributions of any kind welcome! Logo icon was made by Freepik from www.flaticon.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].