121 lines
4.2 KiB
JavaScript
121 lines
4.2 KiB
JavaScript
|
"use strict";
|
||
|
"use client";
|
||
|
|
||
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.default = void 0;
|
||
|
var React = _interopRequireWildcard(require("react"));
|
||
|
var _EllipsisOutlined = _interopRequireDefault(require("@ant-design/icons/EllipsisOutlined"));
|
||
|
var _classnames = _interopRequireDefault(require("classnames"));
|
||
|
var _button = _interopRequireDefault(require("../button"));
|
||
|
var _configProvider = require("../config-provider");
|
||
|
var _space = _interopRequireDefault(require("../space"));
|
||
|
var _Compact = require("../space/Compact");
|
||
|
var _dropdown = _interopRequireDefault(require("./dropdown"));
|
||
|
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
||
|
var t = {};
|
||
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
||
|
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
||
|
}
|
||
|
return t;
|
||
|
};
|
||
|
const DropdownButton = props => {
|
||
|
const {
|
||
|
getPopupContainer: getContextPopupContainer,
|
||
|
getPrefixCls,
|
||
|
direction
|
||
|
} = React.useContext(_configProvider.ConfigContext);
|
||
|
const {
|
||
|
prefixCls: customizePrefixCls,
|
||
|
type = 'default',
|
||
|
danger,
|
||
|
disabled,
|
||
|
loading,
|
||
|
onClick,
|
||
|
htmlType,
|
||
|
children,
|
||
|
className,
|
||
|
menu,
|
||
|
arrow,
|
||
|
autoFocus,
|
||
|
overlay,
|
||
|
trigger,
|
||
|
align,
|
||
|
open,
|
||
|
onOpenChange,
|
||
|
placement,
|
||
|
getPopupContainer,
|
||
|
href,
|
||
|
icon = /*#__PURE__*/React.createElement(_EllipsisOutlined.default, null),
|
||
|
title,
|
||
|
buttonsRender = buttons => buttons,
|
||
|
mouseEnterDelay,
|
||
|
mouseLeaveDelay,
|
||
|
overlayClassName,
|
||
|
overlayStyle,
|
||
|
destroyPopupOnHide,
|
||
|
dropdownRender
|
||
|
} = props,
|
||
|
restProps = __rest(props, ["prefixCls", "type", "danger", "disabled", "loading", "onClick", "htmlType", "children", "className", "menu", "arrow", "autoFocus", "overlay", "trigger", "align", "open", "onOpenChange", "placement", "getPopupContainer", "href", "icon", "title", "buttonsRender", "mouseEnterDelay", "mouseLeaveDelay", "overlayClassName", "overlayStyle", "destroyPopupOnHide", "dropdownRender"]);
|
||
|
const prefixCls = getPrefixCls('dropdown', customizePrefixCls);
|
||
|
const buttonPrefixCls = `${prefixCls}-button`;
|
||
|
const dropdownProps = {
|
||
|
menu,
|
||
|
arrow,
|
||
|
autoFocus,
|
||
|
align,
|
||
|
disabled,
|
||
|
trigger: disabled ? [] : trigger,
|
||
|
onOpenChange,
|
||
|
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
||
|
mouseEnterDelay,
|
||
|
mouseLeaveDelay,
|
||
|
overlayClassName,
|
||
|
overlayStyle,
|
||
|
destroyPopupOnHide,
|
||
|
dropdownRender
|
||
|
};
|
||
|
const {
|
||
|
compactSize,
|
||
|
compactItemClassnames
|
||
|
} = (0, _Compact.useCompactItemContext)(prefixCls, direction);
|
||
|
const classes = (0, _classnames.default)(buttonPrefixCls, compactItemClassnames, className);
|
||
|
if ('overlay' in props) {
|
||
|
dropdownProps.overlay = overlay;
|
||
|
}
|
||
|
if ('open' in props) {
|
||
|
dropdownProps.open = open;
|
||
|
}
|
||
|
if ('placement' in props) {
|
||
|
dropdownProps.placement = placement;
|
||
|
} else {
|
||
|
dropdownProps.placement = direction === 'rtl' ? 'bottomLeft' : 'bottomRight';
|
||
|
}
|
||
|
const leftButton = /*#__PURE__*/React.createElement(_button.default, {
|
||
|
type: type,
|
||
|
danger: danger,
|
||
|
disabled: disabled,
|
||
|
loading: loading,
|
||
|
onClick: onClick,
|
||
|
htmlType: htmlType,
|
||
|
href: href,
|
||
|
title: title
|
||
|
}, children);
|
||
|
const rightButton = /*#__PURE__*/React.createElement(_button.default, {
|
||
|
type: type,
|
||
|
danger: danger,
|
||
|
icon: icon
|
||
|
});
|
||
|
const [leftButtonToRender, rightButtonToRender] = buttonsRender([leftButton, rightButton]);
|
||
|
return /*#__PURE__*/React.createElement(_space.default.Compact, Object.assign({
|
||
|
className: classes,
|
||
|
size: compactSize,
|
||
|
block: true
|
||
|
}, restProps), leftButtonToRender, /*#__PURE__*/React.createElement(_dropdown.default, Object.assign({}, dropdownProps), rightButtonToRender));
|
||
|
};
|
||
|
DropdownButton.__ANT_BUTTON = true;
|
||
|
var _default = exports.default = DropdownButton;
|