UNPKG

chowa

Version:

UI component library based on React

90 lines (89 loc) 3.35 kB
/** * @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. */ "use strict"; 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 spin_1 = require("../spin"); class Button extends React.PureComponent { focus() { this.btnEle.focus(); } blur() { this.btnEle.blur(); } render() { const { children, className, disabled, active, type, htmlType, loading, size, href, target, round, block, ghost, dashed, text } = this.props; const componentClass = classnames_1.default({ [utils_1.preClass('btn')]: true, [utils_1.preClass('btn-active')]: active, [utils_1.preClass(`btn-${type}`)]: type !== 'default', [utils_1.preClass(`btn-${size}`)]: size !== 'default', [utils_1.preClass('round')]: round, [utils_1.preClass('btn-block')]: block, [utils_1.preClass('btn-ghost')]: ghost || dashed, [utils_1.preClass('btn-dashed')]: dashed, [utils_1.preClass('btn-text')]: text, [utils_1.preClass('btn-loading')]: loading, [utils_1.preClass('btn-disabled')]: disabled, [className]: utils_1.isExist(className) }); let lightSpin = false; if ((type === 'primary' || type === 'danger') && !ghost && !text) { lightSpin = true; } if (href) { return (React.createElement("a", Object.assign({}, utils_1.otherProps(Button.propTypes, this.props), { href: href, className: componentClass, target: target, ref: (ele) => { this.btnEle = ele; } }), loading && React.createElement(spin_1.default, { light: lightSpin, md: 'mr' }), children)); } else { return (React.createElement("button", Object.assign({}, utils_1.otherProps(Button.propTypes, this.props), { className: componentClass, type: htmlType, disabled: loading || disabled, ref: (ele) => { this.btnEle = ele; } }), loading && React.createElement(spin_1.default, { light: lightSpin, md: 'mr' }), children)); } } } Button.propTypes = { className: PropTypes.string, disabled: PropTypes.bool, active: PropTypes.bool, type: PropTypes.oneOf(['default', 'primary', 'danger']), htmlType: PropTypes.oneOf(['button', 'submit', 'reset']), loading: PropTypes.bool, size: PropTypes.oneOf(['small', 'default', 'large']), href: PropTypes.string, target: PropTypes.oneOf(['_blank', '_self', '_parent', '_top']), round: PropTypes.bool, block: PropTypes.bool, ghost: PropTypes.bool, dashed: PropTypes.bool, text: PropTypes.bool }; Button.defaultProps = { disabled: false, active: false, type: 'default', htmlType: 'button', loading: false, size: 'default', target: '_self', round: false, block: false, ghost: false, dashed: false, text: false }; exports.default = Button;