Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(menu): support multiple head menu #3296

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions src/menu/_example-composition/multi-head.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<template>
<div class="box">
<t-head-menu defaultValue="1-1-1" :defaultExpanded="expanded">
<template #logo>
<img height="28" src="https://tdesign.gtimg.com/site/baseLogo-light.png" alt="logo" />
</template>
<t-submenu value="1">
<template #title>
<span>菜单1</span>
</template>
<t-submenu value="1-1" title="子菜单1-1">
<t-menu-item value="1-1-1">子菜单1-1-1</t-menu-item>
<t-menu-item value="1-1-2">子菜单1-1-2</t-menu-item>
<t-menu-item value="1-1-3">子菜单1-1-3</t-menu-item>
</t-submenu>
<t-submenu value="1-2" title="子菜单1-2">
<t-menu-item value="1-2-1">子菜单1-2-1</t-menu-item>
<t-menu-item value="1-2-2">子菜单1-2-2</t-menu-item>
<t-menu-item value="1-2-3">子菜单1-2-3</t-menu-item>
</t-submenu>
<t-submenu value="1-3" title="子菜单1-3">
<t-menu-item value="1-3-1">子菜单1-3-1</t-menu-item>
<t-menu-item value="1-3-2">子菜单1-3-2</t-menu-item>
<t-menu-item value="1-3-3">子菜单1-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<t-submenu value="2">
<template #title>
<span>菜单2</span>
</template>
<t-submenu value="2-1" title="子菜单2-1">
<t-menu-item value="2-1-1">子菜单2-1-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-1-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-1-3</t-menu-item>
</t-submenu>
<t-submenu value="2-2" title="子菜单2-2">
<t-menu-item value="2-1-1">子菜单2-2-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-2-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-2-3</t-menu-item>
</t-submenu>
<t-submenu value="2-3" title="子菜单2-3">
<t-menu-item value="2-1-1">子菜单2-3-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-3-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<template #operations>
<t-button variant="text" shape="square">
<search-icon slot="icon" shape="square" />
</t-button>
<t-button variant="text" shape="square">
<mail-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<user-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<ellipsis-icon slot="icon" />
</t-button>
</template>
</t-head-menu>
<t-head-menu
defaultValue="1-1-1"
theme="dark"
:expanded="expanded2"
@expand="expanded2 = $event"
style="margin-top: 24px"
>
<template #logo>
<img height="28" src="https://tdesign.gtimg.com/site/baseLogo-dark.png" alt="logo" />
</template>
<t-submenu value="1">
<template #title>
<span>菜单1</span>
</template>
<t-submenu value="1-1" title="子菜单1-1">
<t-menu-item value="1-1-1">子菜单1-1-1</t-menu-item>
<t-menu-item value="1-1-2">子菜单1-1-2</t-menu-item>
<t-menu-item value="1-1-3">子菜单1-1-3</t-menu-item>
</t-submenu>
<t-submenu value="1-2" title="子菜单1-2">
<t-menu-item value="1-2-1">子菜单1-2-1</t-menu-item>
<t-menu-item value="1-2-2">子菜单1-2-2</t-menu-item>
<t-menu-item value="1-2-3">子菜单1-2-3</t-menu-item>
</t-submenu>
<t-submenu value="1-3" title="子菜单1-3">
<t-menu-item value="1-3-1">子菜单1-3-1</t-menu-item>
<t-menu-item value="1-3-2">子菜单1-3-2</t-menu-item>
<t-menu-item value="1-3-3">子菜单1-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<t-submenu value="2">
<template #title>
<span>菜单2</span>
</template>
<t-submenu value="2-1" title="子菜单2-1">
<t-menu-item value="2-1-1">子菜单2-1-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-1-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-1-3</t-menu-item>
</t-submenu>
<t-submenu value="2-2" title="子菜单2-2">
<t-menu-item value="2-1-1">子菜单2-2-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-2-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-2-3</t-menu-item>
</t-submenu>
<t-submenu value="2-3" title="子菜单2-3">
<t-menu-item value="2-1-1">子菜单2-3-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-3-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<template #operations>
<div class="t-demo-menu--dark">
<t-button variant="text" shape="square">
<search-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<mail-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<user-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<ellipsis-icon slot="icon" />
</t-button>
</div>
</template>
</t-head-menu>
</div>
</template>

<script setup>
import { ref } from 'vue';
import {
SearchIcon, MailIcon, UserIcon, EllipsisIcon,
} from 'tdesign-icons-vue';

const expanded = ref(['1']);
const expanded2 = ref(['1']);
</script>

<style lang="less" scoped>
.t-menu__operations {
.t-button {
margin-left: 8px;
}
}

.t-demo-menu--dark {
.t-button {
color: #fff;

&:hover {
background-color: #4b4b4b;
border-color: transparent;
--ripple-color: #383838;
}
}
}
</style>
170 changes: 170 additions & 0 deletions src/menu/_example/multi-head.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<template>
<div class="box">
<t-head-menu defaultValue="1-1-1" :defaultExpanded="expanded">
<template #logo>
<img height="28" src="https://tdesign.gtimg.com/site/baseLogo-light.png" alt="logo" />
</template>
<t-submenu value="1">
<template #title>
<span>菜单1</span>
</template>
<t-submenu value="1-1" title="子菜单1-1">
<t-menu-item value="1-1-1">子菜单1-1-1</t-menu-item>
<t-menu-item value="1-1-2">子菜单1-1-2</t-menu-item>
<t-menu-item value="1-1-3">子菜单1-1-3</t-menu-item>
</t-submenu>
<t-submenu value="1-2" title="子菜单1-2">
<t-menu-item value="1-2-1">子菜单1-2-1</t-menu-item>
<t-menu-item value="1-2-2">子菜单1-2-2</t-menu-item>
<t-menu-item value="1-2-3">子菜单1-2-3</t-menu-item>
</t-submenu>
<t-submenu value="1-3" title="子菜单1-3">
<t-menu-item value="1-3-1">子菜单1-3-1</t-menu-item>
<t-menu-item value="1-3-2">子菜单1-3-2</t-menu-item>
<t-menu-item value="1-3-3">子菜单1-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<t-submenu value="2">
<template #title>
<span>菜单2</span>
</template>
<t-submenu value="2-1" title="子菜单2-1">
<t-menu-item value="2-1-1">子菜单2-1-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-1-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-1-3</t-menu-item>
</t-submenu>
<t-submenu value="2-2" title="子菜单2-2">
<t-menu-item value="2-2-1">子菜单2-2-1</t-menu-item>
<t-menu-item value="2-2-2">子菜单2-2-2</t-menu-item>
<t-menu-item value="2-2-3">子菜单2-2-3</t-menu-item>
</t-submenu>
<t-submenu value="2-3" title="子菜单2-3">
<t-menu-item value="2-3-1">子菜单2-3-1</t-menu-item>
<t-menu-item value="2-3-2">子菜单2-3-2</t-menu-item>
<t-menu-item value="2-3-3">子菜单2-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<template #operations>
<t-button variant="text" shape="square">
<search-icon slot="icon" shape="square" />
</t-button>
<t-button variant="text" shape="square">
<mail-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<user-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<ellipsis-icon slot="icon" />
</t-button>
</template>
</t-head-menu>
<t-head-menu
defaultValue="1-1-1"
theme="dark"
:expanded="expanded2"
@expand="expanded2 = $event"
style="margin-top: 24px"
>
<template #logo>
<img height="28" src="https://tdesign.gtimg.com/site/baseLogo-dark.png" alt="logo" />
</template>
<t-submenu value="1">
<template #title>
<span>菜单1</span>
</template>
<t-submenu value="1-1" title="子菜单1-1">
<t-menu-item value="1-1-1">子菜单1-1-1</t-menu-item>
<t-menu-item value="1-1-2">子菜单1-1-2</t-menu-item>
<t-menu-item value="1-1-3">子菜单1-1-3</t-menu-item>
</t-submenu>
<t-submenu value="1-2" title="子菜单1-2">
<t-menu-item value="1-2-1">子菜单1-2-1</t-menu-item>
<t-menu-item value="1-2-2">子菜单1-2-2</t-menu-item>
<t-menu-item value="1-2-3">子菜单1-2-3</t-menu-item>
</t-submenu>
<t-submenu value="1-3" title="子菜单1-3">
<t-menu-item value="1-3-1">子菜单1-3-1</t-menu-item>
<t-menu-item value="1-3-2">子菜单1-3-2</t-menu-item>
<t-menu-item value="1-3-3">子菜单1-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<t-submenu value="2">
<template #title>
<span>菜单2</span>
</template>
<t-submenu value="2-1" title="子菜单2-1">
<t-menu-item value="2-1-1">子菜单2-1-1</t-menu-item>
<t-menu-item value="2-1-2">子菜单2-1-2</t-menu-item>
<t-menu-item value="2-1-3">子菜单2-1-3</t-menu-item>
</t-submenu>
<t-submenu value="2-2" title="子菜单2-2">
<t-menu-item value="2-2-1">子菜单2-2-1</t-menu-item>
<t-menu-item value="2-2-2">子菜单2-2-2</t-menu-item>
<t-menu-item value="2-2-3">子菜单2-2-3</t-menu-item>
</t-submenu>
<t-submenu value="2-3" title="子菜单2-3">
<t-menu-item value="2-3-1">子菜单2-3-1</t-menu-item>
<t-menu-item value="2-3-2">子菜单2-3-2</t-menu-item>
<t-menu-item value="2-3-3">子菜单2-3-3</t-menu-item>
</t-submenu>
</t-submenu>
<template #operations>
<div class="t-demo-menu--dark">
<t-button variant="text" shape="square">
<search-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<mail-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<user-icon slot="icon" />
</t-button>
<t-button variant="text" shape="square">
<ellipsis-icon slot="icon" />
</t-button>
</div>
</template>
</t-head-menu>
</div>
</template>

<script>
import {
SearchIcon, MailIcon, UserIcon, EllipsisIcon,
} from 'tdesign-icons-vue';

export default {
components: {
SearchIcon,
MailIcon,
UserIcon,
EllipsisIcon,
},
data() {
return {
expanded: ['1'],
expanded2: ['1'],
};
},
};
</script>
<style lang="less" scoped>
.t-menu__operations {
.t-button {
margin-left: 8px;
}
}

.t-demo-menu--dark {
.t-button {
color: #fff;

&:hover {
background-color: #4b4b4b;
border-color: transparent;
--ripple-color: #383838;
}
}
}
</style>
22 changes: 12 additions & 10 deletions src/menu/head-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TdMenuInterface, TdOpenType } from './const';
import { Tabs, TabPanel } from '../tabs';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode';
import VMenu from './v-menu';
import type { VMenuData } from './v-menu';
import { usePrefixClass } from '../hooks/useConfig';

export default defineComponent({
Expand Down Expand Up @@ -131,17 +132,18 @@ export default defineComponent({
};
},
methods: {
renderNormalSubmenu() {
if (this.submenu.length === 0) return null;
renderNormalSubmenu(node: VMenuData[], depth: number) {
if (node.length === 0) return null;

return (
<ul class={[`${this.classPrefix}-head-menu__submenu`, `${this.classPrefix}-submenu`]}>
{
<t-tabs value={this.activeValue} onChange={this.handleTabChange}>
{this.submenu.map((item) => (
<t-tab-panel value={item.value} label={item.vnode[0].text} />
))}
</t-tabs>
}
<t-tabs value={this.activeValues[depth]} onChange={this.handleTabChange}>
{node.map((item) => (
<t-tab-panel value={item.value} label={typeof item.vnode === 'string' ? item.vnode : item.vnode[0].text}>
{item.children && item.children.length > 0 ? this.renderNormalSubmenu(item.children, depth + 1) : null}
</t-tab-panel>
))}
</t-tabs>
</ul>
);
},
Expand All @@ -159,7 +161,7 @@ export default defineComponent({
<ul class={`${this.classPrefix}-menu`}>{renderContent(this, 'default', 'content')}</ul>
{operations && <div class={`${this.classPrefix}-menu__operations`}>{operations}</div>}
</div>
{this.mode === 'normal' && this.renderNormalSubmenu()}
{this.mode === 'normal' && this.renderNormalSubmenu(this.submenu, 1)}
</div>
);
},
Expand Down
7 changes: 6 additions & 1 deletion src/menu/submenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
h,
defineComponent,
computed,
inject,
Expand Down Expand Up @@ -204,7 +205,11 @@ export default defineComponent({
});

onMounted(() => {
menu?.vMenu?.add({ value: props.value, parent: submenu?.value });
menu?.vMenu?.add({
value: props.value,
parent: submenu?.value,
vnode: isFunction(props.title) ? [props.title(h)] : props.title,
});
const instance = getCurrentInstance();
let node = instance.parent;

Expand Down
Loading
Loading