@ttoss/react-notifications 2.4.25 → 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.
Files changed (2) hide show
  1. package/README.md +48 -4
  2. package/package.json +9 -9
package/README.md CHANGED
@@ -116,7 +116,9 @@ const Component = () => {
116
116
 
117
117
  ### NotificationsBox
118
118
 
119
- You can use `NotificationsBox` to show the notifications in a specific place. You can render as many `NotificationsBox` as you want in your application.
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
- In the example above, both `NotificationsBox` will show the notifications.
151
+ Both `NotificationsBox` instances will display the same notifications.
152
+
153
+ #### Box IDs
144
154
 
145
- To render the notifications in a specific `NotificationsBox`, you can set the `boxId` in the notification, which is the `id` of the `NotificationsBox` you want to show the notification.
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.25",
3
+ "version": "2.4.27",
4
4
  "description": "ttoss notifications module for React apps.",
5
5
  "license": "MIT",
6
6
  "author": "ttoss",
@@ -25,20 +25,20 @@
25
25
  "sideEffects": false,
26
26
  "peerDependencies": {
27
27
  "react": ">=16.8.0",
28
- "@ttoss/components": "^2.7.3",
29
- "@ttoss/react-icons": "^0.5.2",
30
- "@ttoss/ui": "^5.10.7"
28
+ "@ttoss/components": "^2.7.4",
29
+ "@ttoss/react-icons": "^0.5.3",
30
+ "@ttoss/ui": "^5.10.8"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/react": "^19.2.6",
34
34
  "jest": "^30.2.0",
35
35
  "react": "^19.2.0",
36
36
  "tsup": "^8.5.1",
37
- "@ttoss/components": "^2.7.3",
38
- "@ttoss/config": "^1.35.11",
39
- "@ttoss/react-icons": "^0.5.2",
40
- "@ttoss/ui": "^5.10.7",
41
- "@ttoss/test-utils": "^3.0.3"
37
+ "@ttoss/components": "^2.7.4",
38
+ "@ttoss/config": "^1.35.12",
39
+ "@ttoss/react-icons": "^0.5.3",
40
+ "@ttoss/test-utils": "^3.0.4",
41
+ "@ttoss/ui": "^5.10.8"
42
42
  },
43
43
  "keywords": [
44
44
  "React",