@esitorsunil/new-folder 1.0.0 → 1.0.2

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.
package/README.md CHANGED
@@ -0,0 +1,69 @@
1
+ # React Notifications with Redux Toolkit
2
+
3
+ This project demonstrates how to integrate a notification panel using Redux Toolkit and a custom package `@esitorsunil/new-folder`.
4
+
5
+ ## Setup
6
+
7
+ ### 1. Install dependencies
8
+
9
+ ```bash
10
+ npm install
11
+ Make sure to have your custom package installed:
12
+
13
+ bash
14
+
15
+ npm install @esitorsunil/new-folder
16
+
17
+
18
+ 2. Store Configuration (store/appStore.js)
19
+ Configure your Redux store to include the notifications reducer from the custom package:
20
+
21
+
22
+ import { configureStore } from '@reduxjs/toolkit';
23
+ import { notificationsReducer } from '@esitorsunil/new-folder';
24
+
25
+ export const store = configureStore({
26
+ reducer: {
27
+ notifications: notificationsReducer,
28
+ },
29
+ });
30
+
31
+
32
+ 3. Usage in React App (App.jsx)
33
+ Wrap your app with Redux Provider and import the NotificationsPanel and pushNotification action from the package:
34
+
35
+
36
+ import React from 'react';
37
+ import { Provider, useDispatch } from 'react-redux';
38
+ import { store } from './store/appStore';
39
+ import { NotificationsPanel, pushNotification } from '@esitorsunil/new-folder';
40
+
41
+ function SomeComponent() {
42
+ const dispatch = useDispatch();
43
+
44
+ const handleAddNotification = () => {
45
+ dispatch(pushNotification({
46
+ id: Date.now(),
47
+ type: 'success',
48
+ message: 'Hello from SomeComponent!',
49
+ }));
50
+ };
51
+
52
+ return (
53
+ <div>
54
+ <button onClick={handleAddNotification}>Show Notification</button>
55
+ </div>
56
+ );
57
+ }
58
+
59
+ export default function App() {
60
+ return (
61
+ <Provider store={store}>
62
+ <div>
63
+ <h1>My React App</h1>
64
+ <SomeComponent />
65
+ <NotificationsPanel />
66
+ </div>
67
+ </Provider>
68
+ );
69
+ }
package/dist/index.js CHANGED
@@ -1 +1,27 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ NotificationsPanel: true
8
+ };
9
+ Object.defineProperty(exports, "NotificationsPanel", {
10
+ enumerable: true,
11
+ get: function get() {
12
+ return _NotificationsPanel.NotificationsPanel;
13
+ }
14
+ });
15
+ var _NotificationsPanel = require("./notification/NotificationsPanel");
16
+ var _notificationsSlice = require("./notification/notificationsSlice");
17
+ Object.keys(_notificationsSlice).forEach(function (key) {
18
+ if (key === "default" || key === "__esModule") return;
19
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
+ if (key in exports && exports[key] === _notificationsSlice[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _notificationsSlice[key];
25
+ }
26
+ });
27
+ });
@@ -1 +1,50 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NotificationsPanel = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _reactRedux = require("react-redux");
9
+ var _notificationsSlice = require("./notificationsSlice");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
+ // NotificationsPanel.jsx
12
+
13
+ var NotificationsPanel = exports.NotificationsPanel = function NotificationsPanel() {
14
+ var notifications = (0, _reactRedux.useSelector)(function (state) {
15
+ return state.notifications.items;
16
+ });
17
+ var dispatch = (0, _reactRedux.useDispatch)();
18
+ return /*#__PURE__*/_react["default"].createElement("div", {
19
+ style: {
20
+ position: 'fixed',
21
+ top: 10,
22
+ right: 10,
23
+ zIndex: 1000
24
+ }
25
+ }, notifications.map(function (n) {
26
+ return /*#__PURE__*/_react["default"].createElement("div", {
27
+ key: n.id,
28
+ style: {
29
+ background: n.type === 'error' ? '#f44336' : n.type === 'success' ? '#4caf50' : '#2196f3',
30
+ color: '#fff',
31
+ padding: '10px 15px',
32
+ marginBottom: 8,
33
+ borderRadius: 4,
34
+ minWidth: 200,
35
+ boxShadow: '0 2px 4px rgba(0,0,0,0.3)'
36
+ }
37
+ }, n.message, /*#__PURE__*/_react["default"].createElement("button", {
38
+ onClick: function onClick() {
39
+ return dispatch((0, _notificationsSlice.removeNotification)(n.id));
40
+ },
41
+ style: {
42
+ marginLeft: 10,
43
+ background: 'transparent',
44
+ border: 'none',
45
+ color: '#fff',
46
+ cursor: 'pointer'
47
+ }
48
+ }, "\xD7"));
49
+ }));
50
+ };
@@ -1 +1,32 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeNotification = exports.pushNotification = exports.notificationsReducer = exports.clearNotifications = void 0;
7
+ var _toolkit = require("@reduxjs/toolkit");
8
+ var initialState = {
9
+ items: []
10
+ };
11
+ var notificationsSlice = (0, _toolkit.createSlice)({
12
+ name: 'notifications',
13
+ initialState: initialState,
14
+ reducers: {
15
+ pushNotification: function pushNotification(state, action) {
16
+ state.items.push(action.payload);
17
+ },
18
+ removeNotification: function removeNotification(state, action) {
19
+ state.items = state.items.filter(function (n) {
20
+ return n.id !== action.payload;
21
+ });
22
+ },
23
+ clearNotifications: function clearNotifications(state) {
24
+ state.items = [];
25
+ }
26
+ }
27
+ });
28
+ var _notificationsSlice$a = notificationsSlice.actions,
29
+ pushNotification = exports.pushNotification = _notificationsSlice$a.pushNotification,
30
+ removeNotification = exports.removeNotification = _notificationsSlice$a.removeNotification,
31
+ clearNotifications = exports.clearNotifications = _notificationsSlice$a.clearNotifications;
32
+ var notificationsReducer = exports.notificationsReducer = notificationsSlice.reducer;
package/package.json CHANGED
@@ -1,21 +1,26 @@
1
1
  {
2
2
  "name": "@esitorsunil/new-folder",
3
- "version": "1.0.0",
4
- "main": "index.js",
3
+ "version": "1.0.2",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
5
9
  "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1",
7
- "build": "babel src --out-dir dist --copy-files"
10
+ "build": "babel src --out-dir dist --copy-files"
8
11
  },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC",
12
- "description": "",
13
12
  "dependencies": {
14
13
  "@reduxjs/toolkit": "^1.9.0",
15
14
  "react": ">=17.0.0",
16
15
  "react-dom": ">=17.0.0",
17
16
  "react-redux": "^8.0.0"
18
17
  },
18
+ "peerDependencies": {
19
+ "@reduxjs/toolkit": "^1.9.0",
20
+ "react": ">=17.0.0",
21
+ "react-dom": ">=17.0.0",
22
+ "react-redux": "^8.0.0"
23
+ },
19
24
  "devDependencies": {
20
25
  "@babel/cli": "^7.27.2",
21
26
  "@babel/core": "^7.27.1",
@@ -24,10 +29,10 @@
24
29
  "@babel/preset-react": "^7.27.1",
25
30
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24"
26
31
  },
27
- "peerDependencies": {
28
- "@reduxjs/toolkit": "^1.9.0",
29
- "react": ">=17.0.0",
30
- "react-dom": ">=17.0.0",
31
- "react-redux": "^8.0.0"
32
+ "exports": {
33
+ ".": {
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.js"
36
+ }
32
37
  }
33
38
  }
package/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env", "@babel/preset-react"]
3
- }
package/src/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from './notification/NotificationsPanel';
2
- export * from './notification/notificationsSlice';
@@ -1,47 +0,0 @@
1
- // NotificationsPanel.jsx
2
- import React from 'react';
3
- import { useSelector, useDispatch } from 'react-redux';
4
- import { removeNotification } from './notificationsSlice';
5
-
6
- export const NotificationsPanel = () => {
7
- const notifications = useSelector((state) => state.notifications.items);
8
- const dispatch = useDispatch();
9
-
10
- return (
11
- <div style={{ position: 'fixed', top: 10, right: 10, zIndex: 1000 }}>
12
- {notifications.map(n => (
13
- <div
14
- key={n.id}
15
- style={{
16
- background:
17
- n.type === 'error'
18
- ? '#f44336'
19
- : n.type === 'success'
20
- ? '#4caf50'
21
- : '#2196f3',
22
- color: '#fff',
23
- padding: '10px 15px',
24
- marginBottom: 8,
25
- borderRadius: 4,
26
- minWidth: 200,
27
- boxShadow: '0 2px 4px rgba(0,0,0,0.3)',
28
- }}
29
- >
30
- {n.message}
31
- <button
32
- onClick={() => dispatch(removeNotification(n.id))}
33
- style={{
34
- marginLeft: 10,
35
- background: 'transparent',
36
- border: 'none',
37
- color: '#fff',
38
- cursor: 'pointer',
39
- }}
40
- >
41
- ×
42
- </button>
43
- </div>
44
- ))}
45
- </div>
46
- );
47
- };
@@ -1,24 +0,0 @@
1
- import { createSlice } from '@reduxjs/toolkit';
2
-
3
- const initialState = {
4
- items: [],
5
- };
6
-
7
- const notificationsSlice = createSlice({
8
- name: 'notifications',
9
- initialState,
10
- reducers: {
11
- pushNotification: (state, action) => {
12
- state.items.push(action.payload);
13
- },
14
- removeNotification: (state, action) => {
15
- state.items = state.items.filter(n => n.id !== action.payload);
16
- },
17
- clearNotifications: (state) => {
18
- state.items = [];
19
- },
20
- },
21
- });
22
-
23
- export const { pushNotification, removeNotification, clearNotifications } = notificationsSlice.actions;
24
- export const notificationsReducer = notificationsSlice.reducer;