Skip to content

SvgIcon

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

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

You can use this API to extend SvgIcon. This API is the same as in SvgImage, but with additional methods.

Use SvgIcon._updateWrapperBeforeUserAttrsSet, SvgIcon._updateWrapperAfterUserAttrsSet to set custom wrapper (<span>) attributes.

SvgIcon._updateSvgBeforeUserAttrsSet should call super._updateSvgBeforeUserAttrsSet().

new SvgIcon(src, mountTo?): SvgIcon

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

string

ElementOrSelector

SvgIcon

SvgImage.constructor

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

string

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


getContainer(): undefined | Element

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

undefined | Element

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

SvgImage.getContainer


getSize(): string

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

string

Current icon size or empty string, if size is unset


getSrc(): undefined | string

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

undefined | string

SVG source code

SvgImage.getSrc


getSvgEl(): SVGElement

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

Returns <svg> element.

To assign attributes, use setSvgElAttrs instead.

SVGElement

<svg> element

SvgImage.getSvgEl


getUseEl(): SVGUseElement

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

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

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

Sets icon color. Empty string or undefined unsets color.

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

undefined | string

SvgIcon

this


setColorTransition(transition): SvgIcon

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

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"

undefined | string

SvgIcon

this


setSrc(src): SvgIcon

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

Sets SVG source code

string

SVG source code

SvgIcon

this

SvgImage.setSrc


setSvgElAttrs(attrs): SvgIcon

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

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

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

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

Removes image from the container

this

this

SvgImage.unmount