UNPKG

zangai-react

Version:
49 lines (48 loc) 1.94 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { buildClassName } from '../core/css-builder'; import { tuple } from '../core/type'; const ButtonHTMLTypes = tuple('submit', 'button', 'reset'); export class AtButton extends React.Component { constructor(props) { super(props); this.handleClick = e => { const { onClick } = this.props; if (onClick) { onClick(e); } }; } isIcon() { const { atIcon } = this.props; return (atIcon ? (React.createElement("i", { className: `at-btn__icon icon ${atIcon}` })) : null); } isLoading() { const { atIcon, atLoading } = this.props; return ((atLoading && !atIcon) ? (React.createElement("i", { className: `at-btn__icon icon at-btn__loading icon-loader` })) : null); } childrenExist() { const { children } = this.props; return (children) ? (React.createElement("span", { className: "at-btn__text" }, this.props.children, " ")) : null; } render() { const _a = this.props, { atType, atHollow, atSize, atLoading, atShape, atIcon } = _a, rest = tslib_1.__rest(_a, ["atType", "atHollow", "atSize", "atLoading", "atShape", "atIcon"]); const classMap = { 'at-btn': true, [`at-btn--${atType}`]: true, [`at-btn--${atType}--hollow`]: atHollow, [`at-btn--${atSize}`]: atSize, }; const className = buildClassName(classMap); const _b = rest, { htmlType } = _b, otherProps = tslib_1.__rest(_b, ["htmlType"]); return (React.createElement("button", Object.assign({ type: htmlType || 'button' }, otherProps, { onClick: this.handleClick, className: className }), this.isIcon(), this.isLoading(), this.childrenExist())); } } AtButton.defaultProps = { atType: 'default', };