@gizwits/vantui
Version:
机智云组件库
76 lines • 3.78 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"];
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 { BLUE } from '../common/color';
import { getRect } from '../common/utils';
import * as computed from './wxs';
import { jsx as _jsx } from "react/jsx-runtime";
export function Progress(props) {
var _useState = useState(0),
_useState2 = _slicedToArray(_useState, 2),
right = _useState2[0],
setRight = _useState2[1];
useEffect(function () {
nextTick(function () {
Promise.all([getRect(null, '.van-progress'), getRect(null, '.van-progress__pivot')]).then(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
portion = _ref2[0],
pivot = _ref2[1];
if (portion && pivot) {
setRight(pivot.width * (props.percentage - 100) / 100);
}
});
});
}, [props.percentage]);
var _props$strokeWidth = props.strokeWidth,
strokeWidth = _props$strokeWidth === void 0 ? 4 : _props$strokeWidth,
trackColor = props.trackColor,
percentage = props.percentage,
inactive = props.inactive,
_props$color = props.color,
color = _props$color === void 0 ? BLUE : _props$color,
_props$textColor = props.textColor,
textColor = _props$textColor === void 0 ? '#ffffff' : _props$textColor,
pivotColor = props.pivotColor,
pivotText = props.pivotText,
_props$showPivot = props.showPivot,
showPivot = _props$showPivot === void 0 ? true : _props$showPivot,
style = props.style,
className = props.className,
others = _objectWithoutProperties(props, _excluded);
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;