Git Product home page Git Product logo

react-svg's Introduction

react-svg

build status coverage status npm version npm downloads

A React component that uses SVGInjector to add SVG to the DOM.

Usage

import React from 'react'
import ReactDOM from 'react-dom'
import ReactSVG from 'react-svg'

ReactDOM.render(
  <ReactSVG
    path="atomic.svg"
    callback={svg => {
      console.log(svg)
    }}
    className="class-name"
    wrapperClassName="wrapper-class-name"
  />,
  document.querySelector('.Root')
)

There is a working version of the above in the examples/basic dir. First run npm start, then point a browser at localhost:8080/basic.

API

Props

  • path - Path to the SVG.
  • callback - Optional Function to call after the SVG is injected. Receives the newly injected SVG DOM element as a parameter. Defaults to null.
  • className - Optional Class name to be added to the SVG. Defaults to ''.
  • wrapperClassName - Optional Class name to be added to the wrapping div. Defaults to ''.
  • evalScripts - Optional Run any script blocks found in the SVG (always, once, or never). Defaults to never.
  • style - Optional Inline styles to be added to the SVG. Defaults to {}.

Example

<ReactSVG
  path="atomic.svg"
  callback={svg => {
    console.log(svg)
  }}
  className="example"
  wrapperClassName="example-wrapper-classname"
  evalScript="always"
  style={{ width: 200 }}
/>

Refer to the SVGInjector configuration docs for more information.

Install

$ npm install react-svg --save

There are also UMD builds available via unpkg:

If you use these, make sure you have already included React and ReactDOMServer as dependencies.

License

MIT

react-svg's People

Contributors

deadbeef404 avatar faceleg avatar prototypealex avatar ronperris avatar tgroutars 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.