1.0.8 • Published 10 years ago

react-svg-sprite v1.0.8

Weekly downloads
24
License
ISC
Repository
github
Last release
10 years ago

npm version

React SVG Sprite Component

A basic react component that will create an svg sprite based on an svg array.

installation

npm install react-svg-sprite --save

How to Use

This component only requires an array of your given symbols with name, and svg string.

Minimum Example

import React from 'react'
import SvgSprite from 'react-svg-sprite'

export default class MyComponent extends React.Component {
    render () {
        return (
            <SvgSprite
                symbols=[{
                    name: 'cloud',
                    svg: '<svg></svg>'
                }, {
                    name: 'rain',
                    svg: '<svg></svg>'
                }]
            />
        );
    }
}

To then use your svg icons anywhere on your page you'll want to use the following markup.

<svg>
    <use xlink:href="#cloud"></use>
</svg>

You can use an npm package like react-svg-use to help speed up development, and decrease maintainability.

Example Output

Given your component looks like this...

import React from 'react'
import SvgSprite from 'react-svg-sprite'

export default class MyComponent extends React.Component {
    render () {
        return (
            <SvgSprite
                className="weather-icons"
                symbols=[{
                    className: 'weather-icon',
                    name: 'cloud',
                    svg: '<svg viewBox="0 0 32 32">...</svg>'
                }, {
                    className: 'weather-icon',
                    name: 'rain',
                    svg: '<svg viewBox="0 0 32 32">...</svg>'
                }]
            />
        );
    }
}

Your output would look something like this...

<svg class="weather-icons" style="display:none;">
    <symbol id="cloud" viewBox="0 0 32 32" class="weather-icon">
        <path>...</path>
    </symbol>
    <symbol id="rain" viewBox="0 0 32 32" class="weather-icon">
        <path>...</path>
    </symbol>
</svg>
1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago