0.0.9 • Published 5 months ago

fusion-popup v0.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Popup Fusion

Popup Fusion is a lightweight and customizable popup component for Angular, designed to provide a seamless and flexible modal experience.

Installation

npm install fusion-popup

Usage

Import the FusionPopupComponent in your Angular module:

import { PopupFusionModule } from "fusion-popup";

@NgModule({
  imports: [FusionPopupComponent],
})
export class AppModule {}

Use the <fusion-popup> component in your template:

<fusion-popup [visible]="isVisible" [title]="'My Popup'" [width]="'500px'" [height]="'400px'">
  <p>Popup content goes here.</p>
</fusion-popup>

API

Inputs

PropertyTypeDefaultDescription
visiblebooleanfalseControls the visibility of the popup.
titlestring''Title of the popup.
widthstring'400px'Width of the popup.
heightstring'300px'Height of the popup.
shadingbooleantrueEnables/disables the background overlay.
shadingColorstring'rgba(0, 0, 0, 0.2)'Color of the background overlay.
showCloseButtonbooleantrueShows/hides the close button.
dragEnabledbooleantrueEnables/disables dragging.
resizeEnabledbooleantrueEnables/disables resizing.
animationFusionPopupAnimationType'fade'Animation type for the popup.
zIndexnumberautoSets the z-index of the popup.
positionFusionPopupPositionType'top'Position of the popup on the screen.
componentanyundefinedCustom component to be displayed inside the popup.
customTemplateTemplateRef<any>undefinedCustom template for the popup content.
componentInputsRecord<string, unknown>undefinedDynamic inputs for the custom component.
targetElemntIdstring''Target element ID for positioning the popup.
dragEnabledbooleantrueEnables/disables dragging functionality.
resizeEnabledbooleantrueEnables/disables resizing functionality.
maxWidthstringundefinedMaximum width of the popup.
minWidthstring'100px'Minimum width of the popup.
maxHeightstringundefinedMaximum height of the popup.
minHeightstring'100px'Minimum height of the popup.
loadingbooleanfalseShows or hides the loading indicator.
showHeaderbooleantrueShows or hides the header of the popup.
showFooterbooleantrueShows or hides the footer of the popup.
buttonsFusionButtonProperties[][]Array of buttons to be displayed inside the popup Footer.
positionXYobject{ x: 0, y: 0 }XY coordinates for the popup position.
--------------------------------------------------------------------------------------------------------------------
visiblebooleanfalseControls the visibility of the popup.
titlestring''Title of the popup.
widthstring'400px'Width of the popup.
heightstring'300px'Height of the popup.
shadingbooleantrueEnables/disables the background overlay.
shadingColorstring'rgba(0, 0, 0, 0.2)'Color of the background overlay.
showCloseButtonbooleantrueShows/hides the close button.
dragEnabledbooleantrueEnables/disables dragging.
resizeEnabledbooleantrueEnables/disables resizing.
animationFusionPopupAnimationType'fade'Animation type for the popup.

Events

EventTypeDescription
visibleChangeEventEmitter<boolean>Emitted when the visibility of the popup changes.
onOpenedEventEmitter<FusionOpenedEvent>Emitted when the popup is opened.
onClosedEventEmitter<FusionClosedEvent>Emitted when the popup is closed.
onOptionChangedEventEmitter<FusionOptionChangedEvent<FusionPopupComponent>>Emitted when an option of the popup is changed.
onContentLoadedEventEmitter<FusionContentLoadedEvent<FusionPopupComponent>>Emitted when the popup content is loaded.
onDragEventEmitter<FusionDragEndEvent>Emitted when the drag operation of the popup ends.
onResizeEventEmitter<FusionResizeEvent>Emitted when the popup is resized.
onButtonClickEventEmitter<FusionButtonClickEvent>Emitted when a button inside the popup is clicked.

Methods

MethodDescription
open()Opens the popup.
close()Closes the popup.
startLoading()Shows a loading spinner inside the popup.
stopLoading()Hides the loading spinner.
getComponent()return the instance of component rendred dynamicly.
disableButton(id: string): voidDisables the button with the specified id.
enableButton(id: string): voidEnables the button with the specified id.
hideButton(id: string): voidHides the button with the specified id.
showButton(id: string): voidShows the button with the specified id.
startButtonLoading(id: string): voidStarts the loading state on the button with the specified id.
endButtonLoading(id: string): voidEnds the loading state on the button with the specified id.

Dynamic Open Mode

PopupFusionService

The PopupFusionService allows you to create popups dynamically without needing to define them in the template.

Importing the Service

import { PopupFusionService } from "fusion-popup";

Creating a Popup Dynamically

step 1: set the service FusionPopupService as Application provider
import { FusionPopupService } from 'fusion-popup';

@Component({
  selector: 'app-root',
  imports: [],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css',
  providers: [FusionPopupService],
})

constructor(private popupService: PopupFusionService) {}

openPopup() {
  const popupInstance = this.popupService.createPopup({
    title: 'Dynamic Popup',
    width: '500px',
    height: '400px',
    component : YourComponent
  });
}

Closing a Popup

this.popupService.closePopup(popupInstance.id);

Example

open popup with service

import { Component } from "@angular/core";
import { PopupFusionService } from "fusion-popup";

@Component({
  selector: "app-root",
  template: ` <button (click)="openPopup()">Open Popup</button> `,
})
export class AppComponent {
  constructor(private popupService: PopupFusionService) {}

  openPopup() {
    this.popupService.createPopup({
      title: "Dynamic Popup",
      width: "500px",
      height: "400px",
    });
  }
}

Example

handle button click and close popup

import { Component } from "@angular/core";
import { PopupFusionService } from "fusion-popup";

@Component({
  selector: "app-root",
  template: ` <button (click)="openPopup()">Open Popup</button> `,
})
export class AppComponent {
  constructor(private popupService: PopupFusionService) {}

  openPopup() {
    const popup = this.popupFusionService.createPopup({
      width: "700px",
      height: "200px",
      positionXY: { x: 0, y: 0 },
      title: "Popup Title",
      component: AppComponent,
      buttons: [
        {
          id: "close",
          text: "Close",
          type: "info",
          stylingMode: "outlined",
        },
      ],
    });

    popup.onButtonClick.subscribe((event: FusionButtonClickEvent) => {
      if (event.button.id === "close") {
        // controle the buttons properties from event.button
        event.button.loading = true;
        // controle the buttons properties from popup.button
        popup.startButtonLoading("close");
        // controle the popup form event
        event.popup.close();

        // controle the component rendred from outside and access to all public properties and methods
        const rendredComponent = popp.getComponent<YourComponent>();
        // controle the popup from instance
        popup.close();
      }
    });
  }
}

License

MIT

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago

0.0.0

5 months ago