UNPKG

@antmjs/vantui

Version:

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

106 lines 5.79 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; var _excluded = ["steps", "renderStep", "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, useState } from 'react'; import * as utils from '../wxs/utils'; import { GREEN, GRAY_DARK } from '../common/color'; import VanIcon from '../icon/index'; import { get } from '../default-props'; import { jsx as _jsx } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; import { jsxs as _jsxs } 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 _useState = useState(get().Steps), _useState2 = _slicedToArray(_useState, 1), d = _useState2[0]; var _d$props = _objectSpread(_objectSpread({}, d), props), _d$props$steps = _d$props.steps, steps = _d$props$steps === void 0 ? [] : _d$props$steps, renderStep = _d$props.renderStep, _d$props$active = _d$props.active, active = _d$props$active === void 0 ? 0 : _d$props$active, _d$props$direction = _d$props.direction, direction = _d$props$direction === void 0 ? 'horizontal' : _d$props$direction, _d$props$activeColor = _d$props.activeColor, activeColor = _d$props$activeColor === void 0 ? GREEN : _d$props$activeColor, _d$props$inactiveColo = _d$props.inactiveColor, inactiveColor = _d$props$inactiveColo === void 0 ? GRAY_DARK : _d$props$inactiveColo, _d$props$activeIcon = _d$props.activeIcon, activeIcon = _d$props$activeIcon === void 0 ? 'checked' : _d$props$activeIcon, inactiveIcon = _d$props.inactiveIcon, className = _d$props.className, onClickStep = _d$props.onClickStep, _d$props$iconClassPre = _d$props.iconClassPrefix, iconClassPrefix = _d$props$iconClassPre === void 0 ? 'van-icon' : _d$props$iconClassPre, others = _objectWithoutProperties(_d$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__*/_jsx(View, { className: "van-step__title", style: index === active ? 'color: ' + activeColor : '', children: renderStep ? renderStep(item) : /*#__PURE__*/_jsxs(_Fragment, { 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;