SvgIcon
Defined in: vanilla-integration/src/SvgIcon.ts:18
Basic SVG icon, extends SvgImage.
Example
Section titled “Example”import iconSrc from "./path/to/icon.svg";import { SvgIcon } from "vite-awesome-svg-loader/vanilla-integration";
const icon = new SvgIcon(iconSrc, ".my-container") // Create and mount icon .setContainerAttrs({ title: "My icon" }) // Set container attributes .setColor("red") // Set icon color to red .setColorTransition("0.2s ease-out"); // Change icon color transitionExtends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SvgIcon(
src,mountTo?):SvgIcon
Defined in: vanilla-integration/src/SvgIcon.ts:43
Parameters
Section titled “Parameters”string
SVG source code
mountTo?
Section titled “mountTo?”ElementOrSelector
Element or selector of an element to mount image to. If not provided, image won’t be mounted.
Returns
Section titled “Returns”SvgIcon
Overrides
Section titled “Overrides”Properties
Section titled “Properties”_color
Section titled “_color”
protected_color:string=""
Defined in: vanilla-integration/src/SvgIcon.ts:32
Icon color
_colorTransition
Section titled “_colorTransition”
protected_colorTransition:string=""
Defined in: vanilla-integration/src/SvgIcon.ts:37
Icon color transition
_container
Section titled “_container”
protected_container:Element|undefined
Defined in: vanilla-integration/src/SvgImage.ts:51
Element containing this SvgImage (element passed to mount)
Inherited from
Section titled “Inherited from”
protected_size:string=""
Defined in: vanilla-integration/src/SvgIcon.ts:27
Icon size
protected_span:HTMLSpanElement
Defined in: vanilla-integration/src/SvgIcon.ts:22
<span> element that wraps _svgEl
protected_src:string|undefined
Defined in: vanilla-integration/src/SvgImage.ts:46
User-provided source code
Inherited from
Section titled “Inherited from”_svgEl
Section titled “_svgEl”
protectedreadonly_svgEl:SVGElement
Defined in: vanilla-integration/src/SvgImage.ts:56
<svg> element
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: vanilla-integration/src/SvgImage.ts:66
Last onSrcUpdate call result
Inherited from
Section titled “Inherited from”_useEl
Section titled “_useEl”
protectedreadonly_useEl:SVGUseElement
Defined in: vanilla-integration/src/SvgImage.ts:61
<use> element
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”getColor()
Section titled “getColor()”getColor():
string
Defined in: vanilla-integration/src/SvgIcon.ts:143
Returns
Section titled “Returns”string
Current icon color or empty string, if color is unset
getColorTransition()
Section titled “getColorTransition()”getColorTransition():
string
Defined in: vanilla-integration/src/SvgIcon.ts:164
Returns
Section titled “Returns”string
Current icon color transition or empty string, if transition is unset
getContainer()
Section titled “getContainer()”getContainer():
Element|undefined
Defined in: vanilla-integration/src/SvgImage.ts:176
Returns
Section titled “Returns”Element | undefined
A container of this image, or undefined, if image is not mounted
Inherited from
Section titled “Inherited from”getSize()
Section titled “getSize()”getSize():
string
Defined in: vanilla-integration/src/SvgIcon.ts:122
Returns
Section titled “Returns”string
Current icon size or empty string, if size is unset
getSrc()
Section titled “getSrc()”getSrc():
string|undefined
Defined in: vanilla-integration/src/SvgImage.ts:169
Returns
Section titled “Returns”string | undefined
SVG source code
Inherited from
Section titled “Inherited from”getSvgEl()
Section titled “getSvgEl()”getSvgEl():
SVGElement
Defined in: vanilla-integration/src/SvgImage.ts:187
Returns <svg> element.
To assign attributes, use setSvgElAttrs instead.
Returns
Section titled “Returns”SVGElement
<svg> element
Inherited from
Section titled “Inherited from”getUseEl()
Section titled “getUseEl()”getUseEl():
SVGUseElement
Defined in: vanilla-integration/src/SvgImage.ts:198
Returns <use> element.
To assign attributes, use setSvgElAttrs instead.
Returns
Section titled “Returns”SVGUseElement
<use> element
Inherited from
Section titled “Inherited from”getWrapper()
Section titled “getWrapper()”getWrapper():
HTMLSpanElement
Defined in: vanilla-integration/src/SvgIcon.ts:102
Returns
Section titled “Returns”HTMLSpanElement
Wrapper (<span>) element
mount()
Section titled “mount()”mount(
to):this
Defined in: vanilla-integration/src/SvgIcon.ts:56
Mounts image to the given element
Parameters
Section titled “Parameters”ElementOrSelector
Element or selector of an element to mount image to
Returns
Section titled “Returns”this
this
Overrides
Section titled “Overrides”setColor()
Section titled “setColor()”setColor(
color):SvgIcon
Defined in: vanilla-integration/src/SvgIcon.ts:133
Sets icon color
Parameters
Section titled “Parameters”Color to set, for example: "red", "var(--icon-color)". An empty string or undefined unsets
color.
string | undefined
Returns
Section titled “Returns”SvgIcon
this
setColorTransition()
Section titled “setColorTransition()”setColorTransition(
transition):SvgIcon
Defined in: vanilla-integration/src/SvgIcon.ts:154
Sets icon color transition. This transition is applied when icon color is changed.
Parameters
Section titled “Parameters”transition
Section titled “transition”Transition to set, for example: "0.2s ease-out", "var(--icon-transition)"
An empty string or undefined sets default transition. "none" disables transition.
string | undefined
Returns
Section titled “Returns”SvgIcon
this
setSize()
Section titled “setSize()”setSize(
size):SvgIcon
Defined in: vanilla-integration/src/SvgIcon.ts:112
Sets icon size.
Parameters
Section titled “Parameters”Size to set, for example: "24px", "1rem". An empty string or undefined unsets size.
string | undefined
Returns
Section titled “Returns”SvgIcon
this
setSrc()
Section titled “setSrc()”setSrc(
src):SvgIcon
Defined in: vanilla-integration/src/SvgImage.ts:158
Sets SVG source code
Parameters
Section titled “Parameters”string
SVG source code
Returns
Section titled “Returns”SvgIcon
this
Inherited from
Section titled “Inherited from”setSvgElAttrs()
Section titled “setSvgElAttrs()”setSvgElAttrs(
attrs):SvgIcon
Defined in: vanilla-integration/src/SvgImage.ts:110
Sets <svg> element attributes. It won’t remove id, class and style.
Parameters
Section titled “Parameters”Record<string, SettableAttributeValue>
Attributes to set
Returns
Section titled “Returns”SvgIcon
this
Inherited from
Section titled “Inherited from”setUseElAttrs()
Section titled “setUseElAttrs()”setUseElAttrs(
attrs):SvgIcon
Defined in: vanilla-integration/src/SvgImage.ts:134
Sets <use> element attributes. It won’t remove id, class and style.
Parameters
Section titled “Parameters”Record<string, SettableAttributeValue>
Attributes to set
Returns
Section titled “Returns”SvgIcon
this
Inherited from
Section titled “Inherited from”setWrapperAttrs()
Section titled “setWrapperAttrs()”setWrapperAttrs(
attrs):SvgIcon
Defined in: vanilla-integration/src/SvgIcon.ts:82
Sets wrapper (<span>) element attributes.
Warning: you can’t change class, size, color and color transition using this method
Parameters
Section titled “Parameters”Record<string, SettableAttributeValue>
Attributes to set
Returns
Section titled “Returns”SvgIcon
this
unmount()
Section titled “unmount()”unmount():
this
Defined in: vanilla-integration/src/SvgIcon.ts:61
Removes image from the container
Returns
Section titled “Returns”this
this
Overrides
Section titled “Overrides”_setRequiredSvgElAttrs()
Section titled “_setRequiredSvgElAttrs()”
protected_setRequiredSvgElAttrs():SvgIcon
Defined in: vanilla-integration/src/SvgIcon.ts:68
Sets required attributes to the <svg> element
Returns
Section titled “Returns”SvgIcon
this
Overrides
Section titled “Overrides”SvgImage._setRequiredSvgElAttrs
_setRequiredUseElAttrs()
Section titled “_setRequiredUseElAttrs()”
protected_setRequiredUseElAttrs():SvgIcon
Defined in: vanilla-integration/src/SvgImage.ts:145
Sets required attributes to the <use> element
Returns
Section titled “Returns”SvgIcon
this
Inherited from
Section titled “Inherited from”SvgImage._setRequiredUseElAttrs
_setWrapperClass()
Section titled “_setWrapperClass()”
protected_setWrapperClass():void
Defined in: vanilla-integration/src/SvgIcon.ts:95
Sets wrapper’s (_span) class property to match stylesheet
Returns
Section titled “Returns”void