@@ -15,16 +15,26 @@ import {
1515} from '@angular/core' ;
1616import { fromEvent , Subject , Subscription } from 'rxjs' ;
1717import { 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' ;
1921import { showMessage } from '../../core/deprecateDecorators' ;
22+ import { IPositionStrategy } from './position/IPositionStrategy' ;
23+ import { ConnectedPositioningStrategy } from './position/connected-positioning-strategy' ;
2024import { GlobalPositionStrategy } from './position/global-position-strategy' ;
2125import { NoOpScrollStrategy } from './scroll/NoOpScrollStrategy' ;
2226import {
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
3040let 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 ,
0 commit comments