UNPKG

zangai-react

Version:
55 lines (54 loc) 2.41 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { buildClassName } from '../core/css-builder'; import { tuple } from '../core/type'; var ButtonHTMLTypes = tuple('submit', 'button', 'reset'); var AtButton = /** @class */ (function (_super) { tslib_1.__extends(AtButton, _super); function AtButton(props) { var _this = _super.call(this, props) || this; _this.handleClick = function (e) { var onClick = _this.props.onClick; if (onClick) { onClick(e); } }; return _this; } AtButton.prototype.isIcon = function () { var atIcon = this.props.atIcon; return (atIcon ? (React.createElement("i", { className: "at-btn__icon icon " + atIcon })) : null); }; AtButton.prototype.isLoading = function () { var _a = this.props, atIcon = _a.atIcon, atLoading = _a.atLoading; return ((atLoading && !atIcon) ? (React.createElement("i", { className: "at-btn__icon icon at-btn__loading icon-loader" })) : null); }; AtButton.prototype.childrenExist = function () { var children = this.props.children; return (children) ? (React.createElement("span", { className: "at-btn__text" }, this.props.children, " ")) : null; }; AtButton.prototype.render = function () { var _a; var _b = this.props, atType = _b.atType, atHollow = _b.atHollow, atSize = _b.atSize, atLoading = _b.atLoading, atShape = _b.atShape, atIcon = _b.atIcon, rest = tslib_1.__rest(_b, ["atType", "atHollow", "atSize", "atLoading", "atShape", "atIcon"]); var classMap = (_a = { 'at-btn': true }, _a["at-btn--" + atType] = true, _a["at-btn--" + atType + "--hollow"] = atHollow, _a["at-btn--" + atSize] = atSize, _a); var className = buildClassName(classMap); var _c = rest, htmlType = _c.htmlType, otherProps = tslib_1.__rest(_c, ["htmlType"]); return (React.createElement("button", tslib_1.__assign({ type: htmlType || 'button' }, otherProps, { onClick: this.handleClick, className: className }), this.isIcon(), this.isLoading(), this.childrenExist())); }; AtButton.defaultProps = { atType: 'default', }; return AtButton; }(React.Component)); export { AtButton };