Skip to content

Commit

Permalink
Fix dynamic icon path bug (in combination with fixed forRoot sprite p…
Browse files Browse the repository at this point in the history
…ath), resolves #25
  • Loading branch information
jannicz committed Jul 19, 2019
1 parent e144572 commit 9007258
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Janek
Copyright (c) 2017 Jan Suwart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Doing so you will still be able override the default path by using the full synt
- Edge
- IE 11 (with polyfill, see below)

### Polyfill for IE11 (and comparable)
### Polyfill for IE11

Older browsers do not support referencing to (external) SVG symbols. To make it work for IE11 and lower you can add
[svg4everybody](https://github.com/jonathantneal/svg4everybody) to your `polyfills.ts` file:
Expand Down
11 changes: 7 additions & 4 deletions docs/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/main.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-svg-icon-sprite-app",
"version": "1.6.0",
"version": "1.6.1",
"license": "MIT",
"author": "Jan Suwart",
"description": "Angular 7+ package for generating and using inline SVG icons in your project",
Expand Down Expand Up @@ -73,6 +73,7 @@
},
"keywords": [
"icon",
"icons",
"svg",
"sprite",
"angular"
Expand Down
4 changes: 2 additions & 2 deletions projects/icon-sprite/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Janek
Copyright (c) 2017 Jan Suwart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
2 changes: 1 addition & 1 deletion projects/icon-sprite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Doing so you will still be able override the default path by using the full synt
- Edge
- IE 11 (with polyfill, see below)

### Polyfill for IE11 (and comparable)
### Polyfill for IE11

Older browsers do not support referencing to (external) SVG symbols. To make it work for IE11 and lower you can add
[svg4everybody](https://github.com/jonathantneal/svg4everybody) to your `polyfills.ts` file:
Expand Down
3 changes: 2 additions & 1 deletion projects/icon-sprite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-svg-icon-sprite",
"version": "1.6.0",
"version": "1.6.1",
"license": "MIT",
"author": "Jan Suwart",
"description": "Angular 7 package for generating and using inline SVG icons in your project",
Expand All @@ -17,6 +17,7 @@
},
"keywords": [
"icon",
"icons",
"svg",
"sprite",
"angular"
Expand Down
4 changes: 4 additions & 0 deletions projects/icon-sprite/src/lib/icon-sprite.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ describe('IconSpriteComponent using Service', () => {
component = fixture.componentInstance;
component.src = 'star';
component.title = 'A title text';

// Simulate simple input change
// See https://medium.com/@christophkrautz/testing-ngonchanges-in-angular-components-bbb3b4650ee8
component.ngOnChanges({});
fixture.detectChanges();

const nativeElement: HTMLElement = fixture.nativeElement;
Expand Down
8 changes: 4 additions & 4 deletions projects/icon-sprite/src/lib/icon-sprite.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, OnChanges } from '@angular/core';
import { IconSpriteService } from './icon-sprite.service';

@Component({
selector: 'svg-icon-sprite',
styleUrls: ['./icon-sprite.component.scss'],
templateUrl: './icon-sprite.component.html'
})
export class IconSpriteComponent implements OnInit {
export class IconSpriteComponent implements OnChanges {

@Input() public src: string;
@Input() public classes = 'icon';
Expand All @@ -21,8 +21,8 @@ export class IconSpriteComponent implements OnInit {
private iconSpriteService: IconSpriteService
) {}

ngOnInit() {
// If the src does not contain a # and a spritePath is set, concatenate it
ngOnChanges(changes) {
// If the src does not contain a # and a spritePath is set via the service, concatenate them
if (this.src && !this.src.includes('#') && this.iconSpriteService.spritePath) {
this.src = `${ this.iconSpriteService.getPath() }#${ this.src }`;
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ <h2 id="manipulation">Manipulation <small>(using dynamic icon path)</small></h2>
<ul class="vertical">
<li class="icon-change-size">
<div class="icon-row" [style.color]="color">
<svg-icon-sprite #iconSprite [src]="'assets/sprites/sprite.svg#' + icon" [width]="width" [viewBox]="'0 0 100 100'"></svg-icon-sprite>
<svg-icon-sprite #iconSprite [src]="icon" [width]="width" [viewBox]="'0 0 100 100'"></svg-icon-sprite>
<!-- Alternatively use the full sprite path via: [src]="'assets/sprites/sprite.svg#' + icon" -->
</div>
<pre style="height: 30px;">&lt;svg-icon-sprite [src]="icon" [width]="width" [viewBox]="'0 0 100 100'"&gt;&lt;/svg-icon&gt;</pre>
</li>
Expand Down
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AppComponent implements OnInit {

changeIconPath(src) {
this.icon = src.split('#')[1] === 'delete_70x70' ? 'star_100x100_viewbox' : 'delete_70x70';
console.log('changed path', this.icon);
}

changeIconSizePlus(width) {
Expand Down

0 comments on commit 9007258

Please sign in to comment.