projects/wvr-elements/src/lib/wvr-modal/wvr-modal.component.ts
changeDetection | ChangeDetectionStrategy.Default |
selector | wvr-modal-component |
styleUrls | ./wvr-modal.component.scss |
templateUrl | ./wvr-modal.component.html |
Properties |
|
Methods |
Inputs |
Outputs |
HostBindings |
Accessors |
constructor(injector: Injector, modalService: NgbModal)
|
animation | |
Type : boolean
|
|
Default value : true
|
|
backdrop | |
Type : "static" | boolean
|
|
Default value : 'static'
|
|
btnText | |
Type : string
|
|
The text value to be displayed for the button launching the modal. |
btnThemeVariant | |
Type : ThemeVariantName
|
|
Allows for the override of theme variant for the button launching the modal component. |
btnVisible | |
Type : "true" | "false"
|
|
Default value : 'true'
|
|
This allows for the modal button to be toggle able. |
centered | |
Type : boolean
|
|
Default value : false
|
|
keyboard | |
Type : boolean
|
|
Default value : false
|
|
modalFooterThemeVariant | |
Type : ThemeVariantName
|
|
Default value : 'light'
|
|
Allows for the override of theme variant for modal footer. |
modalHeaderThemeVariant | |
Type : ThemeVariantName
|
|
Allows for the override of theme variant for modal header. |
modalId | |
Type : string
|
|
This defines the modal id. |
size | |
Type : "sm" | "lg" | "xl"
|
|
Default value : 'lg'
|
|
themeVariant | |
Type : ThemeVariantName
|
|
Default value : 'primary'
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:37
|
|
Allows for the override of theme variant for modal component. |
title | |
Type : string
|
|
The header title value to be displayed as a modal title. |
animate | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:68
|
|
A setter which parses a json string describing animation instructions and stores the derived object in |
animateConfig | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:76
|
|
A setter which parses a json string describing animation setting and stores the derived object in |
animateId | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:84
|
|
An attribute input allowing for the designation of an animation identifier for the purpose of animation targeting. |
animateTarget | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:87
|
|
An attribute input allowing for the designation of an animation target for animation events. |
hiddenInMobile | |
Type : boolean
|
|
Default value : false
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:107
|
|
An attribute input specifying if this component should be hidden in the mobile layout. |
ngBindings | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:116
|
wvrData | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:45
|
wvrTheme | |
Type : string
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:50
|
|
Allows for the override of theme for the particular component. |
animationEventTrigger | |
Type : EventEmitter
|
|
Inherited from
WvrBaseComponent
|
|
Defined in
WvrBaseComponent:110
|
|
An Output biding used for triggering animations. |
class.wvr-bootstrap |
Type : boolean
|
Default value : true
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:58
|
A host binding used to ensure the presense of the |
class.wvr-hidden |
Type : boolean
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:102
|
A host bound accessor which applies the wvr-hidden class if both isMobileLayout and hiddenInMobile evaluate to true. |
style |
Type : any
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:60
|
ngOnDestroy |
ngOnDestroy()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:136
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:67
|
Returns :
void
|
openModal |
openModal()
|
Returns :
void
|
applyThemeOverride |
applyThemeOverride(customProperty: string, value: string)
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:237
|
Returns :
void
|
bootstrapNgBindings |
bootstrapNgBindings()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:175
|
Returns :
void
|
getWvrData |
getWvrData()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:262
|
Returns :
string
|
hasWvrData |
hasWvrData()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:258
|
Returns :
boolean
|
initializeAnimationElement |
initializeAnimationElement()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:267
|
Returns :
void
|
initializeAnimationRegistration |
initializeAnimationRegistration()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:273
|
Returns :
void
|
ngAfterContentInit |
ngAfterContentInit()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:160
|
Used for post content initialization animation setup.
Returns :
void
|
onAnimationEvent | ||||||
onAnimationEvent($event: Event)
|
||||||
Inherited from
WvrBaseComponent
|
||||||
Defined in
WvrBaseComponent:290
|
||||||
Trigger's the animation specified by the incoming event.
Parameters :
Returns :
void
|
Private processData |
processData()
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:295
|
Returns :
void
|
triggerAnimations | ||||||
triggerAnimations(animationTriggerType: string)
|
||||||
Inherited from
WvrBaseComponent
|
||||||
Defined in
WvrBaseComponent:244
|
||||||
Plays the animation specified by the incoming animation trigger.
Parameters :
Returns :
void
|
getTextColor |
Default value : () => {...}
|
modalRef |
Type : NgbModalRef
|
modalTemplateContent |
Type : TemplateRef<Element>
|
Decorators :
@ViewChild('modalTemplateContent')
|
subscription |
Type : Subscription
|
Private _animationConfig |
Type : any
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:73
|
An object representation of the settings specifying the specific behavior of the animation for this component. |
Private Readonly _animationService |
Type : AnimationService<WvrBaseComponent>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:93
|
A reference to the AnimationService |
Private _animationSettings |
Type : any
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:65
|
An object representation of the animation instructions for this component. |
Private _ngBindings |
Type : literal type
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:114
|
animationRootElem |
Type : ElementRef
|
Decorators :
@ViewChild('animationRoot')
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:90
|
A view child of the template element containing the #animationRoot identifier. |
Private animationStateId |
Type : number
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:81
|
An identifier used to access the animation state for this component. |
Readonly appConfig |
Type : AppConfig
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:37
|
A reference to the AppConfig |
Readonly cdRef |
Type : ChangeDetectorRef
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:34
|
A reference to the ChangeDetectorRef |
Readonly componentRegistry |
Type : ComponentRegistryService<WvrBaseComponent>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:25
|
A reference to the ComponentRegistryService |
data |
Type : literal type
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:42
|
Readonly eRef |
Type : ElementRef
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:31
|
A reference to the ElementRef |
Readonly id |
Type : number
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:28
|
A generated unique identifier for this comonent. |
isMobile |
Type : Observable<boolean>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:120
|
isMobileLayout |
Type : boolean
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:112
|
Private Readonly kebabize |
Default value : () => {...}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:321
|
Private Readonly ngBindingsService |
Type : NgBindingsService
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:99
|
A reference to the NgBindingsService |
Readonly store |
Type : Store<RootState>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:40
|
A reference to the Store |
style |
Decorators :
@HostBinding('style')
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:60
|
Protected subscriptions |
Type : Array<Subscription>
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:122
|
themeOverrides |
Type : object
|
Default value : {}
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:47
|
Private Readonly themeService |
Type : ThemeService
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:96
|
A reference to the ThemeService |
variantTypes |
Type : []
|
Default value : []
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:62
|
wvrBootstrap |
Default value : true
|
Decorators :
@HostBinding('class.wvr-bootstrap')
|
Inherited from
WvrBaseComponent
|
Defined in
WvrBaseComponent:58
|
A host binding used to ensure the presense of the |
openProps |
getopenProps()
|
additionalHeaderClasses |
getadditionalHeaderClasses()
|
additionalFooterClasses |
getadditionalFooterClasses()
|
import { ChangeDetectionStrategy, Component, Injector, Input, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { Subscription } from 'rxjs';
import { select } from '@ngrx/store';
import { filter } from 'rxjs/operators';
import * as ModalActions from '../core/modal/modal.actions';
import { selectModalState } from '../core/store';
import { ThemeVariantName } from '../shared/theme';
import { preserveContent, projectContent } from '../shared/utility/projection.utility';
import { WvrBaseComponent } from '../shared/wvr-base.component';
@Component({
selector: 'wvr-modal-component',
templateUrl: './wvr-modal.component.html',
styleUrls: ['./wvr-modal.component.scss'],
changeDetection: ChangeDetectionStrategy.Default
})
export class WvrModalComponent extends WvrBaseComponent implements OnInit, OnDestroy {
@ViewChild('modalTemplateContent') modalTemplateContent: TemplateRef<Element>;
modalRef: NgbModalRef;
/** This allows for the modal button to be toggle able. */
@Input() btnVisible: 'true' | 'false' = 'true';
/** The header title value to be displayed as a modal title. */
@Input() title: string;
/** The text value to be displayed for the button launching the modal. */
@Input() btnText: string;
/** This defines the modal id. */
@Input() modalId: string;
/** Allows for the override of theme variant for modal component. */
@Input() themeVariant: ThemeVariantName = 'primary';
/** Allows for the override of theme variant for the button launching the modal component. */
@Input() btnThemeVariant: ThemeVariantName;
/** Allows for the override of theme variant for modal header. */
@Input() modalHeaderThemeVariant: ThemeVariantName;
/** Allows for the override of theme variant for modal footer. */
@Input() modalFooterThemeVariant: ThemeVariantName = 'light';
@Input() size: 'sm' | 'lg' | 'xl' = 'lg';
@Input() backdrop: 'static' | boolean = 'static';
@Input() centered = false;
@Input() animation = true;
@Input() keyboard = false;
subscription: Subscription;
constructor(
injector: Injector,
private readonly modalService: NgbModal
) {
super(injector);
}
ngOnInit(): void {
super.ngOnInit();
this.modalService.activeInstances.subscribe((modalRefs: Array<NgbModalRef>) => {
setTimeout(() => {
if (!!this.modalRef && modalRefs.length > 0) {
['body', 'footer'].forEach(content => {
projectContent(this.eRef, `template[modal-${content}]`, `div[modal-${content}]`);
});
}
});
});
const defaultName = 'Weaver Modal';
this.modalId = !!this.modalId
? this.modalId
: !!this.title
? this.title
: `${defaultName
.split(' ')
.join('')}-${this.id}`;
this.title = !this.title ? defaultName : this.title;
this.btnText = this.btnText ? this.btnText : this.title;
this.btnThemeVariant = this.btnThemeVariant ? this.btnThemeVariant : this.themeVariant;
this.store.dispatch(ModalActions.addModal({
modal: {
name: this.modalId,
open: false
}
}));
this.subscription = this.store.pipe(
select(selectModalState),
filter(modalState => !!modalState)
)
.subscribe(modalState => {
const modal = modalState.entities[this.modalId];
if (modal.open) {
this.modalRef = this.modalService.open(this.modalTemplateContent, {
ariaLabelledBy: 'modal-basic-title',
container: this.eRef.nativeElement,
size: this.size,
backdrop: this.backdrop,
centered: this.centered,
animation: this.animation,
keyboard: this.keyboard,
modalDialogClass: 'modal-dialog',
beforeDismiss: () => {
this.store.dispatch(ModalActions.closeModal({ id: this.modalId }));
return false;
}
});
} else if (this.modalRef) {
['body', 'footer'].forEach(content => {
preserveContent(this.eRef, `template[modal-${content}]`, `div[modal-${content}]`);
});
this.modalRef.close();
delete this.modalRef;
}
});
}
ngOnDestroy(): void {
this.modalService.activeInstances.unsubscribe();
this.subscription.unsubscribe();
}
openModal(): void {
this.store.dispatch(ModalActions.openModal({ id: this.modalId }));
}
get openProps(): string {
return `{ id: '${this.modalId}'}`;
}
get additionalHeaderClasses(): string {
return this.modalHeaderThemeVariant ?
`bg-${this.modalHeaderThemeVariant} border-${this.modalHeaderThemeVariant} ${this.getTextColor(this.modalHeaderThemeVariant)}` :
this.themeVariant ?
`bg-${this.themeVariant} border-${this.themeVariant} ${this.getTextColor(this.themeVariant)}` :
'bg-light text-dark';
}
get additionalFooterClasses(): string {
return this.modalFooterThemeVariant ?
`bg-${this.modalFooterThemeVariant} border-${this.modalFooterThemeVariant} ${this.getTextColor(this.modalFooterThemeVariant)}` :
this.themeVariant ?
`bg-${this.themeVariant} border-${this.themeVariant} ${this.getTextColor(this.themeVariant)}` :
'bg-light text-dark';
}
getTextColor = (themeVariant): string => ((themeVariant === 'warning') || (themeVariant === 'light')) ? 'text-dark' : 'text-white';
}
<wvr-modal-wrapper #animationRoot>
<wvr-button-component
*ngIf="btnVisible === 'true'"
[btnTxt]="btnText"
[dispatchAction]="'Modal.openModal'"
[dispatchActionProps]="openProps"
[themeVariant]="btnThemeVariant">
</wvr-button-component>
<ng-template #modalTemplateContent>
<div class="modal-header {{additionalHeaderClasses}}">
<h4 class="modal-title" id="modal-basic-title">{{title}}</h4>
</div>
<div class="modal-body" modal-body>
<ng-content select="template[modal-body]"></ng-content>
</div>
<div class="modal-footer {{additionalFooterClasses}}" modal-footer>
<ng-content select="template[modal-footer]"></ng-content>
</div>
</ng-template>
</wvr-modal-wrapper>
./wvr-modal.component.scss
@import "../shared/styles/variables";
:host {
@extend .variables;
font-family: var(--wvr-font-family-sans-serif);
::ng-deep {
.modal-dialog {
font-family: var(--wvr-font-family-sans-serif);
.modal-footer {
padding: 4px 10px 0px 10px;
}
}
}
}