@4i/modal-manager 1.0.9 → 1.0.10

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 +151 -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.10",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/readme.md ADDED
@@ -0,0 +1,151 @@
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
+
58
+ ```javascript
59
+ import { Manager } from "@4i/modal-manager";
60
+
61
+ class CustomManager extends Manager {
62
+ // Custom methods and logic here
63
+ }
64
+
65
+ const customManager = new CustomManager();
66
+ ````
67
+
68
+ ### index.js
69
+
70
+ ```javascript
71
+ import React from "react";
72
+ import ReactDOM from "react-dom/client";
73
+ import "./index.css";
74
+ import App from "./App";
75
+ import ModalPrompts from "./modals/prompt";
76
+ import { ModalProvider } from "@4i/modal-manager";
77
+ import "@4i/modal-manager/src/styles.css";
78
+
79
+ const root = ReactDOM.createRoot(document.getElementById("root"));
80
+
81
+ // Define your modal actions here
82
+ export const modalAction = {
83
+ MODAL_PROMPT: "modal-prompt",
84
+ };
85
+
86
+ // Your modal list should be an object with modal names
87
+ // as keys and modal components as values.
88
+ const list = {
89
+ [modalAction.MODAL_PROMPT]: ModalPrompts,
90
+ };
91
+
92
+ root.render(
93
+ <React.StrictMode>
94
+ <App />
95
+ <ModalProvider modalList={list} />
96
+ </React.StrictMode>
97
+ );
98
+ ```
99
+
100
+ ### App.js
101
+
102
+ ```javascript
103
+ import { modalAction } from ".";
104
+ import "./App.css";
105
+ import { modal } from "@4i/modal-manager";
106
+
107
+ const App = () => {
108
+ const handleClick = () => {
109
+ // Call the modal by its action name
110
+ modal.call(modalAction.MODAL_PROMPT, {
111
+ // You can pass any props to your modal component
112
+ title: "Modal title",
113
+ content: "Modal content",
114
+ });
115
+ };
116
+
117
+ return (
118
+ <div className="app">
119
+ <button
120
+ onClick={handleClick}
121
+ className="w-[200px] h-[80px] mx-auto bg-teal-800 text-white"
122
+ >
123
+ Click to call modal
124
+ </button>
125
+ </div>
126
+ );
127
+ };
128
+
129
+ export default App;
130
+ ```
131
+
132
+ ### ModalPrompts.js
133
+
134
+ ```javascript
135
+ import React from "react";
136
+
137
+ // Get props
138
+ const ModalPrompts = ({ title, content }) => {
139
+ return (
140
+ <div className="w-[400px] h-[300px] bg-slate-50 p-[24px] flex flex-col justify-center items-center">
141
+ <h1>{title}</h1>
142
+ <p>{content}</p>
143
+ <button>Close</button>
144
+ </div>
145
+ );
146
+ };
147
+
148
+ export default ModalPrompts;
149
+ ```
150
+
151
+ Feel free to tailor this documentation to better fit your package's specific features and capabilities.