2.8.1 • Published 1 month ago

@lemonadejs/modal v2.8.1

Weekly downloads
-
License
-
Repository
-
Last release
1 month ago

LemonadeJS Modal

Official website and documentation is here

Compatible with Vanilla JavaScript, LemonadeJS, React, Vue or Angular.

The LemonadeJS JavaScript Modal is a responsive and reactive component that creates floating modals. With its flexible settings, users can easily configure draggability, closability, and resizability according to their needs.

Features

  • Lightweight: The JavaScript Modal is only about 4 KBytes;
  • Reactive: Any changes to the underlying data are automatically applied to the HTML, making it easy to keep your grid up-to-date;
  • Integration: It can be used as a standalone library or integrated with any modern framework;

Getting Started

You can install using NPM or using directly from a CDN.

npm Installation

To install it in your project using npm, run the following command:

$ npm install @lemonadejs/modal

CDN

To use modal via a CDN, include the following script tags in your HTML file:

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/index.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/style.min.css" />

Usage

Declarative - Quick example with Lemonade

import lemonade from 'lemonadejs'
import Modal from '@lemonadejs/modal';
import '@lemonadejs/modal/dist/style.css';

export default function App() {
    const self = this;

    self.toggle = function () {
        self.modalRef.closed = !self.modalRef.closed
    }

    return `<>
        <Modal :center="true" :width="400" :height="200" title="My window modal" :ref="self.modalRef">
            <div style="display: flex; flex-direction: column; justify-content: center; padding: 10px;">
                <p>Quick example!</p>
                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...</div>
            </div>
        </Modal>
        <input type="button" value="Toggle Modal" id="button" onclick="self.toggle" />        
    </>`
}

Quick example with React

import React, { useRef } from 'react';
import Modal from '@lemonadejs/modal/dist/react';
import '@lemonadejs/modal/dist/style.css';

export default function App() {
    const modal = useRef();

    const toggle = () => {
        modal.current.closed = !modal.current.closed;
    };

    return (
        <div>
            <Modal center={true} width={400} height={200} title="My window modal" ref={modal}>
            <div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', padding: '10px' }}>
                <p>Quick example!</p>
                <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...</div>
            </div>
            </Modal>
            <input type="button" value="Toggle Modal" id="button" onClick={toggle} />
        </div>
    );
}

Quick example with Vue

<template>
    <Modal ref='modal' :center="true" :width="400" :height="200" title="My window modal" >
     <div style="display: flex; flex-direction: column; justify-content: center; padding: 10px;">
       <p>Quick example!</p>
       <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...</div>
     </div>
    </Modal>
     <input type="button" value="Toggle Modal" id="button" @click="toggleModal" />
 </template>
 <script>
 import Modal from '@lemonadejs/modal/dist/vue';
 import '@lemonadejs/modal/dist/style.css'
 
 export default {
     name: 'App',
     components: {
         Modal,
     },
     methods: {
     toggleModal() {
        console.log(this.$refs.modal);
       this.$refs.modal.current.closed = !this.$refs.modal.current.closed;
     }
   }
 };
 </script>

Programmatical - Quick example with Javascript

<html>
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/index.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/modal/dist/style.min.css" />

<div id="root">
    <div style="display: flex; flex-direction: column; justify-content: center; padding: 10px;">
        <p>Quick example!</p>
        <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor...</div>
    </div>
</div>
<input type="button" value="Toggle Modal" id="button" />

<script>
const modal = Modal(document.getElementById("root"), {
    width: 400,
    height: 200,
    title: "My window modal",
    closed: true,
    center: true,
});
button.addEventListener('click', () => {
    console.log(modal.closed)
    modal.closed = !modal.closed;
});
</script>
</html>

Configuration

You can configure things such as position, size, and functionalities.

Settings

AttributeTypeDescription
title?StringThe header title of the modal. If empty, the header will be not displayed.
height?NumberThe height of the modal in pixels.
width?NumberThe width of the modal in pixels.
top?NumberThe vertical position of the modal within its window in pixels.
left?NumberThe horizontal position of the modal within its window in pixels.
draggable?BooleanDetermines if the modal can be dragged. Default: false.
resizable?BooleanDetermines if the modal can be resized. Default: false.
closed?BooleanControls the open and close state of the modal. Default: false.
closable?BooleanDisables the ability to close the modal. Default: false.
center?BooleanEnables rendering the modal in the center of its window. Default: false.
url?StringThe URL from which to fetch and render content.
auto-close?BooleanClose the modal when it loses the focus. Default: false.
auto-adjust?BooleanEnsures modal will be visible on screen. Default: false.
backdrop?BooleanEnables the backdrop when the modal is opened.
minimizable?BooleanModal can be minimized. Default: false.
minimized?BooleanCurrent minimized state of the modal.
position?StringModal is automatic align during initialization.
title?StringTitle of the modal.
responsive?BooleanEnables responsive mode. Default: true.
layers?BooleanBring to front on focus.
focus?BooleanFocus on the modal when open it. Default: true.
overflow?BooleanCreate scroll when the content is larger than the modal. Default: false.

Events

EventDescription
onclose?Called when modal closes.
onopen?Called when modal opens.

License

The LemonadeJS Modal is released under the MIT.

Other Tools

2.8.1

1 month ago

2.8.0

2 months ago

2.7.2

4 months ago

2.7.0

4 months ago

2.6.1

4 months ago

2.6.0

4 months ago

2.7.1

4 months ago

2.5.0

5 months ago

2.4.10

5 months ago

2.4.9

5 months ago

2.4.6

5 months ago

2.4.5

5 months ago

2.4.3

5 months ago

2.4.2

5 months ago

2.4.4

5 months ago

2.3.0

7 months ago

2.2.1

8 months ago

2.2.0

8 months ago

2.1.1

8 months ago

2.0.2

10 months ago

2.4.1

5 months ago

2.3.2

7 months ago

2.4.0

5 months ago

2.3.1

7 months ago

2.0.4

10 months ago

2.3.3

7 months ago

2.3.6

5 months ago

2.3.5

5 months ago

2.1.0

8 months ago

2.0.1

10 months ago

1.2.0

2 years ago