UNPKG

ukelli-ui

Version:

Base on React's UI lib. Make frontend's dev simpler and faster.

55 lines (54 loc) 2.98 kB
/* eslint-disable react/button-has-type */ var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React from 'react'; import classnames from 'classnames'; import { Call } from 'basic-helper'; import { Icon } from '../icon'; var defaultProps = { loading: false, loadingHint: true, loadingDisable: true, disabled: false, textLayout: 'a-i-c j-c-c', className: '', icon: '', }; var Button = function (props) { var loading = props.loading, disabled = props.disabled, text = props.text, icon = props.icon, s = props.s, _a = props.type, type = _a === void 0 ? 'button' : _a, children = props.children, status = props.status, _b = props.color, color = _b === void 0 ? 'theme' : _b, _c = props.size, size = _c === void 0 ? 'md' : _c, _d = props.block, block = _d === void 0 ? false : _d, className = props.className, _e = props.hola, hola = _e === void 0 ? false : _e, loadingHint = props.loadingHint, loadingDisable = props.loadingDisable, textLayout = props.textLayout, onClick = props.onClick, other = __rest(props, ["loading", "disabled", "text", "icon", "s", "type", "children", "status", "color", "size", "block", "className", "hola", "loadingHint", "loadingDisable", "textLayout", "onClick"]); var clickable = !disabled && (!loading || !loadingDisable); var iconDOM = icon ? (React.createElement(Icon, { n: icon, s: s, classNames: ['btn-icon'] })) : null; var loadingTip = loadingHint && loading ? (React.createElement(Icon, { n: "loading", s: s, classNames: ['btn-loading'] })) : null; var child = children || text; var classNames = classnames('btn', status || color, size, className, hola && 'hola', block && 'block'); return (React.createElement("button", __assign({}, other, { disabled: !clickable, type: type, className: classNames, onClick: function (e) { if (clickable) Call(onClick, e); } }), React.createElement("span", { className: "layout " + textLayout }, iconDOM, child && React.createElement("span", { className: "ms10" }, child), loadingTip))); }; Button.defaultProps = defaultProps; export default Button;