| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- import _extends from "@babel/runtime/helpers/esm/extends";
- import { getArrowOffset } from '../../style/placementArrow';
- import { initMoveMotion, initSlideMotion, initZoomMotion, slideDownIn, slideDownOut, slideUpIn, slideUpOut } from '../../style/motion';
- import { genComponentStyleHook, mergeToken } from '../../theme/internal';
- import genButtonStyle from './button';
- import genStatusStyle from './status';
- import { genFocusStyle, resetComponent, roundedArrow } from '../../style';
- // =============================== Base ===============================
- const genBaseStyle = token => {
- const {
- componentCls,
- menuCls,
- zIndexPopup,
- dropdownArrowDistance,
- dropdownArrowOffset,
- sizePopupArrow,
- antCls,
- iconCls,
- motionDurationMid,
- dropdownPaddingVertical,
- fontSize,
- dropdownEdgeChildPadding,
- colorTextDisabled,
- fontSizeIcon,
- controlPaddingHorizontal,
- colorBgElevated,
- boxShadowPopoverArrow
- } = token;
- return [{
- [componentCls]: _extends(_extends({}, resetComponent(token)), {
- position: 'absolute',
- top: -9999,
- left: {
- _skip_check_: true,
- value: -9999
- },
- zIndex: zIndexPopup,
- display: 'block',
- // A placeholder out of dropdown visible range to avoid close when user moving
- '&::before': {
- position: 'absolute',
- insetBlock: -dropdownArrowDistance + sizePopupArrow / 2,
- // insetInlineStart: -7, // FIXME: Seems not work for hidden element
- zIndex: -9999,
- opacity: 0.0001,
- content: '""'
- },
- [`${componentCls}-wrap`]: {
- position: 'relative',
- [`${antCls}-btn > ${iconCls}-down`]: {
- fontSize: fontSizeIcon
- },
- [`${iconCls}-down::before`]: {
- transition: `transform ${motionDurationMid}`
- }
- },
- [`${componentCls}-wrap-open`]: {
- [`${iconCls}-down::before`]: {
- transform: `rotate(180deg)`
- }
- },
- [`
- &-hidden,
- &-menu-hidden,
- &-menu-submenu-hidden
- `]: {
- display: 'none'
- },
- // =============================================================
- // == Arrow ==
- // =============================================================
- // Offset the popover to account for the dropdown arrow
- [`
- &-show-arrow${componentCls}-placement-topLeft,
- &-show-arrow${componentCls}-placement-top,
- &-show-arrow${componentCls}-placement-topRight
- `]: {
- paddingBottom: dropdownArrowDistance
- },
- [`
- &-show-arrow${componentCls}-placement-bottomLeft,
- &-show-arrow${componentCls}-placement-bottom,
- &-show-arrow${componentCls}-placement-bottomRight
- `]: {
- paddingTop: dropdownArrowDistance
- },
- // Note: .popover-arrow is outer, .popover-arrow:after is inner
- [`${componentCls}-arrow`]: _extends({
- position: 'absolute',
- zIndex: 1,
- display: 'block'
- }, roundedArrow(sizePopupArrow, token.borderRadiusXS, token.borderRadiusOuter, colorBgElevated, boxShadowPopoverArrow)),
- [`
- &-placement-top > ${componentCls}-arrow,
- &-placement-topLeft > ${componentCls}-arrow,
- &-placement-topRight > ${componentCls}-arrow
- `]: {
- bottom: dropdownArrowDistance,
- transform: 'translateY(100%) rotate(180deg)'
- },
- [`&-placement-top > ${componentCls}-arrow`]: {
- left: {
- _skip_check_: true,
- value: '50%'
- },
- transform: 'translateX(-50%) translateY(100%) rotate(180deg)'
- },
- [`&-placement-topLeft > ${componentCls}-arrow`]: {
- left: {
- _skip_check_: true,
- value: dropdownArrowOffset
- }
- },
- [`&-placement-topRight > ${componentCls}-arrow`]: {
- right: {
- _skip_check_: true,
- value: dropdownArrowOffset
- }
- },
- [`
- &-placement-bottom > ${componentCls}-arrow,
- &-placement-bottomLeft > ${componentCls}-arrow,
- &-placement-bottomRight > ${componentCls}-arrow
- `]: {
- top: dropdownArrowDistance,
- transform: `translateY(-100%)`
- },
- [`&-placement-bottom > ${componentCls}-arrow`]: {
- left: {
- _skip_check_: true,
- value: '50%'
- },
- transform: `translateY(-100%) translateX(-50%)`
- },
- [`&-placement-bottomLeft > ${componentCls}-arrow`]: {
- left: {
- _skip_check_: true,
- value: dropdownArrowOffset
- }
- },
- [`&-placement-bottomRight > ${componentCls}-arrow`]: {
- right: {
- _skip_check_: true,
- value: dropdownArrowOffset
- }
- },
- // =============================================================
- // == Motion ==
- // =============================================================
- // When position is not enough for dropdown, the placement will revert.
- // We will handle this with revert motion name.
- [`&${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottomLeft,
- &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottomLeft,
- &${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottom,
- &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottom,
- &${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottomRight,
- &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottomRight`]: {
- animationName: slideUpIn
- },
- [`&${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-topLeft,
- &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-topLeft,
- &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-top,
- &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-top,
- &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-topRight,
- &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-topRight`]: {
- animationName: slideDownIn
- },
- [`&${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottomLeft,
- &${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottom,
- &${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottomRight`]: {
- animationName: slideUpOut
- },
- [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-topLeft,
- &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-top,
- &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-topRight`]: {
- animationName: slideDownOut
- }
- })
- }, {
- // =============================================================
- // == Menu ==
- // =============================================================
- [`${componentCls} ${menuCls}`]: {
- position: 'relative',
- margin: 0
- },
- [`${menuCls}-submenu-popup`]: {
- position: 'absolute',
- zIndex: zIndexPopup,
- background: 'transparent',
- boxShadow: 'none',
- transformOrigin: '0 0',
- 'ul,li': {
- listStyle: 'none'
- },
- ul: {
- marginInline: '0.3em'
- }
- },
- [`${componentCls}, ${componentCls}-menu-submenu`]: {
- [menuCls]: _extends(_extends({
- padding: dropdownEdgeChildPadding,
- listStyleType: 'none',
- backgroundColor: colorBgElevated,
- backgroundClip: 'padding-box',
- borderRadius: token.borderRadiusLG,
- outline: 'none',
- boxShadow: token.boxShadowSecondary
- }, genFocusStyle(token)), {
- [`${menuCls}-item-group-title`]: {
- padding: `${dropdownPaddingVertical}px ${controlPaddingHorizontal}px`,
- color: token.colorTextDescription,
- transition: `all ${motionDurationMid}`
- },
- // ======================= Item Content =======================
- [`${menuCls}-item`]: {
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- borderRadius: token.borderRadiusSM
- },
- [`${menuCls}-item-icon`]: {
- minWidth: fontSize,
- marginInlineEnd: token.marginXS,
- fontSize: token.fontSizeSM
- },
- [`${menuCls}-title-content`]: {
- flex: 'auto',
- '> a': {
- color: 'inherit',
- transition: `all ${motionDurationMid}`,
- '&:hover': {
- color: 'inherit'
- },
- '&::after': {
- position: 'absolute',
- inset: 0,
- content: '""'
- }
- }
- },
- // =========================== Item ===========================
- [`${menuCls}-item, ${menuCls}-submenu-title`]: _extends(_extends({
- clear: 'both',
- margin: 0,
- padding: `${dropdownPaddingVertical}px ${controlPaddingHorizontal}px`,
- color: token.colorText,
- fontWeight: 'normal',
- fontSize,
- lineHeight: token.lineHeight,
- cursor: 'pointer',
- transition: `all ${motionDurationMid}`,
- [`&:hover, &-active`]: {
- backgroundColor: token.controlItemBgHover
- }
- }, genFocusStyle(token)), {
- '&-selected': {
- color: token.colorPrimary,
- backgroundColor: token.controlItemBgActive,
- '&:hover, &-active': {
- backgroundColor: token.controlItemBgActiveHover
- }
- },
- '&-disabled': {
- color: colorTextDisabled,
- cursor: 'not-allowed',
- '&:hover': {
- color: colorTextDisabled,
- backgroundColor: colorBgElevated,
- cursor: 'not-allowed'
- },
- a: {
- pointerEvents: 'none'
- }
- },
- '&-divider': {
- height: 1,
- margin: `${token.marginXXS}px 0`,
- overflow: 'hidden',
- lineHeight: 0,
- backgroundColor: token.colorSplit
- },
- [`${componentCls}-menu-submenu-expand-icon`]: {
- position: 'absolute',
- insetInlineEnd: token.paddingXS,
- [`${componentCls}-menu-submenu-arrow-icon`]: {
- marginInlineEnd: '0 !important',
- color: token.colorTextDescription,
- fontSize: fontSizeIcon,
- fontStyle: 'normal'
- }
- }
- }),
- [`${menuCls}-item-group-list`]: {
- margin: `0 ${token.marginXS}px`,
- padding: 0,
- listStyle: 'none'
- },
- [`${menuCls}-submenu-title`]: {
- paddingInlineEnd: controlPaddingHorizontal + token.fontSizeSM
- },
- [`${menuCls}-submenu-vertical`]: {
- position: 'relative'
- },
- [`${menuCls}-submenu${menuCls}-submenu-disabled ${componentCls}-menu-submenu-title`]: {
- [`&, ${componentCls}-menu-submenu-arrow-icon`]: {
- color: colorTextDisabled,
- backgroundColor: colorBgElevated,
- cursor: 'not-allowed'
- }
- },
- // https://github.com/ant-design/ant-design/issues/19264
- [`${menuCls}-submenu-selected ${componentCls}-menu-submenu-title`]: {
- color: token.colorPrimary
- }
- })
- }
- },
- // Follow code may reuse in other components
- [initSlideMotion(token, 'slide-up'), initSlideMotion(token, 'slide-down'), initMoveMotion(token, 'move-up'), initMoveMotion(token, 'move-down'), initZoomMotion(token, 'zoom-big')]];
- };
- // ============================== Export ==============================
- export default genComponentStyleHook('Dropdown', (token, _ref) => {
- let {
- rootPrefixCls
- } = _ref;
- const {
- marginXXS,
- sizePopupArrow,
- controlHeight,
- fontSize,
- lineHeight,
- paddingXXS,
- componentCls,
- borderRadiusOuter,
- borderRadiusLG
- } = token;
- const dropdownPaddingVertical = (controlHeight - fontSize * lineHeight) / 2;
- const {
- dropdownArrowOffset
- } = getArrowOffset({
- sizePopupArrow,
- contentRadius: borderRadiusLG,
- borderRadiusOuter
- });
- const dropdownToken = mergeToken(token, {
- menuCls: `${componentCls}-menu`,
- rootPrefixCls,
- dropdownArrowDistance: sizePopupArrow / 2 + marginXXS,
- dropdownArrowOffset,
- dropdownPaddingVertical,
- dropdownEdgeChildPadding: paddingXXS
- });
- return [genBaseStyle(dropdownToken), genButtonStyle(dropdownToken), genStatusStyle(dropdownToken)];
- }, token => ({
- zIndexPopup: token.zIndexPopupBase + 50
- }));
|