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 🙏

© 2025 – Pkg Stats / Ryan Hefner

pixo

v1.1.2

Published

Convert SVG icons into React components

Readme

pixo

Convert SVG icons into React components

npm i pixo

Pass a directory or SVG file path as the first argument.

$ pixo src --out-dir dist

Each SVG icon will be automatically optimized and renamed to a pascal case filename for the component. Icon components can then be imported into a React application.

import React from 'react'
import CheckIcon from './CheckIcon'

const App = props => (
  <div>
    <CheckIcon />
  </div>
)

The default component template includes props for:

  • size (number) pixel width and height (default 24)
  • color (string) color value passed to the SVG fill attribute (default 'currentcolor')

SVG Requirements

Each SVG icon must conform to the following:

  • Use a square viewBox attribute, preferably 0 0 24 24
  • Only use a single color (e.g. black)
  • For best results, only use <path> elements
  • Do not use transforms

Pixo includes experimental support for <circle>, <polygon>, and <rect> elements.

The following elements will be ignored:

  • Elements within a <defs> or <clipPath>
  • Elements with the fill="none" attribute
  • <ellipse> elements
  • <line> elements
  • <polyline> elements

Converting SVG shapes into <path> elements

Most graphics applications can convert shapes into SVG paths.

  • Adobe Illustrator: use the Compound Path command
  • Figma: TK
  • Sketch: TK

Templates

Pixo uses a default template for rendering, but includes some built-in options.

Custom Templates

To use a custom template, pass a path to your template to the --template flag.

pixo icons --template custom-template.js

A template should be a function that returns a string for the component source code, written as a Node.js module.

// default template
module.exports = ({
  name,
  viewBox,
  pathData
}) => `import React from 'react'

const ${name}Icon = ({
  size,
  color,
  ...props
}) => (
  <svg
    {...props}
    viewBox='${viewBox}'
    width={size}
    height={size}
    fill={color}
  >
    <path d='${pathData}' />
  </svg>
)

${name}Icon.displayName = '${name}Icon'

${name}Icon.defaultProps = {
  size: 24,
  color: 'currentcolor'
}

export default ${name}`

Template function arguments

  • name camel cased name that can be used for the component name
  • viewBox the original viewBox value from the SVG
  • pathData extracted path data for the <path> element's d attribute

Options

Options can be passed as flags to the CLI or added to a pixo field in your package.json

Run pixo --help to see the list of options.

  • outDir (string) output directory (default dist)
  • template (string) name of built-in template or path to custom template
  • index (boolean) create an index.js barrel module
  • iconComponent (boolean) create an Icon.js wrapper component
  • recursive (boolean) recursively read all SVGs in subdirectories

CLI flags

-d --out-dir          Output directory
-t --template         Name of built-in template or path to custom template
-i --index            Include index.js barrel module
-c --icon-component   Include wrapper Icon.js component
-r --recursive        Recursively read all SVGs in subdirectories

Example package.json

{
  "pixo": {
    "outDir": "dist",
    "template": "./custom-template.js",
    "index": true,
    "iconComponent": true,
    "recursive": true
  }
}

Related


MIT License