Skip to content

πŸŒ… Converts SVG files into components 🌞

Notifications You must be signed in to change notification settings

kossnocorp/desvg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

desvg

desvg converts SVG files into React/Preact components. It inlines SVG source so that you can alter it (animate, set color, control size, etc.).

Installation

If you want to use desvg with webpack, install desvg-loader and svg-loader:

npm install desvg-loader svg-loader --save-dev
# or
yarn add --dev desvg-loader svg-loader

To use the low-level API, or to manage the core library version, install desvg:

npm install @kossnocorp/desvg --save
# or
yarn add @kossnocorp/desvg

Configuration

// ...
{
  test: /\.svg$/,
  use: [
    'desvg-loader/react', // πŸ‘ˆ Add loader (use 'desvg-loader/preact' for Preact)
    'svg-loader' // πŸ‘ˆ svg-loader must precede desvg-loader
  ],

  // or if you prefer classic:

  loader: 'desvg-loader/react!svg-loader'
},
// ...

Usage

See low-level API docs for more implementation details.

React

import React from 'react'
import WarningIcon from './icon.svg'

export default function () {
  return (
    <div>
      <WarningIcon fill='yellow' width='32px' />
      Warning, this is a warning!
    </div>
  )
}

Preact

import { h } from 'preact'
import WarningIcon from './icon.svg'

export default function () {
  return (
    <div>
      <WarningIcon fill='yellow' width='32px' />
      Warning, this is a warning!
    </div>
  )
}

Related

License

MIT Β© Sasha Koss

About

πŸŒ… Converts SVG files into components 🌞

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published