Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

just-a-modal

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-a-modal

just a modal. simple modal with no dependencies for confirmation and info modals

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

Just A Modal

Sometimes you just need a simple modal, to either get a confirmation before deleting something or to present some info to a user. This is one. You won't get 500 npm modules added to your project with this.

  • zero dependencies
  • overlay automatically added to dim the background
  • small, currently around 16KB
  • easy to get started with and use

Installation

npm install --save just-a-modal

Usage

import React, { useState } from 'react';
import JustAModal from 'just-a-modal';

const [modalInfo, setModalInfo] = useState({
    showModal: false,
    actionID: '',
    action: '',
    config: {}
});

const handleDelete = (id) => {
    let modalInfo = {
        showModal: true,
        actionID: id,
        action: 'deleteBook',
        config: {}
    };

    setModalInfo(modalInfo);
};

const handleCancel = () => {
    let modalInfo = {
        showModal: false,
        actionID: '',
        action: '',
        config: {}
    };

    setModalInfo(modalInfo);
};

const handleAction = (actionID) => {
    if(modalInfo.action === 'deleteBook'){
        //api call to delete book with id of actionID
        //after it completes, close the modal
        handleCancel();
    }
};

<JustAModal modalInfo={modalInfo} handleCancel={handleCancel} handleAction={handleAction} />

with an actionID set:
alt text

set actionID to 0 and modal will change from a delete confirmation to a info box:
alt text alt text

modalInfo
showModalboolean true to show the modal, false to hide it
actionIDid of item to delete. if missing, modal will be be an info modal
actionaction that you want to perform if user clicks ok
configobject, modal config options

config
titledefault for confirmation is "Alert", info is "Info"
bodydefault for confirmation is "Are you sure?", info needs a body
buttonOKTextdefault is "OK"
buttonDeleteTextdefault is "Delete"
buttonCancelTextdefault is "Cancel"

config:{
    title: 'Alert!!',
    buttonDeleteText: 'I am super sure'
}

Keywords

modal

FAQs

Package last updated on 11 May 2021

Did you know?

Socket

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