UNPKG

@beisen/ethos

Version:

beisencloud pc react components

155 lines (129 loc) 4.87 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 _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactDom = require('react-dom'); require('./style/all.scss'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var IconButton = function (_Component) { (0, _inherits3.default)(IconButton, _Component); function IconButton(props) { (0, _classCallCheck3.default)(this, IconButton); var _this = (0, _possibleConstructorReturn3.default)(this, (IconButton.__proto__ || (0, _getPrototypeOf2.default)(IconButton)).call(this, props)); _this.state = { IconActive: '', IconStyle: '', IconDisabled: '', top: 0, left: 0 }; _this.initData = { "bsStyle": { "weaken": "icon-btns-weaken ", "default": " ", "link": " " }, "btnDisabled": { "weaken": "icon-btns-bg-gray-weaken ", "default": "icon-btns-bg-gray-defalult ", "link": " " } }; _this.bnRipple = _this.bnRipple.bind(_this); return _this; } (0, _createClass3.default)(IconButton, [{ key: 'bnRipple', value: function bnRipple(e) { //为按钮添加点击效果 var _props = this.props, disabled = _props.disabled, onClick = _props.onClick; if (disabled) return false; var icBtn = this.refs.icBtn; icBtn.setAttribute('class', icBtn.className.replace('icon-bg-ripple-active', '')); var realLeft = e.clientX - icBtn.offsetLeft; var realTop = e.clientY - icBtn.offsetTop; icBtn.setAttribute('class', icBtn.className + 'icon-bg-ripple-active'); this.setState({ top: realTop, left: realLeft }); onClick && onClick(e, true, this.state); } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if (nextProps.disabled != this.props.disabled) { var iDisable = nextProps.disabled ? this.initData.btnDisabled[nextProps.bsStyle] : this.state.IconDisabled = " "; this.setState({ IconDisabled: iDisable }); } } }, { key: 'componentWillMount', value: function componentWillMount() { //初始化数据,为按钮添加样式 var _props2 = this.props, bsStyle = _props2.bsStyle, disabled = _props2.disabled, active = _props2.active; var iActive = active ? iActive = "icon-bg-ripple-active " : " "; var iStyle = this.initData.bsStyle[bsStyle]; var iDisable = disabled ? this.initData.btnDisabled[bsStyle] : this.state.IconDisabled = " "; this.setState({ IconStyle: iStyle, IconDisabled: iDisable, IconActive: iActive }); } }, { key: 'render', value: function render() { var _state = this.state, left = _state.left, top = _state.top, IconDisabled = _state.IconDisabled, IconActive = _state.IconActive, IconStyle = _state.IconStyle; var _props3 = this.props, hidden = _props3.hidden, bsStyle = _props3.bsStyle, title = _props3.title, href = _props3.href, iconName = _props3.iconName; if (hidden) { return _react2.default.createElement('div', null); } else { switch (bsStyle) { case "link": return _react2.default.createElement( 'a', { href: href, target: '_blank' }, title ); default: return _react2.default.createElement( 'div', { className: 'icon-button-component clearfix' }, _react2.default.createElement( 'span', { ref: 'icBtn', className: iconName + ' icon-bg-ripple icon-btn-common-style ' + (IconActive + IconStyle + IconDisabled), onClick: this.bnRipple }, _react2.default.createElement('i', { className: 'ripple', style: { 'left': left, 'top': top } }) ) ); } } } }]); return IconButton; }(_react.Component); module.exports = IconButton;