Skip to content

Commit

Permalink
Merge pull request #2943 from IgniteUI/mvenkov/add-inheritdoc-to-comm…
Browse files Browse the repository at this point in the history
…ents

Add @inheritdoc
  • Loading branch information
kdinev authored Dec 6, 2018
2 parents d0c6e4a + 75f8b87 commit d152de7
Show file tree
Hide file tree
Showing 16 changed files with 194 additions and 39 deletions.
5 changes: 3 additions & 2 deletions projects/igniteui-angular/src/lib/services/overlay/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class IgxOverlayService implements OnDestroy {
*/
// tslint:disable-next-line:unified-signatures
show(component: ElementRef | Type<{}>, settings?: OverlaySettings): string;
show(compOrId: string | ElementRef | Type<{}> , settings?: OverlaySettings): string {
show(compOrId: string | ElementRef | Type<{}>, settings?: OverlaySettings): string {
let info: OverlayInfo;
let id: string;
if (typeof compOrId === 'string') {
Expand Down Expand Up @@ -155,7 +155,8 @@ export class IgxOverlayService implements OnDestroy {
// opening. Otherwise, if there is close animation player playing animation now we should not setup
// overlay this is already done
if (!info.closeAnimationPlayer || (info.closeAnimationPlayer && !info.closeAnimationPlayer.hasStarted())) {
info.initialSize = info.elementRef.nativeElement.getBoundingClientRect();
const elementRect = info.elementRef.nativeElement.getBoundingClientRect();
info.initialSize = { width: elementRect.width, height: elementRect.height };
info.hook = this.placeElementHook(info.elementRef.nativeElement);

this.moveElementToOverlay(info);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { PositionSettings } from './../utilities';
import { PositionSettings, Size } from './../utilities';

/**
* [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/overlay_position.html)
* Position strategies determine where to display the component in the provided IgxOverlayService.
*/
export interface IPositionStrategy {
/**
* PositionSettings to use when position the component in the overlay
*/
settings: PositionSettings;

/**
Expand All @@ -17,5 +20,5 @@ export interface IPositionStrategy {
* settings.positionStrategy.position(content, size, document, true);
* ```
*/
position(contentElement: HTMLElement, size?: {}, document?: Document, initialCall?: boolean): void;
position(contentElement: HTMLElement, size?: Size, document?: Document, initialCall?: boolean): void;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PositionSettings, VerticalAlignment, HorizontalAlignment, Point } from './../utilities';
import { PositionSettings, VerticalAlignment, HorizontalAlignment, Size } from './../utilities';
import { IPositionStrategy } from './IPositionStrategy';
import { ConnectedPositioningStrategy } from './connected-positioning-strategy';

Expand All @@ -9,6 +9,7 @@ enum Axis {
export class AutoPositionStrategy extends ConnectedPositioningStrategy implements IPositionStrategy {
public offsetPadding = 16;
private _initialSettings;

getViewPort(document) { // Material Design implementation
const clientRect = document.documentElement.getBoundingClientRect();
const scrollPosition = {
Expand All @@ -29,9 +30,9 @@ export class AutoPositionStrategy extends ConnectedPositioningStrategy implement

}


// The position method should return a <div> container that will host the component
position(contentElement: HTMLElement, size: { width: number, height: number }, document?: Document, initialCall?: boolean): void {
/** @inheritdoc */
position(contentElement: HTMLElement, size?: Size, document?: Document, initialCall?: boolean): void {
if (!initialCall) {
super.position(contentElement, size);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPositionStrategy } from './IPositionStrategy';
import { PositionSettings, Point, HorizontalAlignment, VerticalAlignment, getPointFromPositionsSettings } from './../utilities';
import { PositionSettings, Point, HorizontalAlignment, VerticalAlignment, getPointFromPositionsSettings, Size } from './../utilities';
import { scaleInVerTop, scaleOutVerTop } from '../../../animations/main';

export class ConnectedPositioningStrategy implements IPositionStrategy {
Expand All @@ -14,13 +14,16 @@ export class ConnectedPositioningStrategy implements IPositionStrategy {
closeAnimation: scaleOutVerTop
};

/** @inheritdoc */
public settings: PositionSettings;

constructor(settings?: PositionSettings) {
this.settings = Object.assign({}, this._defaultSettings, settings);
}

// we no longer use the element inside the position() as its dimensions are cached in rect
position(contentElement: HTMLElement, size: { width: number, height: number}, document?: Document, initialCall?: boolean): void {
/** @inheritdoc */
position(contentElement: HTMLElement, size?: Size, document?: Document, initialCall?: boolean): void {
const startPoint = getPointFromPositionsSettings(this.settings, contentElement.parentElement);

contentElement.style.top = startPoint.y + this.settings.verticalDirection * size.height + 'px';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPositionStrategy } from './IPositionStrategy';
import { PositionSettings, Point, HorizontalAlignment, VerticalAlignment } from './../utilities';
import { PositionSettings, Point, HorizontalAlignment, VerticalAlignment, Size } from './../utilities';
import { fadeIn, fadeOut } from '../../../animations/main';

export class GlobalPositionStrategy implements IPositionStrategy {
Expand All @@ -12,12 +12,15 @@ export class GlobalPositionStrategy implements IPositionStrategy {
closeAnimation: fadeOut
};

/** @inheritdoc */
public settings: PositionSettings;

constructor(settings?: PositionSettings) {
this.settings = Object.assign({}, this._defaultSettings, settings);
}

position(contentElement: HTMLElement, size?: { width: number, height: number}, document?: Document, initialCall?: boolean): void {
/** @inheritdoc */
position(contentElement: HTMLElement, size?: Size, document?: Document, initialCall?: boolean): void {
switch (this.settings.horizontalDirection) {
case HorizontalAlignment.Left:
contentElement.parentElement.style.justifyContent = 'flex-start';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { IgxOverlayService } from '../overlay';
* [Documentation](https://www.infragistics.com/products/ignite-ui-angular/angular/components/overlay_scroll.html).
* Scroll strategies determines how the scrolling will be handled in the provided IgxOverlayService.
*/
export class IScrollStrategy {
constructor(scrollContainer?: HTMLElement) { }

export interface IScrollStrategy {
/**
* Initializes the strategy. Should be called once
* @param document reference to Document object.
Expand All @@ -15,21 +13,21 @@ export class IScrollStrategy {
* settings.scrollStrategy.initialize(document, overlay, id);
* ```
*/
initialize(document: Document, overlayService: IgxOverlayService, id: string) { }
initialize(document: Document, overlayService: IgxOverlayService, id: string);

/**
* Attaches the strategy
* ```typescript
* settings.scrollStrategy.attach();
* ```
*/
attach(): void { }
attach(): void;

/**
* Detaches the strategy
* ```typescript
* settings.scrollStrategy.detach();
* ```
*/
detach(): void { }
detach(): void;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class NoOpScrollStrategy implements IScrollStrategy {
constructor(scrollContainer?: HTMLElement) { }
initialize(document: Document, overlayService: IgxOverlayService, id: string) {}
export class NoOpScrollStrategy extends ScrollStrategy {
constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
}
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) { }

/** @inheritdoc */
attach(): void { }

/** @inheritdoc */
detach(): void { }
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class AbsoluteScrollStrategy implements IScrollStrategy {
export class AbsoluteScrollStrategy extends ScrollStrategy {
private _initialized = false;
private _document: Document;
private _overlayService: IgxOverlayService;
private _id: string;
private _scrollContainer: HTMLElement;

constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
this._scrollContainer = scrollContainer;
}

initialize(document: Document, overlayService: IgxOverlayService, id: string) {
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) {
if (this._initialized) {
return;
}
Expand All @@ -22,15 +24,17 @@ export class AbsoluteScrollStrategy implements IScrollStrategy {
this._initialized = true;
}

attach(): void {
/** @inheritdoc */
public attach(): void {
if (this._scrollContainer) {
this._scrollContainer.addEventListener('scroll', this.onScroll, true);
} else {
this._document.addEventListener('scroll', this.onScroll, true);
}
}

detach(): void {
/** @inheritdoc */
public detach(): void {
if (this._scrollContainer) {
this._scrollContainer.removeEventListener('scroll', this.onScroll, true);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class BlockScrollStrategy implements IScrollStrategy {
export class BlockScrollStrategy extends ScrollStrategy {
private _initialized = false;
private _document: Document;
private _initialScrollTop: number;
private _initialScrollLeft: number;
private _sourceElement: Element;

constructor(scrollContainer?: HTMLElement) { }
constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
}

initialize(document: Document, overlayService: IgxOverlayService, id: string) {
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) {
if (this._initialized) {
return;
}
Expand All @@ -19,11 +22,13 @@ export class BlockScrollStrategy implements IScrollStrategy {
this._initialized = true;
}

/** @inheritdoc */
public attach(): void {
this._document.addEventListener('scroll', this.onScroll, true);
this._document.addEventListener('wheel', this.onWheel, true);
}

/** @inheritdoc */
public detach(): void {
this._document.removeEventListener('scroll', this.onScroll, true);
this._document.removeEventListener('wheel', this.onWheel, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';
import { ScrollStrategy } from './scroll-strategy';

export class CloseScrollStrategy implements IScrollStrategy {
export class CloseScrollStrategy extends ScrollStrategy {
private _document: Document;
private _overlayService: IgxOverlayService;
private _id: string;
Expand All @@ -15,13 +15,15 @@ export class CloseScrollStrategy implements IScrollStrategy {
private _scrollContainer: HTMLElement;

constructor(scrollContainer?: HTMLElement) {
super(scrollContainer);
this._scrollContainer = scrollContainer;
this._threshold = 10;
this.cumulativeScrollTop = 0;
this.cumulativeScrollLeft = 0;
}

initialize(document: Document, overlayService: IgxOverlayService, id: string) {
/** @inheritdoc */
public initialize(document: Document, overlayService: IgxOverlayService, id: string) {
if (this._initialized) {
return;
}
Expand All @@ -31,7 +33,8 @@ export class CloseScrollStrategy implements IScrollStrategy {
this._initialized = true;
}

attach(): void {
/** @inheritdoc */
public attach(): void {
if (this._scrollContainer) {
this._scrollContainer.addEventListener('scroll', this.onScroll);
this._sourceElement = this._scrollContainer;
Expand All @@ -54,7 +57,8 @@ export class CloseScrollStrategy implements IScrollStrategy {
this.initialScrollLeft = this._sourceElement.scrollLeft;
}

detach(): void {
/** @inheritdoc */
public detach(): void {
// TODO: check why event listener removes only on first call and remains on each next!!!
if (this._scrollContainer) {
this._scrollContainer.removeEventListener('scroll', this.onScroll);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

// Export scroll strategies
export * from './scroll-strategy';
export * from './IScrollStrategy';
export * from './absolute-scroll-strategy';
export * from './block-scroll-strategy';
export * from './close-scroll-strategy';
export * from './IScrollStrategy';
export * from './NoOpScrollStrategy';

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IScrollStrategy } from './IScrollStrategy';
import { IgxOverlayService } from '../overlay';

export abstract class ScrollStrategy implements IScrollStrategy {
constructor(scrollContainer?: HTMLElement) { }
/** @inheritdoc */
abstract initialize(document: Document, overlayService: IgxOverlayService, id: string);

/** @inheritdoc */
abstract attach(): void;

/** @inheritdoc */
abstract detach(): void;
}
22 changes: 21 additions & 1 deletion projects/igniteui-angular/src/lib/services/overlay/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,32 @@ export class Point {
}

export interface PositionSettings {
/** Attaching target for the component to show */
target?: Point | HTMLElement;
/** Direction in which the component should show */
horizontalDirection?: HorizontalAlignment;
/** Direction in which the component should show */
verticalDirection?: VerticalAlignment;
/** Target's starting point */
horizontalStartPoint?: HorizontalAlignment;
/** Target's starting point */
verticalStartPoint?: VerticalAlignment;
/** Animation applied while overlay opens */
openAnimation?: AnimationReferenceMetadata;
/** Animation applied while overlay closes */
closeAnimation?: AnimationReferenceMetadata;
}

export interface OverlaySettings {
/** Position strategy to use with this settings */
positionStrategy?: IPositionStrategy;
/** Scroll strategy to use with this settings */
scrollStrategy?: IScrollStrategy;
/** Set if the overlay should be in modal mode */
modal?: boolean;
/** Set if the overlay should closed on outside click */
closeOnOutsideClick?: boolean;
/** Set the outlet container to attach the overlay to */
outlet?: IgxOverlayOutletDirective | ElementRef;
}

Expand All @@ -60,6 +72,14 @@ export interface OverlayAnimationEventArgs {
animationType: 'open' | 'close';
}

export interface Size {
/** Gets or sets the horizontal component of Size */
width: number;

/** Gets or sets the vertical component of Size */
height: number;
}

/** @hidden */
export function getPointFromPositionsSettings(settings: PositionSettings, overlayWrapper: HTMLElement): Point {
let result: Point = new Point(0, 0);
Expand Down Expand Up @@ -90,7 +110,7 @@ export interface OverlayInfo {
elementRef?: ElementRef;
componentRef?: ComponentRef<{}>;
settings?: OverlaySettings;
initialSize?: { width?: number, height?: number, x?: number, y?: number };
initialSize?: Size;
hook?: HTMLElement;
openAnimationPlayer?: AnimationPlayer;
closeAnimationPlayer?: AnimationPlayer;
Expand Down
Loading

0 comments on commit d152de7

Please sign in to comment.