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.
455 lines
14 KiB
455 lines
14 KiB
2 years ago
|
import { getArrowOffset } from '../../style/placementArrow';
|
||
3 years ago
|
import {
|
||
2 years ago
|
initMoveMotion,
|
||
3 years ago
|
initSlideMotion,
|
||
2 years ago
|
initZoomMotion,
|
||
3 years ago
|
slideDownIn,
|
||
|
slideDownOut,
|
||
2 years ago
|
slideUpIn,
|
||
|
slideUpOut,
|
||
3 years ago
|
} from '../../style/motion';
|
||
2 years ago
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
||
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
||
3 years ago
|
import genButtonStyle from './button';
|
||
|
import genStatusStyle from './status';
|
||
2 years ago
|
import { genFocusStyle, resetComponent, roundedArrow } from '../../style';
|
||
9 years ago
|
|
||
3 years ago
|
export interface ComponentToken {
|
||
3 years ago
|
zIndexPopup: number;
|
||
3 years ago
|
}
|
||
|
|
||
|
export interface DropdownToken extends FullToken<'Dropdown'> {
|
||
|
rootPrefixCls: string;
|
||
|
dropdownArrowDistance: number;
|
||
|
dropdownArrowOffset: number;
|
||
|
dropdownPaddingVertical: number;
|
||
2 years ago
|
dropdownEdgeChildPadding: number;
|
||
3 years ago
|
menuCls: string;
|
||
|
}
|
||
|
|
||
|
// =============================== Base ===============================
|
||
2 years ago
|
const genBaseStyle: GenerateStyle<DropdownToken> = (token) => {
|
||
3 years ago
|
const {
|
||
|
componentCls,
|
||
|
menuCls,
|
||
3 years ago
|
zIndexPopup,
|
||
3 years ago
|
dropdownArrowDistance,
|
||
|
dropdownArrowOffset,
|
||
|
sizePopupArrow,
|
||
|
antCls,
|
||
|
iconCls,
|
||
|
motionDurationMid,
|
||
|
dropdownPaddingVertical,
|
||
2 years ago
|
fontSize,
|
||
2 years ago
|
dropdownEdgeChildPadding,
|
||
3 years ago
|
colorTextDisabled,
|
||
|
fontSizeIcon,
|
||
|
controlPaddingHorizontal,
|
||
2 years ago
|
colorBgElevated,
|
||
2 years ago
|
boxShadowPopoverArrow,
|
||
3 years ago
|
} = token;
|
||
|
|
||
|
return [
|
||
|
{
|
||
|
[componentCls]: {
|
||
|
...resetComponent(token),
|
||
|
|
||
|
position: 'absolute',
|
||
|
top: -9999,
|
||
|
left: {
|
||
|
_skip_check_: true,
|
||
|
value: -9999,
|
||
|
},
|
||
3 years ago
|
zIndex: zIndexPopup,
|
||
3 years ago
|
display: 'block',
|
||
|
|
||
|
// A placeholder out of dropdown visible range to avoid close when user moving
|
||
|
'&::before': {
|
||
|
position: 'absolute',
|
||
2 years ago
|
insetBlock: -dropdownArrowDistance + sizePopupArrow / 2,
|
||
3 years ago
|
// 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&-placement-topLeft,
|
||
|
&-show-arrow&-placement-top,
|
||
|
&-show-arrow&-placement-topRight
|
||
|
`]: {
|
||
|
paddingBottom: dropdownArrowDistance,
|
||
|
},
|
||
|
|
||
|
[`
|
||
|
&-show-arrow&-placement-bottomLeft,
|
||
|
&-show-arrow&-placement-bottom,
|
||
|
&-show-arrow&-placement-bottomRight
|
||
|
`]: {
|
||
|
paddingTop: dropdownArrowDistance,
|
||
|
},
|
||
|
|
||
|
// Note: .popover-arrow is outer, .popover-arrow:after is inner
|
||
|
[`${componentCls}-arrow`]: {
|
||
|
position: 'absolute',
|
||
|
zIndex: 1, // lift it up so the menu wouldn't cask shadow on it
|
||
|
display: 'block',
|
||
|
|
||
2 years ago
|
...roundedArrow(
|
||
|
sizePopupArrow,
|
||
2 years ago
|
token.borderRadiusXS,
|
||
|
token.borderRadiusOuter,
|
||
2 years ago
|
colorBgElevated,
|
||
|
boxShadowPopoverArrow,
|
||
|
),
|
||
3 years ago
|
},
|
||
|
|
||
|
[`
|
||
|
&-placement-top > ${componentCls}-arrow,
|
||
|
&-placement-topLeft > ${componentCls}-arrow,
|
||
|
&-placement-topRight > ${componentCls}-arrow
|
||
|
`]: {
|
||
2 years ago
|
bottom: dropdownArrowDistance,
|
||
|
transform: 'translateY(100%) rotate(180deg)',
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-top > ${componentCls}-arrow`]: {
|
||
|
left: {
|
||
|
_skip_check_: true,
|
||
|
value: '50%',
|
||
|
},
|
||
2 years ago
|
transform: 'translateX(-50%) translateY(100%) rotate(180deg)',
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-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
|
||
|
`]: {
|
||
2 years ago
|
top: dropdownArrowDistance,
|
||
|
transform: `translateY(-100%)`,
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-bottom > ${componentCls}-arrow`]: {
|
||
|
left: {
|
||
|
_skip_check_: true,
|
||
|
value: '50%',
|
||
|
},
|
||
2 years ago
|
transform: `translateY(-100%) translateX(-50%)`,
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-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&-placement-bottomLeft,
|
||
|
&${antCls}-slide-down-appear${antCls}-slide-down-appear-active&-placement-bottomLeft
|
||
|
&${antCls}-slide-down-enter${antCls}-slide-down-enter-active&-placement-bottom,
|
||
|
&${antCls}-slide-down-appear${antCls}-slide-down-appear-active&-placement-bottom,
|
||
|
&${antCls}-slide-down-enter${antCls}-slide-down-enter-active&-placement-bottomRight,
|
||
|
&${antCls}-slide-down-appear${antCls}-slide-down-appear-active&-placement-bottomRight`]: {
|
||
|
animationName: slideUpIn,
|
||
|
},
|
||
|
|
||
|
[`&${antCls}-slide-up-enter${antCls}-slide-up-enter-active&-placement-topLeft,
|
||
|
&${antCls}-slide-up-appear${antCls}-slide-up-appear-active&-placement-topLeft,
|
||
|
&${antCls}-slide-up-enter${antCls}-slide-up-enter-active&-placement-top,
|
||
|
&${antCls}-slide-up-appear${antCls}-slide-up-appear-active&-placement-top,
|
||
|
&${antCls}-slide-up-enter${antCls}-slide-up-enter-active&-placement-topRight,
|
||
|
&${antCls}-slide-up-appear${antCls}-slide-up-appear-active&-placement-topRight`]: {
|
||
|
animationName: slideDownIn,
|
||
|
},
|
||
|
|
||
|
[`&${antCls}-slide-down-leave${antCls}-slide-down-leave-active&-placement-bottomLeft,
|
||
|
&${antCls}-slide-down-leave${antCls}-slide-down-leave-active&-placement-bottom,
|
||
|
&${antCls}-slide-down-leave${antCls}-slide-down-leave-active&-placement-bottomRight`]: {
|
||
|
animationName: slideUpOut,
|
||
|
},
|
||
|
|
||
|
[`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active&-placement-topLeft,
|
||
|
&${antCls}-slide-up-leave${antCls}-slide-up-leave-active&-placement-top,
|
||
|
&${antCls}-slide-up-leave${antCls}-slide-up-leave-active&-placement-topRight`]: {
|
||
|
animationName: slideDownOut,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
|
||
|
{
|
||
|
// =============================================================
|
||
|
// == Menu ==
|
||
|
// =============================================================
|
||
|
[`${componentCls} ${menuCls}`]: {
|
||
|
position: 'relative',
|
||
|
margin: 0,
|
||
|
},
|
||
|
|
||
|
[`${menuCls}-submenu-popup`]: {
|
||
|
position: 'absolute',
|
||
3 years ago
|
zIndex: zIndexPopup,
|
||
3 years ago
|
background: 'transparent',
|
||
|
boxShadow: 'none',
|
||
|
transformOrigin: '0 0',
|
||
|
|
||
|
'ul,li': {
|
||
|
listStyle: 'none',
|
||
|
},
|
||
|
|
||
|
ul: {
|
||
|
marginInline: '0.3em',
|
||
|
},
|
||
|
},
|
||
|
|
||
|
[`${componentCls}, ${componentCls}-menu-submenu`]: {
|
||
|
[menuCls]: {
|
||
2 years ago
|
padding: dropdownEdgeChildPadding,
|
||
3 years ago
|
listStyleType: 'none',
|
||
2 years ago
|
backgroundColor: colorBgElevated,
|
||
3 years ago
|
backgroundClip: 'padding-box',
|
||
2 years ago
|
borderRadius: token.borderRadiusLG,
|
||
3 years ago
|
outline: 'none',
|
||
2 years ago
|
boxShadow: token.boxShadowSecondary,
|
||
2 years ago
|
...genFocusStyle(token),
|
||
3 years ago
|
|
||
|
[`${menuCls}-item-group-title`]: {
|
||
|
padding: `${dropdownPaddingVertical}px ${controlPaddingHorizontal}px`,
|
||
2 years ago
|
color: token.colorTextDescription,
|
||
2 years ago
|
transition: `all ${motionDurationMid}`,
|
||
3 years ago
|
},
|
||
|
|
||
|
// ======================= Item Content =======================
|
||
|
[`${menuCls}-item`]: {
|
||
|
position: 'relative',
|
||
|
display: 'flex',
|
||
|
alignItems: 'center',
|
||
2 years ago
|
borderRadius: token.borderRadiusSM,
|
||
3 years ago
|
},
|
||
|
|
||
|
[`${menuCls}-item-icon`]: {
|
||
2 years ago
|
minWidth: fontSize,
|
||
3 years ago
|
marginInlineEnd: token.marginXS,
|
||
|
fontSize: token.fontSizeSM,
|
||
|
},
|
||
|
|
||
|
[`${menuCls}-title-content`]: {
|
||
|
flex: 'auto',
|
||
|
|
||
|
'> a': {
|
||
|
color: 'inherit',
|
||
2 years ago
|
transition: `all ${motionDurationMid}`,
|
||
3 years ago
|
|
||
|
'&:hover': {
|
||
|
color: 'inherit',
|
||
|
},
|
||
|
|
||
|
'&::after': {
|
||
|
position: 'absolute',
|
||
|
inset: 0,
|
||
|
content: '""',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
|
||
|
// =========================== Item ===========================
|
||
|
[`${menuCls}-item, ${menuCls}-submenu-title`]: {
|
||
|
clear: 'both',
|
||
|
margin: 0,
|
||
|
padding: `${dropdownPaddingVertical}px ${controlPaddingHorizontal}px`,
|
||
|
color: token.colorText,
|
||
|
fontWeight: 'normal',
|
||
2 years ago
|
fontSize,
|
||
3 years ago
|
lineHeight: token.lineHeight,
|
||
|
cursor: 'pointer',
|
||
2 years ago
|
transition: `all ${motionDurationMid}`,
|
||
3 years ago
|
|
||
2 years ago
|
[`&:hover, &-active`]: {
|
||
|
backgroundColor: token.controlItemBgHover,
|
||
|
},
|
||
|
|
||
2 years ago
|
...genFocusStyle(token),
|
||
|
|
||
3 years ago
|
'&-selected': {
|
||
|
color: token.colorPrimary,
|
||
|
backgroundColor: token.controlItemBgActive,
|
||
2 years ago
|
'&:hover, &-active': {
|
||
|
backgroundColor: token.controlItemBgActiveHover,
|
||
|
},
|
||
3 years ago
|
},
|
||
|
|
||
|
'&-disabled': {
|
||
|
color: colorTextDisabled,
|
||
|
cursor: 'not-allowed',
|
||
|
|
||
|
'&:hover': {
|
||
|
color: colorTextDisabled,
|
||
2 years ago
|
backgroundColor: colorBgElevated,
|
||
3 years ago
|
cursor: 'not-allowed',
|
||
|
},
|
||
|
|
||
|
a: {
|
||
|
pointerEvents: 'none',
|
||
|
},
|
||
|
},
|
||
|
|
||
|
'&-divider': {
|
||
|
height: 1, // By design
|
||
|
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',
|
||
2 years ago
|
color: token.colorTextDescription,
|
||
3 years ago
|
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,
|
||
2 years ago
|
backgroundColor: colorBgElevated,
|
||
3 years ago
|
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
|
||
|
[
|
||
2 years ago
|
initSlideMotion(token, 'slide-up'),
|
||
|
initSlideMotion(token, 'slide-down'),
|
||
|
initMoveMotion(token, 'move-up'),
|
||
|
initMoveMotion(token, 'move-down'),
|
||
2 years ago
|
initZoomMotion(token, 'zoom-big'),
|
||
3 years ago
|
],
|
||
|
];
|
||
|
};
|
||
|
|
||
|
// ============================== Export ==============================
|
||
|
export default genComponentStyleHook(
|
||
|
'Dropdown',
|
||
|
(token, { rootPrefixCls }) => {
|
||
|
const {
|
||
|
marginXXS,
|
||
|
sizePopupArrow,
|
||
|
controlHeight,
|
||
2 years ago
|
fontSize,
|
||
3 years ago
|
lineHeight,
|
||
|
paddingXXS,
|
||
|
componentCls,
|
||
2 years ago
|
borderRadiusOuter,
|
||
|
borderRadiusLG,
|
||
3 years ago
|
} = token;
|
||
|
|
||
2 years ago
|
const dropdownPaddingVertical = (controlHeight - fontSize * lineHeight) / 2;
|
||
2 years ago
|
const { dropdownArrowOffset } = getArrowOffset({
|
||
|
sizePopupArrow,
|
||
2 years ago
|
contentRadius: borderRadiusLG,
|
||
|
borderRadiusOuter,
|
||
2 years ago
|
});
|
||
3 years ago
|
|
||
|
const dropdownToken = mergeToken<DropdownToken>(token, {
|
||
|
menuCls: `${componentCls}-menu`,
|
||
|
rootPrefixCls,
|
||
2 years ago
|
dropdownArrowDistance: sizePopupArrow / 2 + marginXXS,
|
||
2 years ago
|
dropdownArrowOffset,
|
||
3 years ago
|
dropdownPaddingVertical,
|
||
2 years ago
|
dropdownEdgeChildPadding: paddingXXS,
|
||
3 years ago
|
});
|
||
|
return [
|
||
|
genBaseStyle(dropdownToken),
|
||
|
genButtonStyle(dropdownToken),
|
||
|
genStatusStyle(dropdownToken),
|
||
|
];
|
||
|
},
|
||
2 years ago
|
(token) => ({
|
||
3 years ago
|
zIndexPopup: token.zIndexPopupBase + 50,
|
||
3 years ago
|
}),
|
||
|
);
|