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

Internal API

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().

Hierarchy (view full)

Constructors

Properties

_color: undefined | string
_colorTransition: undefined | string
_container: undefined | Element
_size: undefined | string
_span: HTMLSpanElement
_src: undefined | string

User-provided source code

_svgAttrs: Record<string, any> = {}

User-provided attributes

_svgEl: SVGElement
_updateSrcRes: {
    attrs?: undefined;
    id?: undefined;
} | {
    attrs: {
        height: string;
        viewBox: string;
        width: string;
    };
    id: string;
} | {
    attrs?: undefined;
    id: string;
} = {}

Last src update result

Type declaration

  • Optional attrs?: undefined
  • Optional id?: undefined

Type declaration

  • attrs: {
        height: string;
        viewBox: string;
        width: string;
    }
    • height: string
    • viewBox: string
    • width: string
  • id: string

Type declaration

  • Optional attrs?: undefined
  • id: string
_useEl: SVGUseElement
_useElAttrs: Record<string, any> = {}

User-provided attributes

Methods

  • Called after user-provided attributes are set. You can use this function to set custom wrapper (<span>) attributes.

    Returns void

  • Called before user-provided attributes are set. You can use this function to set custom wrapper (<span>) attributes.

    Returns void

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

    Parameters

    • transition: string = DEFAULT_COLOR_TRANSITION

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

    Returns SvgIcon

    this

  • Sets wrapper (<span>) element attributes.

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

    Parameters

    • attrs: Record<string, any>

      Attributes to set

    Returns SvgIcon

    this

Generated using TypeDoc