forked from react-component/trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalignUtil.ts
40 lines (34 loc) · 1002 Bytes
/
alignUtil.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { AlignType, BuildInPlacements, AlignPoint } from '../interface';
function isPointsEq(a1: AlignPoint[], a2: AlignPoint[], isAlignPoint: boolean): boolean {
if (isAlignPoint) {
return a1[0] === a2[0];
}
return a1[0] === a2[0] && a1[1] === a2[1];
}
export function getAlignFromPlacement(
builtinPlacements: BuildInPlacements,
placementStr: string,
align: AlignType,
): AlignType {
const baseAlign = builtinPlacements[placementStr] || {};
return {
...baseAlign,
...align,
};
}
export function getAlignPopupClassName(
builtinPlacements: BuildInPlacements,
prefixCls: string,
align: AlignType,
isAlignPoint: boolean,
): string {
const { points } = align;
const placements = Object.keys(builtinPlacements);
for (let i = 0; i < placements.length; i += 1) {
const placement = placements[i];
if (isPointsEq(builtinPlacements[placement].points, points, isAlignPoint)) {
return `${prefixCls}-placement-${placement}`;
}
}
return '';
}