icon.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { ElementRef, OnChanges, OnInit, SimpleChanges, InjectionToken, OnDestroy, AfterViewChecked } from '@angular/core';
  9. import { CanColor, CanColorCtor } from '@angular/material/core';
  10. import { MatIconRegistry } from './icon-registry';
  11. /** @docs-private */
  12. declare class MatIconBase {
  13. _elementRef: ElementRef;
  14. constructor(_elementRef: ElementRef);
  15. }
  16. declare const _MatIconMixinBase: CanColorCtor & typeof MatIconBase;
  17. /**
  18. * Injection token used to provide the current location to `MatIcon`.
  19. * Used to handle server-side rendering and to stub out during unit tests.
  20. * @docs-private
  21. */
  22. export declare const MAT_ICON_LOCATION: InjectionToken<MatIconLocation>;
  23. /**
  24. * Stubbed out location for `MatIcon`.
  25. * @docs-private
  26. */
  27. export interface MatIconLocation {
  28. getPathname: () => string;
  29. }
  30. /** @docs-private */
  31. export declare function MAT_ICON_LOCATION_FACTORY(): MatIconLocation;
  32. /**
  33. * Component to display an icon. It can be used in the following ways:
  34. *
  35. * - Specify the svgIcon input to load an SVG icon from a URL previously registered with the
  36. * addSvgIcon, addSvgIconInNamespace, addSvgIconSet, or addSvgIconSetInNamespace methods of
  37. * MatIconRegistry. If the svgIcon value contains a colon it is assumed to be in the format
  38. * "[namespace]:[name]", if not the value will be the name of an icon in the default namespace.
  39. * Examples:
  40. * `<mat-icon svgIcon="left-arrow"></mat-icon>
  41. * <mat-icon svgIcon="animals:cat"></mat-icon>`
  42. *
  43. * - Use a font ligature as an icon by putting the ligature text in the content of the `<mat-icon>`
  44. * component. By default the Material icons font is used as described at
  45. * http://google.github.io/material-design-icons/#icon-font-for-the-web. You can specify an
  46. * alternate font by setting the fontSet input to either the CSS class to apply to use the
  47. * desired font, or to an alias previously registered with MatIconRegistry.registerFontClassAlias.
  48. * Examples:
  49. * `<mat-icon>home</mat-icon>
  50. * <mat-icon fontSet="myfont">sun</mat-icon>`
  51. *
  52. * - Specify a font glyph to be included via CSS rules by setting the fontSet input to specify the
  53. * font, and the fontIcon input to specify the icon. Typically the fontIcon will specify a
  54. * CSS class which causes the glyph to be displayed via a :before selector, as in
  55. * https://fortawesome.github.io/Font-Awesome/examples/
  56. * Example:
  57. * `<mat-icon fontSet="fa" fontIcon="alarm"></mat-icon>`
  58. */
  59. export declare class MatIcon extends _MatIconMixinBase implements OnChanges, OnInit, AfterViewChecked, CanColor, OnDestroy {
  60. private _iconRegistry;
  61. /**
  62. * @deprecated `location` parameter to be made required.
  63. * @breaking-change 8.0.0
  64. */
  65. private _location?;
  66. /**
  67. * Whether the icon should be inlined, automatically sizing the icon to match the font size of
  68. * the element the icon is contained in.
  69. */
  70. inline: boolean;
  71. private _inline;
  72. /** Name of the icon in the SVG icon set. */
  73. svgIcon: string;
  74. /** Font set that the icon is a part of. */
  75. fontSet: string;
  76. private _fontSet;
  77. /** Name of an icon within a font set. */
  78. fontIcon: string;
  79. private _fontIcon;
  80. private _previousFontSetClass;
  81. private _previousFontIconClass;
  82. /** Keeps track of the current page path. */
  83. private _previousPath?;
  84. /** Keeps track of the elements and attributes that we've prefixed with the current path. */
  85. private _elementsWithExternalReferences?;
  86. constructor(elementRef: ElementRef<HTMLElement>, _iconRegistry: MatIconRegistry, ariaHidden: string,
  87. /**
  88. * @deprecated `location` parameter to be made required.
  89. * @breaking-change 8.0.0
  90. */
  91. _location?: MatIconLocation | undefined);
  92. /**
  93. * Splits an svgIcon binding value into its icon set and icon name components.
  94. * Returns a 2-element array of [(icon set), (icon name)].
  95. * The separator for the two fields is ':'. If there is no separator, an empty
  96. * string is returned for the icon set and the entire value is returned for
  97. * the icon name. If the argument is falsy, returns an array of two empty strings.
  98. * Throws an error if the name contains two or more ':' separators.
  99. * Examples:
  100. * `'social:cake' -> ['social', 'cake']
  101. * 'penguin' -> ['', 'penguin']
  102. * null -> ['', '']
  103. * 'a:b:c' -> (throws Error)`
  104. */
  105. private _splitIconName;
  106. ngOnChanges(changes: SimpleChanges): void;
  107. ngOnInit(): void;
  108. ngAfterViewChecked(): void;
  109. ngOnDestroy(): void;
  110. private _usingFontIcon;
  111. private _setSvgElement;
  112. private _clearSvgElement;
  113. private _updateFontIconClasses;
  114. /**
  115. * Cleans up a value to be used as a fontIcon or fontSet.
  116. * Since the value ends up being assigned as a CSS class, we
  117. * have to trim the value and omit space-separated values.
  118. */
  119. private _cleanupFontValue;
  120. /**
  121. * Prepends the current path to all elements that have an attribute pointing to a `FuncIRI`
  122. * reference. This is required because WebKit browsers require references to be prefixed with
  123. * the current path, if the page has a `base` tag.
  124. */
  125. private _prependPathToReferences;
  126. /**
  127. * Caches the children of an SVG element that have `url()`
  128. * references that we need to prefix with the current path.
  129. */
  130. private _cacheChildrenWithExternalReferences;
  131. }
  132. export {};