UNPKG

vantui-edit

Version:

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

129 lines (107 loc) 7.18 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Steps = Steps; exports.default = void 0; exports.getStatus = getStatus; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _components = require("@tarojs/components"); var _react = require("react"); var utils = _interopRequireWildcard(require("../wxs/utils")); var _color = require("../common/color"); var _index = _interopRequireDefault(require("../icon/index")); var _jsxRuntime = require("react/jsx-runtime"); var _excluded = ["steps", "active", "direction", "activeColor", "inactiveColor", "activeIcon", "inactiveIcon", "className", "onClickStep", "iconClassPrefix"]; function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } 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) { (0, _defineProperty2.default)(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; } function getStatus(index, active) { if (index < active) { return 'finish'; } else if (index === active) { return 'process'; } return 'inactive'; } 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 ? _color.GREEN : _props$activeColor, _props$inactiveColor = props.inactiveColor, inactiveColor = _props$inactiveColor === void 0 ? _color.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 = (0, _objectWithoutProperties2.default)(props, _excluded); var _onClick = (0, _react.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__*/(0, _jsxRuntime.jsx)(_components.View, _objectSpread(_objectSpread({ className: utils.bem('steps', [direction]) + " ".concat(className || '') }, others), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, { className: "van-step__wrapper", children: steps.map(function (item, index) { return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.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__*/(0, _jsxRuntime.jsxs)(_components.View, { className: "van-step__title", style: index === active ? 'color: ' + activeColor : '', children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, { children: item.text }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, { className: "desc-class", children: item.desc })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, { className: "van-step__circle-container", children: index !== active ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, { children: item.inactiveIcon || inactiveIcon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.default, { classPrefix: iconClassPrefix, color: getStatus(index, active) === 'inactive' ? inactiveColor : activeColor, name: item.inactiveIcon || inactiveIcon || '', className: "van-step__icon" }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, { className: "van-step__circle", style: 'background-color: ' + (active !== undefined && index < active ? activeColor : inactiveColor) }) }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.default, { name: item.activeIcon || activeIcon, color: activeColor, className: "van-step__icon", classPrefix: iconClassPrefix }) }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, { children: index !== steps.length - 1 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.View, { className: "van-step__line", style: 'background-color: ' + (active !== undefined && index < active ? activeColor : inactiveColor) }) })] }, index); }) }) })); } var _default = Steps; exports.default = _default;