@ttoss/react-notifications 1.24.12 → 1.24.13

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/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@ttoss/react-notifications",
3
- "version": "1.24.12",
3
+ "version": "1.24.13",
4
4
  "description": "ttoss notifications module for React apps.",
5
- "license": "UNLICENSED",
6
5
  "author": "ttoss",
7
6
  "contributors": [
8
7
  "Pedro Arantes <pedro@arantespp.com> (https://arantespp.com/contact)"
@@ -12,8 +11,8 @@
12
11
  "url": "https://github.com/ttoss/ttoss.git",
13
12
  "directory": "packages/react-notifications"
14
13
  },
15
- "main": "dist/index.js",
16
- "module": "dist/esm/index.js",
14
+ "type": "module",
15
+ "exports": "./dist/esm/index.js",
17
16
  "files": [
18
17
  "dist",
19
18
  "src"
@@ -22,7 +21,7 @@
22
21
  "typings": "dist/index.d.ts",
23
22
  "peerDependencies": {
24
23
  "react": ">=16.8.0",
25
- "@ttoss/components": "^1.29.21",
24
+ "@ttoss/components": "^1.29.22",
26
25
  "@ttoss/react-icons": "^0.2.0",
27
26
  "@ttoss/ui": "^3.1.6"
28
27
  },
@@ -31,7 +30,7 @@
31
30
  "jest": "^29.7.0",
32
31
  "react": "^18.2.0",
33
32
  "tsup": "^7.2.0",
34
- "@ttoss/components": "^1.29.21",
33
+ "@ttoss/components": "^1.29.22",
35
34
  "@ttoss/config": "^1.31.0",
36
35
  "@ttoss/test-utils": "^1.24.0"
37
36
  },
@@ -39,6 +38,9 @@
39
38
  "React",
40
39
  "notifications"
41
40
  ],
41
+ "engines": {
42
+ "node": ">=16"
43
+ },
42
44
  "publishConfig": {
43
45
  "access": "public",
44
46
  "provenance": true
package/dist/index.d.mts DELETED
@@ -1,27 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as React from 'react';
3
-
4
- type NotifyParams = {
5
- key?: string;
6
- message: 'string' | React.ReactNode;
7
- type: 'success' | 'error' | 'warning' | 'info';
8
- };
9
- type NotificationsProviderProps = {
10
- children: React.ReactNode;
11
- enableNotificationBox?: boolean;
12
- };
13
- declare const NotificationsProvider: ({ children, enableNotificationBox, }: NotificationsProviderProps) => react_jsx_runtime.JSX.Element;
14
- declare const useNotifications: () => {
15
- isLoading: boolean;
16
- setLoading: (arg: boolean) => void;
17
- notifications: NotifyParams | NotifyParams[] | undefined;
18
- setNotifications: (args: NotifyParams | NotifyParams[] | undefined) => void;
19
- };
20
-
21
- declare const NotificationsBox: ({ direction, }: {
22
- direction?: "row" | "column" | undefined;
23
- }) => react_jsx_runtime.JSX.Element | null;
24
-
25
- declare const NotificationsModal: () => react_jsx_runtime.JSX.Element;
26
-
27
- export { NotificationsBox, NotificationsModal, NotificationsProvider, NotificationsProviderProps, NotifyParams, useNotifications };
package/dist/index.js DELETED
@@ -1,228 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- "use strict";
3
-
4
- var __create = Object.create;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __export = (target, all) => {
11
- for (var name in all) __defProp(target, name, {
12
- get: all[name],
13
- enumerable: true
14
- });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
- get: () => from[key],
20
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
- });
22
- }
23
- return to;
24
- };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
31
- value: mod,
32
- enumerable: true
33
- }) : target, mod));
34
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
35
- value: true
36
- }), mod);
37
-
38
- // src/index.ts
39
- var src_exports = {};
40
- __export(src_exports, {
41
- NotificationsBox: () => NotificationsBox,
42
- NotificationsModal: () => NotificationsModal,
43
- NotificationsProvider: () => NotificationsProvider,
44
- useNotifications: () => useNotifications
45
- });
46
- module.exports = __toCommonJS(src_exports);
47
-
48
- // src/Provider.tsx
49
- var React = __toESM(require("react"));
50
- var import_ui = require("@ttoss/ui");
51
- var import_jsx_runtime = require("react/jsx-runtime");
52
- var NotificationsContext = React.createContext({
53
- isLoading: false,
54
- setLoading: () => {
55
- return void 0;
56
- },
57
- setNotifications: () => {
58
- return void 0;
59
- }
60
- });
61
- var NotificationsProvider = ({
62
- children,
63
- enableNotificationBox
64
- }) => {
65
- const [isLoading, setLoading] = React.useState(false);
66
- const [notifications, setNotifications] = React.useState();
67
- return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(NotificationsContext.Provider, {
68
- value: {
69
- isLoading,
70
- setLoading,
71
- setNotifications,
72
- notifications,
73
- enableNotificationBox
74
- },
75
- children: [isLoading && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.Flex, {
76
- sx: {
77
- position: "absolute",
78
- width: "100%",
79
- top: 0
80
- },
81
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ui.InfiniteLinearProgress, {})
82
- }), children]
83
- });
84
- };
85
- var useNotifications = () => {
86
- const {
87
- isLoading,
88
- setLoading,
89
- notifications,
90
- setNotifications
91
- } = React.useContext(NotificationsContext);
92
- return {
93
- isLoading,
94
- setLoading,
95
- notifications,
96
- setNotifications
97
- };
98
- };
99
-
100
- // src/NotificationsBox.tsx
101
- var React2 = __toESM(require("react"));
102
- var import_ui2 = require("@ttoss/ui");
103
- var import_jsx_runtime2 = require("react/jsx-runtime");
104
- var NotificationBoxWrapper = ({
105
- direction,
106
- notifications,
107
- children
108
- }) => {
109
- const sx = {
110
- alignItems: "center",
111
- justifyContent: "center",
112
- gap: "md",
113
- marginTop: !notifications || Array.isArray(notifications) && !notifications.length ? 0 : "2xl"
114
- };
115
- return direction === "row" ? /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.Flex, {
116
- sx,
117
- children
118
- }) : /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.Stack, {
119
- sx,
120
- children
121
- });
122
- };
123
- var resolveNotifications = notifications => {
124
- if (!Array.isArray(notifications)) return notifications;
125
- const keyedNotifications = new Map(notifications.filter(notification => {
126
- return notification.key;
127
- }).map(notification => {
128
- return [notification?.key, notification];
129
- })).values();
130
- const nonKeyedNotifications = notifications.filter(notification => {
131
- return !notification.key;
132
- }).map((notification, index) => {
133
- return {
134
- ...notification,
135
- key: index.toString()
136
- };
137
- });
138
- return Array.from(keyedNotifications).concat(nonKeyedNotifications);
139
- };
140
- var NotificationsBox = ({
141
- direction = "row"
142
- }) => {
143
- const {
144
- setNotifications,
145
- notifications
146
- } = useNotifications();
147
- if (!notifications) {
148
- return null;
149
- }
150
- const renderNotifications = resolveNotifications(notifications);
151
- const ButtonMemoized = React2.memo(({
152
- notification: {
153
- key,
154
- type,
155
- message
156
- }
157
- }) => {
158
- return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui2.Button, {
159
- sx: {
160
- backgroundColor: type === "error" ? "danger" : "positive"
161
- },
162
- onClick: () => {
163
- if (Array.isArray(renderNotifications) && renderNotifications.length > 1) {
164
- return setNotifications(renderNotifications.filter(notification => {
165
- return notification.key !== key;
166
- }));
167
- }
168
- return setNotifications(void 0);
169
- },
170
- rightIcon: "close",
171
- leftIcon: type === "error" ? "warning" : void 0,
172
- children: message
173
- });
174
- });
175
- ButtonMemoized.displayName = "ButtonMemoized";
176
- return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(NotificationBoxWrapper, {
177
- ...{
178
- notifications,
179
- direction
180
- },
181
- children: Array.isArray(renderNotifications) ? renderNotifications.map(notification => {
182
- return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(ButtonMemoized, {
183
- notification
184
- }, notification.key);
185
- }) : /* @__PURE__ */(0, import_jsx_runtime2.jsx)(ButtonMemoized, {
186
- notification: renderNotifications
187
- })
188
- });
189
- };
190
-
191
- // src/NotificationsModal.tsx
192
- var import_ui3 = require("@ttoss/ui");
193
- var import_components = require("@ttoss/components");
194
- var import_jsx_runtime3 = require("react/jsx-runtime");
195
- var NotificationsModal = () => {
196
- const {
197
- notifications,
198
- setNotifications
199
- } = useNotifications();
200
- return /* @__PURE__ */(0, import_jsx_runtime3.jsxs)(import_components.Modal, {
201
- isOpen: !!notifications,
202
- style: {
203
- content: {
204
- minWidth: "30%",
205
- display: "flex",
206
- flexDirection: "column",
207
- alignItems: "center"
208
- }
209
- },
210
- children: [/* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_ui3.CloseButton, {
211
- sx: {
212
- alignSelf: "flex-end"
213
- },
214
- onClick: () => {
215
- setNotifications(void 0);
216
- }
217
- }), /* @__PURE__ */(0, import_jsx_runtime3.jsx)(NotificationsBox, {
218
- direction: "column"
219
- })]
220
- });
221
- };
222
- // Annotate the CommonJS export names for ESM import in node:
223
- 0 && (module.exports = {
224
- NotificationsBox,
225
- NotificationsModal,
226
- NotificationsProvider,
227
- useNotifications
228
- });