SvgImage
Defined in: web-components-integration/src/SvgImage.ts:58
Basic SVG image. Implements SVG sprites. Adds <svg> element with the symbols to the <body>.
Pass SVG source code to the src property, so the image will be rendered.
Every attribute that starts with svg- string will be passed down to the <svg> element.
Every attribute that starts with use- string will be passed down to the <use> element.
Example
Section titled “Example”// Import SVG source code:import imgSrc from "@/assets/image.svg?src";
// Import web component:import { SvgImage } from "vite-awesome-svg-loader/web-components-integration";
// Define a custom element:SvgImage.define();
// Create image:const img = new SvgImage();// or:const img = document.createElement("svg-image");
// Assign SVG source code to the image:img.src = imgSrc;
// Add image to the DOM:document.body.appendChild(img);
// Set attributes to <svg> element:img.setAttribute("svg-preserveAspectRatio", "xMaxYMin"); // Will set preserveAspectRatio="xMaxYMin"
// Set attributes to <use> element:img.setAttribute("use-data-test", "use-el"); // will set data-test="use-el"Extends
Section titled “Extends”Implements
Section titled “Implements”CustomElement
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SvgImage():
SvgImage
Defined in: web-components-integration/src/SvgImage.ts:90
Returns
Section titled “Returns”SvgImage
Overrides
Section titled “Overrides”Properties
Section titled “Properties”src:
string
Defined in: web-components-integration/src/SvgImage.ts:66
SVG 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”_updateSrcRes
Section titled “_updateSrcRes”
protected_updateSrcRes: {attrs?:undefined;id?:undefined; } | {attrs: {height:string;viewBox:string;width:string; };id:string; } | {attrs?:undefined;id:string; } ={}
Defined in: web-components-integration/src/SvgImage.ts:71
Last src update result
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:object[]
Defined in: web-components-integration/src/SvgImage.ts:59
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.
default
Section titled “default”default:
string=EMPTY_SVG
name:
string="src"
Overrides
Section titled “Overrides”Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get svgEl():
SVGElement
Defined in: web-components-integration/src/SvgImage.ts:86
<svg> element
Returns
Section titled “Returns”SVGElement
Get Signature
Section titled “Get Signature”get useEl():
SVGUseElement
Defined in: web-components-integration/src/SvgImage.ts:79
<use> element
Returns
Section titled “Returns”SVGUseElement
Methods
Section titled “Methods”attributeChangedCallback()
Section titled “attributeChangedCallback()”attributeChangedCallback(
name,oldValue,newValue):void
Defined in: web-components-integration/src/SvgImage.ts:110
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
Implementation of
Section titled “Implementation of”CustomElement.attributeChangedCallback
Overrides
Section titled “Overrides”WebComponent.attributeChangedCallback
connectedCallback()
Section titled “connectedCallback()”connectedCallback():
void
Defined in: web-components-integration/src/SvgImage.ts:97
Called when the element is added to a document.
If overridden, super.connectedCallback() must be the first statement.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”CustomElement.connectedCallback
Overrides
Section titled “Overrides”WebComponent.connectedCallback
disconnectedCallback()
Section titled “disconnectedCallback()”disconnectedCallback():
void
Defined in: web-components-integration/src/SvgImage.ts:106
Called when the element is removed from a document.
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”CustomElement.disconnectedCallback
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
Implementation of
Section titled “Implementation of”CustomElement.getAttribute
Inherited from
Section titled “Inherited from”getStyleId()
Section titled “getStyleId()”getStyleId():
string
Defined in: web-components-integration/src/SvgImage.ts:131
Returns
Section titled “Returns”string
ID of a <style> element that styles this component
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
Implementation of
Section titled “Implementation of”CustomElement.removeAttribute
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
Implementation of
Section titled “Implementation of”CustomElement.setAttribute
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
Implementation of
Section titled “Implementation of”CustomElement.toggleAttribute
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/SvgImage.ts:159
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