Skip to content

Commit

Permalink
include lib
Browse files Browse the repository at this point in the history
  • Loading branch information
XJouYi committed Jun 30, 2016
1 parent 687fc15 commit a0d7cbd
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

/dist/

/lib/
185 changes: 185 additions & 0 deletions lib/button/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
'use strict';

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _reactDom = require('react-dom');

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 rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/;
var isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar);
function isString(str) {
return typeof str === 'string';
}

// Insert one space between two chinese characters automatically.
function insertSpace(child) {
if (isString(child.type) && isTwoCNChar(child.props.children)) {
return _react2.default.cloneElement(child, {}, child.props.children.split('').join(' '));
}
if (isString(child)) {
if (isTwoCNChar(child)) {
child = child.split('').join(' ');
}
return _react2.default.createElement(
'span',
null,
child
);
}
return child;
}

var Button = function (_React$Component) {
_inherits(Button, _React$Component);

function Button() {
_classCallCheck(this, Button);

return _possibleConstructorReturn(this, Object.getPrototypeOf(Button).apply(this, arguments));
}

_createClass(Button, [{
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (this.clickedTimeout) {
clearTimeout(this.clickedTimeout);
}
if (this.timeout) {
clearTimeout(this.timeout);
}
}
}, {
key: 'clearButton',
value: function clearButton(button) {
button.className = button.className.replace(' ' + this.props.prefixCls + '-clicked', '');
}
}, {
key: 'handleClick',
value: function handleClick() {
var _this2 = this,
_props;

// Add click effect
var buttonNode = (0, _reactDom.findDOMNode)(this);
this.clearButton(buttonNode);
this.clickedTimeout = setTimeout(function () {
return buttonNode.className += ' ' + _this2.props.prefixCls + '-clicked';
}, 10);
clearTimeout(this.timeout);
this.timeout = setTimeout(function () {
return _this2.clearButton(buttonNode);
}, 500);

(_props = this.props).onClick.apply(_props, arguments);
}

// Handle auto focus when click button in Chrome

}, {
key: 'handleMouseUp',
value: function handleMouseUp(e) {
(0, _reactDom.findDOMNode)(this).blur();
if (this.props.onMouseUp) {
this.props.onMouseUp(e);
}
}
}, {
key: 'render',
value: function render() {
var _classNames;

var props = this.props;
var type = props.type;
var shape = props.shape;
var size = props.size;
var className = props.className;
var htmlType = props.htmlType;
var children = props.children;
var icon = props.icon;
var loading = props.loading;
var prefixCls = props.prefixCls;

var others = _objectWithoutProperties(props, ['type', 'shape', 'size', 'className', 'htmlType', 'children', 'icon', 'loading', 'prefixCls']);

// large => lg
// small => sm


var sizeCls = {
large: 'lg',
small: 'sm'
}[size] || '';

var classes = (0, _classnames2.default)((_classNames = {}, _defineProperty(_classNames, prefixCls, true), _defineProperty(_classNames, prefixCls + '-' + type, type), _defineProperty(_classNames, prefixCls + '-' + shape, shape), _defineProperty(_classNames, prefixCls + '-' + sizeCls, sizeCls), _defineProperty(_classNames, prefixCls + '-icon-only', !children && icon), _defineProperty(_classNames, prefixCls + '-loading', loading), _defineProperty(_classNames, className, className), _classNames));

var iconType = loading ? 'loading' : icon;

var kids = _react2.default.Children.map(children, insertSpace);

return _react2.default.createElement(
'button',
_extends({}, others, {
type: htmlType || 'button',
className: classes,
onMouseUp: this.handleMouseUp.bind(this),
onClick: this.handleClick.bind(this)
}),
iconType ? _react2.default.createElement(_icon2.default, { type: iconType }) : null,
kids
);
}
}]);

return Button;
}(_react2.default.Component);

exports.default = Button;


Button.propTypes = {
type: _react2.default.PropTypes.string,
shape: _react2.default.PropTypes.oneOf(['circle', 'circle-outline']),
size: _react2.default.PropTypes.oneOf(['large', 'default', 'small']),
htmlType: _react2.default.PropTypes.oneOf(['submit', 'button', 'reset']),
onClick: _react2.default.PropTypes.func,
loading: _react2.default.PropTypes.bool,
className: _react2.default.PropTypes.string,
icon: _react2.default.PropTypes.string,
prefixCls: _react2.default.PropTypes.string
};

Button.defaultProps = {
prefixCls: 'ant-btn',
onClick: function onClick() {},

loading: false
};
13 changes: 13 additions & 0 deletions lib/button/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _button = require('./button');

var _button2 = _interopRequireDefault(_button);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = _button2.default;
1 change: 1 addition & 0 deletions lib/dist/monkeyui.css

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions lib/icon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }

exports.default = function (props) {
var type = props.type;
var _props$className = props.className;
var className = _props$className === undefined ? '' : _props$className;

var other = _objectWithoutProperties(props, ['type', 'className']);

className += ' anticon anticon-' + type;
return _react2.default.createElement('i', _extends({ className: className }, other));
};
107 changes: 107 additions & 0 deletions lib/layout/col.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
'use strict';

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 _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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 stringOrNumber = _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.number]);
var objectOrNumber = _react.PropTypes.oneOfType([_react.PropTypes.object, _react.PropTypes.number]);

var Col = function (_React$Component) {
_inherits(Col, _React$Component);

function Col(props) {
_classCallCheck(this, Col);

var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Col).call(this, props));

_this.props = props;
return _this;
}

_createClass(Col, [{
key: 'render',
value: function render() {
var _extends3;

var props = this.props;
var _props = this.props;
var span = _props.span;
var order = _props.order;
var offset = _props.offset;
var push = _props.push;
var pull = _props.pull;
var className = _props.className;
var children = _props.children;

var others = _objectWithoutProperties(_props, ['span', 'order', 'offset', 'push', 'pull', 'className', 'children']);

var sizeClassObj = {};

['xs', 'sm', 'md', 'lg'].forEach(function (size) {
var _extends2;

var sizeProps = {};
if (typeof props[size] === 'number') {
sizeProps.span = props[size];
} else if (_typeof(props[size]) === 'object') {
sizeProps = props[size] || {};
}
sizeClassObj = _extends({}, sizeClassObj, (_extends2 = {}, _defineProperty(_extends2, 'ant-col-' + size + '-' + sizeProps.span, sizeProps.span !== undefined), _defineProperty(_extends2, 'ant-col-' + size + '-order-' + sizeProps.order, sizeProps.order), _defineProperty(_extends2, 'ant-col-' + size + '-offset-' + sizeProps.offset, sizeProps.offset), _defineProperty(_extends2, 'ant-col-' + size + '-push-' + sizeProps.push, sizeProps.push), _defineProperty(_extends2, 'ant-col-' + size + '-pull-' + sizeProps.pull, sizeProps.pull), _extends2));
});

var classes = (0, _classnames2.default)(_extends((_extends3 = {}, _defineProperty(_extends3, 'ant-col-' + span, span !== undefined), _defineProperty(_extends3, 'ant-col-order-' + order, order), _defineProperty(_extends3, 'ant-col-offset-' + offset, offset), _defineProperty(_extends3, 'ant-col-push-' + push, push), _defineProperty(_extends3, 'ant-col-pull-' + pull, pull), _defineProperty(_extends3, className, !!className), _extends3), sizeClassObj));

return _react2.default.createElement(
'div',
_extends({}, others, { className: classes }),
children
);
}
}]);

return Col;
}(_react2.default.Component);

exports.default = Col;


Col.propTypes = {
span: stringOrNumber,
order: stringOrNumber,
offset: stringOrNumber,
push: stringOrNumber,
pull: stringOrNumber,
className: _react.PropTypes.string,
children: _react.PropTypes.node,
xs: objectOrNumber,
sm: objectOrNumber,
md: objectOrNumber,
lg: objectOrNumber
};
Loading

0 comments on commit a0d7cbd

Please sign in to comment.