UNPKG

@gizwits/vantui

Version:

机智云组件库

112 lines 4.91 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["type", "size", "block", "round", "plain", "square", "loading", "disabled", "hairline", "color", "loadingSize", "loadingType", "loadingText", "icon", "classPrefix", "onClick", "children", "style", "className"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import { pxTransform } from '@tarojs/taro'; import { Button as TaroButton, View } from '@tarojs/components'; import * as utils from '../wxs/utils'; import { Icon } from '../icon/index'; import { Loading } from '../loading/index'; import * as computed from './wxs'; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; var removed = false; // 次输是为了在开发环境有一个中止状态 var time = 10; // 动态删除taro-button-core的style if (process.env.TARO_ENV === 'h5' && !removed) { var _timer = setInterval(function () { time--; if (time > 0) { var allStyle = document.getElementsByTagName('style') || []; for (var i = allStyle.length - 1; i >= 0; i--) { var sty = allStyle[i]; var htm = sty.innerHTML; if (htm && /^taro-button-core{/.test(htm)) { sty.remove(); removed = true; _timer && clearInterval(_timer); break; } } } else { _timer && clearInterval(_timer); } }, 200); } export function Button(props) { var _props$type = props.type, type = _props$type === void 0 ? 'default' : _props$type, _props$size = props.size, size = _props$size === void 0 ? 'normal' : _props$size, block = props.block, round = props.round, plain = props.plain, square = props.square, loading = props.loading, disabled = props.disabled, hairline = props.hairline, color = props.color, _props$loadingSize = props.loadingSize, loadingSize = _props$loadingSize === void 0 ? pxTransform(40) : _props$loadingSize, _props$loadingType = props.loadingType, loadingType = _props$loadingType === void 0 ? 'circular' : _props$loadingType, loadingText = props.loadingText, icon = props.icon, _props$classPrefix = props.classPrefix, classPrefix = _props$classPrefix === void 0 ? 'van-icon' : _props$classPrefix, onClick = props.onClick, children = props.children, style = props.style, className = props.className, others = _objectWithoutProperties(props, _excluded); return /*#__PURE__*/_jsx(TaroButton, _objectSpread(_objectSpread({ className: ' ' + utils.bem('button', [type, size, { block: block, round: round, plain: plain, square: square, loading: loading, disabled: disabled, hairline: hairline, unclickable: disabled || loading }]) + ' ' + (hairline ? 'van-hairline--surround' : '') + " ".concat(className || ''), hoverClass: "van-button--active hover-class", style: utils.style([computed.rootStyle({ plain: plain, color: color }), style]), onClick: disabled || loading ? undefined : onClick }, others), {}, { children: loading ? /*#__PURE__*/_jsxs(View, { style: "display: flex", children: [/*#__PURE__*/_jsx(Loading, { className: "loading-class", size: loadingSize, type: loadingType, color: computed.loadingColor({ type: type, color: color, plain: plain }) }), loadingText && /*#__PURE__*/_jsx(View, { className: "van-button__loading-text", children: loadingText })] }) : /*#__PURE__*/_jsxs(_Fragment, { children: [icon && /*#__PURE__*/_jsx(Icon, { size: "1.2em", name: icon, classPrefix: classPrefix, className: "van-button__icon", style: "line-height: inherit;" }), /*#__PURE__*/_jsx(View, { className: "van-button__text", children: children })] }) })); } export default Button;