add menu
parent
c8d6e4b039
commit
baec906d5c
|
@ -31,10 +31,10 @@ const Menu = {
|
||||||
let openKeys = props.defaultOpenKeys
|
let openKeys = props.defaultOpenKeys
|
||||||
selectedKeys = props.selectedKeys || []
|
selectedKeys = props.selectedKeys || []
|
||||||
openKeys = props.openKeys || []
|
openKeys = props.openKeys || []
|
||||||
|
this.isRootMenu = true
|
||||||
return {
|
return {
|
||||||
selectedKeys,
|
selectedKeys,
|
||||||
openKeys,
|
openKeys,
|
||||||
isRootMenu: true,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import PropTypes from 'vue-types'
|
import PropTypes from '../../_util/vue-types'
|
||||||
import KeyCode from '../../_util/KeyCode'
|
import KeyCode from '../../_util/KeyCode'
|
||||||
|
|
||||||
const MenuItem = {
|
const MenuItem = {
|
||||||
|
@ -136,7 +136,7 @@ const MenuItem = {
|
||||||
const liProps = {
|
const liProps = {
|
||||||
attrs,
|
attrs,
|
||||||
on: {
|
on: {
|
||||||
mouseEvent,
|
...mouseEvent,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import PropTypes from 'vue-types'
|
import PropTypes from '../../_util/vue-types'
|
||||||
|
|
||||||
const MenuItemGroup = {
|
const MenuItemGroup = {
|
||||||
name: 'MenuItemGroup',
|
name: 'MenuItemGroup',
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import React from 'react'
|
<script>
|
||||||
import ReactDOM from 'react-dom'
|
import PropTypes from '../../_util/vue-types'
|
||||||
import PropTypes from 'prop-types'
|
import Trigger from '../../trigger'
|
||||||
import createReactClass from 'create-react-class'
|
import KeyCode from '../../_util/KeyCode'
|
||||||
import Trigger from 'rc-trigger'
|
|
||||||
import KeyCode from 'rc-util/lib/KeyCode'
|
|
||||||
import classNames from 'classnames'
|
|
||||||
import SubPopupMenu from './SubPopupMenu'
|
import SubPopupMenu from './SubPopupMenu'
|
||||||
import placements from './placements'
|
import placements from './placements'
|
||||||
import { noop, loopMenuItemRecusively } from './util'
|
import { noop, loopMenuItemRecusively } from './util'
|
||||||
|
@ -18,10 +15,10 @@ const popupPlacementMap = {
|
||||||
'vertical-right': 'leftTop',
|
'vertical-right': 'leftTop',
|
||||||
}
|
}
|
||||||
|
|
||||||
const SubMenu = createReactClass({
|
const SubMenu = {
|
||||||
displayName: 'SubMenu',
|
name: 'SubMenu',
|
||||||
|
|
||||||
propTypes: {
|
props: {
|
||||||
parentMenu: PropTypes.object,
|
parentMenu: PropTypes.object,
|
||||||
title: PropTypes.node,
|
title: PropTypes.node,
|
||||||
children: PropTypes.any,
|
children: PropTypes.any,
|
||||||
|
@ -78,7 +75,7 @@ const SubMenu = createReactClass({
|
||||||
if (!this.subMenuTitle || !this.menuInstance) {
|
if (!this.subMenuTitle || !this.menuInstance) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const popupMenu = ReactDOM.findDOMNode(this.menuInstance)
|
const popupMenu = this.$refs.menuInstance.$el
|
||||||
if (popupMenu.offsetWidth >= this.subMenuTitle.offsetWidth) {
|
if (popupMenu.offsetWidth >= this.subMenuTitle.offsetWidth) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -311,7 +308,7 @@ const SubMenu = createReactClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
renderChildren (children) {
|
renderChildren (children) {
|
||||||
const props = this.props
|
const props = this.$props
|
||||||
const baseProps = {
|
const baseProps = {
|
||||||
mode: props.mode === 'horizontal' ? 'vertical' : props.mode,
|
mode: props.mode === 'horizontal' ? 'vertical' : props.mode,
|
||||||
visible: this.isOpen(),
|
visible: this.isOpen(),
|
||||||
|
@ -346,17 +343,18 @@ const SubMenu = createReactClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const props = this.props
|
const props = this.$props
|
||||||
const isOpen = this.isOpen()
|
const isOpen = this.isOpen()
|
||||||
const prefixCls = this.getPrefixCls()
|
const prefixCls = this.getPrefixCls()
|
||||||
const isInlineMode = props.mode === 'inline'
|
const isInlineMode = props.mode === 'inline'
|
||||||
const className = classNames(prefixCls, `${prefixCls}-${props.mode}`, {
|
const className = {
|
||||||
[props.className]: !!props.className,
|
prefixCls: true,
|
||||||
|
[`${prefixCls}-${props.mode}`]: true,
|
||||||
[this.getOpenClassName()]: isOpen,
|
[this.getOpenClassName()]: isOpen,
|
||||||
[this.getActiveClassName()]: props.active || (isOpen && !isInlineMode),
|
[this.getActiveClassName()]: props.active || (isOpen && !isInlineMode),
|
||||||
[this.getDisabledClassName()]: props.disabled,
|
[this.getDisabledClassName()]: props.disabled,
|
||||||
[this.getSelectedClassName()]: this.isChildrenSelected(),
|
[this.getSelectedClassName()]: this.isChildrenSelected(),
|
||||||
})
|
}
|
||||||
|
|
||||||
if (!this._menuId) {
|
if (!this._menuId) {
|
||||||
if (props.eventKey) {
|
if (props.eventKey) {
|
||||||
|
@ -391,9 +389,9 @@ const SubMenu = createReactClass({
|
||||||
}
|
}
|
||||||
const title = (
|
const title = (
|
||||||
<div
|
<div
|
||||||
ref={this.saveSubMenuTitle}
|
ref='subMenuTitle'
|
||||||
style={style}
|
style={style}
|
||||||
className={`${prefixCls}-title`}
|
class={`${prefixCls}-title`}
|
||||||
{...titleMouseEvents}
|
{...titleMouseEvents}
|
||||||
{...titleClickEvents}
|
{...titleClickEvents}
|
||||||
aria-expanded={isOpen}
|
aria-expanded={isOpen}
|
||||||
|
@ -402,7 +400,7 @@ const SubMenu = createReactClass({
|
||||||
title={typeof props.title === 'string' ? props.title : undefined}
|
title={typeof props.title === 'string' ? props.title : undefined}
|
||||||
>
|
>
|
||||||
{props.title}
|
{props.title}
|
||||||
<i className={`${prefixCls}-arrow`} />
|
<i class={`${prefixCls}-arrow`} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
const children = this.renderChildren(props.children)
|
const children = this.renderChildren(props.children)
|
||||||
|
@ -412,7 +410,7 @@ const SubMenu = createReactClass({
|
||||||
const popupPlacement = popupPlacementMap[props.mode]
|
const popupPlacement = popupPlacementMap[props.mode]
|
||||||
const popupClassName = props.mode === 'inline' ? '' : props.popupClassName
|
const popupClassName = props.mode === 'inline' ? '' : props.popupClassName
|
||||||
return (
|
return (
|
||||||
<li {...mouseEvents} className={className} style={props.style}>
|
<li {...mouseEvents} class={className}>
|
||||||
{isInlineMode && title}
|
{isInlineMode && title}
|
||||||
{isInlineMode && children}
|
{isInlineMode && children}
|
||||||
{!isInlineMode && (
|
{!isInlineMode && (
|
||||||
|
@ -436,8 +434,9 @@ const SubMenu = createReactClass({
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
SubMenu.isSubMenu = 1
|
SubMenu.isSubMenu = 1
|
||||||
|
|
||||||
export default SubMenu
|
export default SubMenu
|
||||||
|
</script>
|
|
@ -1,12 +1,10 @@
|
||||||
import PropTypes from 'vue-types'
|
<script>
|
||||||
import createReactClass from 'create-react-class'
|
import PropTypes from '../../_util/vue-types'
|
||||||
import Animate from 'rc-animate'
|
|
||||||
import MenuMixin from './MenuMixin'
|
import MenuMixin from './MenuMixin'
|
||||||
|
|
||||||
const SubPopupMenu = createReactClass({
|
export default {
|
||||||
displayName: 'SubPopupMenu',
|
name: 'SubPopupMenu',
|
||||||
|
props: {
|
||||||
propTypes: {
|
|
||||||
onSelect: PropTypes.func,
|
onSelect: PropTypes.func,
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
onDeselect: PropTypes.func,
|
onDeselect: PropTypes.func,
|
||||||
|
@ -22,34 +20,34 @@ const SubPopupMenu = createReactClass({
|
||||||
mixins: [MenuMixin],
|
mixins: [MenuMixin],
|
||||||
|
|
||||||
onDeselect (selectInfo) {
|
onDeselect (selectInfo) {
|
||||||
this.props.onDeselect(selectInfo)
|
this.$emit('deselect', selectInfo)
|
||||||
},
|
},
|
||||||
|
|
||||||
onSelect (selectInfo) {
|
onSelect (selectInfo) {
|
||||||
this.props.onSelect(selectInfo)
|
this.$emit('select', selectInfo)
|
||||||
},
|
},
|
||||||
|
|
||||||
onClick (e) {
|
onClick (e) {
|
||||||
this.props.onClick(e)
|
this.$emit('click', e)
|
||||||
},
|
},
|
||||||
|
|
||||||
onOpenChange (e) {
|
onOpenChange (e) {
|
||||||
this.props.onOpenChange(e)
|
this.$emit('openChange', e)
|
||||||
},
|
},
|
||||||
|
|
||||||
onDestroy (key) {
|
onDestroy (key) {
|
||||||
this.props.onDestroy(key)
|
this.$$emit('destroy', key)
|
||||||
},
|
},
|
||||||
|
|
||||||
getOpenTransitionName () {
|
getOpenTransitionName () {
|
||||||
return this.props.openTransitionName
|
return this.$props.openTransitionName
|
||||||
},
|
},
|
||||||
|
|
||||||
renderMenuItem (c, i, subIndex) {
|
renderMenuItem (c, i, subIndex) {
|
||||||
if (!c) {
|
if (!c) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const props = this.props
|
const props = this.$props
|
||||||
const extraProps = {
|
const extraProps = {
|
||||||
openKeys: props.openKeys,
|
openKeys: props.openKeys,
|
||||||
selectedKeys: props.selectedKeys,
|
selectedKeys: props.selectedKeys,
|
||||||
|
@ -59,7 +57,7 @@ const SubPopupMenu = createReactClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const props = { ...this.props }
|
const props = { ...this.$props }
|
||||||
|
|
||||||
const haveRendered = this.haveRendered
|
const haveRendered = this.haveRendered
|
||||||
this.haveRendered = true
|
this.haveRendered = true
|
||||||
|
@ -93,6 +91,5 @@ const SubPopupMenu = createReactClass({
|
||||||
</Animate>
|
</Animate>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
</script>
|
||||||
export default SubPopupMenu
|
|
Loading…
Reference in New Issue