GithubHelp home page GithubHelp logo

zidian257 / reiconify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ambar/reiconify

0.0 1.0 0.0 5.84 MB

Convert SVG icons to React components eg.: https://ambar.li/reiconify/md.icons/#/Browse

JavaScript 90.77% CSS 9.23%

reiconify's Introduction

reiconify

Convert SVG icons to React components.

Features

  • Custom component templates, includes base class.
  • Export both ES modules and CommonJS modules.
  • Provide center prop for aligning icon with text,see how it works.
  • Provide dev tool for generating static icon site.
  • Generate unique IDs for SVG elements if needed.
  • Format codes with Prettier

Install

npm install reiconify-cli --save-dev

CLI Options

reiconify [options] [files]

Options:
  --version  Show version number                                       [boolean]
  --src      Build JSX source files                   [boolean] [default: false]
  --src-dir  JSX output directory                      [string] [default: "src"]
  --es       Build ES module files                    [boolean] [default: false]
  --es-dir   ES output directory                        [string] [default: "es"]
  --cjs      Build CommonJS files                     [boolean] [default: false]
  --cjs-dir  CommonJS output directory                 [string] [default: "cjs"]
  --serve    Serve source icons                       [boolean] [default: false]
  --static   Build static site                        [boolean] [default: false]
  -h         Show help                                                 [boolean]

Configuration File

Add reiconify.config.js(optional) to your project:

module.exports = {
  template: Function,
  baseTemplate: Function,
  filenameTemplate: Function,
  defaultProps: {},
  baseClassName: 'Icon',
  baseDefaultProps: {
    viewBox: '0 0 24 24',
  },
  svgoPlugins: [
    {
      removeAttrs: {attrs: ['fill', 'svg:(viewBox)']},
    },
  ],
}

CLI Usage

Add npm scripts:

{
  "name": "my-icons",
  "main": "cjs/index.js",
  "module": "es/index.js",
  "files": ["src", "es", "cjs"],
  "scripts": {
    "start": "reiconify --serve",
    "build": "reiconify --src --es --cjs icons/*.svg"
  }
}

Structure SVG files:

icons
├── check.svg
├── thumb-up.svg
└── ...

Build icons:

npm run build

Import icons:

import * as Icons from 'my-icons'

<Icons.Check />
<Icons.ThumbUp size={20} fill={'#rgb'} />

API Usage

import {transform} from 'reiconify'

const code = transform(svg, {format: 'esm', baseName: 'base-icon'})

reiconify's People

Contributors

ambar avatar dependabot[bot] avatar wangcheng avatar kitayoshi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.