Skip to content

Commit

Permalink
fix: hardcoded iconhref in icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoninoBonanno authored and astagi committed May 15, 2023
1 parent bb3f03b commit dff8a25
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ChangeDetectionStrategy, Component, Inject, Input } from '@angular/core';
import { IconColor, IconName, IconSize } from '../../../interfaces/icon';
import { BooleanInput, isTrueBooleanInput } from '../../../utils/boolean-input';
import { DESIGN_ANGULAR_KIT_CONFIG, DesignAngularKitConfig } from '../../../design-angular-kit-config';

@Component({
selector: 'it-icon[name]',
Expand Down Expand Up @@ -38,7 +39,7 @@ export class IconComponent {
* Return the icon href
*/
get iconHref(): string {
return `./bootstrap-italia/dist/svg/sprites.svg#it-${this.name}`;
return `${this.config.iconHref}#it-${this.name}`;
}

/**
Expand All @@ -61,4 +62,8 @@ export class IconComponent {
return iconClass;
}

constructor(
@Inject(DESIGN_ANGULAR_KIT_CONFIG) private readonly config: DesignAngularKitConfig
) {
}
}
5 changes: 5 additions & 0 deletions src/app/icon/icon-index/icon-index.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ <h1 class="bd-title">Icone</h1>
</it-tab-item>
<it-tab-item label="API" class="pt-3">
<h3>IconComponent</h3>

<p>E' possibile configurare il path <strong>href</strong> del componente attraverso la configurazione iniziale della libreria.</p>

<it-source-display [typescript]="hrefLibraryConfig"></it-source-display>

<it-api-parameters [component]="component"></it-api-parameters>
</it-tab-item>
</it-tab-container>
17 changes: 17 additions & 0 deletions src/app/icon/icon-index/icon-index.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ export class IconIndexComponent {

component: any;

readonly hrefLibraryConfig = "import {DesignAngularKitModule, DesignAngularKitInit} from 'design-angular-kit';\n" +
" \n" +
" const initConfig: DesignAngularKitInit = {\n" +
" /**\n" +
" * The initial path in the `href` attribute in the `IconComponent` component\n" +
" * @default './bootstrap-italia/dist/svg/sprites.svg'\n" +
" */\n" +
" iconHref: 'my-path/svg/sprites.svg',\n" +
" };\n" +
" \n" +
" @NgModule({\n" +
" imports: [\n" +
" ...\n" +
" DesignAngularKitModule.forRoot(initConfig)\n" +
" ]\n" +
" })";

constructor() {
this.component = (<any>Documentation).components.find(component => component.name === 'IconComponent');
}
Expand Down

0 comments on commit dff8a25

Please sign in to comment.