react插件包

react-scoped-style

  • support ie8,ie8+,chrome,firefox,safari
  • does not support css priority (just apply rules by css order in source text)
  • does not support css property inheritance (no shadow dom...)
  • does not support :hover, :active ....
  • does not support css media query 

不支持css优先级(仅在源文本中按css顺序应用规则)

不支持css属性继承(没有影子dom…)

不支持伪类标签

不支持css媒体查询

所以有点鸡肋

import ScopedStyle, { createStyleSheet } from 'react-scoped-style';
import React from 'react';
import ReactDOM from 'react-dom';
var style = createStyleSheet(`
.test {
  color:red;
  zoom:1.5;
}
div>span{
  color:green;
  zoom:1.5;
}
`);
 
var html = <div>
  <p className="test">scope react element by transform external style into inline styles</p>
  <p>
    <a href="https://github.com/yiminghe/react-scoped-style">repo</a>
  </p>
 
  <ScopedStyle style={style}>
    <div>
      <span>green zoom</span>
      <span style={{color: 'blue'}}>blue zoom</span>
      <p>
        <span>black</span>
        <span>  -   </span>
        <a className='test'>red zoom</a>
      </p>
 
      <ScopedStyle>
        <a className='test'>black isolate</a>
      </ScopedStyle>
 
      <ScopedStyle scoped={false}>
        <a className='test'>red zoom penetrate</a>
      </ScopedStyle>
    </div>
  </ScopedStyle>
</div>;
 
ReactDOM.render(html, document.getElementById('__react-content'));

API

props

nametypedefaultdescription
scopedBooleantruewhether isolated from outside
styleString|ParsedCssResult style to be applied

methods

  • ParsedCssResult createStyleSheet(css:String) parse css into object

  • ReactElement transformElement(root:ReactElement, css:String|ParsedCssResult)

转载于:https://www.cnblogs.com/l8l8/p/9510273.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值