2023-01-19 11:21:05 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2023-12-22 03:26:11 +08:00
|
|
|
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { AliasToken } from '../theme/internal';
|
2022-07-11 15:35:58 +08:00
|
|
|
import type { TokenWithCommonCls } from '../theme/util/genComponentStyleHook';
|
2023-11-08 14:56:15 +08:00
|
|
|
import type { ArrowToken } from './roundedArrow';
|
|
|
|
import { genRoundedArrow } from './roundedArrow';
|
2022-05-27 11:07:58 +08:00
|
|
|
|
2022-09-13 17:07:16 +08:00
|
|
|
export const MAX_VERTICAL_CONTENT_RADIUS = 8;
|
|
|
|
|
2023-11-08 14:56:15 +08:00
|
|
|
export interface ArrowOffsetToken {
|
|
|
|
/** @internal */
|
|
|
|
arrowOffsetHorizontal: number;
|
|
|
|
/** @internal */
|
|
|
|
arrowOffsetVertical: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getArrowOffsetToken(options: {
|
2022-09-13 17:07:16 +08:00
|
|
|
contentRadius: number;
|
|
|
|
limitVerticalRadius?: boolean;
|
2023-11-08 14:56:15 +08:00
|
|
|
}): ArrowOffsetToken {
|
2023-02-03 14:36:46 +08:00
|
|
|
const { contentRadius, limitVerticalRadius } = options;
|
2023-11-08 14:56:15 +08:00
|
|
|
const arrowOffset = contentRadius > 12 ? contentRadius + 2 : 12;
|
|
|
|
const arrowOffsetVertical = limitVerticalRadius ? MAX_VERTICAL_CONTENT_RADIUS : arrowOffset;
|
|
|
|
return { arrowOffsetHorizontal: arrowOffset, arrowOffsetVertical };
|
2022-09-13 17:07:16 +08:00
|
|
|
}
|
|
|
|
|
2023-01-19 11:21:05 +08:00
|
|
|
function isInject(valid: boolean, code: CSSObject): CSSObject {
|
2023-12-22 03:26:11 +08:00
|
|
|
if (!valid) {
|
|
|
|
return {};
|
|
|
|
}
|
2023-01-19 11:21:05 +08:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2023-11-08 14:56:15 +08:00
|
|
|
export default function getArrowStyle<
|
|
|
|
Token extends TokenWithCommonCls<AliasToken> & ArrowOffsetToken & ArrowToken,
|
|
|
|
>(
|
2022-05-27 11:07:58 +08:00
|
|
|
token: Token,
|
2023-11-08 14:56:15 +08:00
|
|
|
colorBg: string,
|
|
|
|
options?: {
|
2023-01-19 11:21:05 +08:00
|
|
|
arrowDistance?: number;
|
|
|
|
arrowPlacement?: {
|
|
|
|
left?: boolean;
|
|
|
|
right?: boolean;
|
|
|
|
top?: boolean;
|
|
|
|
bottom?: boolean;
|
|
|
|
};
|
2022-09-13 17:07:16 +08:00
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
): CSSInterpolation {
|
2023-11-08 14:56:15 +08:00
|
|
|
const { componentCls, boxShadowPopoverArrow, arrowOffsetVertical, arrowOffsetHorizontal } = token;
|
2022-09-13 17:07:16 +08:00
|
|
|
|
2022-11-01 15:06:38 +08:00
|
|
|
const {
|
2023-01-19 11:21:05 +08:00
|
|
|
arrowDistance = 0,
|
|
|
|
arrowPlacement = {
|
|
|
|
left: true,
|
|
|
|
right: true,
|
|
|
|
top: true,
|
|
|
|
bottom: true,
|
|
|
|
},
|
2023-11-08 14:56:15 +08:00
|
|
|
} = options || {};
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
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',
|
|
|
|
|
2023-11-08 14:56:15 +08:00
|
|
|
...genRoundedArrow(token, 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
|
2023-01-19 11:21:05 +08:00
|
|
|
...isInject(!!arrowPlacement.top, {
|
|
|
|
[[
|
2023-12-24 20:05:44 +08:00
|
|
|
`&-placement-top > ${componentCls}-arrow`,
|
|
|
|
`&-placement-topLeft > ${componentCls}-arrow`,
|
|
|
|
`&-placement-topRight > ${componentCls}-arrow`,
|
2023-01-19 11:21:05 +08:00
|
|
|
].join(',')]: {
|
|
|
|
bottom: arrowDistance,
|
|
|
|
transform: 'translateY(100%) rotate(180deg)',
|
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-top > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
|
|
|
transform: 'translateX(-50%) translateY(100%) rotate(180deg)',
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-topLeft > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
2023-11-08 14:56:15 +08:00
|
|
|
value: arrowOffsetHorizontal,
|
2023-01-19 11:21:05 +08:00
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-topRight > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
right: {
|
|
|
|
_skip_check_: true,
|
2023-11-08 14:56:15 +08:00
|
|
|
value: arrowOffsetHorizontal,
|
2023-01-19 11:21:05 +08:00
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
2023-01-19 11:21:05 +08:00
|
|
|
}),
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
// >>>>> Bottom
|
2023-01-19 11:21:05 +08:00
|
|
|
...isInject(!!arrowPlacement.bottom, {
|
|
|
|
[[
|
2023-12-24 20:05:44 +08:00
|
|
|
`&-placement-bottom > ${componentCls}-arrow`,
|
|
|
|
`&-placement-bottomLeft > ${componentCls}-arrow`,
|
|
|
|
`&-placement-bottomRight > ${componentCls}-arrow`,
|
2023-01-19 11:21:05 +08:00
|
|
|
].join(',')]: {
|
|
|
|
top: arrowDistance,
|
|
|
|
transform: `translateY(-100%)`,
|
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-bottom > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
|
|
|
transform: `translateX(-50%) translateY(-100%)`,
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-bottomLeft > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
2023-11-08 14:56:15 +08:00
|
|
|
value: arrowOffsetHorizontal,
|
2023-01-19 11:21:05 +08:00
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-bottomRight > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
right: {
|
|
|
|
_skip_check_: true,
|
2023-11-08 14:56:15 +08:00
|
|
|
value: arrowOffsetHorizontal,
|
2023-01-19 11:21:05 +08:00
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
2023-01-19 11:21:05 +08:00
|
|
|
}),
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
// >>>>> Left
|
2023-01-19 11:21:05 +08:00
|
|
|
...isInject(!!arrowPlacement.left, {
|
|
|
|
[[
|
2023-12-24 20:05:44 +08:00
|
|
|
`&-placement-left > ${componentCls}-arrow`,
|
|
|
|
`&-placement-leftTop > ${componentCls}-arrow`,
|
|
|
|
`&-placement-leftBottom > ${componentCls}-arrow`,
|
2023-01-19 11:21:05 +08:00
|
|
|
].join(',')]: {
|
|
|
|
right: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: arrowDistance,
|
|
|
|
},
|
|
|
|
transform: 'translateX(100%) rotate(90deg)',
|
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-left > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
top: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
|
|
|
transform: 'translateY(-50%) translateX(100%) rotate(90deg)',
|
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-leftTop > ${componentCls}-arrow`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
top: arrowOffsetVertical,
|
2023-01-19 11:21:05 +08:00
|
|
|
},
|
2022-05-27 11:07:58 +08:00
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-leftBottom > ${componentCls}-arrow`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
bottom: arrowOffsetVertical,
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
2023-01-19 11:21:05 +08:00
|
|
|
}),
|
2022-05-27 11:07:58 +08:00
|
|
|
|
|
|
|
// >>>>> Right
|
2023-01-19 11:21:05 +08:00
|
|
|
...isInject(!!arrowPlacement.right, {
|
|
|
|
[[
|
2023-12-24 20:05:44 +08:00
|
|
|
`&-placement-right > ${componentCls}-arrow`,
|
|
|
|
`&-placement-rightTop > ${componentCls}-arrow`,
|
|
|
|
`&-placement-rightBottom > ${componentCls}-arrow`,
|
2023-01-19 11:21:05 +08:00
|
|
|
].join(',')]: {
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: arrowDistance,
|
|
|
|
},
|
|
|
|
transform: 'translateX(-100%) rotate(-90deg)',
|
|
|
|
},
|
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-right > ${componentCls}-arrow`]: {
|
2023-01-19 11:21:05 +08:00
|
|
|
top: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
|
|
|
transform: 'translateY(-50%) translateX(-100%) rotate(-90deg)',
|
|
|
|
},
|
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-rightTop > ${componentCls}-arrow`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
top: arrowOffsetVertical,
|
2023-01-19 11:21:05 +08:00
|
|
|
},
|
|
|
|
|
2023-12-24 20:05:44 +08:00
|
|
|
[`&-placement-rightBottom > ${componentCls}-arrow`]: {
|
2023-11-08 14:56:15 +08:00
|
|
|
bottom: arrowOffsetVertical,
|
2023-01-19 11:21:05 +08:00
|
|
|
},
|
|
|
|
}),
|
2022-05-27 11:07:58 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|