dropdown-button.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
  3. var _excluded = ["type", "disabled", "loading", "htmlType", "class", "overlay", "trigger", "align", "visible", "onVisibleChange", "placement", "href", "title", "icon", "mouseEnterDelay", "mouseLeaveDelay", "overlayClassName", "overlayStyle", "destroyPopupOnHide", "onClick", "onUpdate:visible"];
  4. import { resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
  5. import { defineComponent } from 'vue';
  6. import Button from '../button';
  7. import classNames from '../_util/classNames';
  8. import Dropdown from './dropdown';
  9. import { initDefaultProps } from '../_util/props-util';
  10. import { dropdownButtonProps } from './props';
  11. import EllipsisOutlined from "@ant-design/icons-vue/es/icons/EllipsisOutlined";
  12. import useConfigInject from '../_util/hooks/useConfigInject';
  13. var ButtonGroup = Button.Group;
  14. export default defineComponent({
  15. compatConfig: {
  16. MODE: 3
  17. },
  18. name: 'ADropdownButton',
  19. inheritAttrs: false,
  20. __ANT_BUTTON: true,
  21. props: initDefaultProps(dropdownButtonProps(), {
  22. trigger: 'hover',
  23. placement: 'bottomRight',
  24. type: 'default'
  25. }),
  26. // emits: ['click', 'visibleChange', 'update:visible'],
  27. slots: ['icon', 'leftButton', 'rightButton', 'overlay'],
  28. setup: function setup(props, _ref) {
  29. var slots = _ref.slots,
  30. attrs = _ref.attrs,
  31. emit = _ref.emit;
  32. var handleVisibleChange = function handleVisibleChange(val) {
  33. emit('update:visible', val);
  34. emit('visibleChange', val);
  35. };
  36. var _useConfigInject = useConfigInject('dropdown-button', props),
  37. prefixCls = _useConfigInject.prefixCls,
  38. direction = _useConfigInject.direction,
  39. getPopupContainer = _useConfigInject.getPopupContainer;
  40. return function () {
  41. var _slots$overlay, _slots$icon;
  42. var _props$attrs = _objectSpread(_objectSpread({}, props), attrs),
  43. _props$attrs$type = _props$attrs.type,
  44. type = _props$attrs$type === void 0 ? 'default' : _props$attrs$type,
  45. disabled = _props$attrs.disabled,
  46. loading = _props$attrs.loading,
  47. htmlType = _props$attrs.htmlType,
  48. _props$attrs$class = _props$attrs.class,
  49. className = _props$attrs$class === void 0 ? '' : _props$attrs$class,
  50. _props$attrs$overlay = _props$attrs.overlay,
  51. _overlay = _props$attrs$overlay === void 0 ? (_slots$overlay = slots.overlay) === null || _slots$overlay === void 0 ? void 0 : _slots$overlay.call(slots) : _props$attrs$overlay,
  52. trigger = _props$attrs.trigger,
  53. align = _props$attrs.align,
  54. visible = _props$attrs.visible,
  55. _onVisibleChange = _props$attrs.onVisibleChange,
  56. _props$attrs$placemen = _props$attrs.placement,
  57. placement = _props$attrs$placemen === void 0 ? direction.value === 'rtl' ? 'bottomLeft' : 'bottomRight' : _props$attrs$placemen,
  58. href = _props$attrs.href,
  59. title = _props$attrs.title,
  60. _props$attrs$icon = _props$attrs.icon,
  61. icon = _props$attrs$icon === void 0 ? ((_slots$icon = slots.icon) === null || _slots$icon === void 0 ? void 0 : _slots$icon.call(slots)) || _createVNode(EllipsisOutlined, null, null) : _props$attrs$icon,
  62. mouseEnterDelay = _props$attrs.mouseEnterDelay,
  63. mouseLeaveDelay = _props$attrs.mouseLeaveDelay,
  64. overlayClassName = _props$attrs.overlayClassName,
  65. overlayStyle = _props$attrs.overlayStyle,
  66. destroyPopupOnHide = _props$attrs.destroyPopupOnHide,
  67. onClick = _props$attrs.onClick,
  68. _updateVisible = _props$attrs['onUpdate:visible'],
  69. restProps = _objectWithoutProperties(_props$attrs, _excluded);
  70. var dropdownProps = {
  71. align: align,
  72. disabled: disabled,
  73. trigger: disabled ? [] : trigger,
  74. placement: placement,
  75. getPopupContainer: getPopupContainer.value,
  76. onVisibleChange: handleVisibleChange,
  77. mouseEnterDelay: mouseEnterDelay,
  78. mouseLeaveDelay: mouseLeaveDelay,
  79. visible: visible,
  80. overlayClassName: overlayClassName,
  81. overlayStyle: overlayStyle,
  82. destroyPopupOnHide: destroyPopupOnHide
  83. };
  84. var leftButton = _createVNode(Button, {
  85. "type": type,
  86. "disabled": disabled,
  87. "loading": loading,
  88. "onClick": onClick,
  89. "htmlType": htmlType,
  90. "href": href,
  91. "title": title
  92. }, {
  93. default: slots.default
  94. });
  95. var rightButton = _createVNode(Button, {
  96. "type": type,
  97. "icon": icon
  98. }, null);
  99. return _createVNode(ButtonGroup, _objectSpread(_objectSpread({}, restProps), {}, {
  100. "class": classNames(prefixCls.value, className)
  101. }), {
  102. default: function _default() {
  103. return [slots.leftButton ? slots.leftButton({
  104. button: leftButton
  105. }) : leftButton, _createVNode(Dropdown, dropdownProps, {
  106. default: function _default() {
  107. return [slots.rightButton ? slots.rightButton({
  108. button: rightButton
  109. }) : rightButton];
  110. },
  111. overlay: function overlay() {
  112. return _overlay;
  113. }
  114. })];
  115. }
  116. });
  117. };
  118. }
  119. });