import React from 'react' import PropTypes from 'prop-types' import CX from 'classnames' import _ from 'lodash' import './index.less' function RadioButton(props) { const { style, title, isChecked, onClick, } = props const wrapperStyle = _.assign({}, style) return ( <div className="checkbox-wrap" style={wrapperStyle} onClick={onClick} role="button" tabIndex={0} > <span className={CX({ checkbox: true, checked: isChecked === true, })} /> <span className="tip-text">{title}</span> </div> ) } RadioButton.propTypes = { style: PropTypes.object, title: PropTypes.string, isChecked: PropTypes.bool, onClick: PropTypes.func, } RadioButton.defaultProps = { style: {}, title: '', isChecked: false, onClick: _.noop, } export default RadioButton
下面是组件样式
.checkbox-wrap { display: flex; justify-content: flex-start; align-items: center; padding: 3px 0; margin-right: 24px; cursor: pointer; .checkbox { display: inline-block; box-sizing: border-box; width: 10px; height: 10px; border-radius: 50%; border: 2px solid rgba(79, 159, 255, 1); position: relative; &.checked { &::before { content: ''; display: block; width: 4px; height: 4px; border-radius: 50%; background-color: #56afff; position: absolute; top: 1px; left: 1px; } } } .tip-text { opacity: 0.4; line-height: 18px; margin-left: 3px; } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理