npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-simple-svg

v2.0.2

Published

A simple Vue.js plugin that allows you to use a component that loads a SVG image as an inline SVG so you can easily control its fill color from the parent component.

Downloads

6,450

Readme

vue-simple-svg (V2)

A simple Vue.js plugin that allows you to use a component that dynamically loads a .svg file as an inline SVG so you can easily control its style programmatically. No jQuery required.

I recommend using vue-svg-loader for many cases when you just need to load a SVG file as a component. This plugin is built to cover some other cases the library doesn't fit, which are:

  • loading a SVG file dynamically. You don't have to hardcode the filename in the source code. Instead you can specify it at rendering time or change it even after the component is rendered.
  • changing fill color or stroke color of the SVG programmatically with ease and no global css usage.

Installation:

$ npm install vue-simple-svg

Usage:

  1. initialize in your main file,
// as a plugin
import VueSimpleSVG from 'vue-simple-svg'
Vue.use(VueSimpleSVG)

// or as a component
import {SimpleSVG} from 'vue-simple-svg'
Vue.component('simple-svg', SimpleSVG)
  1. specify which elements in the SVG will be manipulated their fill and stroke colors by setting dedicated class names to them
<svg xmlns="http://www.w3.org/2000/svg">
  <g>
    <path class="fill-to-change" d="XXXXX XXXXX XXXXX" />
    <path class="stroke-to-change" d="XXXXX XXXXX XXXXX" />
  </g>
</svg>
  1. and use it in your component,
<simple-svg
  :src="svgSrc"
  fill-class-name="fill-to-change"
  :fill="svgFillColor"
  stroke-class-name="stroke-to-change"
  :stroke="svgFillColor"
  width="100%"
  height="100%"
  custom-id="my-id"
  custom-class-name="my-class"
  @load="svgLoaded()"
/>

Available props and events:

| props | type | description | default | | ------ | ------ | ------ | ------ | | src | string | path to your SVG file | *required | | fillClassName | string | class name set to the elements in your SVG file whose fill color you want to change | '' | | fill | string | CSS-valid fill color value | '' | | strokeClassName | string | class name set to the elements in your SVG file whose stroke color you want to change | '' | | stroke | string | CSS-valid stroke color value | '' | | width | string | root SVG element's style width | 'auto' | | height | string | root SVG element's style height | 'auto' | | customId | string | root SVG element's id | '' | | customClassName | string | root SVG element's class | '' |

| events | description | | ------ | ------ | | @load | called when the inline SVG is generated |

Notes:

  • To generate the inline SVG properly, you need to manually clean up and edit your SVG files beforehand. Tips: remove all hardcoded inline styles and unnecessary attributes, especially the ones specifying colors.

Demo:

result

To run demo in your local environment,

$ npm run dev-demo

You can see the example of how to use simple-svg component at demo/components/SvgButton.vue

Reference:

  • Loading a SVG with XMLHttpRequest and DOMParser https://github.com/jonnyhaynes/inline-svg
  • Parsing inline svg tags https://github.com/MMF-FE/vue-svgicon