import { CloseOutlined } from '@ant-design/icons'; import { DefaultSlotView, view, ViewOption, ViewInstance, ViewContext, ViewManager, ViewRender, } from '@difizen/mana-core'; import type { View, SlotViewOption } from '@difizen/mana-core'; import { useInject } from '@difizen/mana-observable'; import { prop } from '@difizen/mana-observable'; import { Tabs, Dropdown } from '@difizen/mana-react'; import type { TabPaneProps, TabsProps } from '@difizen/mana-react'; import { inject, transient } from '@difizen/mana-syringe'; import classnames from 'classnames'; import type { ReactNode } from 'react'; import { forwardRef } from 'react'; import './index.less'; import { MenuRender } from '../../menu/menu-render'; import { ToolbarRender } from '../../toolbar/toolbar-render'; import { TabBarContextMenu } from './tab-protocol'; export const TabViewComponent = forwardRef( function TabViewComponent(_props, containerRef) { const viewInstance = useInject(ViewInstance); const views = viewInstance.children; const activeKey = viewInstance.active?.id || '__no_select__'; return (
{views.map((item) => ( {viewInstance.showTabContent ? viewInstance.renderTabContent(item) : null} ))}
); }, ); const TabSlotViewId = 'tab-view'; type TabProps = Record; export interface TabOption extends SlotViewOption { sort?: boolean; showTabContent?: boolean; tabProps: TabProps; } @transient() @view(TabSlotViewId) export class TabSlotView extends DefaultSlotView { @prop() showTabContent?: boolean | undefined = true; override view = TabViewComponent; protected override option: TabOption; constructor( @inject(ViewOption) option: TabOption, @inject(ViewManager) viewManager: ViewManager, ) { super(option, viewManager); this.option = option; this.id = `tab-${this.id}`; this.showTabContent = option.showTabContent ?? true; } onChange = (activeKey: string) => { if (activeKey !== this.active?.id) { this.showTabContent = true; this.active = this.children.find((item) => item.id === activeKey); } }; getTabProps(): TabsProps { const { tabProps = {} } = this.option; return { type: 'line', hideAdd: true, tabPosition: 'left', onChange: this.onChange, ...tabProps, }; } getTabPaneProps(item: View): TabPaneProps { if (item.title) { const props = { tab: this.renderTab(item), style: { height: '100%' }, }; return props; } return { tab: item.label, style: { height: '100%' }, }; } renderTabContent(item: View) { return ; } close(item: View) { item.dispose(); } protected renderTab(item: View) { return ( } >
{item.title.icon && ( {this.renderTitleIcon(item.title.icon)} )} {this.renderTitleLabel(item.title.label)} {item.title.closable && ( this.close(item)} className="mana-tab-close" /> )}
); } renderTabToolbar() { return ; } }