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.
250 lines
6.8 KiB
250 lines
6.8 KiB
3 years ago
|
import type { CSSInterpolation } from '@ant-design/cssinjs';
|
||
2 years ago
|
import type { AliasToken } from '../theme/internal';
|
||
2 years ago
|
import type { TokenWithCommonCls } from '../theme/util/genComponentStyleHook';
|
||
3 years ago
|
import { roundedArrow } from './roundedArrow';
|
||
3 years ago
|
|
||
|
function connectArrowCls(classList: string[], showArrowCls: string = '') {
|
||
2 years ago
|
return classList.map((cls) => `${showArrowCls}${cls}`).join(',');
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
export const MAX_VERTICAL_CONTENT_RADIUS = 8;
|
||
|
|
||
|
export function getArrowOffset(options: {
|
||
|
sizePopupArrow: number;
|
||
|
contentRadius: number;
|
||
2 years ago
|
borderRadiusOuter: number;
|
||
2 years ago
|
limitVerticalRadius?: boolean;
|
||
|
}) {
|
||
|
const maxVerticalContentRadius = MAX_VERTICAL_CONTENT_RADIUS;
|
||
2 years ago
|
const { sizePopupArrow, contentRadius, borderRadiusOuter, limitVerticalRadius } = options;
|
||
|
const arrowInnerOffset = sizePopupArrow / 2 - Math.ceil(borderRadiusOuter * (Math.sqrt(2) - 1));
|
||
2 years ago
|
const dropdownArrowOffset = (contentRadius > 12 ? contentRadius + 2 : 12) - arrowInnerOffset;
|
||
|
const dropdownArrowOffsetVertical = limitVerticalRadius
|
||
|
? maxVerticalContentRadius - arrowInnerOffset
|
||
|
: dropdownArrowOffset;
|
||
|
return { dropdownArrowOffset, dropdownArrowOffsetVertical };
|
||
|
}
|
||
|
|
||
3 years ago
|
export default function getArrowStyle<Token extends TokenWithCommonCls<AliasToken>>(
|
||
|
token: Token,
|
||
2 years ago
|
options: {
|
||
|
colorBg: string;
|
||
|
showArrowCls?: string;
|
||
|
contentRadius?: number;
|
||
|
limitVerticalRadius?: boolean;
|
||
|
},
|
||
3 years ago
|
): CSSInterpolation {
|
||
2 years ago
|
const {
|
||
|
componentCls,
|
||
|
sizePopupArrow,
|
||
|
marginXXS,
|
||
|
borderRadiusXS,
|
||
|
borderRadiusOuter,
|
||
|
boxShadowPopoverArrow,
|
||
|
} = token;
|
||
2 years ago
|
|
||
2 years ago
|
const {
|
||
|
colorBg,
|
||
|
showArrowCls,
|
||
|
contentRadius = token.borderRadiusLG,
|
||
|
limitVerticalRadius,
|
||
|
} = options;
|
||
2 years ago
|
|
||
|
const { dropdownArrowOffsetVertical, dropdownArrowOffset } = getArrowOffset({
|
||
2 years ago
|
sizePopupArrow,
|
||
2 years ago
|
contentRadius,
|
||
2 years ago
|
borderRadiusOuter,
|
||
2 years ago
|
limitVerticalRadius,
|
||
|
});
|
||
2 years ago
|
const dropdownArrowDistance = sizePopupArrow / 2 + marginXXS;
|
||
3 years ago
|
|
||
|
return {
|
||
|
[componentCls]: {
|
||
|
// ============================ Basic ============================
|
||
3 years ago
|
[`${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,
|
||
|
borderRadiusXS,
|
||
|
borderRadiusOuter,
|
||
|
colorBg,
|
||
|
boxShadowPopoverArrow,
|
||
|
),
|
||
3 years ago
|
|
||
|
'&:before': {
|
||
|
background: colorBg,
|
||
|
},
|
||
|
},
|
||
|
],
|
||
3 years ago
|
|
||
|
// ========================== 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,
|
||
2 years ago
|
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,
|
||
|
},
|
||
|
},
|
||
|
|
||
|
// >>>>> Bottom
|
||
|
[[
|
||
|
`&-placement-bottom ${componentCls}-arrow`,
|
||
|
`&-placement-bottomLeft ${componentCls}-arrow`,
|
||
|
`&-placement-bottomRight ${componentCls}-arrow`,
|
||
|
].join(',')]: {
|
||
|
top: 0,
|
||
2 years ago
|
transform: `translateY(-100%)`,
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-bottom ${componentCls}-arrow`]: {
|
||
|
left: {
|
||
|
_skip_check_: true,
|
||
|
value: '50%',
|
||
|
},
|
||
2 years ago
|
transform: `translateX(-50%) translateY(-100%)`,
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-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,
|
||
|
},
|
||
2 years ago
|
transform: 'translateX(100%) rotate(90deg)',
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-left ${componentCls}-arrow`]: {
|
||
|
top: {
|
||
|
_skip_check_: true,
|
||
|
value: '50%',
|
||
|
},
|
||
2 years ago
|
transform: 'translateY(-50%) translateX(100%) rotate(90deg)',
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-leftTop ${componentCls}-arrow`]: {
|
||
2 years ago
|
top: dropdownArrowOffsetVertical,
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-leftBottom ${componentCls}-arrow`]: {
|
||
2 years ago
|
bottom: dropdownArrowOffsetVertical,
|
||
3 years ago
|
},
|
||
|
|
||
|
// >>>>> Right
|
||
|
[[
|
||
|
`&-placement-right ${componentCls}-arrow`,
|
||
|
`&-placement-rightTop ${componentCls}-arrow`,
|
||
|
`&-placement-rightBottom ${componentCls}-arrow`,
|
||
|
].join(',')]: {
|
||
|
left: {
|
||
|
_skip_check_: true,
|
||
|
value: 0,
|
||
|
},
|
||
2 years ago
|
transform: 'translateX(-100%) rotate(-90deg)',
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-right ${componentCls}-arrow`]: {
|
||
|
top: {
|
||
|
_skip_check_: true,
|
||
|
value: '50%',
|
||
|
},
|
||
2 years ago
|
transform: 'translateY(-50%) translateX(-100%) rotate(-90deg)',
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-rightTop ${componentCls}-arrow`]: {
|
||
2 years ago
|
top: dropdownArrowOffsetVertical,
|
||
3 years ago
|
},
|
||
|
|
||
|
[`&-placement-rightBottom ${componentCls}-arrow`]: {
|
||
2 years ago
|
bottom: dropdownArrowOffsetVertical,
|
||
3 years ago
|
},
|
||
|
|
||
|
// =========================== 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,
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
};
|
||
|
}
|