Skip to content

SvgIcon

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

Basic SVG icon, extends SvgImage.

Usage:

import iconSrc from "./path/to/icon.svg";
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:46

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:35

Icon color


protected _colorTransition: string = ""

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

Icon color transition


protected _container: Element | undefined

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

Element containing this SvgImage (element passed to mount)

SvgImage._container


protected _size: string = ""

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

Icon size


protected _span: HTMLSpanElement

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

<span> element that wraps _svgEl


protected _src: string | undefined

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

User-provided source code

SvgImage._src


protected _svgAttrs: Record<string, any> = {}

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

User-provided attributes

SvgImage._svgAttrs


protected readonly _svgEl: SVGElement

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

<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:78

Last onSrcUpdate call result

SvgImage._updateSrcRes


protected readonly _useEl: SVGUseElement

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

<use> element

SvgImage._useEl


protected _useElAttrs: Record<string, any> = {}

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

User-provided attributes

SvgImage._useElAttrs

protected _setWrapperClass(): void

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

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

void


protected _updateSvgEl(): this

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

Updates SVG element: sets SVG source code, clears previous attributes, sets new attributes

this

this

SvgImage._updateSvgEl


protected _updateUseEl(): SvgIcon

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

Updates <use> element attributes

SvgIcon

this

SvgImage._updateUseEl


getColor(): string

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

string

Current icon color or empty string, if color is unset


getColorTransition(): string

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

string

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


getContainer(): Element | undefined

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

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:124

string

Current icon size or empty string, if size is unset


getSrc(): string | undefined

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

string | undefined

SVG source code

SvgImage.getSrc


getSvgEl(): SVGElement

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

Returns <svg> element.

To assign attributes, use setSvgElAttrs instead.

SVGElement

<svg> element

SvgImage.getSvgEl


getUseEl(): SVGUseElement

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

Returns <use> element.

To assign attributes, use setSvgElAttrs instead.

SVGUseElement

<use> element

SvgImage.getUseEl


getWrapper(): HTMLSpanElement

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

HTMLSpanElement

Wrapper (<span>) element


mount(to): this

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

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. Empty string or undefined unsets color.

Color to set, for example: "red", "var(--icon-color)".

string | undefined

SvgIcon

this


setColorTransition(transition): SvgIcon

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

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

string = DEFAULT_COLOR_TRANSITION

Transition to set, for example: "0.3s linear", "var(--icon-transition)"

SvgIcon

this


setSize(size): SvgIcon

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

Sets icon size. Empty string or undefined unsets size.

Size to set, for example: "24px", "1rem"

string | undefined

SvgIcon

this


setSrc(src): SvgIcon

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

Sets SVG source code

string

SVG source code

SvgIcon

this

SvgImage.setSrc


setSvgElAttrs(attrs): SvgIcon

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

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

Record<string, any>

Attributes to set

SvgIcon

this

SvgImage.setSvgElAttrs


setUseElAttrs(attrs): SvgIcon

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

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

Record<string, any>

Attributes to set

SvgIcon

this

SvgImage.setUseElAttrs


setWrapperAttrs(attrs): SvgIcon

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

Sets wrapper (<span>) element attributes.

Warning: you can’t change class, size, color and color transition using this method

Record<string, any>

Attributes to set

SvgIcon

this


unmount(): this

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

Removes image from the container

this

this

SvgImage.unmount