@xui/components
Version:
xUI Components for Angular
143 lines (142 loc) • 6.89 kB
TypeScript
import { AfterViewChecked, ElementRef, ErrorHandler, InjectionToken, OnDestroy, OnInit } from '@angular/core';
import { XuiIconRegistry } from './icon-registry';
import * as i0 from "@angular/core";
export type IconColor = 'primary';
/** Default options for `xui-icon`. */
export interface XuiIconDefaultOptions {
/** Default color of the icon. */
color?: IconColor;
/** Font set that the icon is a part of. */
fontSet?: string;
}
/** Injection token to be used to override the default options for `xui-icon`. */
export declare const XUI_ICON_DEFAULT_OPTIONS: InjectionToken<XuiIconDefaultOptions>;
/**
* Injection token used to provide the current location to `XuiIcon`.
* Used to handle server-side rendering and to stub out during unit tests.
* @docs-private
*/
export declare const XUI_ICON_LOCATION: InjectionToken<XuiIconLocation>;
/**
* Stubbed out location for `XuiIcon`.
* @docs-private
*/
export interface XuiIconLocation {
getPathname: () => string;
}
/** @docs-private */
export declare function XUI_ICON_LOCATION_FACTORY(): XuiIconLocation;
/**
* Component to display an icon. It can be used in the following ways:
*
* - Specify the svgIcon input to load an SVG icon from a URL previously registered with the
* addSvgIcon, addSvgIconInNamespace, addSvgIconSet, or addSvgIconSetInNamespace methods of
* XuiIconRegistry. If the svgIcon value contains a colon it is assumed to be in the format
* "[namespace]:[name]", if not the value will be the name of an icon in the default namespace.
* Examples:
* `<xui-icon svgIcon="left-arrow"></xui-icon>
* <xui-icon svgIcon="animals:cat"></xui-icon>`
*
* - Use a font ligature as an icon by putting the ligature text in the `fontIcon` attribute or the
* content of the `<xui-icon>` component. If you register a custom font class, don't forget to also
* include the special class `x-ligature-font`. It is recommended to use the attribute alternative
* to prevent the ligature text to be selectable and to appear in search engine results.
* By default, the Material icons font is used as described at
* http://google.github.io/material-design-icons/#icon-font-for-the-web. You can specify an
* alternate font by setting the fontSet input to either the CSS class to apply to use the
* desired font, or to an alias previously registered with XuiIconRegistry.registerFontClassAlias.
* Examples:
* `<xui-icon fontIcon="home"></xui-icon>
* <xui-icon>home</xui-icon>
* <xui-icon fontSet="myfont" fontIcon="sun"></xui-icon>
* <xui-icon fontSet="myfont">sun</xui-icon>`
*
* - Specify a font glyph to be included via CSS rules by setting the fontSet input to specify the
* font, and the fontIcon input to specify the icon. Typically, the fontIcon will specify a
* CSS class which causes the glyph to be displayed via a :before selector, as in
* https://fortawesome.github.io/Font-Awesome/examples/
* Example:
* `<xui-icon fontSet="fa" fontIcon="alarm"></xui-icon>`
*/
export declare class XuiIcon implements OnInit, AfterViewChecked, OnDestroy {
readonly _elementRef: ElementRef<HTMLElement>;
private _iconRegistry;
private _location;
private readonly _errorHandler;
private readonly _defaultColor;
private _color;
private _svgIcon;
private _fontSet;
private _fontIcon;
private _previousFontSetClass;
private _previousFontIconClass;
_svgName: string | null;
_svgNamespace: string | null;
/** Keeps track of the current page path. */
private _previousPath?;
/** Keeps track of the elements and attributes that we've prefixed with the current path. */
private _elementsWithExternalReferences?;
/** Subscription to the current in-progress SVG icon request. */
private _currentIconFetch;
/** Color of the icon. */
get color(): string | null | undefined;
set color(value: string | null | undefined);
/**
* Whether the icon should be inlined, automatically sizing the icon to match the font size of
* the element the icon is contained in.
*/
inline: boolean;
/** Name of the icon in the SVG icon set. */
get svgIcon(): string;
set svgIcon(value: string);
/** Font set that the icon is a part of. */
get fontSet(): string;
set fontSet(value: string);
/** Name of an icon within a font set. */
get icon(): string;
set icon(value: string);
constructor(_elementRef: ElementRef<HTMLElement>, _iconRegistry: XuiIconRegistry, ariaHidden: string, _location: XuiIconLocation, _errorHandler: ErrorHandler, defaults?: XuiIconDefaultOptions);
/**
* Splits an svgIcon binding value into its icon set and icon name components.
* Returns a 2-element array of [(icon set), (icon name)].
* The separator for the two fields is ':'. If there is no separator, an empty
* string is returned for the icon set and the entire value is returned for
* the icon name. If the argument is falsy, returns an array of two empty strings.
* Throws an error if the name contains two or more ':' separators.
* Examples:
* `'social:cake' -> ['social', 'cake']
* 'penguin' -> ['', 'penguin']
* null -> ['', '']
* 'a:b:c' -> (throws Error)`
*/
private _splitIconName;
ngOnInit(): void;
ngAfterViewChecked(): void;
ngOnDestroy(): void;
_usingFontIcon(): boolean;
private _setSvgElement;
private _clearSvgElement;
private _updateFontIconClasses;
/**
* Cleans up a value to be used as a fontIcon or fontSet.
* Since the value ends up being assigned as a CSS class, we
* have to trim the value and omit space-separated values.
*/
private _cleanupFontValue;
/**
* Prepends the current path to all elements that have an attribute pointing to a `FuncIRI`
* reference. This is required because WebKit browsers require references to be prefixed with
* the current path, if the page has a `base` tag.
*/
private _prependPathToReferences;
/**
* Caches the children of an SVG element that have `url()`
* references that we need to prefix with the current path.
*/
private _cacheChildrenWithExternalReferences;
/** Sets a new SVG icon with a particular name. */
private _updateSvgIcon;
static ɵfac: i0.ɵɵFactoryDeclaration<XuiIcon, [null, null, { attribute: "aria-hidden"; }, null, null, { optional: true; }]>;
static ɵcmp: i0.ɵɵComponentDeclaration<XuiIcon, "xui-icon", ["xuiIcon"], { "color": { "alias": "color"; "required": false; }; "inline": { "alias": "inline"; "required": false; }; "svgIcon": { "alias": "svgIcon"; "required": false; }; "fontSet": { "alias": "fontSet"; "required": false; }; "icon": { "alias": "icon"; "required": false; }; }, {}, never, ["*"], true, never>;
static ngAcceptInputType_inline: unknown;
}