vantui-edit
Version:
一套适用于Taro3及React的vantui组件库
103 lines (97 loc) • 5.32 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["steps", "active", "direction", "activeColor", "inactiveColor", "activeIcon", "inactiveIcon", "className", "onClickStep", "iconClassPrefix"];
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 } from '@tarojs/components';
import { useCallback } from 'react';
import * as utils from '../wxs/utils';
import { GREEN, GRAY_DARK } from '../common/color';
import VanIcon from '../icon/index';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
export function getStatus(index, active) {
if (index < active) {
return 'finish';
} else if (index === active) {
return 'process';
}
return 'inactive';
}
export function Steps(props) {
var _props$steps = props.steps,
steps = _props$steps === void 0 ? [] : _props$steps,
_props$active = props.active,
active = _props$active === void 0 ? 0 : _props$active,
_props$direction = props.direction,
direction = _props$direction === void 0 ? 'horizontal' : _props$direction,
_props$activeColor = props.activeColor,
activeColor = _props$activeColor === void 0 ? GREEN : _props$activeColor,
_props$inactiveColor = props.inactiveColor,
inactiveColor = _props$inactiveColor === void 0 ? GRAY_DARK : _props$inactiveColor,
_props$activeIcon = props.activeIcon,
activeIcon = _props$activeIcon === void 0 ? 'checked' : _props$activeIcon,
inactiveIcon = props.inactiveIcon,
className = props.className,
onClickStep = props.onClickStep,
_props$iconClassPrefi = props.iconClassPrefix,
iconClassPrefix = _props$iconClassPrefi === void 0 ? 'van-icon' : _props$iconClassPrefi,
others = _objectWithoutProperties(props, _excluded);
var _onClick = useCallback(function (event) {
var index = event.currentTarget.dataset.index;
Object.defineProperty(event, 'detail', {
value: index
});
onClickStep === null || onClickStep === void 0 ? void 0 : onClickStep(event);
}, [onClickStep]);
return /*#__PURE__*/_jsx(View, _objectSpread(_objectSpread({
className: utils.bem('steps', [direction]) + " ".concat(className || '')
}, others), {}, {
children: /*#__PURE__*/_jsx(View, {
className: "van-step__wrapper",
children: steps.map(function (item, index) {
return /*#__PURE__*/_jsxs(View, {
onClick: _onClick,
"data-index": index,
className: utils.bem('step', [direction, getStatus(index, active)]) + ' van-hairline',
style: getStatus(index, active) === 'inactive' ? 'color: ' + inactiveColor : '',
children: [/*#__PURE__*/_jsxs(View, {
className: "van-step__title",
style: index === active ? 'color: ' + activeColor : '',
children: [/*#__PURE__*/_jsx(View, {
children: item.text
}), /*#__PURE__*/_jsx(View, {
className: "desc-class",
children: item.desc
})]
}), /*#__PURE__*/_jsx(View, {
className: "van-step__circle-container",
children: index !== active ? /*#__PURE__*/_jsx(_Fragment, {
children: item.inactiveIcon || inactiveIcon ? /*#__PURE__*/_jsx(VanIcon, {
classPrefix: iconClassPrefix,
color: getStatus(index, active) === 'inactive' ? inactiveColor : activeColor,
name: item.inactiveIcon || inactiveIcon || '',
className: "van-step__icon"
}) : /*#__PURE__*/_jsx(View, {
className: "van-step__circle",
style: 'background-color: ' + (active !== undefined && index < active ? activeColor : inactiveColor)
})
}) : /*#__PURE__*/_jsx(VanIcon, {
name: item.activeIcon || activeIcon,
color: activeColor,
className: "van-step__icon",
classPrefix: iconClassPrefix
})
}), /*#__PURE__*/_jsx(View, {
children: index !== steps.length - 1 && /*#__PURE__*/_jsx(View, {
className: "van-step__line",
style: 'background-color: ' + (active !== undefined && index < active ? activeColor : inactiveColor)
})
})]
}, index);
})
})
}));
}
export default Steps;