import { Dropdown, Menu, Space, Tabs } from 'ant-design-vue' import { DownOutlined } from '@ant-design/icons-vue' import './index.less' import type { VueKey, VueNode } from '../../../types' import type { ExtractPropTypes, PropType } from 'vue' import { computed, defineComponent } from 'vue' export type ListToolBarMenuItem = { key: VueKey label: VueNode disabled?: boolean } // export type ListToolBarHeaderMenuProps = { // type?: 'inline' | 'dropdown' | 'tab' // activeKey?: VueKey // items?: ListToolBarMenuItem[] // onChange?: (activeKey?: VueKey) => void // prefixCls?: string // } export const listToolBarHeaderMenuProps = () => ({ type: { type: String as PropType<'inline' | 'dropdown' | 'tab'>, default: 'inline' }, activeKey: { type: [String, Number] as PropType, default: undefined }, items: { type: Array as PropType, default: () => [] }, prefixCls: String, onChange: { type: Function as PropType<(activeKey?: VueKey) => void> }, 'onUpdate:activeKey': { type: Function as PropType<(key: VueKey) => void> } }) export type ListToolBarHeaderMenuProps = Partial< ExtractPropTypes> > const HeaderMenu = defineComponent({ name: 'HeaderMenu', props: listToolBarHeaderMenuProps(), emits: ['update:activeKey'], setup(props, { emit }) { const localActiveKey = ref(props.activeKey) const setActiveKey = (key: VueKey) => { localActiveKey.value = key emit('update:activeKey', key) props.onChange?.(key) } if (props.items.length < 1) { return null } const activeItem = computed( () => props.items.find(item => { return item.key === localActiveKey.value }) || props.items[0] ) return () => { if (props.type === 'inline') { return (
{props.items.map((item, index) => (
{ setActiveKey(item.key) }} class={[ `${props.prefixCls}-inline-menu-item`, activeItem.value.key === item.key ? `${props.prefixCls}-inline-menu-item-active` : undefined ]} > {item.label}
))}
) } if (props.type === 'tab') { return ( setActiveKey(key)}> {props.items.map(({ label, key, ...rest }, index) => { return })} ) } const menuItemDomes = props.items.map((item, index) => { if ( typeof item.label === 'undefined' || typeof item.label === 'boolean' || typeof item.label === 'string' ) { return } return ( {{ title: () => item.label }} ) }) return (
{ setActiveKey(item.key) }} > {menuItemDomes} } > {activeItem.value.label}
) } } }) export default HeaderMenu