@progress/kendo-angular-icons
Version:
Kendo UI Angular component starter template
97 lines (96 loc) • 4.2 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Inject, Injectable, Optional } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { isPresent } from './../common/util';
import { IconSettingsService } from './icon-settings.service';
import { ICON_SETTINGS } from './icon-settings';
import { areObjectsEqual } from '@progress/kendo-angular-common';
import * as i0 from "@angular/core";
import * as i1 from "./icon-settings.service";
const DEFAULT_ICON_SETTINGS = { type: 'svg' };
/**
* Represents the service that manages icon settings.
* Add this service to the `providers` array when you use it in a standalone component.
*
* @example
* ```typescript
* import { IconsService } from '@progress/kendo-angular-icons';
*
* @Component({
* selector: 'my-component',
* standalone: true,
* imports: [ ... ],
* providers: [IconsService, { provide: ICON_SETTINGS, useValue: { type: 'font' } }],
* template: `...`
* })
* export class AppComponent {}
* ```
*/
export class IconsService {
_iconSettings;
iconSettingsService;
/**
* Notifies subscribers of the initial icon settings and on each call to `notify`.
* @hidden
*/
changes = new BehaviorSubject(this.iconSettings || DEFAULT_ICON_SETTINGS);
subs = new Subscription();
constructor(_iconSettings, iconSettingsService) {
this._iconSettings = _iconSettings;
this.iconSettingsService = iconSettingsService;
if (iconSettingsService) {
this.subs.add(iconSettingsService.changes
.pipe(map(iconSettings => isPresent(iconSettings) ? iconSettings : this._iconSettings), tap(iconSettings => this._iconSettings = iconSettings))
.subscribe(iconSettings => this.changes.next(iconSettings)));
}
if (isPresent(this.iconSettings) && !areObjectsEqual(this.iconSettings, DEFAULT_ICON_SETTINGS)) {
this.changes.next(this.iconSettings);
}
}
/**
* @hidden
*/
get iconSettings() {
return this._iconSettings;
}
ngOnDestroy() {
this.subs.unsubscribe();
}
/**
* Returns the [`SVGIcon`](slug:api_icons_svgicon) object for the provided key.
* Override in a custom service to provide custom SVG icons.
* @hidden
*/
getSvgIcon(name) {
const customIcon = this.iconSettingsService && this.iconSettingsService.getSvgIcon(name);
return customIcon;
}
/**
* Returns the list of classes to be rendered on the host `SPAN` element of custom font icons.
* Override in a custom service to provide classes for custom font icons.
* @hidden
*/
getCustomFontIconClass(key) {
const customClass = this.iconSettingsService && this.iconSettingsService.getCustomFontIconClass(key);
return customClass;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IconsService, deps: [{ token: ICON_SETTINGS, optional: true }, { token: i1.IconSettingsService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IconsService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IconsService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [ICON_SETTINGS]
}] }, { type: i1.IconSettingsService, decorators: [{
type: Optional
}] }]; } });