Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-svg-ikon

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-svg-ikon

Opinionated React component for caching and displaying SVG Icons.

  • 2.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

react-svg-ikon

Opinionated React component for caching and displaying SVG Icons.

Installation

> yarn add react-svg-ikon

Requires react, react-dom, aphrodite and recompose as peerDependencies.

Usage

SVG Files

SVG icons need to follow some simple rules to be compatible:

  • The svg element must have width, height and viewbox attrbutes defined.
  • There must be a g element with an id somewhere, preferably the outermost group. The id must start with icon- (this will be made less strict in a future release)
  • Remove fill and stroke attrbutes where you want dynamic coloring

Example svg file:

<?xml version="1.0" encoding="UTF-8"?>
<svg width="14px" height="9px" viewBox="0 0 14 9" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <g id="icon-polygon" class="icon icon-polygon" stroke-width="1" fill-rule="evenodd" stroke-linecap="round">
        <g transform="translate(-271.000000, -21.000000)" stroke-width="2">
            <g transform="translate(272.000000, 22.000000)">
                <polyline points="1.000 2.000 3.000 Z"></polyline>
            </g>
        </g>
    </g>
</svg>

React component

import Icon from 'react-svg-ikon';
import svgImg from '../img/some-svg.svg';

...

<Icon src={ svgImg } fill="red" />
<Icon src={ svgImg } stroke="red" />
<Icon src={ svgImg } className={ css( redIcon ) } />
<Icon src="/static/img/foo.svg" fill="#ff0000" />

FAQs

Package last updated on 29 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc