You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/dropdown/dropdown.jsx

81 lines
2.2 KiB

7 years ago
import RcDropdown from './src/index'
7 years ago
import DropdownButton from './dropdown-button'
// import warning from '../_util/warning'
import PropTypes from '../_util/vue-types'
7 years ago
import { cloneElement } from '../_util/vnode'
import { getOptionProps, getPropsData } from '../_util/props-util'
7 years ago
import getDropdownProps from './getDropdownProps'
const DropdownProps = getDropdownProps()
const Dropdown = {
name: 'ADropdown',
7 years ago
props: {
...DropdownProps,
prefixCls: PropTypes.string.def('ant-dropdown'),
mouseEnterDelay: PropTypes.number.def(0.15),
mouseLeaveDelay: PropTypes.number.def(0.1),
placement: DropdownProps.placement.def('bottomLeft'),
},
model: {
prop: 'visible',
event: 'visibleChange',
},
methods: {
getTransitionName () {
const { placement = '', transitionName } = this.$props
if (transitionName !== undefined) {
return transitionName
}
if (placement.indexOf('top') >= 0) {
return 'slide-down'
}
return 'slide-up'
},
},
render () {
const { $slots, prefixCls, trigger, disabled, $listeners } = this
const dropdownTrigger = cloneElement($slots.default, {
class: `${prefixCls}-trigger`,
disabled,
})
7 years ago
const overlay = this.overlay || $slots.overlay && $slots.overlay[0]
// menu cannot be selectable in dropdown defaultly, but multiple type can be selectable
7 years ago
const overlayProps = overlay && getPropsData(overlay)
7 years ago
let selectable = false
if (overlayProps) {
selectable = !!overlayProps.selectable || overlayProps.multiple
}
const fixedModeOverlay = overlay && cloneElement(overlay, {
7 years ago
props: {
mode: 'vertical',
selectable,
7 years ago
isRootMenu: false,
7 years ago
},
})
const dropdownProps = {
props: {
...getOptionProps(this),
transitionName: this.getTransitionName(),
trigger: disabled ? [] : trigger,
},
on: $listeners,
}
return (
<RcDropdown
{...dropdownProps}
>
{dropdownTrigger}
<template slot='overlay'>
{fixedModeOverlay}
</template>
</RcDropdown>
)
},
}
Dropdown.Button = DropdownButton
export default Dropdown
7 years ago
export { DropdownProps }
7 years ago