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-button.jsx

82 lines
2.3 KiB

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;
7 years ago
const DropdownButtonProps = {
...ButtonGroupProps,
...DropdownProps,
type: PropTypes.oneOf(['primary', 'ghost', 'dashed', 'danger', 'default']).def('default'),
htmlType: ButtonTypesProps.htmlType,
7 years ago
disabled: PropTypes.bool,
prefixCls: PropTypes.string.def('ant-dropdown-button'),
placement: DropdownProps.placement.def('bottomRight'),
};
export { DropdownButtonProps };
7 years ago
export default {
name: 'ADropdownButton',
model: {
prop: 'visible',
event: 'visibleChange',
},
7 years ago
props: DropdownButtonProps,
7 years ago
methods: {
onClick(e) {
this.$emit('click', e);
7 years ago
},
onVisibleChange(val) {
this.$emit('visibleChange', val);
7 years ago
},
},
inject: {
configProvider: { default: () => ({}) },
},
render() {
7 years ago
const {
type,
disabled,
htmlType,
prefixCls,
trigger,
align,
visible,
placement,
getPopupContainer,
7 years ago
...restProps
} = this.$props;
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
7 years ago
const dropdownProps = {
props: {
align,
disabled,
trigger: disabled ? [] : trigger,
placement,
getPopupContainer: getPopupContainer || getContextPopupContainer,
7 years ago
},
on: {
visibleChange: this.onVisibleChange,
},
};
7 years ago
if (hasProp(this, 'visible')) {
dropdownProps.props.visible = visible;
7 years ago
}
return (
<ButtonGroup {...restProps} class={prefixCls}>
<Button type={type} disabled={disabled} onClick={this.onClick} htmlType={htmlType}>
7 years ago
{this.$slots.default}
</Button>
<Dropdown {...dropdownProps}>
<template slot="overlay">{getComponentFromProp(this, 'overlay')}</template>
<Button type={type} disabled={disabled} icon="ellipsis" />
7 years ago
</Dropdown>
</ButtonGroup>
);
7 years ago
},
};