Use SVG Icons As Components – SVG-ICON

Category: Javascript | October 4, 2021
Author:designstorming
Views Total:366 views
Official Page:Go to website
Last Update:October 4, 2021
License:MIT

Preview:

Use SVG Icons As Components – SVG-ICON

Description:

A Vanilla JavaScript component (custom element) that allows you to render SVG icons as components.

How to use it:

1. Load the svg-icon.js web component.

<script src="./svg-icon.js"></script>

2. Add the svg-icon component to the page and specify the path to the SVG icon.

<svg-icon src="demo.svg" />

3. Set the size of the icon.

<svg-icon src="demo.svg" size="24" />

4. Determine whether to move the svg inside shadowRoot.

<svg-icon src="demo.svg" size="24" sealed />

5. Apply your own styles to the SVG icon.

svg-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 0.2rem;
}

You Might Be Interested In:


Leave a Reply