Skip to content

Commit

Permalink
add icon api for blazor (#97)
Browse files Browse the repository at this point in the history
add convenience methods for icon registry for blazor.

Co-authored-by: Galina Edinakova <gedinakova@infragistics.com>
  • Loading branch information
gmurray81 and gedinakova authored Nov 3, 2021
1 parent e213af0 commit 64e4f05
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/components/common/decorators/blazorInclude.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Indicates a member should be included in the Blazor API even if non-public.
* @returns a function that does nothing, given that this decorator is for static analysis only.
*/
export function blazorInclude() {
return (_descriptor: any, _memberName: string): any => {};
}
1 change: 1 addition & 0 deletions src/components/common/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './watch';
export * from './alternateName';
export * from './blazorSuppress';
export * from './blazorInclude';
export * from './blazorTwoWayBind';
28 changes: 26 additions & 2 deletions src/components/icon/icon.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { html, LitElement } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
import { alternateName, blazorInclude } from '../common/decorators';
import { SizableMixin } from '../common/mixins/sizable.js';
import { styles } from './icon.material.css';
import { IconsRegistry } from './icon.registry.js';
import {
IconsRegistry,
registerIcon as registerIcon_impl,
registerIconFromText as registerIconFromText_impl,
} from './icon.registry.js';

/**
* Icon component
Expand All @@ -25,6 +30,8 @@ export default class IgcIconComponent extends SizableMixin(LitElement) {

private _collection = 'default';

@property()
@alternateName('iconName')
public set name(value: string) {
if (this._name !== value) {
this._name = value;
Expand All @@ -37,7 +44,6 @@ export default class IgcIconComponent extends SizableMixin(LitElement) {
*
* @attr [name=""]
*/
@property()
public get name(): string {
return this._name;
}
Expand Down Expand Up @@ -99,6 +105,24 @@ export default class IgcIconComponent extends SizableMixin(LitElement) {
protected render() {
return html` ${unsafeSVG(this.svg)} `;
}

@blazorInclude()
protected async registerIcon(
name: string,
url: string,
collection = 'default'
) {
await registerIcon_impl(name, url, collection);
}

@blazorInclude()
protected registerIconFromText(
name: string,
iconText: string,
collection = 'default'
) {
registerIconFromText_impl(name, iconText, collection);
}
}

declare global {
Expand Down

0 comments on commit 64e4f05

Please sign in to comment.