Code Monkey home page Code Monkey logo

vue-simple-svg's Introduction

vue-simple-svg

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. No jQuery required.

Installation:

$ npm install vue-simple-svg

Usage:

in your Vue's main file,

import VueSimpleSVG from 'vue-simple-svg'
Vue.use(VueSimpleSVG)

and in your component,

<simple-svg
  :filepath="'/PATH_/TO_/YOUR_/FILE.svg'"
  :fill="getFillColor"
  :stroke="getStrokeColor"
  :width="'400px'"
  :height="'400px'"
  :id="'custom-id'"
  @ready="onSvgReady()"
  />

Available props and events:

props type description default
filepath string path to your svg file
fill string svg's fill color 'black'
stroke string svg's stroke color 'black'
width string svg's width '1em'
height string svg's height '1em'
id string custom color ''
events description
@ready called when the svg is loaded

Notes:

  • inline svg element has a class '.simple-svg'
  • inline svg has a div wrapper with a class '.simple-svg-wrapper'
  • fill/stroke style set to a path of a SVG will be removed unless its value is 'none'

Demo:

result

To run demo in your local environment,

$ npm run dev-demo

You can find the code of an example component that has a simple-svg component as its child in demo/components/SvgButton.vue

Todo:

  • enable applying various colors to multiple paths in an SVG

Reference:

vue-simple-svg's People

Contributors

seiyable avatar catherineh avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.