# @lorndev/modal

> Provide a simple modal

Latest version **1.0.7** (published 2022-01-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install @lorndev/modal
pnpm add @lorndev/modal
yarn add @lorndev/modal
bun add @lorndev/modal
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2022-01-30 |
| First published | 2020-06-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 641.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Paul Weinsberg |
| Maintainers | lorndev |

## Links

- npm: https://www.npmjs.com/package/@lorndev/modal
- Repository: https://github.com/PaulWeinsberg/modal
- Homepage: https://github.com/PaulWeinsberg/modal#readme
- Issues: https://github.com/PaulWeinsberg/modal/issues
- npm.io page: https://npm.io/package/@lorndev/modal

## Recent versions

- 1.0.7 (latest) — 2022-01-30
- 1.0.6 — 2022-01-30
- 1.0.5 — 2021-01-11
- 1.0.4 — 2020-06-25

## README

This package provide a simple JS modal.

# Install

To install package, run `npm install @lorndev/modal`.

# Usage

## Example

**JS**
Create a modal which display a simple 'Hello word'.
Note: Your document body element need to be accessible: DOMContentLoaded before modal.insert() method.

```typescript
import { Modal } from '@lorndev/modal/modal';

// Create your modal content HTML element
const paraph = document.createElement('p');
paraph.textContent = 'Hello world';

// Create modal instance
const modal = new Modal({
    // Your options here
    closeOverlay: true
});

modal.addChild(paraph);
modal.insert();

// Your open modal button
const button = document.querySelector('.my-button');
modal.addOpenButton(button);
```

**CSS**
Import default CSS stylesheet

```scss
@import '~@lorndev/modal/modal';
```

## Available options

```typescript
declare type modalOptions = {

  closeButton?: HTMLElement;
  closeOverlay?: boolean;
  transition?: string;
}
```

## Basic methods

```typescript
    /**
     * Close modal
     */
    open(e?: MouseEvent): void;
    /**
     * Close modal
     */
    close(e?: MouseEvent): void;
    /**
     * Insert modal in DOM
     */
    insert(): void;
    /**
     * Destroying modal (remove from DOM)
     */
    destroy(): void;
    /**
     * Set open event on custom element
     * @param element HTML DOM element which trigger open event
     */
    addOpenButton(element: HTMLModalElement): void;
    /**
     * Set close event on custom element
     * @param element HTML DOM element which trigger close event
     */
    addCloseButton(element: HTMLModalElement): void;
    /**
     * Set class to parent element (overlay)
     * @param classes class array to add
     */
    addParentClass(...classes: string[]): void;
    /**
     * Set class to modal element (overlay)
     * @param classes class array to add
     */
    addModalClass(...classes: string[]): void;
    /**
     * Append child on modal element
     * @param child DOM element to append
     */
    addChild(child: HTMLElement): void;
    /**
     * Insert html in element, create and append child in modal
     * @param html inner html to add
     */
    addHTML(html: string): void;
    /**
     * Create a Youtube video player with options in parameters
     * @param options your options values
     */
	addYoutubeVideo(options: youtubeOptions): void;
```

---
_Source: https://npm.io/package/@lorndev/modal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
