mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 01:41:20 +08:00
d8faf46ada
- Make the menu-item-group exported correctly
67 lines
1.3 KiB
Vue
67 lines
1.3 KiB
Vue
<template>
|
|
<li class="el-menu-item-group">
|
|
<div
|
|
class="el-menu-item-group__title"
|
|
:style="{ paddingLeft: levelPadding + 'px' }"
|
|
>
|
|
<template v-if="!slots.title">{{ title }}</template>
|
|
<slot v-else name="title"></slot>
|
|
</div>
|
|
<ul>
|
|
<slot></slot>
|
|
</ul>
|
|
</li>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import {
|
|
defineComponent,
|
|
computed,
|
|
getCurrentInstance,
|
|
inject,
|
|
reactive,
|
|
} from 'vue'
|
|
import { IMenuGroupProps, RootMenuProvider } from './menu'
|
|
|
|
export default defineComponent({
|
|
name: 'ElMenuItemGroup',
|
|
componentName: 'ElMenuItemGroup',
|
|
|
|
props: {
|
|
title: {
|
|
type: String,
|
|
},
|
|
},
|
|
setup(props: IMenuGroupProps, { slots }) {
|
|
// data
|
|
const data = reactive({
|
|
paddingLeft: 20,
|
|
})
|
|
const instance = getCurrentInstance()
|
|
// computed
|
|
const levelPadding = computed(() => {
|
|
let padding = 20
|
|
let parent = instance.parent
|
|
if (rootProps.collapse) return 20
|
|
while (parent && parent.type.name !== 'ElMenu') {
|
|
if (parent.type.name === 'ElSubmenu') {
|
|
padding += 20
|
|
}
|
|
parent = parent.parent
|
|
}
|
|
return padding
|
|
})
|
|
|
|
// inject
|
|
const { props: rootProps } = inject<RootMenuProvider>('rootMenu')
|
|
|
|
return {
|
|
data,
|
|
levelPadding,
|
|
props,
|
|
slots,
|
|
}
|
|
},
|
|
})
|
|
</script>
|