@ttoss/react-notifications 2.4.26 → 2.4.27
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 +48 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -116,7 +116,9 @@ const Component = () => {
|
|
|
116
116
|
|
|
117
117
|
### NotificationsBox
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
`NotificationsBox` displays notifications in a specific area of your application. It filters and shows only notifications intended for box display.
|
|
120
|
+
|
|
121
|
+
#### Basic Usage
|
|
120
122
|
|
|
121
123
|
```tsx
|
|
122
124
|
import { NotificationsBox } from '@ttoss/react-notifications';
|
|
@@ -129,7 +131,13 @@ const Component = () => {
|
|
|
129
131
|
</Box>
|
|
130
132
|
);
|
|
131
133
|
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### Multiple Boxes
|
|
132
137
|
|
|
138
|
+
You can render multiple `NotificationsBox` components. By default, all boxes show the same notifications:
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
133
141
|
const App = () => {
|
|
134
142
|
return (
|
|
135
143
|
<Box>
|
|
@@ -140,9 +148,11 @@ const App = () => {
|
|
|
140
148
|
};
|
|
141
149
|
```
|
|
142
150
|
|
|
143
|
-
|
|
151
|
+
Both `NotificationsBox` instances will display the same notifications.
|
|
152
|
+
|
|
153
|
+
#### Box IDs
|
|
144
154
|
|
|
145
|
-
To
|
|
155
|
+
To show notifications in a specific box, use the `id` prop and set the `boxId` in the notification:
|
|
146
156
|
|
|
147
157
|
```tsx
|
|
148
158
|
import { useNotifications, NotificationsBox } from '@ttoss/react-notifications';
|
|
@@ -157,7 +167,7 @@ const Component = () => {
|
|
|
157
167
|
<Button
|
|
158
168
|
onClick={() =>
|
|
159
169
|
addNotification({
|
|
160
|
-
message: "I'm a notification",
|
|
170
|
+
message: "I'm a notification for my-box",
|
|
161
171
|
type: 'info',
|
|
162
172
|
boxId: 'my-box',
|
|
163
173
|
})
|
|
@@ -170,6 +180,40 @@ const Component = () => {
|
|
|
170
180
|
};
|
|
171
181
|
```
|
|
172
182
|
|
|
183
|
+
#### Filtering Behavior
|
|
184
|
+
|
|
185
|
+
`NotificationsBox` filters notifications based on these rules:
|
|
186
|
+
|
|
187
|
+
1. **View Type**: Only shows notifications with `viewType: 'box'` or when `defaultViewType` is `'box'` and no `viewType` is specified
|
|
188
|
+
2. **Box ID**:
|
|
189
|
+
- If the box has no `id`, it shows notifications without a `boxId`
|
|
190
|
+
- If the box has an `id`, it only shows notifications with a matching `boxId`
|
|
191
|
+
3. **Direct Notifications**: You can pass notifications directly via the `notifications` prop to bypass the global state
|
|
192
|
+
|
|
193
|
+
#### Direct Notifications
|
|
194
|
+
|
|
195
|
+
You can pass notifications directly to a specific box, bypassing the global notification state:
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
import { NotificationsBox } from '@ttoss/react-notifications';
|
|
199
|
+
|
|
200
|
+
const Component = () => {
|
|
201
|
+
const localNotifications = [
|
|
202
|
+
{ id: 1, message: 'Local notification', type: 'info' },
|
|
203
|
+
{ id: 2, message: 'Another local one', type: 'success' },
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
return <NotificationsBox notifications={localNotifications} />;
|
|
207
|
+
};
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Props
|
|
211
|
+
|
|
212
|
+
| Prop | Type | Description |
|
|
213
|
+
| --------------- | ------------------ | ---------------------------------------------------------------------------- |
|
|
214
|
+
| `id` | `string \| number` | Optional identifier for the box. Used to match with `boxId` in notifications |
|
|
215
|
+
| `notifications` | `Notification[]` | Optional array of notifications to display directly, bypassing global state |
|
|
216
|
+
|
|
173
217
|
### NotificationsHeader
|
|
174
218
|
|
|
175
219
|
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-notifications",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.27",
|
|
4
4
|
"description": "ttoss notifications module for React apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"tsup": "^8.5.1",
|
|
37
37
|
"@ttoss/components": "^2.7.4",
|
|
38
38
|
"@ttoss/config": "^1.35.12",
|
|
39
|
+
"@ttoss/react-icons": "^0.5.3",
|
|
39
40
|
"@ttoss/test-utils": "^3.0.4",
|
|
40
|
-
"@ttoss/ui": "^5.10.8"
|
|
41
|
-
"@ttoss/react-icons": "^0.5.3"
|
|
41
|
+
"@ttoss/ui": "^5.10.8"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"React",
|