vantui-edit
Version:
一套适用于Taro3及React的vantui组件库
63 lines (55 loc) • 3.53 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["safeAreaInsetBottom", "style", "children", "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 { cloneElement, isValidElement } from 'react';
import { View } from '@tarojs/components';
import toArray from 'rc-util/lib/Children/toArray';
import * as utils from '../wxs/utils';
import { jsx as _jsx } from "react/jsx-runtime";
function parseTabList(children) {
return toArray(children).map(function (node) {
if ( /*#__PURE__*/isValidElement(node)) {
var key = node.key !== undefined ? String(node.key) : undefined;
return _objectSpread(_objectSpread({
key: key
}, node.props), {}, {
node: node
});
}
return null;
}).filter(function (tab) {
return tab;
});
}
export function GoodsAction(props) {
var _props$safeAreaInsetB = props.safeAreaInsetBottom,
safeAreaInsetBottom = _props$safeAreaInsetB === void 0 ? true : _props$safeAreaInsetB,
style = props.style,
children = props.children,
className = props.className,
others = _objectWithoutProperties(props, _excluded);
var tabs = parseTabList(children);
var newChildren = tabs.map(function (tab, index) {
var _tab$node, _tab$node$type, _tabs, _tabs$node, _tabs$node$type, _tabs2, _tabs2$node, _tabs2$node$type;
var isGAB = ((_tab$node = tab.node) === null || _tab$node === void 0 ? void 0 : (_tab$node$type = _tab$node.type) === null || _tab$node$type === void 0 ? void 0 : _tab$node$type.displayName) === 'GoodsActionButton';
var preIsGAB = ((_tabs = tabs[index - 1]) === null || _tabs === void 0 ? void 0 : (_tabs$node = _tabs.node) === null || _tabs$node === void 0 ? void 0 : (_tabs$node$type = _tabs$node.type) === null || _tabs$node$type === void 0 ? void 0 : _tabs$node$type.displayName) === 'GoodsActionButton';
var nextIsGAB = ((_tabs2 = tabs[index + 1]) === null || _tabs2 === void 0 ? void 0 : (_tabs2$node = _tabs2.node) === null || _tabs2$node === void 0 ? void 0 : (_tabs2$node$type = _tabs2$node.type) === null || _tabs2$node$type === void 0 ? void 0 : _tabs2$node$type.displayName) === 'GoodsActionButton';
return /*#__PURE__*/cloneElement(tab.node, {
key: index,
index: index,
isFirst: !preIsGAB && isGAB,
isLast: !nextIsGAB && isGAB
});
});
return /*#__PURE__*/_jsx(View, _objectSpread(_objectSpread({
className: ' ' + utils.bem('goods-action', {
safe: safeAreaInsetBottom
}) + " ".concat(className || ''),
style: style
}, others), {}, {
children: newChildren
}));
}
export default GoodsAction;