feat: update cascader from 0.14.0 to 0.16.0

pull/309/head
tangjinzhou 2018-10-29 20:48:58 +08:00
parent f24d5efb2b
commit be5be9b775
3 changed files with 25 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { getComponentFromProp } from '../_util/props-util'
import PropTypes from '../_util/vue-types'
import Trigger from '../trigger'
import Menus from './Menus'
@ -65,6 +65,8 @@ export default {
// onKeyDown: PropTypes.func,
expandTrigger: PropTypes.string.def('click'),
fieldNames: PropTypes.object.def({ label: 'label', value: 'value', children: 'children' }),
expandIcon: PropTypes.any,
loadingIcon: PropTypes.any,
},
mixins: [BaseMixin],
model: {
@ -285,6 +287,8 @@ export default {
let menus = <div />
let emptyMenuClassName = ''
if (options && options.length > 0) {
const loadingIcon = getComponentFromProp(this, 'loadingIcon')
const expandIcon = getComponentFromProp(this, 'expandIcon') || '>'
const menusProps = {
props: {
...$props,
@ -292,6 +296,8 @@ export default {
defaultFieldNames: this.defaultFieldNames,
activeValue: sActiveValue,
visible: sPopupVisible,
loadingIcon,
expandIcon,
},
on: {
...$listeners,

View File

@ -1,4 +1,4 @@
import { getComponentFromProp } from '../_util/props-util'
import PropTypes from '../_util/vue-types'
import arrayTreeFilter from 'array-tree-filter'
import BaseMixin from '../_util/BaseMixin'
@ -17,6 +17,8 @@ export default {
dropdownMenuColumnStyle: PropTypes.object,
defaultFieldNames: PropTypes.object,
fieldNames: PropTypes.object,
expandIcon: PropTypes.any,
loadingIcon: PropTypes.any,
},
data () {
this.menuItems = {}
@ -44,6 +46,8 @@ export default {
},
getOption (option, menuIndex) {
const { prefixCls, expandTrigger } = this
const loadingIcon = getComponentFromProp(this, 'loadingIcon')
const expandIcon = getComponentFromProp(this, 'expandIcon')
const onSelect = (e) => {
this.__emit('select', option, menuIndex, e)
}
@ -57,10 +61,18 @@ export default {
key: Array.isArray(key) ? key.join('__ant__') : key,
}
let menuItemCls = `${prefixCls}-menu-item`
let expandIconNode = null
const hasChildren = option[this.getFieldName('children')] &&
option[this.getFieldName('children')].length > 0
if (hasChildren || option.isLeaf === false) {
menuItemCls += ` ${prefixCls}-menu-item-expand`
if (!option.loading) {
expandIconNode = (
<span class={`${prefixCls}-menu-item-expand-icon`}>
{expandIcon}
</span>
)
}
}
if (expandTrigger === 'hover' && hasChildren) {
expandProps.on = {
@ -76,8 +88,10 @@ export default {
if (option.disabled) {
menuItemCls += ` ${prefixCls}-menu-item-disabled`
}
let loadingIconNode = null
if (option.loading) {
menuItemCls += ` ${prefixCls}-menu-item-loading`
loadingIconNode = loadingIcon || null
}
let title = ''
if (option.title) {
@ -90,6 +104,8 @@ export default {
return (
<li {...expandProps}>
{option[this.getFieldName('label')]}
{expandIconNode}
{loadingIconNode}
</li>
)
},

View File

@ -1,3 +1,3 @@
// based on rc-cascader 0.14.0
// based on rc-cascader 0.16.0
import Cascader from './Cascader'
export default Cascader