@fvc/notification 1.2.1 → 1.2.2-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997

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 +224 -0
  2. package/package.json +15 -3
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # @fvc/notification
2
+
3
+ `@fvc/notification` wraps Ant Design's notification system with FE-VIS design tokens and icons. It applies the dark card background, per-type icon colours, and Roboto typography automatically. Supports both a hook-based API (recommended) and static methods for non-component contexts.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @fvc/notification
9
+ ```
10
+
11
+ ## Peer Dependencies
12
+
13
+ ```bash
14
+ bun add react antd @fvc/icons
15
+ ```
16
+
17
+ ## Import
18
+
19
+ ```ts
20
+ import { notification } from '@fvc/notification';
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```tsx
26
+ import { notification } from '@fvc/notification';
27
+
28
+ function SaveButton() {
29
+ const [api, contextHolder] = notification.useNotification({});
30
+
31
+ return (
32
+ <>
33
+ {contextHolder}
34
+ <button onClick={() => api.success({ message: 'Changes saved' })}>
35
+ Save
36
+ </button>
37
+ </>
38
+ );
39
+ }
40
+ ```
41
+
42
+ ## Notification Types
43
+
44
+ | Type | Auto icon | Message colour |
45
+ | --- | --- | --- |
46
+ | `success` | `CheckCircleOutline` | `--link-on-dark-bg-color-400` |
47
+ | `info` | `Info` | `--gray-300` |
48
+ | `warning` | `Warning` | `--orange-200` |
49
+ | `error` | `Report` | `--warning-icon-on-dark-bg-color-400` |
50
+
51
+ Icons and colours are applied automatically by type. Pass `icon` explicitly to override.
52
+
53
+ ## Usage Patterns
54
+
55
+ ### `useNotification` — recommended
56
+
57
+ Binds the notification to the React tree so it inherits `ConfigProvider` context (locale, theme, etc.). `contextHolder` must be rendered somewhere in the tree above where the notification is triggered — placing it at the top of the component is sufficient.
58
+
59
+ ```tsx
60
+ function Page() {
61
+ const [api, contextHolder] = notification.useNotification({});
62
+
63
+ const handleError = () => {
64
+ api.error({
65
+ message: 'Request failed',
66
+ innerComponent: <button onClick={retry}>Retry</button>,
67
+ });
68
+ };
69
+
70
+ return (
71
+ <>
72
+ {contextHolder}
73
+ <button onClick={handleError}>Submit</button>
74
+ </>
75
+ );
76
+ }
77
+ ```
78
+
79
+ ### Static API — deprecated
80
+
81
+ Works without a hook but does not inherit React context. Suitable for non-component code such as axios interceptors where a hook cannot be called.
82
+
83
+ ```tsx
84
+ notification.success({ message: 'Done' });
85
+ notification.error({ message: 'Something went wrong' });
86
+ ```
87
+
88
+ > **Deprecated.** Static methods (`success`, `error`, `info`, `warning`) will be removed in a future major version. Use `notification.useNotification()` for all new code.
89
+
90
+ ## Methods
91
+
92
+ | Method | Description |
93
+ | --- | --- |
94
+ | `useNotification(config)` | Returns `[api, contextHolder]`. Recommended pattern. |
95
+ | `open(config)` | Opens a notification without a preset type. |
96
+ | `success(config)` | Opens a success notification. Deprecated. |
97
+ | `info(config)` | Opens an info notification. Deprecated. |
98
+ | `warning(config)` | Opens a warning notification. Deprecated. |
99
+ | `error(config)` | Opens an error notification. Deprecated. |
100
+ | `destroy(key?)` | Destroys one notification by key, or all if no key is provided. |
101
+ | `config(globalConfig)` | Sets global defaults (placement, duration, maxCount, etc.). |
102
+
103
+ ## Config (`ArgsProps`)
104
+
105
+ Extends antd's `ArgsProps`. The `description` field from antd is replaced by `innerComponent`.
106
+
107
+ | Prop | Type | Description |
108
+ | --- | --- | --- |
109
+ | `message` | `ReactNode` | Notification title. |
110
+ | `innerComponent` | `ReactNode` | Content rendered below the title. Replaces antd's `description`. |
111
+ | `icon` | `ReactNode` | Overrides the automatic type icon. |
112
+ | `duration` | `number` | Auto-close in seconds. `0` disables auto-close. |
113
+ | `placement` | `NotificationPlacement` | Where the notification appears. Default: `topRight`. |
114
+ | `key` | `string` | Unique key for programmatic updates or targeted destruction. |
115
+ | `onClose` | `() => void` | Called when the notification closes. |
116
+
117
+ ## Common Usage
118
+
119
+ ### With `innerComponent`
120
+
121
+ ```tsx
122
+ api.warning({
123
+ message: 'Session expiring soon',
124
+ duration: 0,
125
+ innerComponent: (
126
+ <button onClick={extendSession}>Extend session</button>
127
+ ),
128
+ });
129
+ ```
130
+
131
+ ### Custom placement
132
+
133
+ ```tsx
134
+ const [api, contextHolder] = notification.useNotification({
135
+ placement: 'bottomRight',
136
+ });
137
+ ```
138
+
139
+ ### Custom icon
140
+
141
+ ```tsx
142
+ import { Icon } from '@fvc/icons';
143
+
144
+ api.open({
145
+ message: 'Upload complete',
146
+ icon: <Icon.CheckCircle color="var(--green-400)" width={24} height={24} />,
147
+ });
148
+ ```
149
+
150
+ ### Persistent notification
151
+
152
+ ```tsx
153
+ api.error({
154
+ key: 'save-error',
155
+ message: 'Could not save changes',
156
+ duration: 0,
157
+ });
158
+
159
+ // Dismiss programmatically
160
+ api.destroy('save-error');
161
+ ```
162
+
163
+ ## Consumer Example
164
+
165
+ ```tsx
166
+ import { notification } from '@fvc/notification';
167
+
168
+ function useFormSubmit() {
169
+ const [api, contextHolder] = notification.useNotification({
170
+ placement: 'bottomRight',
171
+ });
172
+
173
+ const submit = async (data: FormData) => {
174
+ try {
175
+ await postData(data);
176
+ api.success({ message: 'Record saved successfully' });
177
+ } catch {
178
+ api.error({
179
+ message: 'Save failed',
180
+ duration: 0,
181
+ innerComponent: (
182
+ <button onClick={() => submit(data)}>Try again</button>
183
+ ),
184
+ });
185
+ }
186
+ };
187
+
188
+ return { submit, contextHolder };
189
+ }
190
+ ```
191
+
192
+ ## Testing
193
+
194
+ Notifications render outside the React tree in a portal. Call `notification.destroy()` in `afterEach` to prevent toast leakage between test cases.
195
+
196
+ ```ts
197
+ afterEach(() => {
198
+ notification.destroy();
199
+ });
200
+ ```
201
+
202
+ ## CSS Classes
203
+
204
+ | Class | Description |
205
+ | --- | --- |
206
+ | `.fvc-notification` | Root notification container |
207
+ | `.fvc-notification-notice-wrapper` | Individual notification card (dark background) |
208
+ | `.fvc-notification-notice` | Inner notice element |
209
+ | `.fvc-notification-notice-message` | Title text |
210
+ | `.fvc-notification-notice-icon` | Icon slot |
211
+ | `.fvc-notification-notice-btn` | `innerComponent` slot |
212
+ | `.fvc-notification-notice-close` | Close button |
213
+ | `.fvc-notification-notice-success` | Applied on `success` type notifications |
214
+ | `.fvc-notification-notice-info` | Applied on `info` type notifications |
215
+ | `.fvc-notification-notice-warning` | Applied on `warning` type notifications |
216
+ | `.fvc-notification-notice-error` | Applied on `error` type notifications |
217
+
218
+ ## Development
219
+
220
+ ```bash
221
+ bun run lint
222
+ bun run type-check
223
+ bun run test
224
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fvc/notification",
3
- "version": "1.2.1",
3
+ "version": "1.2.2-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997",
4
4
  "main": "./dist/lib/index.js",
5
5
  "types": "./dist/lib/notification/src/index.d.ts",
6
6
  "files": [
@@ -27,8 +27,20 @@
27
27
  "test": "bun test --preload ../../tests/happydom.ts --preload ../../tests/testing-library.tsx"
28
28
  },
29
29
  "peerDependencies": {
30
- "@fvc/icons": "*",
30
+ "@fvc/icons": "1.1.4-next-ec65dfb844e6183b3d7f417eee613cfe5ecfd997",
31
31
  "react": "^18.0.0",
32
32
  "antd": "^5.0.0"
33
- }
33
+ },
34
+ "keywords": [
35
+ "react",
36
+ "react-component",
37
+ "fvc",
38
+ "fe-vis-core",
39
+ "ui",
40
+ "notification",
41
+ "toast",
42
+ "alert",
43
+ "design-system",
44
+ "antd"
45
+ ]
34
46
  }