File

projects/wvr-elements/src/lib/wvr-modal/wvr-modal.component.ts

Extends

WvrBaseComponent

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
Outputs
HostBindings
Accessors

Constructor

constructor(injector: Injector, modalService: NgbModal)
Parameters :
Name Type Optional
injector Injector No
modalService NgbModal No

Inputs

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

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

A setter which parses a json string describing animation instructions and stores the derived object in _animationSettings.

animateConfig
Type : string
Inherited from WvrBaseComponent

A setter which parses a json string describing animation setting and stores the derived object in _animationConfig.

animateId
Type : string
Inherited from WvrBaseComponent

An attribute input allowing for the designation of an animation identifier for the purpose of animation targeting.

animateTarget
Type : string
Inherited from WvrBaseComponent

An attribute input allowing for the designation of an animation target for animation events.

hiddenInMobile
Type : boolean
Default value : false
Inherited from WvrBaseComponent

An attribute input specifying if this component should be hidden in the mobile layout.

ngBindings
Type : string
Inherited from WvrBaseComponent
wvrData
Type : string
Inherited from WvrBaseComponent
wvrTheme
Type : string
Inherited from WvrBaseComponent

Allows for the override of theme for the particular component.

Outputs

animationEventTrigger
Type : EventEmitter
Inherited from WvrBaseComponent

An Output biding used for triggering animations.

HostBindings

class.wvr-bootstrap
Type : boolean
Default value : true
Inherited from WvrBaseComponent

A host binding used to ensure the presense of the wvr-bootstrap class.

class.wvr-hidden
Type : boolean
Inherited from WvrBaseComponent

A host bound accessor which applies the wvr-hidden class if both isMobileLayout and hiddenInMobile evaluate to true.

style
Type : any
Inherited from WvrBaseComponent

Methods

ngOnDestroy
ngOnDestroy()
Inherited from WvrBaseComponent
Returns : void
ngOnInit
ngOnInit()
Inherited from WvrBaseComponent
Returns : void
openModal
openModal()
Returns : void
applyThemeOverride
applyThemeOverride(customProperty: string, value: string)
Inherited from WvrBaseComponent
Parameters :
Name Type Optional
customProperty string No
value string No
Returns : void
bootstrapNgBindings
bootstrapNgBindings()
Inherited from WvrBaseComponent
Returns : void
getWvrData
getWvrData()
Inherited from WvrBaseComponent
Returns : string
hasWvrData
hasWvrData()
Inherited from WvrBaseComponent
Returns : boolean
initializeAnimationElement
initializeAnimationElement()
Inherited from WvrBaseComponent
Returns : void
initializeAnimationRegistration
initializeAnimationRegistration()
Inherited from WvrBaseComponent
Returns : void
ngAfterContentInit
ngAfterContentInit()
Inherited from WvrBaseComponent

Used for post content initialization animation setup.

Returns : void
onAnimationEvent
onAnimationEvent($event: Event)
Inherited from WvrBaseComponent

Trigger's the animation specified by the incoming event.

Parameters :
Name Type Optional
$event Event No
Returns : void
Private processData
processData()
Inherited from WvrBaseComponent
Returns : void
triggerAnimations
triggerAnimations(animationTriggerType: string)
Inherited from WvrBaseComponent

Plays the animation specified by the incoming animation trigger.

Parameters :
Name Type Optional
animationTriggerType string No
Returns : void

Properties

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

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

A reference to the AnimationService

Private _animationSettings
Type : any
Default value : {}
Inherited from WvrBaseComponent

An object representation of the animation instructions for this component.

Private _ngBindings
Type : literal type
Inherited from WvrBaseComponent
animationRootElem
Type : ElementRef
Decorators :
@ViewChild('animationRoot')
Inherited from WvrBaseComponent

A view child of the template element containing the #animationRoot identifier.

Private animationStateId
Type : number
Inherited from WvrBaseComponent

An identifier used to access the animation state for this component.

Readonly appConfig
Type : AppConfig
Inherited from WvrBaseComponent

A reference to the AppConfig

Readonly cdRef
Type : ChangeDetectorRef
Inherited from WvrBaseComponent

A reference to the ChangeDetectorRef

Readonly componentRegistry
Type : ComponentRegistryService<WvrBaseComponent>
Inherited from WvrBaseComponent

A reference to the ComponentRegistryService

data
Type : literal type
Default value : {}
Inherited from WvrBaseComponent
Readonly eRef
Type : ElementRef
Inherited from WvrBaseComponent

A reference to the ElementRef

Readonly id
Type : number
Inherited from WvrBaseComponent

A generated unique identifier for this comonent.

isMobile
Type : Observable<boolean>
Inherited from WvrBaseComponent
isMobileLayout
Type : boolean
Inherited from WvrBaseComponent
Private Readonly kebabize
Default value : () => {...}
Inherited from WvrBaseComponent
Private Readonly ngBindingsService
Type : NgBindingsService
Inherited from WvrBaseComponent

A reference to the NgBindingsService

Readonly store
Type : Store<RootState>
Inherited from WvrBaseComponent

A reference to the Store

style
Decorators :
@HostBinding('style')
Inherited from WvrBaseComponent
Protected subscriptions
Type : Array<Subscription>
Inherited from WvrBaseComponent
themeOverrides
Type : object
Default value : {}
Inherited from WvrBaseComponent
Private Readonly themeService
Type : ThemeService
Inherited from WvrBaseComponent

A reference to the ThemeService

variantTypes
Type : []
Default value : []
Inherited from WvrBaseComponent
wvrBootstrap
Default value : true
Decorators :
@HostBinding('class.wvr-bootstrap')
Inherited from WvrBaseComponent

A host binding used to ensure the presense of the wvr-bootstrap class.

Accessors

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;
      }
    }
  }

}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""