ost-ui
Version:
ost ui for react
81 lines (66 loc) • 2.45 kB
JavaScript
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
var OstButton = function (_Component) {
_inherits(OstButton, _Component);
function OstButton(props) {
_classCallCheck(this, OstButton);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this.isString = function (str) {
return typeof str === 'string';
};
_this.insertSpace = function (child) {
var rxTwoCNChar = /^[\u4e00-\u9fa5]{2}$/;
var isTwoCNChar = rxTwoCNChar.test.bind(rxTwoCNChar);
if (_this.isString(child.type) && isTwoCNChar(child.props.children)) {
return React.cloneElement(child, {}, child.props.children.split('').join(' '));
}
if (_this.isString(child)) {
if (isTwoCNChar(child)) {
child = child.split('').join(' ');
}
return React.createElement(
'span',
null,
child
);
}
return child;
};
return _this;
}
// Insert one space between two chinese characters automatically.
OstButton.prototype.render = function render() {
var _classnames;
var _props = this.props,
children = _props.children,
fixedCls = _props.fixedCls,
className = _props.className,
type = _props.type,
size = _props.size,
inline = _props.inline,
disabled = _props.disabled,
loading = _props.loading,
iconType = _props.iconType;
var wrapClass = classnames(fixedCls, className, (_classnames = {}, _classnames[fixedCls + '-' + type] = type, _classnames[fixedCls + '-ghost'] = type === 'ghost', _classnames[fixedCls + '-warning'] = type === 'warning', _classnames[fixedCls + '-small'] = size === 'small', _classnames[fixedCls + '-inline'] = inline, _classnames));
var kids = React.Children.map(children, this.insertSpace);
return React.createElement(
'a',
{ className: wrapClass },
kids
);
};
return OstButton;
}(Component);
OstButton.defaultProps = {
fixedCls: 'ost-button',
inline: false
};
export default OstButton;
OstButton.propTypes = {
fixedCls: PropTypes.string,
inline: PropTypes.bool.isRequired
};