@4i/modal-manager 1.0.9 → 1.0.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +149 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4i/modal-manager",
3
- "version": "1.0.9",
3
+ "version": "1.0.101",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/readme.md ADDED
@@ -0,0 +1,149 @@
1
+ # Modal manager
2
+
3
+ [![npm version](https://badge.fury.io/js/%404i%2Fmodal-manager.svg)](https://badge.fury.io/js/%404i%2Fmodal-manager)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Usage in Managing Multiple Modals, Popups, Notifications
7
+
8
+ This package simplifies the management of multiple modals, popups, notifications, and similar UI elements within a project. It achieves this by leveraging events, maintaining a centralized list of modals, and assigning actions to them.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @4i/modal-manager
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ #### Define Modal Actions:
19
+
20
+ In your project, define modal actions as keys in the modalAction object. Each key represents a specific modal or UI element.
21
+
22
+ ```javascript
23
+ export const modalAction = {
24
+ MODAL_PROMPT: "modal-prompt",
25
+ // Additional modal actions...
26
+ };
27
+ ```
28
+
29
+ #### Create Modal List:
30
+
31
+ Create a list of modals in the list object, where keys are modal actions, and values are the corresponding modal components.
32
+
33
+ ```javascript
34
+ const list = {
35
+ [modalAction.MODAL_PROMPT]: ModalPrompts,
36
+ // Additional modals...
37
+ };
38
+ ```
39
+
40
+ #### Call modals
41
+
42
+ Call modals in your components by invoking modal.call with the desired modal action.
43
+
44
+ ```javascript
45
+ modal.call(modalAction.MODAL_PROMPT, {
46
+ // Recieve props in your modal component
47
+ title: "Modal title",
48
+ content: "Modal content",
49
+ });
50
+ ```
51
+
52
+ #### Extensibility
53
+
54
+ If desired, you can inherit from the Manager class to create your own classes for handling custom notifications, popups, and more. And then pass your custom class to the CustomProvider component using ModalProvider as an example
55
+
56
+ ```javascript
57
+ import { Manager } from "@4i/modal-manager";
58
+
59
+ class CustomManager extends Manager {
60
+ // Custom methods and logic here
61
+ }
62
+
63
+ const customManager = new CustomManager();
64
+ ```
65
+
66
+ ### index.js
67
+
68
+ ```javascript
69
+ import React from "react";
70
+ import ReactDOM from "react-dom/client";
71
+ import "./index.css";
72
+ import App from "./App";
73
+ import ModalPrompts from "./modals/prompt";
74
+ import { ModalProvider } from "@4i/modal-manager";
75
+ import "@4i/modal-manager/src/styles.css";
76
+
77
+ const root = ReactDOM.createRoot(document.getElementById("root"));
78
+
79
+ // Define your modal actions here
80
+ export const modalAction = {
81
+ MODAL_PROMPT: "modal-prompt",
82
+ };
83
+
84
+ // Your modal list should be an object with modal names
85
+ // as keys and modal components as values.
86
+ const list = {
87
+ [modalAction.MODAL_PROMPT]: ModalPrompts,
88
+ };
89
+
90
+ root.render(
91
+ <React.StrictMode>
92
+ <App />
93
+ <ModalProvider modalList={list} />
94
+ </React.StrictMode>
95
+ );
96
+ ```
97
+
98
+ ### App.js
99
+
100
+ ```javascript
101
+ import { modalAction } from ".";
102
+ import "./App.css";
103
+ import { modal } from "@4i/modal-manager";
104
+
105
+ const App = () => {
106
+ const handleClick = () => {
107
+ // Call the modal by its action name
108
+ modal.call(modalAction.MODAL_PROMPT, {
109
+ // You can pass any props to your modal component
110
+ title: "Modal title",
111
+ content: "Modal content",
112
+ });
113
+ };
114
+
115
+ return (
116
+ <div className="app">
117
+ <button
118
+ onClick={handleClick}
119
+ className="w-[200px] h-[80px] mx-auto bg-teal-800 text-white"
120
+ >
121
+ Click to call modal
122
+ </button>
123
+ </div>
124
+ );
125
+ };
126
+
127
+ export default App;
128
+ ```
129
+
130
+ ### ModalPrompts.js
131
+
132
+ ```javascript
133
+ import React from "react";
134
+
135
+ // Get props
136
+ const ModalPrompts = ({ title, content }) => {
137
+ return (
138
+ <div className="w-[400px] h-[300px] bg-slate-50 p-[24px] flex flex-col justify-center items-center">
139
+ <h1>{title}</h1>
140
+ <p>{content}</p>
141
+ <button>Close</button>
142
+ </div>
143
+ );
144
+ };
145
+
146
+ export default ModalPrompts;
147
+ ```
148
+
149
+ Feel free to tailor this documentation to better fit your package's specific features and capabilities.