Skip to content

Commit

Permalink
Merge pull request #158 from czeckd/bugfix/src-should-not-be-required
Browse files Browse the repository at this point in the history
Remove required src and allow for html-loading to set name
  • Loading branch information
czeckd authored Jul 4, 2024
2 parents 63e65a8 + 09b6779 commit 7256b3d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ Basic usage is:
```
*Note that without a height or width set, the SVG may not display!*

If svg was previously loaded via registry with name it can be used like this:
Loading with a name:
```html
<svg-icon src="images/eye.svg" name="eye" [svgStyle]="{ 'width.px':90 }"></svg-icon>
```

If the SVG was previously loaded with a name either via the component or registry, then it can be used like this:
```html
<svg-icon name="eye" [svgStyle]="{ 'width.px':90 }"></svg-icon>
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "svg-icon",
"description": "Angular 18 component and service for inlining SVGs allowing them to be easily styled with CSS.",
"version": "18.0.0",
"version": "18.0.1",
"repository": {
"type": "git",
"url": "https://github.com/czeckd/angular-svg-icon.git"
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-svg-icon/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-svg-icon",
"description": "Angular 18 component and service for inlining SVGs allowing them to be easily styled with CSS.",
"version": "18.0.0",
"version": "18.0.1",
"repository": {
"type": "git",
"url": "https://github.com/czeckd/angular-svg-icon.git"
Expand Down
11 changes: 8 additions & 3 deletions projects/angular-svg-icon/src/lib/svg-icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SvgIconComponent implements OnDestroy {
private renderer = inject(Renderer2);
private iconReg = inject(SvgIconRegistryService);

src = input.required<string>();
src = input<string>();
name = input<string>();
stretch = input(false);
applyClass = input(false);
Expand Down Expand Up @@ -115,8 +115,13 @@ export class SvgIconComponent implements OnDestroy {
return this.element.nativeElement.firstChild;
}

private init(src: string, name?: string) {
if (name) {
private init(src?: string, name?: string) {
if (src && name) {
const svgObs = this.iconReg.loadSvg(src, name);
if (svgObs) {
this.helper.icnSub = svgObs.subscribe(svg => this.initSvg(svg));
}
} else if (name) {
const svgObs = this.iconReg.getSvgByName(name);
if (svgObs) {
this.helper.icnSub = svgObs.subscribe(svg => this.initSvg(svg));
Expand Down
4 changes: 2 additions & 2 deletions src/app/demo-app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<div class="example"> <!-- style="width:500px;display: flex;"> -->
<svg-icon src="assets/images/eye.svg" class="red"></svg-icon>
<svg-icon src="assets/images/eye.svg" class="green" style="transform: scaleX(-1);"></svg-icon>
<svg-icon src="assets/images/eye.svg" class="blue"></svg-icon>
<svg-icon src="assets/images/eye.svg" name="eye" class="green" style="transform: scaleX(-1);"></svg-icon>
<svg-icon name="eye" class="blue"></svg-icon>
</div>

<form style="clear:both;">
Expand Down

0 comments on commit 7256b3d

Please sign in to comment.