Skip to content

SvgIcon

Defined in: vanilla-integration/src/SvgIcon.ts:18

Basic SVG icon, extends SvgImage.

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 transition

new SvgIcon(src, mountTo?): SvgIcon

Defined in: vanilla-integration/src/SvgIcon.ts:43

string

SVG source code

ElementOrSelector

Element or selector of an element to mount image to. If not provided, image won’t be mounted.

SvgIcon

SvgImage.constructor

protected _color: string = ""

Defined in: vanilla-integration/src/SvgIcon.ts:32

Icon color


protected _colorTransition: string = ""

Defined in: vanilla-integration/src/SvgIcon.ts:37

Icon color transition


protected _container: Element | undefined

Defined in: vanilla-integration/src/SvgImage.ts:51

Element containing this SvgImage (element passed to mount)

SvgImage._container


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

SvgImage._src


protected readonly _svgEl: SVGElement

Defined in: vanilla-integration/src/SvgImage.ts:56

<svg> element

SvgImage._svgEl


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

SvgImage._updateSrcRes


protected readonly _useEl: SVGUseElement

Defined in: vanilla-integration/src/SvgImage.ts:61

<use> element

SvgImage._useEl

getColor(): string

Defined in: vanilla-integration/src/SvgIcon.ts:143

string

Current icon color or empty string, if color is unset


getColorTransition(): string

Defined in: vanilla-integration/src/SvgIcon.ts:164

string

Current icon color transition or empty string, if transition is unset


getContainer(): Element | undefined

Defined in: vanilla-integration/src/SvgImage.ts:176

Element | undefined

A container of this image, or undefined, if image is not mounted

SvgImage.getContainer


getSize(): string

Defined in: vanilla-integration/src/SvgIcon.ts:122

string

Current icon size or empty string, if size is unset


getSrc(): string | undefined

Defined in: vanilla-integration/src/SvgImage.ts:169

string | undefined

SVG source code

SvgImage.getSrc


getSvgEl(): SVGElement

Defined in: vanilla-integration/src/SvgImage.ts:187

Returns <svg> element.

To assign attributes, use setSvgElAttrs instead.

SVGElement

<svg> element

SvgImage.getSvgEl


getUseEl(): SVGUseElement

Defined in: vanilla-integration/src/SvgImage.ts:198

Returns <use> element.

To assign attributes, use setSvgElAttrs instead.

SVGUseElement

<use> element

SvgImage.getUseEl


getWrapper(): HTMLSpanElement

Defined in: vanilla-integration/src/SvgIcon.ts:102

HTMLSpanElement

Wrapper (<span>) element


mount(to): this

Defined in: vanilla-integration/src/SvgIcon.ts:56

Mounts image to the given element

ElementOrSelector

Element or selector of an element to mount image to

this

this

SvgImage.mount


setColor(color): SvgIcon

Defined in: vanilla-integration/src/SvgIcon.ts:133

Sets icon color

Color to set, for example: "red", "var(--icon-color)". An empty string or undefined unsets color.

string | undefined

SvgIcon

this


setColorTransition(transition): SvgIcon

Defined in: vanilla-integration/src/SvgIcon.ts:154

Sets icon color transition. This transition is applied when icon color is changed.

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

SvgIcon

this


setSize(size): SvgIcon

Defined in: vanilla-integration/src/SvgIcon.ts:112

Sets icon size.

Size to set, for example: "24px", "1rem". An empty string or undefined unsets size.

string | undefined

SvgIcon

this


setSrc(src): SvgIcon

Defined in: vanilla-integration/src/SvgImage.ts:158

Sets SVG source code

string

SVG source code

SvgIcon

this

SvgImage.setSrc


setSvgElAttrs(attrs): SvgIcon

Defined in: vanilla-integration/src/SvgImage.ts:110

Sets <svg> element attributes. It won’t remove id, class and style.

Record<string, SettableAttributeValue>

Attributes to set

SvgIcon

this

SvgImage.setSvgElAttrs


setUseElAttrs(attrs): SvgIcon

Defined in: vanilla-integration/src/SvgImage.ts:134

Sets <use> element attributes. It won’t remove id, class and style.

Record<string, SettableAttributeValue>

Attributes to set

SvgIcon

this

SvgImage.setUseElAttrs


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

Record<string, SettableAttributeValue>

Attributes to set

SvgIcon

this


unmount(): this

Defined in: vanilla-integration/src/SvgIcon.ts:61

Removes image from the container

this

this

SvgImage.unmount


protected _setRequiredSvgElAttrs(): SvgIcon

Defined in: vanilla-integration/src/SvgIcon.ts:68

Sets required attributes to the <svg> element

SvgIcon

this

SvgImage._setRequiredSvgElAttrs


protected _setRequiredUseElAttrs(): SvgIcon

Defined in: vanilla-integration/src/SvgImage.ts:145

Sets required attributes to the <use> element

SvgIcon

this

SvgImage._setRequiredUseElAttrs


protected _setWrapperClass(): void

Defined in: vanilla-integration/src/SvgIcon.ts:95

Sets wrapper’s (_span) class property to match stylesheet

void