mr-component
Version:
A library for Mr components
72 lines (66 loc) • 2.97 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["type", "variant", "text", "fontSize", "isAmount", "size", "color", "disabled", "loading", "round", "square", "block", "icon", "iconPosition", "onClick", "className", "style"],
_excluded2 = ["forwardRef"];
import * as React from 'react';
import { forwardRef } from 'react';
import { Button } from 'react-vant';
// Mr Button 变体类型
// 成功操作按钮 - 绿色
var MrButton = function MrButton(props, ref) {
var _props$type = props.type,
type = _props$type === void 0 ? 'default' : _props$type,
_props$variant = props.variant,
variant = _props$variant === void 0 ? 'payment-primary' : _props$variant,
_props$text = props.text,
text = _props$text === void 0 ? '按钮' : _props$text,
_props$fontSize = props.fontSize,
fontSize = _props$fontSize === void 0 ? 'h5' : _props$fontSize,
_props$isAmount = props.isAmount,
isAmount = _props$isAmount === void 0 ? false : _props$isAmount,
_props$size = props.size,
size = _props$size === void 0 ? 'normal' : _props$size,
color = props.color,
_props$disabled = props.disabled,
disabled = _props$disabled === void 0 ? false : _props$disabled,
_props$loading = props.loading,
loading = _props$loading === void 0 ? false : _props$loading,
_props$round = props.round,
round = _props$round === void 0 ? false : _props$round,
_props$square = props.square,
square = _props$square === void 0 ? false : _props$square,
_props$block = props.block,
block = _props$block === void 0 ? false : _props$block,
icon = props.icon,
_props$iconPosition = props.iconPosition,
iconPosition = _props$iconPosition === void 0 ? 'left' : _props$iconPosition,
onClick = props.onClick,
className = props.className,
style = props.style,
others = _objectWithoutPropertiesLoose(props, _excluded);
// 手动构建CSS类名
var classNames = ['mr-button', variant && "mr-button--" + variant, fontSize && "mr-button--font-" + fontSize, isAmount && 'mr-button--amount', className].filter(Boolean).join(' ');
// 如果有variant,优先使用variant样式,否则使用原生type
var buttonType = variant ? 'default' : type;
// 过滤掉可能被错误传递的forwardRef属性
var _ = others.forwardRef,
restProps = _objectWithoutPropertiesLoose(others, _excluded2);
return /*#__PURE__*/React.createElement(Button, _extends({
type: buttonType,
size: size,
color: color,
disabled: disabled,
loading: loading,
round: round,
square: square,
block: block,
icon: icon,
iconPosition: iconPosition,
className: classNames,
style: style,
onClick: onClick
}, restProps), text);
};
var RefMrButton = /*#__PURE__*/forwardRef(MrButton);
RefMrButton.displayName = 'MrButton';
export default RefMrButton;