dragon-mobile-ui
Version:
UI for react.js
141 lines (111 loc) • 6.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _classnames2 = require('classnames');
var _classnames3 = _interopRequireDefault(_classnames2);
var _Icon = require('../Icon');
var _Icon2 = _interopRequireDefault(_Icon);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Button = function (_Component) {
_inherits(Button, _Component);
function Button() {
_classCallCheck(this, Button);
return _possibleConstructorReturn(this, (Button.__proto__ || Object.getPrototypeOf(Button)).apply(this, arguments));
}
_createClass(Button, [{
key: 'render',
value: function render() {
var _classnames;
var props = this.props;
var _props = this.props,
theme = _props.theme,
size = _props.size,
isBlock = _props.isBlock,
isRadius = _props.isRadius,
isRound = _props.isRound,
isCircle = _props.isCircle,
isActive = _props.isActive,
isFocus = _props.isFocus,
isBordered = _props.isBordered,
isDisabled = _props.isDisabled,
isLoading = _props.isLoading,
className = _props.className,
_onClick = _props.onClick,
children = _props.children,
others = _objectWithoutProperties(_props, ['theme', 'size', 'isBlock', 'isRadius', 'isRound', 'isCircle', 'isActive', 'isFocus', 'isBordered', 'isDisabled', 'isLoading', 'className', 'onClick', 'children']);
var disabled = 'disabled' in props || isDisabled;
var loading = 'loading' in props || isLoading;
var classes = (0, _classnames3.default)((_classnames = {
'ui-button': true,
block: 'block' in props || isBlock,
radius: 'radius' in props || isRadius,
round: 'round' in props || isRound,
circle: 'circle' in props || isCircle,
bordered: 'bordered' in props || isBordered,
active: 'active' in props || isActive,
focus: 'focus' in props || isFocus,
disabled: disabled
}, _defineProperty(_classnames, 'theme-' + theme, !!theme), _defineProperty(_classnames, 'size-' + size, !!size), _defineProperty(_classnames, className, !!className), _classnames));
var textContent = loading ? _react2.default.createElement(
'span',
null,
_react2.default.createElement(_Icon2.default, { type: 'loading', className: 'rotate360' }),
' ',
children
) : children;
return _react2.default.createElement(
'button',
_extends({}, others, { className: classes, disabled: disabled, onClick: function onClick(e) {
return !disabled && _onClick(e);
} }),
textContent
);
}
}]);
return Button;
}(_react.Component);
Button.propTypes = {
type: _propTypes2.default.string,
theme: _propTypes2.default.oneOf(['default', 'info', 'success', 'warning', 'error']),
size: _propTypes2.default.oneOf(['xl', 'lg', 'sm', 'xs']),
isBlock: _propTypes2.default.bool,
isRadius: _propTypes2.default.bool,
isRound: _propTypes2.default.bool,
isCircle: _propTypes2.default.bool,
isBordered: _propTypes2.default.bool,
isActive: _propTypes2.default.bool,
isFocus: _propTypes2.default.bool,
isDisabled: _propTypes2.default.bool,
isLoading: _propTypes2.default.bool,
className: _propTypes2.default.string,
onClick: _propTypes2.default.func
};
Button.defaultProps = {
type: 'button',
theme: 'default',
size: null,
isBlock: false,
isRadius: false,
isRound: false,
isCircle: false,
isBordered: false,
isActive: false,
isFocus: false,
isDisabled: false,
isLoading: false,
className: null,
onClick: function onClick() {}
};
exports.default = Button;