UNPKG

@beisen/ethos

Version:

beisencloud pc react components

226 lines (195 loc) 7.88 kB
'use strict'; var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require('babel-runtime/helpers/inherits'); var _inherits3 = _interopRequireDefault(_inherits2); var _class, _temp; var _react = require('react'); var _react2 = _interopRequireDefault(_react); require('./styles/all.scss'); var _toolTip = require('../tool-tip'); var _toolTip2 = _interopRequireDefault(_toolTip); var _commonFunc = require('../common-func'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var BaseButton = (_temp = _class = function (_Component) { (0, _inherits3.default)(BaseButton, _Component); function BaseButton(props) { (0, _classCallCheck3.default)(this, BaseButton); var _this = (0, _possibleConstructorReturn3.default)(this, (BaseButton.__proto__ || (0, _getPrototypeOf2.default)(BaseButton)).call(this, props)); _this.state = { btnActive: '', btnStyle: '', btnSize: '', btnDisabled: '', maxWidth: '', top: 0, left: 0 }; _this.bnRipple = _this.bnRipple.bind(_this); _this.initData = { "bsSize": { "small": "base-btns-bgc-small ", "block": "base-btns-bgc-block ", "default": "base-btns-bgc-big " }, "bsStyle": { "weaken": "base-btns-weaken ", "reward": " ", "default": " ", "link": " " }, "btnDisabled": { "weaken": "base-btns-bg-gray-weaken ", "default": "base-btns-bg-gray-defalult ", "link": " " } }; return _this; } (0, _createClass3.default)(BaseButton, [{ key: 'bnRipple', value: function bnRipple(e) { //点击按钮扩散效果 var _props = this.props, disabled = _props.disabled, onClick = _props.onClick; if (disabled) return false; var bgBtn = this.refs.bgBtn; bgBtn.setAttribute('class', bgBtn.className.replace('base-bg-ripple-active', '')); var bgBtn_offset = bgBtn.getBoundingClientRect(); var realLeft = e.clientX - bgBtn_offset.left; var realTop = e.clientY - bgBtn_offset.top; bgBtn.setAttribute('class', bgBtn.className + 'base-bg-ripple-active'); this.setState({ top: realTop, left: realLeft }); setTimeout(function () { bgBtn.setAttribute('class', bgBtn.className.replace('base-bg-ripple-active', '')); }, 350); (0, _commonFunc.clearToolTipDom)(); onClick && onClick(e, true, this.state); } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { var btnDisabled = nextProps.disabled ? this.initData.btnDisabled[nextProps.bsStyle] : this.state.btnDisabled = " "; this.setState({ btnDisabled: btnDisabled }); } }, { key: 'componentWillMount', value: function componentWillMount() { //初始化数据,为按钮添加样式 var _props2 = this.props, active = _props2.active, bsStyle = _props2.bsStyle, bsSize = _props2.bsSize, maxWidth = _props2.maxWidth, disabled = _props2.disabled; if (active) this.state.btnActive = "base-bg-ripple-active "; var btnDisabled = disabled ? this.initData.btnDisabled[bsStyle] : this.state.btnDisabled = " ", btnSize = this.initData.bsSize[bsSize], maxBtnWidth = maxWidth && maxWidth.length > 0 ? maxWidth : 'none'; this.setState({ btnDisabled: btnDisabled, btnSize: btnSize, maxWidth: maxBtnWidth }); } }, { key: 'render', value: function render() { var _state = this.state, maxWidth = _state.maxWidth, btnSize = _state.btnSize, btnDisabled = _state.btnDisabled, left = _state.left, top = _state.top; var _props3 = this.props, hidden = _props3.hidden, bsStyle = _props3.bsStyle, title = _props3.title, href = _props3.href, bsSize = _props3.bsSize, tipsReason = _props3.tipsReason, tipsDes = _props3.tipsDes, dataUdt = _props3.dataUdt, dataUdc = _props3.dataUdc; var btnStyle = this.initData.bsStyle[bsStyle]; var status = bsSize != "block" ? "" : "block-btn-style"; if (hidden) { return _react2.default.createElement('div', null); } else { switch (bsStyle) { case "link": return _react2.default.createElement( 'a', { href: href, title: (0, _commonFunc.decode)(title), target: '_blank' }, (0, _commonFunc.decode)(title) ); case "reward": return _react2.default.createElement( 'div', { 'data-udt': encodeURIComponent(dataUdt), 'data-udc': encodeURIComponent(dataUdc), className: 'base-button-component clearfix base-button-reward' }, _react2.default.createElement( _toolTip2.default, { title: (0, _commonFunc.decode)(title), tipsReason: tipsReason, tipsDes: tipsDes, alwaysShowTips: tipsReason && tipsReason.length > 0 ? 'true' : '' }, _react2.default.createElement( 'span', { ref: 'bgBtn', style: { "maxWidth": maxWidth }, className: 'base-bg-ripple ' + (btnStyle + btnSize), onClick: this.bnRipple }, _react2.default.createElement( 'span', { className: 'base-btn-reward-content' }, _react2.default.createElement('span', { className: 'base-btn-reward-img' }) ), _react2.default.createElement( 'span', { className: 'base-btn-title' }, (0, _commonFunc.decode)(title) ) ) ) ); default: return _react2.default.createElement( 'div', { 'data-udt': encodeURIComponent(dataUdt), 'data-udc': encodeURIComponent(dataUdc), className: 'base-button-component clearfix ' + status }, _react2.default.createElement( _toolTip2.default, { title: (0, _commonFunc.decode)(title), tipsReason: tipsReason, tipsDes: tipsDes, alwaysShowTips: tipsReason && tipsReason.length > 0 ? 'true' : '' }, _react2.default.createElement( 'span', { ref: 'bgBtn', style: { "maxWidth": maxWidth }, className: 'base-bg-ripple ' + (btnStyle + btnSize + btnDisabled), onClick: this.bnRipple }, _react2.default.createElement( 'span', { className: 'base-btn-title' }, (0, _commonFunc.decode)(title) ), _react2.default.createElement('i', { className: 'ripple', style: { 'left': left, 'top': top } }) ) ) ); } } } }]); return BaseButton; }(_react.Component), _class.defaultProps = { tipsReason: '', dataUdt: '' }, _temp); module.exports = BaseButton;