@ttoss/react-notifications 1.24.55 → 1.24.56

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/react-notifications",
3
- "version": "1.24.55",
3
+ "version": "1.24.56",
4
4
  "description": "ttoss notifications module for React apps.",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -25,20 +25,20 @@
25
25
  "sideEffects": false,
26
26
  "peerDependencies": {
27
27
  "react": ">=16.8.0",
28
- "@ttoss/components": "^2.0.7",
29
- "@ttoss/ui": "^5.0.5",
30
- "@ttoss/react-icons": "^0.4.1"
28
+ "@ttoss/ui": "^5.0.6",
29
+ "@ttoss/components": "^2.0.8",
30
+ "@ttoss/react-icons": "^0.4.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/react": "^18.3.7",
34
34
  "jest": "^29.7.0",
35
35
  "react": "^18.3.1",
36
36
  "tsup": "^8.3.0",
37
- "@ttoss/components": "^2.0.7",
38
- "@ttoss/react-icons": "^0.4.1",
39
- "@ttoss/ui": "^5.0.5",
40
- "@ttoss/test-utils": "^2.1.14",
41
- "@ttoss/config": "^1.32.10"
37
+ "@ttoss/test-utils": "^2.1.15",
38
+ "@ttoss/components": "^2.0.8",
39
+ "@ttoss/ui": "^5.0.6",
40
+ "@ttoss/react-icons": "^0.4.2",
41
+ "@ttoss/config": "^1.33.0"
42
42
  },
43
43
  "keywords": [
44
44
  "React",
package/dist/esm/index.js DELETED
@@ -1,177 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
-
3
- // src/Provider.tsx
4
- import * as React from "react";
5
- import { Flex, InfiniteLinearProgress } from "@ttoss/ui";
6
- import { jsx, jsxs } from "react/jsx-runtime";
7
- var NotificationsContext = React.createContext({
8
- isLoading: false,
9
- setLoading: () => {
10
- return void 0;
11
- },
12
- setNotifications: () => {
13
- return void 0;
14
- }
15
- });
16
- var NotificationsProvider = ({
17
- children,
18
- enableNotificationBox
19
- }) => {
20
- const [isLoading, setLoading] = React.useState(false);
21
- const [notifications, setNotifications] = React.useState();
22
- return /* @__PURE__ */jsxs(NotificationsContext.Provider, {
23
- value: {
24
- isLoading,
25
- setLoading,
26
- setNotifications,
27
- notifications,
28
- enableNotificationBox
29
- },
30
- children: [isLoading && /* @__PURE__ */jsx(Flex, {
31
- sx: {
32
- position: "absolute",
33
- width: "100%",
34
- top: 0
35
- },
36
- children: /* @__PURE__ */jsx(InfiniteLinearProgress, {})
37
- }), children]
38
- });
39
- };
40
- var useNotifications = () => {
41
- const {
42
- isLoading,
43
- setLoading,
44
- notifications,
45
- setNotifications
46
- } = React.useContext(NotificationsContext);
47
- return {
48
- isLoading,
49
- setLoading,
50
- notifications,
51
- setNotifications
52
- };
53
- };
54
-
55
- // src/NotificationsBox.tsx
56
- import * as React2 from "react";
57
- import { Button, Flex as Flex2, Stack } from "@ttoss/ui";
58
- import { jsx as jsx2 } from "react/jsx-runtime";
59
- var NotificationBoxWrapper = ({
60
- direction,
61
- notifications,
62
- children
63
- }) => {
64
- const sx = {
65
- alignItems: "center",
66
- justifyContent: "center",
67
- gap: "md",
68
- marginTop: !notifications || Array.isArray(notifications) && !notifications.length ? 0 : "2xl"
69
- };
70
- return direction === "row" ? /* @__PURE__ */jsx2(Flex2, {
71
- sx,
72
- children
73
- }) : /* @__PURE__ */jsx2(Stack, {
74
- sx,
75
- children
76
- });
77
- };
78
- var resolveNotifications = notifications => {
79
- if (!Array.isArray(notifications)) return notifications;
80
- const keyedNotifications = new Map(notifications.filter(notification => {
81
- return notification.key;
82
- }).map(notification => {
83
- return [notification?.key, notification];
84
- })).values();
85
- const nonKeyedNotifications = notifications.filter(notification => {
86
- return !notification.key;
87
- }).map((notification, index) => {
88
- return {
89
- ...notification,
90
- key: index.toString()
91
- };
92
- });
93
- return Array.from(keyedNotifications).concat(nonKeyedNotifications);
94
- };
95
- var NotificationsBox = ({
96
- direction = "row"
97
- }) => {
98
- const {
99
- setNotifications,
100
- notifications
101
- } = useNotifications();
102
- if (!notifications) {
103
- return null;
104
- }
105
- const renderNotifications = resolveNotifications(notifications);
106
- const ButtonMemoized = React2.memo(({
107
- notification: {
108
- key,
109
- type,
110
- message
111
- }
112
- }) => {
113
- return /* @__PURE__ */jsx2(Button, {
114
- sx: {
115
- backgroundColor: type === "error" ? "danger" : "positive"
116
- },
117
- onClick: () => {
118
- if (Array.isArray(renderNotifications) && renderNotifications.length > 1) {
119
- return setNotifications(renderNotifications.filter(notification => {
120
- return notification.key !== key;
121
- }));
122
- }
123
- return setNotifications(void 0);
124
- },
125
- rightIcon: "close",
126
- leftIcon: type === "error" ? "warning" : void 0,
127
- children: message
128
- });
129
- });
130
- ButtonMemoized.displayName = "ButtonMemoized";
131
- return /* @__PURE__ */jsx2(NotificationBoxWrapper, {
132
- ...{
133
- notifications,
134
- direction
135
- },
136
- children: Array.isArray(renderNotifications) ? renderNotifications.map(notification => {
137
- return /* @__PURE__ */jsx2(ButtonMemoized, {
138
- notification
139
- }, notification.key);
140
- }) : /* @__PURE__ */jsx2(ButtonMemoized, {
141
- notification: renderNotifications
142
- })
143
- });
144
- };
145
-
146
- // src/NotificationsModal.tsx
147
- import { CloseButton } from "@ttoss/ui";
148
- import { Modal } from "@ttoss/components/Modal";
149
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
150
- var NotificationsModal = () => {
151
- const {
152
- notifications,
153
- setNotifications
154
- } = useNotifications();
155
- return /* @__PURE__ */jsxs2(Modal, {
156
- isOpen: !!notifications,
157
- style: {
158
- content: {
159
- minWidth: "30%",
160
- display: "flex",
161
- flexDirection: "column",
162
- alignItems: "center"
163
- }
164
- },
165
- children: [/* @__PURE__ */jsx3(CloseButton, {
166
- sx: {
167
- alignSelf: "flex-end"
168
- },
169
- onClick: () => {
170
- setNotifications(void 0);
171
- }
172
- }), /* @__PURE__ */jsx3(NotificationsBox, {
173
- direction: "column"
174
- })]
175
- });
176
- };
177
- export { NotificationsBox, NotificationsModal, NotificationsProvider, useNotifications };
package/dist/index.d.ts 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";
23
- }) => react_jsx_runtime.JSX.Element | null;
24
-
25
- declare const NotificationsModal: () => react_jsx_runtime.JSX.Element;
26
-
27
- export { NotificationsBox, NotificationsModal, NotificationsProvider, type NotificationsProviderProps, type NotifyParams, useNotifications };