chowa
Version:
UI component library based on React
74 lines (73 loc) • 2.98 kB
JavaScript
/**
* @license chowa v1.1.3
*
* Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn).
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const PropTypes = require("prop-types");
const classnames_1 = require("classnames");
const utils_1 = require("../utils");
const icon_1 = require("../icon");
class Spin extends React.PureComponent {
singleSpin() {
const { className, style, light, md, iconType } = this.props;
const componentClass = classnames_1.default({
[utils_1.preClass('spin')]: true,
[utils_1.preClass('spin-single')]: true,
[utils_1.preClass('spin-light')]: light,
[utils_1.preClass(`spin-${md}`)]: utils_1.isExist(md),
[className]: utils_1.isExist(className)
});
return (React.createElement("span", { style: style, className: componentClass },
React.createElement(icon_1.default, { type: iconType === undefined ? 'spin' : iconType })));
}
wrapperSpin() {
const { children, loading, loadingText, className } = this.props;
const wrapperClass = classnames_1.default({
[utils_1.preClass('spin-wrapper')]: true,
[className]: utils_1.isExist(className)
});
const filterWrapClass = classnames_1.default({
[utils_1.preClass('spin-children-wrapper')]: true,
[utils_1.preClass('spin-filter')]: loading
});
return (React.createElement("div", { className: wrapperClass },
React.createElement("div", { className: filterWrapClass }, children),
loading &&
React.createElement("div", { className: utils_1.preClass('spin-loader-wrapper') },
React.createElement("div", { className: utils_1.preClass('spin-loader') },
React.createElement("span", null),
React.createElement("span", null),
React.createElement("span", null),
React.createElement("span", null)),
utils_1.isExist(loadingText) &&
React.createElement("p", { className: utils_1.preClass('spin-loading-text') }, loadingText))));
}
render() {
const { children } = this.props;
if (!utils_1.isExist(children)) {
return this.singleSpin();
}
return this.wrapperSpin();
}
}
Spin.propTypes = {
className: PropTypes.string,
style: PropTypes.object,
type: PropTypes.oneOf(['default', 'primary']),
md: PropTypes.oneOf(['mt', 'ml', 'mr', 'mb']),
light: PropTypes.bool,
iconType: PropTypes.string,
loading: PropTypes.bool,
loadingText: PropTypes.string
};
Spin.defaultProps = {
light: false,
loading: false
};
exports.default = Spin;