@ttoss/react-notifications 2.1.28 → 2.2.0
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 +33 -0
- package/dist/esm/index.js +25 -11
- package/dist/index.d.ts +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -169,6 +169,39 @@ const Component = () => {
|
|
|
169
169
|
};
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
+
### NotificationsHeader
|
|
173
|
+
|
|
174
|
+
You can use `NotificationsHeader` to display notifications with `viewType: 'header'` in a specific place, such as your application's header. Only notifications with `viewType: 'header'` will be shown by this component.
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
import {
|
|
178
|
+
NotificationsHeader,
|
|
179
|
+
useNotifications,
|
|
180
|
+
} from '@ttoss/react-notifications';
|
|
181
|
+
import { Box, Button } from '@ttoss/ui';
|
|
182
|
+
|
|
183
|
+
const Header = () => {
|
|
184
|
+
const { addNotification } = useNotifications();
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<Box>
|
|
188
|
+
<NotificationsHeader />
|
|
189
|
+
<Button
|
|
190
|
+
onClick={() =>
|
|
191
|
+
addNotification({
|
|
192
|
+
message: "I'm a header notification",
|
|
193
|
+
type: 'info',
|
|
194
|
+
viewType: 'header',
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
>
|
|
198
|
+
Show Header Notification
|
|
199
|
+
</Button>
|
|
200
|
+
</Box>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
```
|
|
204
|
+
|
|
172
205
|
#### Recommendation
|
|
173
206
|
|
|
174
207
|
"You can place the `NotificationsBox` component at the root of your application to handle notifications rendering automatically, eliminating the need to manage it manually elsewhere. If you need a specific `NotificationsBox`, simply render the `NotificationsBox` in the desired location and use the `boxId` property to differentiate it."
|
package/dist/esm/index.js
CHANGED
|
@@ -9,10 +9,24 @@ import { toast, ToastContainer } from "@ttoss/components/Toast";
|
|
|
9
9
|
import { Flex, InfiniteLinearProgress } from "@ttoss/ui";
|
|
10
10
|
import * as React from "react";
|
|
11
11
|
|
|
12
|
+
// src/NotificationsHeader.tsx
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
var NotificationsHeader = () => {
|
|
15
|
+
const {
|
|
16
|
+
notifications
|
|
17
|
+
} = useNotifications();
|
|
18
|
+
const headerNotifications = notifications?.filter(notification => {
|
|
19
|
+
return notification.viewType === "header";
|
|
20
|
+
});
|
|
21
|
+
return /* @__PURE__ */jsx(NotificationsBox, {
|
|
22
|
+
notifications: headerNotifications
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
12
26
|
// src/NotificationsModal.tsx
|
|
13
27
|
import { Modal } from "@ttoss/components/Modal";
|
|
14
28
|
import { CloseButton } from "@ttoss/ui";
|
|
15
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
16
30
|
var NotificationsModal = () => {
|
|
17
31
|
const {
|
|
18
32
|
notifications,
|
|
@@ -37,7 +51,7 @@ var NotificationsModal = () => {
|
|
|
37
51
|
gap: "4"
|
|
38
52
|
}
|
|
39
53
|
},
|
|
40
|
-
children: [/* @__PURE__ */
|
|
54
|
+
children: [/* @__PURE__ */jsx2(CloseButton, {
|
|
41
55
|
"aria-label": "Close",
|
|
42
56
|
sx: {
|
|
43
57
|
alignSelf: "flex-end"
|
|
@@ -45,14 +59,14 @@ var NotificationsModal = () => {
|
|
|
45
59
|
onClick: () => {
|
|
46
60
|
clearNotifications();
|
|
47
61
|
}
|
|
48
|
-
}), /* @__PURE__ */
|
|
62
|
+
}), /* @__PURE__ */jsx2(NotificationsBox, {
|
|
49
63
|
notifications: modalNotifications
|
|
50
64
|
})]
|
|
51
65
|
});
|
|
52
66
|
};
|
|
53
67
|
|
|
54
68
|
// src/Provider.tsx
|
|
55
|
-
import { jsx as
|
|
69
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
56
70
|
var NotificationsContext = React.createContext({
|
|
57
71
|
isLoading: false,
|
|
58
72
|
setLoading: () => {
|
|
@@ -142,16 +156,16 @@ var NotificationsProvider = props => {
|
|
|
142
156
|
clearNotifications,
|
|
143
157
|
defaultViewType: props.defaultViewType || "box"
|
|
144
158
|
},
|
|
145
|
-
children: [/* @__PURE__ */
|
|
159
|
+
children: [/* @__PURE__ */jsx3(ToastContainer, {
|
|
146
160
|
...props.toast
|
|
147
|
-
}), /* @__PURE__ */
|
|
161
|
+
}), /* @__PURE__ */jsx3(NotificationsModal, {}), isLoading && /* @__PURE__ */jsx3(Flex, {
|
|
148
162
|
sx: {
|
|
149
163
|
position: "absolute",
|
|
150
164
|
width: "100%",
|
|
151
165
|
top: 0
|
|
152
166
|
},
|
|
153
|
-
children: /* @__PURE__ */
|
|
154
|
-
}), props.children]
|
|
167
|
+
children: /* @__PURE__ */jsx3(InfiniteLinearProgress, {})
|
|
168
|
+
}), /* @__PURE__ */jsx3(NotificationsHeader, {}), props.children]
|
|
155
169
|
});
|
|
156
170
|
};
|
|
157
171
|
var useNotifications = () => {
|
|
@@ -159,7 +173,7 @@ var useNotifications = () => {
|
|
|
159
173
|
};
|
|
160
174
|
|
|
161
175
|
// src/NotificationsBox.tsx
|
|
162
|
-
import { jsx as
|
|
176
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
163
177
|
var NotificationsBox = props => {
|
|
164
178
|
const {
|
|
165
179
|
notifications,
|
|
@@ -182,13 +196,13 @@ var NotificationsBox = props => {
|
|
|
182
196
|
if (!hasBoxNotifications) {
|
|
183
197
|
return null;
|
|
184
198
|
}
|
|
185
|
-
return /* @__PURE__ */
|
|
199
|
+
return /* @__PURE__ */jsx4(Stack, {
|
|
186
200
|
sx: {
|
|
187
201
|
width: "full",
|
|
188
202
|
gap: "1"
|
|
189
203
|
},
|
|
190
204
|
children: boxNotifications.map(notification => {
|
|
191
|
-
return /* @__PURE__ */
|
|
205
|
+
return /* @__PURE__ */jsx4(NotificationCard, {
|
|
192
206
|
type: notification.type,
|
|
193
207
|
title: notification.title,
|
|
194
208
|
message: notification.message,
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ToastOptions, ToastContainerProps } from '@ttoss/components/Toast';
|
|
|
3
3
|
export { toast } from '@ttoss/components/Toast';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
|
|
6
|
-
type ViewType = 'toast' | 'modal' | 'box';
|
|
6
|
+
type ViewType = 'toast' | 'modal' | 'box' | 'header';
|
|
7
7
|
type Notification = {
|
|
8
8
|
id?: string | number;
|
|
9
9
|
title?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-notifications",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "ttoss notifications module for React apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=16.8.0",
|
|
28
|
-
"@ttoss/ui": "^5.8.2",
|
|
29
28
|
"@ttoss/components": "^2.2.22",
|
|
30
|
-
"@ttoss/react-icons": "^0.4.12"
|
|
29
|
+
"@ttoss/react-icons": "^0.4.12",
|
|
30
|
+
"@ttoss/ui": "^5.8.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/react": "^19.1.8",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"tsup": "^8.5.0",
|
|
37
37
|
"@ttoss/components": "^2.2.22",
|
|
38
38
|
"@ttoss/config": "^1.35.4",
|
|
39
|
+
"@ttoss/react-icons": "^0.4.12",
|
|
39
40
|
"@ttoss/test-utils": "^2.1.24",
|
|
40
|
-
"@ttoss/ui": "^5.8.2"
|
|
41
|
-
"@ttoss/react-icons": "^0.4.12"
|
|
41
|
+
"@ttoss/ui": "^5.8.2"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"React",
|