Skip to content

Commit

Permalink
Remove option to inject IconSettings via IconRegistryService construc…
Browse files Browse the repository at this point in the history
…tor (#2171)

* 🔥 Remove unused icon config

These custom icons are registered in the module (examples.module.ts)
and this is most likely leftover functionality from before that.

* 🔥 Remove option for injecting icons via ctor

* 🔥 Remove injected IconSettings
  • Loading branch information
RasmusKjeldgaard authored Apr 20, 2022
1 parent ee02617 commit f906f40
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 49 deletions.
19 changes: 0 additions & 19 deletions apps/cookbook/src/app/examples/examples.common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { DropdownExampleComponent } from '~/app/examples/dropdown-example/dropdown-example.component';
import { PagePullToRefreshExampleComponent } from '~/app/examples/page-example/pull-to-refresh/page-pull-to-refresh-example.component';

import { IconSettings, ICON_SETTINGS } from '@kirbydesign/designsystem';

import { AccordionExampleComponent } from './accordion-example/accordion-example.component';
import { ActionSheetExampleComponent } from './action-sheet-example/action-sheet-example.component';
import { AlertExampleComponent } from './alert-example/alert-example.component';
Expand Down Expand Up @@ -53,20 +51,6 @@ import { TabsExampleComponent } from './tabs-example/tabs-example.component';
import { ToastExampleComponent } from './toast-example/toast-example.component';
import { ToggleExampleComponent } from './toggle-example/toggle-example.component';

// Example of "custom" icons
export const iconSettings: IconSettings = {
icons: [
{
name: 'football',
svg: 'assets/icons/football.svg',
},
{
name: 'umbrella',
svg: 'assets/icons/umbrella.svg',
},
],
};

export const COMPONENT_DECLARATIONS: any[] = [
ExamplesComponent,
ButtonExampleComponent,
Expand Down Expand Up @@ -121,6 +105,3 @@ export const COMPONENT_DECLARATIONS: any[] = [
SectionHeaderExampleComponent,
ListExperimentalExampleComponent,
];

// Configure custom icons (used by example to show the usage of custom icons)
export const PROVIDER_DECLARATIONS: any[] = [{ provide: ICON_SETTINGS, useValue: iconSettings }];
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IconRegistryService } from './icon-registry.service';
import { IconSettings } from './icon-settings';

describe('KirbyIconRegistryService', () => {
let service: IconRegistryService;
Expand All @@ -12,21 +11,6 @@ describe('KirbyIconRegistryService', () => {
expect(service).toBeTruthy();
});

it('should register icons if injected', () => {
const consoleWarnSpy = spyOn(console, 'warn');
const iconSettings: IconSettings = {
icons: [
{ name: 'name1', svg: 'svg1' },
{ name: 'name2', svg: 'svg2' },
],
};
service = new IconRegistryService(iconSettings);
expect(service.getIcons()).toEqual(iconSettings.icons);
expect(consoleWarnSpy).toHaveBeenCalledWith(
'Use of IconSettings is deprecated, use IconRegistryService instead'
);
});

describe('getIcon', () => {
it('should return undefined if no icons registered', () => {
expect(service.getIcon('test')).toBeUndefined();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { Inject, Injectable, Optional } from '@angular/core';
import { Injectable } from '@angular/core';

import { Icon, IconSettings, ICON_SETTINGS } from './icon-settings';
import { Icon } from './icon-settings';

@Injectable({
providedIn: 'root',
})
export class IconRegistryService {
private iconRegistry = new Map<string, string>();

constructor(@Optional() @Inject(ICON_SETTINGS) iconSettings?: IconSettings) {
if (iconSettings) {
this.addIcons(iconSettings.icons);
console.warn(`Use of IconSettings is deprecated, use IconRegistryService instead`);
}
}

public addIcon(iconName: string, svgPath: string): void {
if (!this.iconRegistry.has(iconName)) {
this.iconRegistry.set(iconName, svgPath);
Expand Down
4 changes: 0 additions & 4 deletions libs/designsystem/src/lib/components/icon/icon-settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { InjectionToken } from '@angular/core';

export interface Icon {
name: string;
svg?: string;
Expand All @@ -8,5 +6,3 @@ export interface Icon {
export interface IconSettings {
icons: Icon[];
}

export const ICON_SETTINGS = new InjectionToken<IconSettings>('IconSettings');
2 changes: 1 addition & 1 deletion libs/designsystem/src/lib/components/icon/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { IconComponent, IconSize } from './icon.component';
export { IconModule } from './icon.module';
export { IconSettings, ICON_SETTINGS, Icon } from './icon-settings';
export { IconSettings, Icon } from './icon-settings';
export { defaultIcons } from './kirby-icon-settings';
export { IconRegistryService } from './icon-registry.service';

0 comments on commit f906f40

Please sign in to comment.