Created
December 5, 2017 21:30
-
-
Save colebemis/21659e4db4e8cbdba401cea68f155377 to your computer and use it in GitHub Desktop.
Using Feather with Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DomSanitizer } from '@angular/platform-browser'; | |
import { Pipe, PipeTransform } from '@angular/core'; | |
import { icons } from 'feather-icons'; // v4+ | |
@Pipe({ name: 'feather' }) | |
export class FeatherIconsPipe implements PipeTransform { | |
constructor(private sanitizer: DomSanitizer) {} | |
transform(icon: string, size: number = 24, color: string = 'inherit') { | |
return this.sanitizer.bypassSecurityTrustHtml(icons[icon].toSvg({ | |
width: size, | |
height: size, | |
color: color | |
})); | |
} | |
} |
Thank you for the update @colebemis. My solution was based on Feather icons 3.3. Just upgraded to v4 and it is awesome. You did a great job.
I'll update the blog post soon.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 4
Since we only need the
icons
object, we can import justicons
from thefeather-icons
package.Line 11
I prefer to use
color
to set the color of the icons. This works because the stroke of all the SVGs are set tocurrentColor
. This approach is a little more flexible than setting thefill
because we can set the color of elements with bothstroke
andfill
with one property.Line 12
I recently released Feather v4 which came with some breaking API changes. This is the new way to use the
toSvg()
function.v4.0.0 Release Notes