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

react-download-svg

v0.0.4

Published

Decorate an SVG so you can download it

Downloads

379

Readme

react-download-svg

Use react-download-svg to decorate an SVG component/element, and when triggered, will download a serialized PNG at a desired size.

Features

  • ...

Example with Trigger helper

<Wrapper> listens to an event from <Trigger>, meaning you can import the trigger elsewhere in your application, no need to have them directly connected. Unique event names can be used if you need to avoid collisions.


import {
  Wrapper,
  Trigger
} from 'react-download-svg';

const SomeComponent = React.createComponent({

  render: function () {
    return (
      <div>
        <Wrapper>
          <SomeSVGThing />
        </Wrapper>
        <div>
          <Trigger>Click to download</Trigger>
        </div>
      </div>
    );
  }
});

Example with refs

To initiate a download without using the <Trigger>, you can hit the startDownload() method directly if you're using a ref.


import {
  Wrapper
} from 'react-download-svg';

const SomeComponent = React.createComponent({

  handleClick: function () {
    ReactDOM.findDOMNode(this.wrapper).startDownload({
      width: 400,
      height: 400,
      filename: 'somefile.png'
    });
  },

  render: function () {
    return (
      <div>
        <Wrapper ref={n => this.wrapper = n}>
          <SomeSVGThing />
        </Wrapper>
        <div>
          <button onClick={this.handleClick}>Click to download</button>
        </div>
      </div>
    );
  }
});

Props

Wrapper

| prop | default | | |---|---|---| | filename | String: 'untitled.png' | Sets the filename on the downloaded file. | | listenFor | String: 'downloadSvg' | Sets the event name to listen for from the <Trigger>. Must be the same as set on desired <Trigger> instance. |

Wrapper

| prop | default | | |---|---|---| | filename | String: 'untitled.png' | Sets the filename on the downloaded file. This takes priority over the filename on the <Wrapper> if one is set there as well. | | eventName | String: 'downloadSvg' | Sets the event name to send to <Wrapper>. Must be the same as set on desired <Wrapper> instance. | | width | Number: 400 | The desired width of the png | | height | Number: 400 | The desired height of the png | | component | 'button' | Defaults to a button instance, otherwise use a valid element type or a react component. |