Git Product home page Git Product logo

react-svg-wrapper's Introduction

react-svg-wrapper

A react component for injecting a svg file (or string) into a DOM tree.

demo

Check it out here in sandbox ๐Ÿ”—

usage

props description
src required, svg file or string to be passed via this prop
type optional, default value = file, if svg string has to be passed, we need to use type='string'

Also, numerous vaild html, svg props can be passed to top-level too :), see example below for reference.

import React from "react";
import SVGWrapper from "react-svg-wrapper";

// import the svg you want to render
import myLogo from "../images/myLogo.svg";

const MyComp = () => {
  return (
    // some wrapper/parent component if needed
    <someComp>
      <SVGWrapper
        src={myLogo}
        className="App-logo"
        style={{
          backgroundColor: "red",
          border: "solid 1px",
          borderRadius: "10px",
        }}
      />
    </someComp>
  );
};

export default MyComp;

motive & idea

  • To make a zero-dependency and light-weight package โšก for injecting a svg into DOM tree.
  • The problem was simple we wanted to use svg in our react apps directly and control it's behaviour based on some business logic.
  • So, we thought of making a wrapper from ground-zero by using basic DFS and dom tree analysis.

in near future ...

  • accepting svg's via hyperlinks
  • reducing package size to 15Kb

react-svg-wrapper's People

Contributors

deepsourcebot avatar nobi1007 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

react-svg-wrapper's Issues

Too much time to load/render a svg

Describe the bug
While using in an app, it takes like 0.5-1sec to load a svg and this change(glitch) is quite obvious.

To Reproduce
Steps to reproduce the behavior:

  1. render a svg using react-svg-wrapper

Expected behavior
Instant load of a svg <100ms (and loading from cache if already rendered)

Screenshots

svg-wrapper-glitch.mov

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.