SvgIcon
Defined in: web-components-integration/src/SvgIcon.ts:40
Basic SVG icon.
If you plan to define SvgImage under a non-default tag, define it before creating SVG icons. Otherwise, an error will be thrown.
Example
Section titled “Example”// Import SVG source code:import imgSrc from "@/assets/image.svg?src";
// Import web component:import { SvgIcon } from "vite-awesome-svg-loader/web-components-integration";
// Define a custom element:SvgIcon.define();
// Create icon:const icon = new SvgIcon();// or:const icon = document.createElement("svg-icon");
// Assign SVG source code to the image:icon.src = imgSrc;
// Stylize icon:icon.color = "red";icon.size = "24px";icon.colorTransition = "0.2s ease-out";
// Add image to the DOM:document.body.appendChild(icon);Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SvgIcon():
SvgIcon
Defined in: web-components-integration/src/SvgIcon.ts:72
Returns
Section titled “Returns”SvgIcon
Overrides
Section titled “Overrides”Properties
Section titled “Properties”color?
Section titled “color?”
optionalcolor:string
Defined in: web-components-integration/src/SvgIcon.ts:58
Icon color. Empty string unsets color.
colorTransition
Section titled “colorTransition”colorTransition:
string
Defined in: web-components-integration/src/SvgIcon.ts:65
Icon color transition. Empty string unsets transition.
To set default value, use DEFAULT_COLOR_TRANSITION.
optionalsize:string
Defined in: web-components-integration/src/SvgIcon.ts:53
Icon size. Empty string unsets size.
optionalsrc:string
Defined in: web-components-integration/src/SvgIcon.ts:48
Image source code
_state
Section titled “_state”
protected_state:WebComponentState="uninitialized"
Defined in: web-components-integration/src/WebComponent.ts:284
Current component state. See WebComponentState for the details.
Inherited from
Section titled “Inherited from”DEFAULT_COLOR_TRANSITION
Section titled “DEFAULT_COLOR_TRANSITION”
staticDEFAULT_COLOR_TRANSITION:string=SVG_ICON_DEFAULT_COLOR_TRANSITION
Defined in: web-components-integration/src/SvgIcon.ts:41
observedAttributes?
Section titled “observedAttributes?”
staticoptionalobservedAttributes:string[]
Defined in: web-components-integration/src/WebComponent.ts:270
Doesn’t do anything. All attributes are already observed. This property will be deleted when custom element will be defined.
This property is recognized for compatibility reasons only.
Inherited from
Section titled “Inherited from”WebComponent.observedAttributes
readonlystaticprops: (string| {default:string;name:string; })[]
Defined in: web-components-integration/src/SvgIcon.ts:43
Properties that will be synced with attributes.
Properties must be in camelCase. Synchronized attributes will be in kebab-case.
To not confuse cases, prefer single-word names.
Overrides
Section titled “Overrides”Methods
Section titled “Methods”attributeChangedCallback()
Section titled “attributeChangedCallback()”attributeChangedCallback(
name,oldValue,newValue):void
Defined in: web-components-integration/src/SvgIcon.ts:89
Called when:
-
Component has just finished initialization. Then:
- _state property will be
attrs-first-change. oldValueargument will benull.newValuewill have a default value ornull, if there’s no default.- Thus, following may be true:
oldValue === newValue && newValue === null.
- _state property will be
-
Any of the element’s attributes has actually changed (unlike default custom elements’ behavior where this method is called even if the same value has been set). Then:
- _state property will be
normal. oldValueandnewValuewill be always different.
- _state property will be
Parameters
Section titled “Parameters”string
oldValue
Section titled “oldValue”string | null
newValue
Section titled “newValue”string | null
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”WebComponent.attributeChangedCallback
connectedCallback()
Section titled “connectedCallback()”connectedCallback():
void
Defined in: web-components-integration/src/SvgIcon.ts:80
Called when the element is added to a document.
If overridden, super.connectedCallback() must be the first statement.
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”WebComponent.connectedCallback
getAttribute()
Section titled “getAttribute()”getAttribute(
name):string|null
Defined in: web-components-integration/src/WebComponent.ts:412
The getAttribute() method of the element.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string | null
Inherited from
Section titled “Inherited from”removeAttribute()
Section titled “removeAttribute()”removeAttribute(
name):void
Defined in: web-components-integration/src/WebComponent.ts:423
The Element method removeAttribute() removes the attribute with the specified name from the element.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”setAttribute()
Section titled “setAttribute()”setAttribute(
name,value):void
Defined in: web-components-integration/src/WebComponent.ts:419
The setAttribute() method of the Element interface sets the value of an attribute on the specified element.
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”toggleAttribute()
Section titled “toggleAttribute()”toggleAttribute(
name,force?):boolean
Defined in: web-components-integration/src/WebComponent.ts:427
The toggleAttribute() method of the present and adding it if it is not present) on the given element.
Parameters
Section titled “Parameters”string
force?
Section titled “force?”boolean
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”_ctor()
Section titled “_ctor()”
protected_ctor(): typeofWebComponent
Defined in: web-components-integration/src/WebComponent.ts:485
Returns a constructor of this class
If you need to refer to your own class, type it like so:
class MyClass extends WebComponent { declare protected _ctor: () => typeof MyClass}Returns
Section titled “Returns”typeof WebComponent
constructor of this class
Inherited from
Section titled “Inherited from”_init()
Section titled “_init()”
protected_init():void
Defined in: web-components-integration/src/WebComponent.ts:353
Initializes component state.
Custom elements may not add attributes or children in a constructor, so separate initialization is required. Thus, this method is called whenever an attribute is accessed or in a microtask after component’s constructor has run.
Initialization is performed only once.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”define()
Section titled “define()”
staticdefine(options):void
Defined in: web-components-integration/src/SvgIcon.ts:97
Defines a custom element for this web component.
Won’t throw an error if called multiple times with the same tag.
Will throw an error (unless suppressed via BasicWebComponentDefinitionOptions.noRedefinitionError) if defined under a different tag.
Parameters
Section titled “Parameters”options
Section titled “options”WebComponentDefinitionOptions = {}
Definition options
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”_initClass()
Section titled “_initClass()”
protectedstatic_initClass():void
Defined in: web-components-integration/src/WebComponent.ts:527
Initializes class itself. Called by define and by the constructor. Initialization happens only once.
Returns
Section titled “Returns”void