UNPKG

@antmjs/vantui

Version:

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

77 lines 4.02 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; var _excluded = ["icon", "name", "iconPrefix", "dot", "info", "renderIconActive", "renderIcon", "index", "active", "activeColor", "inactiveColor", "onChange", "children", "style", "className", "onClick"]; 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 { useState } from 'react'; import * as utils from '../wxs/utils'; import { Icon } from '../icon'; import { Info } from '../info'; 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 TabbarItem(props) { var _useState = useState(get().TabbarItem), _useState2 = _slicedToArray(_useState, 1), d = _useState2[0]; var _d$props = _objectSpread(_objectSpread({}, d), props), icon = _d$props.icon, name = _d$props.name, _d$props$iconPrefix = _d$props.iconPrefix, iconPrefix = _d$props$iconPrefix === void 0 ? 'van-icon' : _d$props$iconPrefix, dot = _d$props.dot, info = _d$props.info, renderIconActive = _d$props.renderIconActive, renderIcon = _d$props.renderIcon, index = _d$props.index, active = _d$props.active, activeColor = _d$props.activeColor, inactiveColor = _d$props.inactiveColor, onChange = _d$props.onChange, children = _d$props.children, style = _d$props.style, className = _d$props.className, onClick = _d$props.onClick, others = _objectWithoutProperties(_d$props, _excluded); var _click = function _click() { if (onChange) { var _active = name !== null && name !== void 0 ? name : index; if (_active !== active) { onChange(_active); } } onClick === null || onClick === void 0 ? void 0 : onClick(name !== null && name !== void 0 ? name : index); }; return onChange ? /*#__PURE__*/_jsxs(View, _objectSpread(_objectSpread({ className: utils.bem('tabbar-item', { active: active === (name !== null && name !== void 0 ? name : index) }) + ' custom-class' + " ".concat(className || ''), style: utils.style([{ color: active === (name !== null && name !== void 0 ? name : index) ? activeColor : inactiveColor }, style]) }, others), {}, { onClick: _click, children: [/*#__PURE__*/_jsxs(View, { className: "van-tabbar-item__icon", children: [icon ? /*#__PURE__*/_jsx(Icon, { size: 38, name: icon, classPrefix: iconPrefix, className: "van-tabbar-item__icon__inner" }) : /*#__PURE__*/_jsx(_Fragment, { children: active === (name !== null && name !== void 0 ? name : index) ? renderIconActive : renderIcon }), /*#__PURE__*/_jsx(Info, { dot: dot, info: info, className: "van-tabbar-item__info" })] }), /*#__PURE__*/_jsx(View, { className: "van-tabbar-item__text", children: children })] })) : /*#__PURE__*/_jsx(_Fragment, {}); } export default TabbarItem;