# pure_js_modal

> Pure javascript modal librairy

Latest version **1.0.0** (published 2020-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install pure_js_modal
pnpm add pure_js_modal
yarn add pure_js_modal
bun add pure_js_modal
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-06-07 |
| First published | 2020-04-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jbristhuille |
| Maintainers | jbristhuille |
| Keywords | modal, pure, js, javascript, html |

## Links

- npm: https://www.npmjs.com/package/pure_js_modal
- Repository: https://github.com/Jbristhuille/pure_js_modal
- Homepage: https://github.com/Jbristhuille/pure_js_modal#readme
- Issues: https://github.com/Jbristhuille/pure_js_modal/issues
- npm.io page: https://npm.io/package/pure_js_modal

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-06-07
- 0.1.0 — 2020-04-14

## README

# pure_js_modal v.1.0.0
Modal library in pure Javascript.

## Summary
1. [Install](#install)  
2. [How to use](#how-to-use)
	
	2.1. [Options](#options)
	
	2.2. [Functions](#functions)
	
3. [Customize](#customize)

	3.1. [HTML structure](#html-structure)
	
	3.2. [Style](#style)
	
4. [Build](#build)
5. [Future versions](#future-versions)
6. [Author](#author)
7. [License](#license)

## Install

You can install **pure_js_modal** by clone this repo or you can use **npm**.

```
npm install pure_js_modal --save
```

Import **pure_js_modal.min.js** and **pure_js_modal.min.css** in your project.

```html
<link rel="stylesheet" href="path/to/style/pure_js_modal.min.css">
<script src="path/to/script/pure_js_modal.min.js"></script>
```

## How to use

To use **pure_js_modal** you can simply bind open function to a button (see example below):

```html
<button onclick="clickEvent()">Open modal</button>

<script type="text/javascript">
    function clickEvent() { // Your open modal function
        var options = { // See avaible options below
            width: "50%",
            content: "<p>Hello world</p>"
        };
    
        ft_openModal(options); // Generate modal by passed options
    }
</script>
```

### Options

* **width** (_Number_): Modal width, can be all valid css unit (px, %, em) (default: "60%"")
* **z-index** (_Number)_: Modal z-index (out-zone z-index = z-index -1) (default: 999)
* **header** (_Boolean_): Generate header or not (default: true)
* **title** (_String_): Modal title, display in header (default: "New modal")
* **animation** (_Boolean_): Enable or not fade-in / fade-out animations (default: false)
* **animation-time** (_String_): Animation duration in seconds (default: 1)
* **custom-class** (_String_): Modal custom class
* **responsive** (_Number_): Activation size for responsive mode (defaul: 375)
* **content** (_String_): Modal body content (default: ```<p>Hello <strong>world</strong></p>```)
```javascript
/*
* Any valid html can be used
*/

// Example:
content: "<p>Hello <strong style='red'>world</strong></p>"
```
* **footer** (_Boolean_): Generate footer or not (default: true)
* **footer-content** (_Object Array_): Footer content, generate button for footer
```javascript
"footer-content": [{
    label: String, // Button name, required
    callback: Function // Callback function's name (without parenthesis), required
}, {...}]
``` 
* **out-zone** (_Boolean_): Generate out zone or not (default: true)
* **open** (_Function_): Triggered on modal open
* **close** (_Function_): Triggered on modal close

Options example: 

```javascript
var options = {
    width: "60%",
    "z-index": 10,
    header: true,
    title: "Hello world",
    animation: true,
    "animation-time": "0.5",
    "custom-class": "custom",
    content:    "<p>Lorem Ipsum...</p>"+
                "<button>Hello</button>"+
                "<a href='#>World</a>"
    }],
    footer: true,
    "footer-content": [{
        label: "Save",
        callback: ft_closeModal
    }],
    "out-zone": true,
    open: function() {
        console.log("Open modal");
    },
    close: function() {
        console.log("Close modal");
    }
}
```

### Functions

* **ft_openModal(options)**: Generate modal with provided options
* **ft_closeModal()**: Close open modal

## Customize

### HTML structure

Modal html is define as following:

```html
<!-- Modal -->
<div class="pure-modal">
    <!-- Modal header -->
    <div class="pure-modal-header">
        <h2 class="pure-modal-title">Title</h2>
    </div>
    <!---->
    
    <!-- Modal body -->
    <div class="pure-modal-body">
        <!-- Injected content -->
    </div>
    <!---->
    
    <!-- Modal footer -->
    <div class="pure-modal-footer">
        <button class="pure-modal-button">Button</button>
    </div>
    <!---->
</div>
<!---->

 <!-- Background zone, quit on click -->
<div class="pure-modal-out"></div>
<!---->

```

### Style

You can overwrite style with these following class:

* **pure-modal**: Main modal div, contain all modal sub-div.
```css
.pure-modal {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
	background: #fff;
	border: solid 1px rgb(25, 25, 25);
}
```
* **pure-modal-header**: Modal header
```css
.pure-modal-header {
	padding: 10px;
	border-bottom: solid 1px rgb(25, 25, 25);
}
```
* **pure-modal-title**: Title in header (no style by default)
* **pure-modal-body**: Modal body
```css
.pure-modal-body {
	padding: 10px;
}
```
* **pure-modal-footer**: Modal footer
```css
.pure-modal-footer {
	padding: 10px;
	border-top: solid 1px rgb(39, 39, 39);
	display: flex;
	align-items: center;
	justify-content: flex-end;
}
``` 
* **pure-modal-button**: Modal footer buttons (no style by default)
* **pure-modal-out**: Modal background, close modal on click
 ```css
.pure-modal-out {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.5);
}
```

## Build

If you want modify **pure_js_modal**, you can update sources files and build dist files with the following command.

```
npm run build
```

## Changelog

### 1.0.0 - (07/06/2020)

#### Changed
* [#3](https://github.com/Jbristhuille/pure_js_modal/issues/3) - Adding custom class to options
* [#4](https://github.com/Jbristhuille/pure_js_modal/issues/4) - Adding fade-if / fade-out animation
* [#5](https://github.com/Jbristhuille/pure_js_modal/issues/5) - Form generation removed
* [#6](https://github.com/Jbristhuille/pure_js_modal/issues/6) - Adding open/close events

### v0.1.0 - (14/04/2020)
* First version

## Authors

**Jbristhuille** - [https://github.com/Jbristhuille](https://github.com/Jbristhuille)

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

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