|
|
@ -5,19 +5,19 @@ import useEvent from 'rc-util/lib/hooks/useEvent'; |
|
|
|
import useMergedState from 'rc-util/lib/hooks/useMergedState'; |
|
|
|
import omit from 'rc-util/lib/omit'; |
|
|
|
import * as React from 'react'; |
|
|
|
import genPurePanel from '../_util/PurePanel'; |
|
|
|
import type { AdjustOverflow } from '../_util/placements'; |
|
|
|
import getPlacements from '../_util/placements'; |
|
|
|
import { cloneElement } from '../_util/reactNode'; |
|
|
|
import warning from '../_util/warning'; |
|
|
|
import { ConfigContext } from '../config-provider'; |
|
|
|
import type { MenuProps } from '../menu'; |
|
|
|
import Menu from '../menu'; |
|
|
|
import { OverrideProvider } from '../menu/OverrideContext'; |
|
|
|
import { NoCompactStyle } from '../space/Compact'; |
|
|
|
import type { AdjustOverflow } from '../_util/placements'; |
|
|
|
import getPlacements from '../_util/placements'; |
|
|
|
import genPurePanel from '../_util/PurePanel'; |
|
|
|
import { cloneElement } from '../_util/reactNode'; |
|
|
|
import warning from '../_util/warning'; |
|
|
|
import theme from '../theme'; |
|
|
|
import DropdownButton from './dropdown-button'; |
|
|
|
import useStyle from './style'; |
|
|
|
import theme from '../theme'; |
|
|
|
|
|
|
|
const Placements = [ |
|
|
|
'topLeft', |
|
|
@ -92,6 +92,29 @@ type CompoundedComponent = React.FC<DropdownProps> & { |
|
|
|
}; |
|
|
|
|
|
|
|
const Dropdown: CompoundedComponent = (props) => { |
|
|
|
const { |
|
|
|
menu, |
|
|
|
arrow, |
|
|
|
prefixCls: customizePrefixCls, |
|
|
|
children, |
|
|
|
trigger, |
|
|
|
disabled, |
|
|
|
dropdownRender, |
|
|
|
getPopupContainer, |
|
|
|
overlayClassName, |
|
|
|
rootClassName, |
|
|
|
open, |
|
|
|
onOpenChange, |
|
|
|
// Deprecated
|
|
|
|
visible, |
|
|
|
onVisibleChange, |
|
|
|
mouseEnterDelay = 0.15, |
|
|
|
mouseLeaveDelay = 0.1, |
|
|
|
autoAdjustOverflow = true, |
|
|
|
placement = '', |
|
|
|
overlay, |
|
|
|
transitionName, |
|
|
|
} = props; |
|
|
|
const { |
|
|
|
getPopupContainer: getContextPopupContainer, |
|
|
|
getPrefixCls, |
|
|
@ -118,9 +141,9 @@ const Dropdown: CompoundedComponent = (props) => { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
const getTransitionName = () => { |
|
|
|
const memoTransitionName = React.useMemo<string>(() => { |
|
|
|
const rootPrefixCls = getPrefixCls(); |
|
|
|
const { placement = '', transitionName } = props; |
|
|
|
|
|
|
|
if (transitionName !== undefined) { |
|
|
|
return transitionName; |
|
|
|
} |
|
|
@ -128,10 +151,9 @@ const Dropdown: CompoundedComponent = (props) => { |
|
|
|
return `${rootPrefixCls}-slide-down`; |
|
|
|
} |
|
|
|
return `${rootPrefixCls}-slide-up`; |
|
|
|
}; |
|
|
|
}, [getPrefixCls, placement, transitionName]); |
|
|
|
|
|
|
|
const getPlacement = () => { |
|
|
|
const { placement } = props; |
|
|
|
const memoPlacement = React.useMemo<string>(() => { |
|
|
|
if (!placement) { |
|
|
|
return direction === 'rtl' ? 'bottomRight' : 'bottomLeft'; |
|
|
|
} |
|
|
@ -147,29 +169,7 @@ const Dropdown: CompoundedComponent = (props) => { |
|
|
|
} |
|
|
|
|
|
|
|
return placement; |
|
|
|
}; |
|
|
|
|
|
|
|
const { |
|
|
|
menu, |
|
|
|
arrow, |
|
|
|
prefixCls: customizePrefixCls, |
|
|
|
children, |
|
|
|
trigger, |
|
|
|
disabled, |
|
|
|
dropdownRender, |
|
|
|
getPopupContainer, |
|
|
|
overlayClassName, |
|
|
|
rootClassName, |
|
|
|
open, |
|
|
|
onOpenChange, |
|
|
|
|
|
|
|
// Deprecated
|
|
|
|
visible, |
|
|
|
onVisibleChange, |
|
|
|
mouseEnterDelay = 0.15, |
|
|
|
mouseLeaveDelay = 0.1, |
|
|
|
autoAdjustOverflow = true, |
|
|
|
} = props; |
|
|
|
}, [placement, direction]); |
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') { |
|
|
|
[ |
|
|
@ -239,7 +239,6 @@ const Dropdown: CompoundedComponent = (props) => { |
|
|
|
const renderOverlay = () => { |
|
|
|
// rc-dropdown already can process the function of overlay, but we have check logic here.
|
|
|
|
// So we need render the element to check and pass back to rc-dropdown.
|
|
|
|
const { overlay } = props; |
|
|
|
|
|
|
|
let overlayNode: React.ReactNode; |
|
|
|
if (menu?.items) { |
|
|
@ -294,10 +293,10 @@ const Dropdown: CompoundedComponent = (props) => { |
|
|
|
overlayClassName={overlayClassNameCustomized} |
|
|
|
prefixCls={prefixCls} |
|
|
|
getPopupContainer={getPopupContainer || getContextPopupContainer} |
|
|
|
transitionName={getTransitionName()} |
|
|
|
transitionName={memoTransitionName} |
|
|
|
trigger={triggerActions} |
|
|
|
overlay={renderOverlay} |
|
|
|
placement={getPlacement()} |
|
|
|
placement={memoPlacement} |
|
|
|
onVisibleChange={onInnerOpenChange} |
|
|
|
> |
|
|
|
{dropdownTrigger} |
|
|
|