Code Monkey home page Code Monkey logo

babel-plugin-jsx-svg-import's Introduction

babel-plugin-jsx-svg-import

中文文档

npm version

add svg file imports for jsx elements。

with svg-sprite-loader

Features

  • There is no need to manually import the svg file, which automatically import svg in the file.
  • There is no need to provide a custom Icon component, the plugin can automatically import the Icon component

Options

{
  "displayName": "Icon",
  "propName": "type",
  "directory": "/assets/",
  "importComponent": false,
}

no use [importComponent]

[
  'babel-plugin-jsx-svg-import',
  {
    displayName: 'Icon',
    propName: 'type',
    directory: '/assets/',
  },
];
import Icon from './Icon.jsx';

ReactDOM.render(<Icon type="close"/>);

           

import './assets/close.svg'

ReactDOM.render(<Icon type="close"/>);

use importComponent

[
  'babel-plugin-jsx-svg-import',
  {
    displayName: 'Icon',
    propName: 'type',
    directory: '/assets/',
    importComponent: true,
  },
];
ReactDOM.render(<Icon type="close"/>);

           

import Icon from 'babel-plugin-jsx-svg-import/lib/runtime';
import './assets/close.svg'

ReactDOM.render(<Icon type="close"/>);

Icon Component

from antd Icon

prop desc type default
width svg element width string | number '1em'
height svg element height string | number '1em'
fill svg element fill color string 'currentColor'
className svg element class string -
style svg element style CSSProperties -

babel-plugin-jsx-svg-import's People

Contributors

dependabot[bot] avatar ti-tian avatar

Watchers

 avatar

Forkers

p2yang

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.