UNPKG

@flatbiz/antd

Version:
67 lines (63 loc) 3.14 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { _ as _objectWithoutProperties, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BYm17lo8.js'; import { classNames } from '@dimjs/utils/class-names/class-names'; import { hooks } from '@wove/react/hooks'; import { isUndefined } from '@dimjs/lang/is-undefined'; import { useMemo } from 'react'; import { Tabs } from 'antd'; import { sessionStorageCache } from '@flatbiz/utils'; import { jsx } from 'react/jsx-runtime'; var _excluded = ["isSticky", "isFixed", "activeCacheKey", "cancelActiveCache", "hiddenTabHeader"]; /** * Tabs 包装组件 * ``` * 1. Tabs Header 提供 Sticky 效果,默认值:true * 2. 使用时,父级必须要有高度,可置于Flex布局中 * 3. 默认缓存激活的tab item(activeKey受控操作下缓存无效) * 当未设置activeKey,非受控操作时,组件内部会会话缓存activeKey,在刷新时,会显示上次的激活的tab item * 缓存Key:如果未设置 activeCacheKey,则使用默认的 cache key(tabs-wrapper-activeKey) * 缓存模式:会话缓存,在浏览器关闭后,会清除 * ``` */ var TabsWrapper = function TabsWrapper(props) { var _props$isSticky = props.isSticky, isSticky = _props$isSticky === void 0 ? true : _props$isSticky, _props$isFixed = props.isFixed, isFixed = _props$isFixed === void 0 ? true : _props$isFixed, activeCacheKey = props.activeCacheKey, cancelActiveCache = props.cancelActiveCache, hiddenTabHeader = props.hiddenTabHeader, otherProps = _objectWithoutProperties(props, _excluded); // 是否受控操作 var isControl = Object.prototype.hasOwnProperty.call(props, 'activeKey'); var cacheKey = activeCacheKey || 'tabs-wrapper-activeKey'; var isFixedNew = isUndefined(isFixed) ? isSticky : isFixed; var onChange = hooks.useCallbackRef(function (activeKey) { var _otherProps$onChange; if (cancelActiveCache !== true && !isControl) { sessionStorageCache.set(cacheKey, { activeKey: activeKey }); } (_otherProps$onChange = otherProps.onChange) === null || _otherProps$onChange === void 0 || _otherProps$onChange.call(otherProps, activeKey); }); var defaultActiveKey = useMemo(function () { var _sessionStorageCache$; if (cancelActiveCache === true || isControl) { return props.defaultActiveKey; } var chcheActiveKey = (_sessionStorageCache$ = sessionStorageCache.get(cacheKey)) === null || _sessionStorageCache$ === void 0 ? void 0 : _sessionStorageCache$.activeKey; return chcheActiveKey || otherProps.defaultActiveKey; }, [cacheKey, cancelActiveCache, isControl, otherProps.defaultActiveKey, props.defaultActiveKey]); var className = classNames('fba-tabs-wrapper', { 'fba-tabs-wrapper-fixed': isFixedNew, 'fba-tabs-wrapper-hidden-header': hiddenTabHeader }, otherProps.className); return /*#__PURE__*/jsx(Tabs, _objectSpread2(_objectSpread2({}, otherProps), {}, { className: className, defaultActiveKey: defaultActiveKey, onChange: onChange })); }; export { TabsWrapper as T }; //# sourceMappingURL=tabs-wrapper-CAj9ErGH.js.map