ant-design-vue/components/menu/MenuItem.vue

48 lines
1.1 KiB
Vue
Raw Normal View History

2018-01-16 15:41:00 +08:00
<script>
import { Item, itemProps } from './src/index'
2018-01-19 18:01:43 +08:00
import { getClass, getStyle, cloneVNodes } from '../_util/vnode'
2018-01-16 15:41:00 +08:00
import Tooltip from '../tooltip'
2018-01-18 10:43:39 +08:00
function noop () {}
2018-01-16 15:41:00 +08:00
export default {
props: itemProps,
inject: {
2018-01-18 10:43:39 +08:00
getInlineCollapsed: { default: () => noop },
2018-01-16 15:41:00 +08:00
},
isMenuItem: 1,
methods: {
onKeyDown (e) {
this.$refs.menuItem.onKeyDown(e)
},
},
2018-01-17 16:12:53 +08:00
render (h) {
2018-01-17 19:15:18 +08:00
const { getInlineCollapsed, $props: props, $slots, $attrs: attrs, $listeners } = this
const inlineCollapsed = getInlineCollapsed()
2018-01-16 15:41:00 +08:00
const itemProps = {
props,
attrs,
2018-01-18 18:58:36 +08:00
on: $listeners,
2018-01-16 15:41:00 +08:00
class: getClass(this),
style: getStyle(this),
}
2018-01-17 19:15:18 +08:00
const toolTipProps = {
props: {
placement: 'right',
overlayClassName: `${props.rootPrefixCls}-inline-collapsed-tooltip`,
},
on: {},
}
2018-01-16 15:41:00 +08:00
return <Tooltip
2018-01-17 19:15:18 +08:00
{...toolTipProps}
2018-01-16 15:41:00 +08:00
>
<template slot='title'>
2018-01-19 18:01:43 +08:00
{inlineCollapsed && props.level === 1 ? cloneVNodes($slots.default, true) : ''}
2018-01-16 15:41:00 +08:00
</template>
<Item {...itemProps} ref='menuItem'>
{$slots.default}
</Item>
</Tooltip>
},
}
</script>