ant-design-vue/components/dropdown/dropdown-button.jsx

98 lines
2.6 KiB
Vue
Raw Normal View History

2019-01-12 03:33:27 +00:00
import Button from '../button';
import buttonTypes from '../button/buttonTypes';
import { ButtonGroupProps } from '../button/button-group';
import Dropdown from './dropdown';
import PropTypes from '../_util/vue-types';
import { hasProp, getComponentFromProp } from '../_util/props-util';
import getDropdownProps from './getDropdownProps';
const ButtonTypesProps = buttonTypes();
const DropdownProps = getDropdownProps();
const ButtonGroup = Button.Group;
2018-01-31 02:30:09 +00:00
const DropdownButtonProps = {
...ButtonGroupProps,
...DropdownProps,
type: PropTypes.oneOf(['primary', 'ghost', 'dashed', 'danger', 'default']).def('default'),
size: PropTypes.oneOf(['small', 'large', 'default']).def('default'),
2018-12-15 07:22:33 +00:00
htmlType: ButtonTypesProps.htmlType,
2018-01-31 02:30:09 +00:00
disabled: PropTypes.bool,
prefixCls: PropTypes.string.def('ant-dropdown-button'),
placement: DropdownProps.placement.def('bottomRight'),
2019-01-12 03:33:27 +00:00
};
export { DropdownButtonProps };
2018-01-29 10:57:20 +00:00
export default {
2018-04-08 13:17:20 +00:00
name: 'ADropdownButton',
2019-02-01 09:23:00 +00:00
model: {
prop: 'visible',
event: 'visibleChange',
},
2018-01-31 02:30:09 +00:00
props: DropdownButtonProps,
2019-07-04 10:12:52 +00:00
provide() {
return {
savePopupRef: this.savePopupRef,
};
},
inject: {
configProvider: { default: () => ({}) },
},
2018-01-29 10:57:20 +00:00
methods: {
2019-07-04 10:12:52 +00:00
savePopupRef(ref) {
this.popupRef = ref;
},
2019-01-12 03:33:27 +00:00
onClick(e) {
this.$emit('click', e);
2018-01-29 10:57:20 +00:00
},
2019-01-12 03:33:27 +00:00
onVisibleChange(val) {
this.$emit('visibleChange', val);
2018-01-29 10:57:20 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
2018-01-29 10:57:20 +00:00
const {
2019-01-12 03:33:27 +00:00
type,
disabled,
htmlType,
prefixCls,
trigger,
align,
visible,
placement,
getPopupContainer,
2018-01-29 10:57:20 +00:00
...restProps
2019-01-12 03:33:27 +00:00
} = this.$props;
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
2018-01-29 10:57:20 +00:00
const dropdownProps = {
props: {
align,
disabled,
trigger: disabled ? [] : trigger,
placement,
getPopupContainer: getPopupContainer || getContextPopupContainer,
2018-01-29 10:57:20 +00:00
},
on: {
visibleChange: this.onVisibleChange,
},
2019-01-12 03:33:27 +00:00
};
2018-01-29 10:57:20 +00:00
if (hasProp(this, 'visible')) {
2019-01-12 03:33:27 +00:00
dropdownProps.props.visible = visible;
2018-01-29 10:57:20 +00:00
}
const buttonGroupProps = {
props: {
...restProps,
},
class: prefixCls,
};
2018-01-29 10:57:20 +00:00
return (
<ButtonGroup {...buttonGroupProps}>
2019-01-12 03:33:27 +00:00
<Button type={type} disabled={disabled} onClick={this.onClick} htmlType={htmlType}>
2018-01-29 10:57:20 +00:00
{this.$slots.default}
</Button>
<Dropdown {...dropdownProps}>
2019-01-12 03:33:27 +00:00
<template slot="overlay">{getComponentFromProp(this, 'overlay')}</template>
<Button type={type} disabled={disabled} icon="ellipsis" />
2018-01-29 10:57:20 +00:00
</Dropdown>
</ButtonGroup>
2019-01-12 03:33:27 +00:00
);
2018-01-29 10:57:20 +00:00
},
2019-01-12 03:33:27 +00:00
};