1.1.2 • Published 4 years ago
just-a-modal v1.1.2
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-modalUsage
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:

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

| modalInfo | |
|---|---|
| showModal | boolean true to show the modal, false to hide it |
| actionID | id of item to delete. if missing, modal will be be an info modal |
| action | action that you want to perform if user clicks ok |
| config | object, modal config options |
| config | |
|---|---|
| title | default for confirmation is "Alert", info is "Info" |
| body | default for confirmation is "Are you sure?", info needs a body |
| buttonOKText | default is "OK" |
| buttonDeleteText | default is "Delete" |
| buttonCancelText | default is "Cancel" |
config:{
title: 'Alert!!',
buttonDeleteText: 'I am super sure'
}1.1.2
4 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.25
5 years ago
1.0.24
5 years ago
1.0.22
5 years ago
1.0.23
5 years ago
1.0.19
5 years ago
1.0.21
5 years ago
1.0.20
5 years ago
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
5 years ago
1.0.12
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago