Socket
Socket
Sign inDemoInstall

@lemonadejs/modal

Package Overview
Dependencies
1
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @lemonadejs/modal

LemonadeJS modal is a JavaScript component to create floating modals.


Version published
Maintainers
2
Install size
140 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 05 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc