UNPKG

yanzhen-design-vue

Version:

118 lines (117 loc) 3.21 kB
import { ref, useAttrs, useSlots, computed, createVNode, mergeProps, withCtx, isVNode, openBlock, createElementBlock, Fragment, renderList, unref } from "vue"; import { Tabs } from "ant-design-vue"; import { isEmptyArray } from "@yanzhen-libs/utils"; import { useProxyProps } from "@yanzhen-libs/utils-vue"; import { pick, omit, isFunction } from "lodash-es"; import { tabsOptions, AntTabs } from "./tabs.mjs"; const { ns } = tabsOptions; function useTabs(props, emit) { const _ref = ref(); const attrs = useAttrs(); const slots = useSlots(); const activeKey = computed({ get() { return props.value ?? props.activeKey; }, set(value) { if (value) { emit("update:value", value); emit("update:activeKey", value); } } }); const config = computed(() => pick(props, ...Object.keys(AntTabs.props))); const proxyProps = useProxyProps(config, AntTabs.emits, { exclude: ["activeKey"], emit: (event, ...args) => { switch (event) { case "update:activeKey": case "change": emit("update:value", args[0]); break; } return emit(event, ...args); }, filter: true }); function createTabPaneVNode(item, props2 = {}) { const { minHeight, renderTabPane } = props2; const _props = omit(item, "name", "tab", "style", "class"); return createVNode( Tabs.TabPane, mergeProps( { forceRender: true, tab: item["name"] ?? item["tab"] }, _props ), { default: withCtx(() => { const renderVNodeFn = slots[_props.key] ?? renderTabPane; if (!isFunction(renderVNodeFn)) return; return createVNode( "div", mergeProps( { style: [String(minHeight).endsWith("px") ? minHeight : `${minHeight}px`], tab: item["name"] ?? item["tab"], class: ns.b("pane-slot-wrap") }, _props ), { default: withCtx(() => { const vNode = renderVNodeFn(item); if (!isVNode(vNode)) return; return vNode; }) } ); }) } ); } function createTabsDefVNode(props2) { if (isFunction(slots.default)) return slots.default(props2); if (isEmptyArray(props2 == null ? void 0 : props2.tabList)) return; openBlock(true); return createElementBlock( Fragment, { key: 0 }, renderList(props2 == null ? void 0 : props2.tabList, (item) => { return createTabPaneVNode(item, props2); }) ); } return [ { _ref, activeKey, proxyProps, TabPane: createTabPaneVNode }, (props2) => { const _props = mergeProps( { animated: false }, unref(attrs), unref(proxyProps), props2, { ref: _ref } ); return createVNode(Tabs, _props, { ...slots, default: withCtx((props3) => { return createTabsDefVNode(mergeProps(_props, props3)); }) }); } ]; } export { useTabs };