2022-05-27 11:07:58 +08:00
|
|
|
import type { CSSInterpolation } from '@ant-design/cssinjs';
|
2022-07-11 15:35:58 +08:00
|
|
|
import type { AliasToken } from '../theme';
|
|
|
|
import type { TokenWithCommonCls } from '../theme/util/genComponentStyleHook';
|
2022-06-02 22:15:54 +08:00
|
|
|
import { roundedArrow } from './roundedArrow';
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
function connectArrowCls(classList: string[], showArrowCls: string = '') {
|
|
|
|
return classList.map(cls => `${showArrowCls}${cls}`).join(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function getArrowStyle<Token extends TokenWithCommonCls<AliasToken>>(
|
|
|
|
token: Token,
|
|
|
|
colorBg: string,
|
|
|
|
showArrowCls?: string,
|
2022-08-29 17:09:41 +08:00
|
|
|
arrowMargin?: number,
|
2022-05-27 11:07:58 +08:00
|
|
|
): CSSInterpolation {
|
2022-08-29 17:09:41 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
sizePopupArrow,
|
|
|
|
marginXXS,
|
|
|
|
radiusXS,
|
|
|
|
radiusOuter,
|
|
|
|
boxShadowPopoverArrow,
|
|
|
|
marginXS,
|
|
|
|
} = token;
|
2022-05-27 11:07:58 +08:00
|
|
|
|
2022-08-29 17:09:41 +08:00
|
|
|
const dropdownArrowOffset = arrowMargin ?? marginXS;
|
2022-05-27 11:07:58 +08:00
|
|
|
const dropdownArrowDistance = sizePopupArrow + marginXXS;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
// ============================ Basic ============================
|
2022-06-02 22:15:54 +08:00
|
|
|
[`${componentCls}-arrow`]: [
|
|
|
|
{
|
|
|
|
position: 'absolute',
|
|
|
|
zIndex: 1, // lift it up so the menu wouldn't cask shadow on it
|
|
|
|
display: 'block',
|
|
|
|
|
2022-08-25 19:39:26 +08:00
|
|
|
...roundedArrow(sizePopupArrow, radiusXS, radiusOuter, colorBg, boxShadowPopoverArrow),
|
2022-06-02 22:15:54 +08:00
|
|
|
|
|
|
|
'&:before': {
|
|
|
|
background: colorBg,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
// ========================== Placement ==========================
|
|
|
|
// Here handle the arrow position and rotate stuff
|
|
|
|
// >>>>> Top
|
|
|
|
[[
|
|
|
|
`&-placement-top ${componentCls}-arrow`,
|
|
|
|
`&-placement-topLeft ${componentCls}-arrow`,
|
|
|
|
`&-placement-topRight ${componentCls}-arrow`,
|
|
|
|
].join(',')]: {
|
|
|
|
bottom: 0,
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: 'translateY(100%) rotate(180deg)',
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-top ${componentCls}-arrow`]: {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: 'translateX(-50%) translateY(100%) rotate(180deg)',
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-topLeft ${componentCls}-arrow`]: {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-topRight ${componentCls}-arrow`]: {
|
|
|
|
right: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// >>>>> Bottom
|
|
|
|
[[
|
|
|
|
`&-placement-bottom ${componentCls}-arrow`,
|
|
|
|
`&-placement-bottomLeft ${componentCls}-arrow`,
|
|
|
|
`&-placement-bottomRight ${componentCls}-arrow`,
|
|
|
|
].join(',')]: {
|
|
|
|
top: 0,
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: `translateY(-100%)`,
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-bottom ${componentCls}-arrow`]: {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: `translateX(-50%) translateY(-100%)`,
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-bottomLeft ${componentCls}-arrow`]: {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-bottomRight ${componentCls}-arrow`]: {
|
|
|
|
right: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// >>>>> Left
|
|
|
|
[[
|
|
|
|
`&-placement-left ${componentCls}-arrow`,
|
|
|
|
`&-placement-leftTop ${componentCls}-arrow`,
|
|
|
|
`&-placement-leftBottom ${componentCls}-arrow`,
|
|
|
|
].join(',')]: {
|
|
|
|
right: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: 0,
|
|
|
|
},
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: 'translateX(100%) rotate(90deg)',
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-left ${componentCls}-arrow`]: {
|
|
|
|
top: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: 'translateY(-50%) translateX(100%) rotate(90deg)',
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-leftTop ${componentCls}-arrow`]: {
|
|
|
|
top: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-leftBottom ${componentCls}-arrow`]: {
|
|
|
|
bottom: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
|
|
|
|
// >>>>> Right
|
|
|
|
[[
|
|
|
|
`&-placement-right ${componentCls}-arrow`,
|
|
|
|
`&-placement-rightTop ${componentCls}-arrow`,
|
|
|
|
`&-placement-rightBottom ${componentCls}-arrow`,
|
|
|
|
].join(',')]: {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: 0,
|
|
|
|
},
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: 'translateX(-100%) rotate(-90deg)',
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-right ${componentCls}-arrow`]: {
|
|
|
|
top: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
2022-08-25 19:39:26 +08:00
|
|
|
transform: 'translateY(-50%) translateX(-100%) rotate(-90deg)',
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-rightTop ${componentCls}-arrow`]: {
|
|
|
|
top: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-placement-rightBottom ${componentCls}-arrow`]: {
|
|
|
|
bottom: dropdownArrowOffset,
|
|
|
|
},
|
|
|
|
|
|
|
|
// =========================== Offset ============================
|
|
|
|
// Offset the popover to account for the dropdown arrow
|
|
|
|
// >>>>> Top
|
|
|
|
[connectArrowCls(
|
|
|
|
[`&-placement-topLeft`, `&-placement-top`, `&-placement-topRight`],
|
|
|
|
showArrowCls,
|
|
|
|
)]: {
|
|
|
|
paddingBottom: dropdownArrowDistance,
|
|
|
|
},
|
|
|
|
|
|
|
|
// >>>>> Bottom
|
|
|
|
[connectArrowCls(
|
|
|
|
[`&-placement-bottomLeft`, `&-placement-bottom`, `&-placement-bottomRight`],
|
|
|
|
showArrowCls,
|
|
|
|
)]: {
|
|
|
|
paddingTop: dropdownArrowDistance,
|
|
|
|
},
|
|
|
|
|
|
|
|
// >>>>> Left
|
|
|
|
[connectArrowCls(
|
|
|
|
[`&-placement-leftTop`, `&-placement-left`, `&-placement-leftBottom`],
|
|
|
|
showArrowCls,
|
|
|
|
)]: {
|
|
|
|
paddingRight: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: dropdownArrowDistance,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// >>>>> Right
|
|
|
|
[connectArrowCls(
|
|
|
|
[`&-placement-rightTop`, `&-placement-right`, `&-placement-rightBottom`],
|
|
|
|
showArrowCls,
|
|
|
|
)]: {
|
|
|
|
paddingLeft: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: dropdownArrowDistance,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|