import React, { useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import _ from 'lodash'
import classnames from 'classnames' import './index.less' function CheckBox(props) {
const {
style, checked: propsChecked, content, onChange, theme,
} = props
const wrapperStyle = _.assign({}, style) const [checked, setChecked] = useState(propsChecked === true) useEffect(() => {
setChecked(propsChecked)
}, [propsChecked]) return (
<div
className={classnames({
'single-checkbox-component-wrap': true,
'theme-dark': theme === 'dark',
checked: checked === true,
})}
onClick={() => {
const nextState = !checked
setChecked(nextState)
onChange(nextState)
}}
role="button"
tabIndex={0}
style={wrapperStyle}
>
<span className="icon" />
<span className="tip">{ content }</span>
</div>
)
} CheckBox.propTypes = {
style: PropTypes.object,
checked: PropTypes.bool,
content: PropTypes.string.isRequired,
onChange: PropTypes.func,
theme: PropTypes.string,
} CheckBox.defaultProps = {
style: {},
checked: false,
onChange: _.noop,
theme: 'normal',
} export default CheckBox
.single-checkbox-component-wrap {
display: flex;
justify-content: flex-start;
align-items: center;
cursor: pointer; &.checked {
.icon {
background-image: url(~ROOT/shared/assets/image/icon-checkbox-checked-30-30.png);
}
} .icon {
display: inline-block;
box-sizing: border-box;
width: 10px;
height: 10px;
border-radius: 50%;
background-image: url(~ROOT/shared/assets/image/icon-checkbox-unchecked-30-30.png);
background-size: 10px;
} .tip {
font-size: 12px;
color: #364152;
opacity: 0.4;
line-height: 18px;
margin-left: 3px;
}
} .single-checkbox-component-wrap {
&.theme-dark {
&.checked {
.icon {
background-image: url(~ROOT/shared/assets/image/icon-checkbox-checked-white-30-30.png);
}
} .icon {
background-image: url(~ROOT/shared/assets/image/icon-checkbox-unchecked-white-30-30.png);
} .tip {
color: #ffffff;
}
}
}

最新文章

  1. [LeetCode] Ransom Note 赎金条
  2. 分享篇——我的Java学习路线
  3. Centos下安装Redis
  4. python中for和if else的使用
  5. 淘宝技术发展(Java时代:脱胎换骨)
  6. OC2_使用系统协议
  7. hdu 4195
  8. 2014牡丹江——Hierarchical Notation
  9. ServletRequest接口召回总结
  10. 201521123110《Java程序设计》第12周学习总结
  11. 墨卡托投影坐标系(Mercator Projection)原理及实现C代码
  12. MySQL InnoDB锁机制
  13. Python后台开发Django( 模板 与 值匹配 )
  14. C++概念小结
  15. 更改oracle归档模式路径
  16. elementui上传文件
  17. Java - 33 Java Applet基础
  18. 【BZOJ1017】[JSOI2008]魔兽地图(动态规划)
  19. vue的全局引用
  20. 关系型数据库(RDBMS)与 MongoDB 的对应关系

热门文章

  1. IdHTTPServer开发https服务器
  2. fork 可能导致subprocess崩溃
  3. PEP 476 -- Enabling certificate verification by default for stdlib http clients
  4. win10: windows+E 改回打开我的电脑
  5. AWS Fargate
  6. Flutter修改应用图标及图标
  7. netty5心跳与阻塞性业务消息分发实例
  8. CompletableFuture Quasar 等并发编程
  9. 【opencv】opencv函数isContinuous
  10. text-align:justify 两端对齐