When we move from CSS to defining styles inside components we lose the ability to override styles with an external style sheet. We also lose the ability add the same class to different types of elements to style them consistently. Recompose allows us to regain the ability of override styles and to apply the same styles to different types of elements.

Feeling using Recompose is a good way to build npm module, custom libaray.

So the comoponent can be highly custmizable.

import React from 'react';
import {setDisplayName, componentFromProp, mapProps, defaultProps, compose} from 'recompose';
import Radium from 'radium'; const addStyle = style => mapProps(props => ({
...props,
style: [
props.style,
style
]
})); const style = {
backgroundColor: 'black',
color: 'white',
transform: 'rotate(-13deg)',
transition: 'all ease 0.43s',
':hover': {
backgroundColor: 'orange',
color: 'lightGreen',
transform: 'rotate(0deg)'
}
}; const enhance = compose(
addStyle(style),
setDisplayName('Button'),
defaultProps({
element: 'button'
}),
Radium
); export default enhance(componentFromProp('element'));

Using:

        <Button
element={'button'}
style={{borderRadius: '10px'}}
onClick={onRemoveBox}
>Remove</Button>

In the code, we are able to override the default style by passing 'style' from props:

const addStyle = style => mapProps(props => ({
...props,
style: [
props.style,
style
]
})); const enhance = compose(
addStyle(style),
setDisplayName('Button'),
defaultProps({
element: 'button'
}),
Radium
);

Here we also using 'Radium', so that we can add 'hover' sudo effect.

We can also say what kind of element we want to show:

    defaultProps({
element: 'button'
}), <Button
element={'a'} href="http://google.fi"
style={{borderRadius: '10px'}}
onClick={onRemoveBox}
>Remove</Button>

We can change to 'a' tag if we want.

最新文章

  1. angular表单
  2. 《30天自制操作系统》18_day_学习笔记
  3. LightSpeed的批量更新和批量删除
  4. VS2010编写动态链接库DLL及单元测试用例,调用DLL测试正确性
  5. Android开发者需要面对的8大挑战
  6. 第一个自定义HTML网页
  7. [Java] Serializable(序列化)的理解
  8. 从robots.txt開始网页爬虫之旅
  9. PHP获取文件后缀名的三种方法
  10. 实验吧Web-FALSE
  11. Windows下QT4.8.4编译环境的搭建(转载http://blog.csdn.net/bestgonghuibin/article/details/38933141)
  12. bzoj 2560: 串珠子
  13. ASUS RT-N16 使用OpenWrt 安装 ss记录
  14. PHP json_decode为什么将json字符串转成数组是对象格式?
  15. win8获取保存的wlan密码方法
  16. VB.NET 窗體操作
  17. UVA.12230.Crossing Rivers(期望)
  18. Eclipse + Pydev问题 : pydev unresolved import
  19. uniGUI试用笔记(七)
  20. 2017-2018 Exp3 MAL_免杀原理与实践 20155214

热门文章

  1. 常见c#正则表达式类学习整理
  2. Android提示版本号更新操作流程
  3. 让人难过的 openssl_pkcs7_encrypt
  4. Apache中PHP5.3 php5.4如何使用ZEND
  5. 1.1 Introduction中 Guarantees官网剖析(博主推荐)
  6. Lucy_Hedgehog techniques
  7. jQuery中$(document).ready()和window.onload的区别?
  8. sql语句的编程手册 SQL PLUS
  9. JAVA一些基础概念
  10. 使用Samba在Linux服务器上搭建共享文件服务