Giter VIP home page Giter VIP logo

babel-plugin-react-styles-merge's Introduction

#babel-plugin-react-styles-merge

react 中 将多个style对象合并成一个style

html中 class 我们可以传入多个:

<a class="cls1 cls2 cls3" ></a>

那么style有没有类似简便的写法?

没有!!!

不过,我们借助 babel 可以模拟实现:

 var o1 = {color:'red'};
 var o2 = {width: '10px'};
 var o3 = {height: '3px'};

 <a styles={[o1, o2, o3]} ></a>

安装

 $ npm install babel-plugin-react-styles-merge

使用

修改 .babelrc 文件

{
  "plugins": ["react-styles-merge"]
}

说明

同时存在style 和 styles时, 会将styles合并到style中, 相同属性,style中会被styles中的属性 覆盖。

In

var obj = {
            "paddingLeft": '75px',
             padding: '6px 10px',
             fontSize:'24px',
             height:'75px',
             length:'100px'
        };


return(
        <li style={{backgroundColor:'grey'}} styles={[{a:1},{b:2}, obj]}></li>
      )

Out

_react2.default.createElement('li', { style: Object.assign({}, { backgroundColor: 'grey' }, { a: 1 }, { b: 2 }, obj) })


babel-plugin-react-styles-merge's People

Stargazers

 avatar

Watchers

 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.