Skip to content

Commit 91b76ec

Browse files
authored
Merge branch 'master' into mvenkov/handle_correctly_target_as_point
2 parents bdb0086 + 71eebd7 commit 91b76ec

File tree

17 files changed

+469
-11
lines changed

17 files changed

+469
-11
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ All notable changes for each version of this project will be documented in this
7373
- `IgxOverlay`
7474
- The `PositionSettings` `target` property has been deprecated and moved to `OverlaySettings`.
7575
- An optional Point/HTML Element parameter `target` has been added to the `position()` method
76+
- Added `createAbsoluteOverlaySettings` and `createRelativeOverlaySettings` methods which create non-modal `OverlaySettings` based on predefined `PositionSettings`. The methods are exposed off the `IgxOverlayService`.
77+
- `createAbsoluteOverlaySettings` creates non-modal `OverlaySettings` with `GlobalPositionStrategy` or `ContainerPositionStrategy` if an outlet is provided. Accepts `AbsolutePosition` enumeration, which could be `Center`, `Top` and `Bottom`. Default is `Center`.
78+
```typescript
79+
const globalOverlaySettings = IgxOverlayService.createAbsoluteOverlaySettings(AbsolutePosition.Top);
80+
```
81+
- `createRelativeOverlaySettings` creates `OverlaySettings` with `AutoPositionStrategy`, `ConnectedPositioningStrategy` or `ElasticPositionStrategy`. Accepts target, strategy and position. The `target` is the attaching point or element for the component to show. The position strategy is a `RelativePositionStrategy` enumeration, which defaults to `Auto`. The position is a `RelativePosition` enumeration. Possible values are `Above`, `Below`, `Before`, `After` and `Default`. The default option is `Default`, which positions the element below the target, left aligned.
82+
```typescript
83+
const targetElement = this.button.nativeElement;
84+
const connectedOverlaySettings = IgxOverlayService.createRelativeOverlaySettings(
85+
targetElement,
86+
RelativePositionStrategy.Connected,
87+
RelativePosition.Above);
88+
```
7689
- `IgxToast`
7790
- The component now utilizes the `IgxOverlayService` to position itself in the DOM.
7891
- An additional input property `outlet` has been added to allow users to specify custom Overlay Outlets using the `IgxOverlayOutletDirective`;

package-lock.json

Lines changed: 43 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"igniteui-trial-watermark": "^1.0.3",
6262
"jszip": "^3.5.0",
6363
"lodash.merge": "^4.6.2",
64+
"uuid": "^8.3.0",
6465
"resize-observer-polyfill": "^1.5.1",
6566
"rxjs": "^6.6.3",
6667
"setimmediate": "^1.0.5",

projects/igniteui-angular/ng-package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"jszip",
1212
"resize-observer-polyfill",
1313
"igniteui-trial-watermark",
14-
"lodash.merge"
14+
"lodash.merge",
15+
"uuid"
1516
]
1617
}

projects/igniteui-angular/ng-package.prod.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"jszip",
1414
"resize-observer-polyfill",
1515
"igniteui-trial-watermark",
16-
"lodash.merge"
16+
"lodash.merge",
17+
"uuid"
1718
]
1819
}

projects/igniteui-angular/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"tslib": "^2.0.0",
7373
"resize-observer-polyfill": "^1.5.1",
7474
"igniteui-trial-watermark": "^1.0.3",
75-
"lodash.merge": "^4.6.2"
75+
"lodash.merge": "^4.6.2",
76+
"uuid": "^8.3.0"
7677
},
7778
"peerDependencies": {
7879
"@angular/common": "^10.0.0",

projects/igniteui-angular/schematics/utils/dependency-handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const DEPENDENCIES_MAP: PackageEntry[] = [
3030
{ name: '@types/hammerjs', target: PackageTarget.DEV },
3131
{ name: 'igniteui-trial-watermark', target: PackageTarget.NONE },
3232
{ name: 'lodash.merge', target: PackageTarget.NONE },
33+
{ name: 'uuid', target: PackageTarget.NONE },
3334
// peerDependencies
3435
{ name: '@angular/forms', target: PackageTarget.NONE },
3536
{ name: '@angular/common', target: PackageTarget.NONE },

projects/igniteui-angular/src/lib/services/overlay/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ this.overlay.show(component, overlaySettings);
119119
| Name | Description | Parameters |
120120
|-----------------|---------------------------------------------------------------------------------|------------|
121121
|getPointFromPositionsSettings| Calculates the point from which the overlay should start showing |settings |
122+
|createAbsoluteOverlaySettings| Creates overlay settings with global or container position strategy based on a preset position settings |position?, outlet?|
123+
|createRelativeOverlaySettings| Creates overlay settings with auto, connected or elastic position strategy based on a preset position settings |target, strategy?, position?|
122124

123125

124126
##### Events

projects/igniteui-angular/src/lib/services/overlay/overlay.ts

Lines changed: 156 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,26 @@ import {
1515
} from '@angular/core';
1616
import { fromEvent, Subject, Subscription } from 'rxjs';
1717
import { filter, takeUntil } from 'rxjs/operators';
18-
import { IAnimationParams } from '../../animations/main';
18+
import { IAnimationParams, slideInTop, slideOutBottom, slideOutTop, slideInBottom, fadeIn, fadeOut,
19+
scaleInVerTop, scaleOutVerTop, scaleOutVerBottom, scaleInVerBottom, scaleInHorRight, scaleOutHorRight,
20+
scaleOutHorLeft, scaleInHorLeft } from '../../animations/main';
1921
import { showMessage } from '../../core/deprecateDecorators';
22+
import { IPositionStrategy } from './position/IPositionStrategy';
23+
import { ConnectedPositioningStrategy } from './position/connected-positioning-strategy';
2024
import { GlobalPositionStrategy } from './position/global-position-strategy';
2125
import { NoOpScrollStrategy } from './scroll/NoOpScrollStrategy';
2226
import {
2327
OverlayAnimationEventArgs,
2428
OverlayCancelableEventArgs,
2529
OverlayClosingEventArgs, OverlayEventArgs,
26-
OverlayInfo, OverlaySettings
30+
OverlayInfo, OverlaySettings,
31+
HorizontalAlignment, VerticalAlignment, Point,
32+
PositionSettings, AbsolutePosition, RelativePosition, RelativePositionStrategy
2733
} from './utilities';
34+
import { ContainerPositionStrategy } from './position/container-position-strategy';
35+
import { ElasticPositionStrategy } from './position/elastic-position-strategy';
36+
import { AutoPositionStrategy } from './position/auto-position-strategy';
37+
import { IgxOverlayOutletDirective } from '../../directives/toggle/toggle.directive';
2838

2939

3040
let warningShown = false;
@@ -111,6 +121,150 @@ export class IgxOverlayService implements OnDestroy {
111121
*/
112122
public onAnimation = new EventEmitter<OverlayAnimationEventArgs>();
113123

124+
/**
125+
* Creates overlay settings with global or container position strategy and preset position settings
126+
* @param position Preset position settings. Default position is 'center'
127+
* @param outlet The outlet container to attach the overlay to
128+
* @returns Non-modal overlay settings based on Global or Container position strategy and the provided position.
129+
*/
130+
public static createAbsoluteOverlaySettings(
131+
position?: AbsolutePosition, outlet?: IgxOverlayOutletDirective | ElementRef): OverlaySettings {
132+
const positionSettings = this.createAbsolutePositionSettings(position);
133+
const strategy = outlet ? new ContainerPositionStrategy(positionSettings) : new GlobalPositionStrategy(positionSettings);
134+
const overlaySettings: OverlaySettings = {
135+
positionStrategy: strategy,
136+
scrollStrategy: new NoOpScrollStrategy(),
137+
modal: false,
138+
closeOnOutsideClick: true,
139+
outlet: outlet
140+
};
141+
return overlaySettings;
142+
}
143+
144+
/**
145+
* Creates overlay settings with auto, connected or elastic position strategy and preset position settings
146+
* @param target Attaching target for the component to show
147+
* @param strategy The relative position strategy to be applied to the overlay settings. Default is Auto positioning strategy.
148+
* @param position Preset position settings. By default the element is positioned below the target, left aligned.
149+
* @returns Non-modal overlay settings based on the provided target, strategy and position.
150+
*/
151+
public static createRelativeOverlaySettings(
152+
target: Point | HTMLElement,
153+
strategy?: RelativePositionStrategy,
154+
position?: RelativePosition):
155+
OverlaySettings {
156+
const positionSettings = this.createRelativePositionSettings(position);
157+
const overlaySettings: OverlaySettings = {
158+
target: target,
159+
positionStrategy: this.createPositionStrategy(strategy, positionSettings),
160+
scrollStrategy: new NoOpScrollStrategy(),
161+
modal: false,
162+
closeOnOutsideClick: true
163+
};
164+
return overlaySettings;
165+
}
166+
167+
private static createAbsolutePositionSettings(position: AbsolutePosition): PositionSettings {
168+
let positionSettings: PositionSettings;
169+
switch (position) {
170+
case AbsolutePosition.Bottom:
171+
positionSettings = {
172+
horizontalDirection: HorizontalAlignment.Center,
173+
verticalDirection: VerticalAlignment.Bottom,
174+
openAnimation: slideInBottom,
175+
closeAnimation: slideOutBottom
176+
};
177+
break;
178+
case AbsolutePosition.Top:
179+
positionSettings = {
180+
horizontalDirection: HorizontalAlignment.Center,
181+
verticalDirection: VerticalAlignment.Top,
182+
openAnimation: slideInTop,
183+
closeAnimation: slideOutTop
184+
};
185+
break;
186+
case AbsolutePosition.Center:
187+
default:
188+
positionSettings = {
189+
horizontalDirection: HorizontalAlignment.Center,
190+
verticalDirection: VerticalAlignment.Middle,
191+
openAnimation: fadeIn,
192+
closeAnimation: fadeOut
193+
};
194+
}
195+
return positionSettings;
196+
}
197+
198+
private static createRelativePositionSettings(position: RelativePosition): PositionSettings {
199+
let positionSettings: PositionSettings;
200+
switch (position) {
201+
case RelativePosition.Above:
202+
positionSettings = {
203+
horizontalStartPoint: HorizontalAlignment.Center,
204+
verticalStartPoint: VerticalAlignment.Top,
205+
horizontalDirection: HorizontalAlignment.Center,
206+
verticalDirection: VerticalAlignment.Top,
207+
openAnimation: scaleInVerBottom,
208+
closeAnimation: scaleOutVerBottom,
209+
};
210+
break;
211+
case RelativePosition.Below:
212+
positionSettings = {
213+
horizontalStartPoint: HorizontalAlignment.Center,
214+
verticalStartPoint: VerticalAlignment.Bottom,
215+
horizontalDirection: HorizontalAlignment.Center,
216+
verticalDirection: VerticalAlignment.Bottom,
217+
openAnimation: scaleInVerTop,
218+
closeAnimation: scaleOutVerTop
219+
};
220+
break;
221+
case RelativePosition.After:
222+
positionSettings = {
223+
horizontalStartPoint: HorizontalAlignment.Right,
224+
verticalStartPoint: VerticalAlignment.Middle,
225+
horizontalDirection: HorizontalAlignment.Right,
226+
verticalDirection: VerticalAlignment.Middle,
227+
openAnimation: scaleInHorLeft,
228+
closeAnimation: scaleOutHorLeft
229+
};
230+
break;
231+
case RelativePosition.Before:
232+
positionSettings = {
233+
horizontalStartPoint: HorizontalAlignment.Left,
234+
verticalStartPoint: VerticalAlignment.Middle,
235+
horizontalDirection: HorizontalAlignment.Left,
236+
verticalDirection: VerticalAlignment.Middle,
237+
openAnimation: scaleInHorRight,
238+
closeAnimation: scaleOutHorRight
239+
};
240+
break;
241+
case RelativePosition.Default:
242+
default:
243+
positionSettings = {
244+
horizontalStartPoint: HorizontalAlignment.Left,
245+
verticalStartPoint: VerticalAlignment.Bottom,
246+
horizontalDirection: HorizontalAlignment.Right,
247+
verticalDirection: VerticalAlignment.Bottom,
248+
openAnimation: scaleInVerTop,
249+
closeAnimation: scaleOutVerTop,
250+
};
251+
break;
252+
}
253+
return positionSettings;
254+
}
255+
256+
private static createPositionStrategy(strategy: RelativePositionStrategy, positionSettings: PositionSettings): IPositionStrategy {
257+
switch (strategy) {
258+
case RelativePositionStrategy.Connected:
259+
return new ConnectedPositioningStrategy(positionSettings);
260+
case RelativePositionStrategy.Elastic:
261+
return new ElasticPositionStrategy(positionSettings);
262+
case RelativePositionStrategy.Auto:
263+
default:
264+
return new AutoPositionStrategy(positionSettings);
265+
}
266+
}
267+
114268
constructor(
115269
private _factoryResolver: ComponentFactoryResolver,
116270
private _appRef: ApplicationRef,

projects/igniteui-angular/src/lib/services/overlay/utilities.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IScrollStrategy } from './scroll';
44
import { AnimationReferenceMetadata, AnimationPlayer } from '@angular/animations';
55
import { ComponentRef, ElementRef, NgZone } from '@angular/core';
66
import { IgxOverlayOutletDirective } from '../../directives/toggle/toggle.directive';
7-
import { CancelableEventArgs, CancelableBrowserEventArgs, cloneValue, IBaseEventArgs } from '../../core/utils';
7+
import { CancelableEventArgs, CancelableBrowserEventArgs, cloneValue, IBaseEventArgs, mkenum } from '../../core/utils';
88

99
export enum HorizontalAlignment {
1010
Left = -1,
@@ -18,6 +18,38 @@ export enum VerticalAlignment {
1818
Bottom = 0
1919
}
2020

21+
/**
22+
* Defines the possible values of the overlays' position strategy.
23+
*/
24+
export const RelativePositionStrategy = mkenum({
25+
Connected: 'connected',
26+
Auto: 'auto',
27+
Elastic: 'elastic'
28+
});
29+
export type RelativePositionStrategy = (typeof RelativePositionStrategy)[keyof typeof RelativePositionStrategy];
30+
31+
/**
32+
* Defines the possible positions for the relative overlay settings presets.
33+
*/
34+
export const RelativePosition = mkenum({
35+
Above: 'above',
36+
Below: 'below',
37+
Before: 'before',
38+
After: 'after',
39+
Default: 'default'
40+
});
41+
export type RelativePosition = (typeof RelativePosition)[keyof typeof RelativePosition];
42+
43+
/**
44+
* Defines the possible positions for the absolute overlay settings presets.
45+
*/
46+
export const AbsolutePosition = mkenum({
47+
Bottom: 'bottom',
48+
Top: 'top',
49+
Center: 'center'
50+
});
51+
export type AbsolutePosition = (typeof AbsolutePosition)[keyof typeof AbsolutePosition];
52+
2153
export class Point {
2254
constructor(public x: number, public y: number) { }
2355
}

0 commit comments

Comments
 (0)