122 lines
3.5 KiB
TypeScript
122 lines
3.5 KiB
TypeScript
import {ConnectedPosition} from '@angular/cdk/overlay';
|
|
import {isArray} from 'rxjs/internal-compatibility';
|
|
|
|
export declare type Placement = 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom';
|
|
export declare type PlacementArray = Placement | Array<Placement>;
|
|
|
|
export class ArOverlayPosition {
|
|
|
|
private static readonly _offsetYVal = 7;
|
|
|
|
public static TOP_LEFT: ConnectedPosition = {
|
|
originX: 'end',
|
|
originY: 'top',
|
|
overlayX: 'end',
|
|
overlayY: 'bottom',
|
|
offsetY: -ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static TOP_RIGHT: ConnectedPosition = {
|
|
originX: 'start',
|
|
originY: 'top',
|
|
overlayX: 'start',
|
|
overlayY: 'bottom',
|
|
offsetY: -ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static BOTTOM_LEFT: ConnectedPosition = {
|
|
originX: 'end',
|
|
originY: 'bottom',
|
|
overlayX: 'end',
|
|
overlayY: 'top',
|
|
offsetY: ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static BOTTOM_RIGHT: ConnectedPosition = {
|
|
originX: 'start',
|
|
originY: 'bottom',
|
|
overlayX: 'start',
|
|
overlayY: 'top',
|
|
offsetY: ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static LEFT_TOP: ConnectedPosition = {
|
|
originX: 'start',
|
|
originY: 'top',
|
|
overlayX: 'end',
|
|
overlayY: 'top',
|
|
offsetX: -ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static LEFT_BOTTOM: ConnectedPosition = {
|
|
originX: 'start',
|
|
originY: 'bottom',
|
|
overlayX: 'end',
|
|
overlayY: 'bottom',
|
|
offsetX: -ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static RIGHT_TOP: ConnectedPosition = {
|
|
originX: 'end',
|
|
originY: 'top',
|
|
overlayX: 'start',
|
|
overlayY: 'top',
|
|
offsetX: ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static RIGHT_BOTTOM: ConnectedPosition = {
|
|
originX: 'end',
|
|
originY: 'bottom',
|
|
overlayX: 'start',
|
|
overlayY: 'bottom',
|
|
offsetX: ArOverlayPosition._offsetYVal
|
|
};
|
|
|
|
public static getConnectedPosition(position: PlacementArray): ConnectedPosition[] {
|
|
if (isArray(position)) {
|
|
return Array.from(position).map(pos => this.getPosition(pos as Placement));
|
|
} else if (position === 'auto') {
|
|
return this.getAutoPosition();
|
|
} else {
|
|
return [this.getPosition(position as Placement)];
|
|
}
|
|
}
|
|
|
|
private static getPosition(position: Placement) {
|
|
switch (position) {
|
|
case 'top':
|
|
return ArOverlayPosition.TOP_RIGHT;
|
|
case 'bottom':
|
|
return ArOverlayPosition.BOTTOM_RIGHT;
|
|
case 'left':
|
|
return ArOverlayPosition.LEFT_TOP;
|
|
case 'right':
|
|
return ArOverlayPosition.RIGHT_TOP;
|
|
case 'top-left':
|
|
return ArOverlayPosition.TOP_LEFT;
|
|
case 'top-right':
|
|
return ArOverlayPosition.TOP_RIGHT;
|
|
case 'bottom-left':
|
|
return ArOverlayPosition.BOTTOM_LEFT;
|
|
case 'bottom-right':
|
|
return ArOverlayPosition.BOTTOM_RIGHT;
|
|
case 'left-top':
|
|
return ArOverlayPosition.LEFT_TOP;
|
|
case 'left-bottom':
|
|
return ArOverlayPosition.LEFT_BOTTOM;
|
|
case 'right-top':
|
|
return ArOverlayPosition.RIGHT_TOP;
|
|
case 'right-bottom':
|
|
return ArOverlayPosition.RIGHT_BOTTOM;
|
|
}
|
|
}
|
|
|
|
private static getAutoPosition(): ConnectedPosition[] {
|
|
return [ArOverlayPosition.TOP_LEFT, ArOverlayPosition.TOP_RIGHT,
|
|
ArOverlayPosition.BOTTOM_LEFT, ArOverlayPosition.BOTTOM_RIGHT,
|
|
ArOverlayPosition.LEFT_TOP, ArOverlayPosition.LEFT_BOTTOM,
|
|
ArOverlayPosition.RIGHT_TOP, ArOverlayPosition.RIGHT_BOTTOM
|
|
];
|
|
}
|
|
}
|