npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-custom-modal

v17.0.0-rc.3

Published

A custom Modal / Dialog (with inner component support) for Angular 17+ projects

Downloads

21

Readme

ngx-custom-modal

npm Version Build Status

A custom Modal / Dialog (with inner component support) for Angular 17+ projects.

It is an update, continuation and improvement of the modal concept Angular Custom Modal.

Demo

For a live demonstration, visit ngx-custom-modal demo.

Install

npm install ngx-custom-modal

Features

Core Features with Angular 17 Standalone Components:

  • Light: No additional CSS/JS frameworks attached.
  • Bootstrap 3 & 4 CSS Compatible: Ensures seamless integration with these versions of Bootstrap.
  • Custom Modal Components:
    • Customizable modal headers, bodies, and footers for tailored UI design.
  • Modal Stacking Support: Allows multiple modals to be opened and managed effectively.
  • Lazy Inner Component Initialization: Components within modals are initialized only as needed.
  • Efficient Lifecycle Management: Inner components are destroyed (ngOnDestroy) when the modal is closed, ensuring resource efficiency.

Minor:

  • Optional CSS animations
  • Optional parent scrolling when modal is visible
  • Escape or button to close modal

Usage

imports: [
  ...
  NgxCustomModalComponent,
  ...
],
...
})

Raw HTML

app.component.html

<button (click)="htmlInsideModal.open()">Raw HTML inside modal</button>
<ngx-custom-modal #htmlInsideModal>
  <ng-template #modalHeader><h2>HTML inside modal</h2></ng-template>
  <ng-template #modalBody>
    <p>HTML content inside modal</p>
  </ng-template>
</ngx-custom-modal>

Component inside Modal

my-component.component.ts

@Component({
  selector: 'app-my-component',
  templateUrl: 'my-component.component.html',
})
export class AppModalContentComponent { }

my-component.component.html

<p>My component's HTML</p>

app.component.html

<button (click)="componentInsideModal.open()">Component inside modal</button>
<ngx-custom-modal #componentInsideModal>
  <ng-template #modalHeader><h2>Component inside modal</h2></ng-template>
  <ng-template #modalBody>
    <app-my-component></app-my-component>
  </ng-template>
  <ng-template #modalFooter></ng-template>
</ngx-custom-modal>

Nested Modal

app.component.html

<ngx-custom-modal #nestedModal>
  <ng-template #modalHeader><h2>Nested modal</h2></ng-template>
  <ng-template #modalBody>
    Nested modals can be created by simply adding a &lt;modal&gt; inside a &lt;modal&gt;
    ...
    <button (click)="nestedModalX.open()">Open nested modal</button>
    <ngx-custom-modal #nestedModalX>
      <ng-template #modalBody>This is the nested modal content.</ng-template>
    </ngx-custom-modal>
  </ng-template>
</ngx-custom-modal>

See example source code for more information.

Development Guidelines

Code Formatting

This project uses Prettier for code formatting. To ensure consistent code style, please format your code using Prettier before submitting any changes.

To format the codebase, run the following command:

npm run format

This command will automatically format all files in the project according to the predefined Prettier configuration.

Why ng-template?

ng-template prevents the parent component from initializing the component. Only when the modal library finds it convenient the component will be initialize and visible to the user. Hence, it preserves the natural ngOnInit() and ngOnDestroy() that we expect.

Similar libraries which make use of <ng-content> and its content transclution strategy, do not prevent the component from initializing, but rather just hide it. The component was already initialized in the parent component.

References: https://angular.io/api/common/NgTemplateOutlet https://blog.angular-university.io/angular-ng-template-ng-container-ngtemplateoutlet/ https://medium.com/claritydesignsystem/ng-content-the-hidden-docs-96a29d70d11b https://netbasal.com/understanding-viewchildren-contentchildren-and-querylist-in-angular-896b0c689f6e

Styles

The library carries the minimum generic styles. Beautifying it is up to you.

Default styles

You can find the demo copy-paste styles in modal.css.

Bootstrap

Bootstrap users require no additional CSS other than the Bootstrap library (either version 3 or 4).

API

ModalComponent

| Name | Type | Description | | ------------------- | ---------------------------------------------- | -------------------------------------------------------------------------------------------- | | header | @ContentChild('modalHeader'): TemplateRef | Angular Template (<ng-template>) to use as header. | | body | @ContentChild('modalBody'): TemplateRef | Angular Template (ng-template) to use as body. | | footer | @ContentChild('modalFooter'): TemplateRef | Angular Template (ng-template) to use as footer. | | closeOnOutsideClick | @Input(): boolean = true | When set to true modal will close when a click is performed outside the modal container. | | open | () => void | Opens the modal. | | close | () => void | Closes the modal. | | isTopMost | () => boolean | Returns true is the modal is the top most modal, or false if it is underneath another modal. |

Special Thanks

This project, ngx-custom-modal, was inspired by and built upon the foundational work of angular-custom-modal, created by Gerard Rovira Sánchez. A special acknowledgment to Stephen Paul for his initial Angular 2 Modal version, which laid the groundwork for these modal dialog implementations in Angular.

License

MIT © Angel Careaga