@antmjs/vantui
Version:
一套适用于Taro3及React的vantui组件库
81 lines • 4.12 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
var _excluded = ["strokeWidth", "trackColor", "percentage", "inactive", "color", "textColor", "pivotColor", "pivotText", "showPivot", "style", "className", "rectWrapper"];
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 { nextTick } from '@tarojs/taro';
import { useState, useEffect } from 'react';
import { View } from '@tarojs/components';
import * as utils from '../wxs/utils';
import { getRect } from '../common/utils';
import { get } from '../default-props';
import * as computed from './wxs';
import { jsx as _jsx } from "react/jsx-runtime";
export function Progress(props) {
var _useState = useState(get().Progress),
_useState2 = _slicedToArray(_useState, 1),
d = _useState2[0];
var _useState3 = useState(0),
_useState4 = _slicedToArray(_useState3, 2),
right = _useState4[0],
setRight = _useState4[1];
var _d$props = _objectSpread(_objectSpread({}, d), props),
_d$props$strokeWidth = _d$props.strokeWidth,
strokeWidth = _d$props$strokeWidth === void 0 ? 4 : _d$props$strokeWidth,
trackColor = _d$props.trackColor,
percentage = _d$props.percentage,
inactive = _d$props.inactive,
_d$props$color = _d$props.color,
color = _d$props$color === void 0 ? '' : _d$props$color,
_d$props$textColor = _d$props.textColor,
textColor = _d$props$textColor === void 0 ? '#ffffff' : _d$props$textColor,
pivotColor = _d$props.pivotColor,
pivotText = _d$props.pivotText,
_d$props$showPivot = _d$props.showPivot,
showPivot = _d$props$showPivot === void 0 ? true : _d$props$showPivot,
style = _d$props.style,
className = _d$props.className,
rectWrapper = _d$props.rectWrapper,
others = _objectWithoutProperties(_d$props, _excluded);
useEffect(function () {
nextTick(function () {
Promise.all([getRect(null, '.van-progress', rectWrapper), getRect(null, '.van-progress__pivot', rectWrapper)]).then(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
portion = _ref2[0],
pivot = _ref2[1];
if (portion && pivot) {
setRight(pivot.width * (Number(props.percentage) - 100) / 100);
}
});
});
}, [props.percentage, rectWrapper]);
return /*#__PURE__*/_jsx(View, _objectSpread(_objectSpread({
className: 'van-progress ' + className,
style: utils.style([computed.rootStyle({
strokeWidth: strokeWidth,
trackColor: trackColor
}), style])
}, others), {}, {
children: /*#__PURE__*/_jsx(View, {
className: "van-progress__portion",
style: computed.portionStyle({
percentage: percentage,
inactive: inactive,
color: color
}),
children: showPivot && computed.pivotText(pivotText, percentage) && /*#__PURE__*/_jsx(View, {
style: computed.pivotStyle({
textColor: textColor,
pivotColor: pivotColor,
inactive: inactive,
color: color,
right: right
}),
className: "van-progress__pivot",
children: computed.pivotText(pivotText, percentage)
})
})
}));
}
export default Progress;