UNPKG

vantui-edit

Version:

一套适用于Taro3及React的vantui组件库

120 lines (115 loc) 5.34 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["tipIcon", "tip", "label", "currency", "suffixLabel", "buttonType", "price", "loading", "disabled", "buttonText", "safeAreaInsetBottom", "renderTop", "renderTip", "decimalLength", "onSubmit", "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 { View, Text } from '@tarojs/components'; import { useEffect, useState } from 'react'; import { Icon } from '../icon'; import { Button } from '../button'; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; export function SubmitBar(props) { var tipIcon = props.tipIcon, tip = props.tip, label = props.label, _props$currency = props.currency, currency = _props$currency === void 0 ? '¥' : _props$currency, suffixLabel = props.suffixLabel, _props$buttonType = props.buttonType, buttonType = _props$buttonType === void 0 ? 'danger' : _props$buttonType, price = props.price, loading = props.loading, disabled = props.disabled, buttonText = props.buttonText, _props$safeAreaInsetB = props.safeAreaInsetBottom, safeAreaInsetBottom = _props$safeAreaInsetB === void 0 ? true : _props$safeAreaInsetB, renderTop = props.renderTop, renderTip = props.renderTip, decimalLength = props.decimalLength, onSubmit = props.onSubmit, children = props.children, style = props.style, className = props.className, others = _objectWithoutProperties(props, _excluded); var _useState = useState({ hasTip: false, integerStr: '', decimalStr: '', hasPrice: false }), _useState2 = _slicedToArray(_useState, 2), state = _useState2[0], setState = _useState2[1]; var hasTip = state.hasTip, integerStr = state.integerStr, decimalStr = state.decimalStr, hasPrice = state.hasPrice; useEffect(function () { setState(function (pre) { return _objectSpread(_objectSpread({}, pre), {}, { hasTip: typeof tip === 'string' }); }); }, [tip]); useEffect(function () { var priceStrArr = typeof price === 'number' && (price / 100).toFixed(decimalLength).split('.'); setState(function (pre) { return _objectSpread(_objectSpread({}, pre), {}, { hasPrice: typeof price === 'number', integerStr: priceStrArr && priceStrArr[0], decimalStr: decimalLength && priceStrArr ? ".".concat(priceStrArr[1]) : '' }); }); }, [decimalLength, price]); return /*#__PURE__*/_jsxs(View, _objectSpread(_objectSpread({ className: "van-submit-bar ".concat(className || ''), style: style }, others), {}, { children: [renderTop, /*#__PURE__*/_jsxs(View, { className: "van-submit-bar__tip", children: [tipIcon && /*#__PURE__*/_jsx(Icon, { size: "12px", name: tipIcon, className: "van-submit-bar__tip-icon" }), hasTip && /*#__PURE__*/_jsx(View, { className: "van-submit-bar__tip-text", children: tip }), renderTip] }), /*#__PURE__*/_jsxs(View, { className: "bar-class van-submit-bar__bar", children: [children, hasPrice && /*#__PURE__*/_jsxs(View, { className: "van-submit-bar__text", children: [/*#__PURE__*/_jsx(Text, { children: label || '合计:' }), /*#__PURE__*/_jsxs(Text, { className: "van-submit-bar__price price-class", children: [/*#__PURE__*/_jsx(Text, { className: "van-submit-bar__currency", children: currency }), /*#__PURE__*/_jsx(Text, { className: "van-submit-bar__price-integer", children: integerStr }), /*#__PURE__*/_jsx(Text, { children: decimalStr })] }), /*#__PURE__*/_jsx(Text, { className: "van-submit-bar__suffix-label", children: suffixLabel })] }), /*#__PURE__*/_jsx(Button, { round: true, type: buttonType, loading: loading, disabled: disabled, className: "van-submit-bar__button button-class", onClick: onSubmit, children: loading ? '' : buttonText })] }), safeAreaInsetBottom && /*#__PURE__*/_jsx(View, { className: "van-submit-bar__safe" })] })); } export default SubmitBar;