1 | # rc-notification
|
2 |
|
3 | React Notification UI Component
|
4 |
|
5 | [![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
|
6 |
|
7 | [npm-image]: http://img.shields.io/npm/v/rc-notification.svg?style=flat-square
|
8 | [npm-url]: http://npmjs.org/package/rc-notification
|
9 | [github-actions-image]: https://github.com/react-component/notification/workflows/CI/badge.svg
|
10 | [github-actions-url]: https://github.com/react-component/notification/actions
|
11 | [coveralls-image]: https://img.shields.io/coveralls/react-component/notification.svg?style=flat-square
|
12 | [coveralls-url]: https://coveralls.io/r/react-component/notification?branch=master
|
13 | [download-image]: https://img.shields.io/npm/dm/rc-notification.svg?style=flat-square
|
14 | [download-url]: https://npmjs.org/package/rc-notification
|
15 | [bundlephobia-url]: https://bundlephobia.com/result?p=rc-notification
|
16 | [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-notification
|
17 |
|
18 | ## Install
|
19 |
|
20 | [![rc-notification](https://nodei.co/npm/rc-notification.png)](https://npmjs.org/package/rc-notification)
|
21 |
|
22 | ## Usage
|
23 |
|
24 | ```js
|
25 | import Notification from 'rc-notification';
|
26 |
|
27 | Notification.newInstance({}, notification => {
|
28 | notification.notice({
|
29 | content: 'content'
|
30 | });
|
31 | });
|
32 | ```
|
33 |
|
34 | ## Compatibility
|
35 |
|
36 | | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>IE / Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Safari | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/electron/electron_48x48.png" alt="Electron" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Electron |
|
37 | | --- | --- | --- | --- | --- |
|
38 | | IE11, Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
|
39 |
|
40 | ## Example
|
41 |
|
42 | http://localhost:8001
|
43 |
|
44 | online example: https://notification-react-component.vercel.app
|
45 |
|
46 | ## API
|
47 |
|
48 | ### Notification.newInstance(props, (notification) => void) => void
|
49 |
|
50 | props details:
|
51 |
|
52 | <table class="table table-bordered table-striped">
|
53 | <thead>
|
54 | <tr>
|
55 | <th style="width: 100px;">name</th>
|
56 | <th style="width: 50px;">type</th>
|
57 | <th style="width: 50px;">default</th>
|
58 | <th>description</th>
|
59 | </tr>
|
60 | </thead>
|
61 | <tbody>
|
62 | <tr>
|
63 | <td>prefixCls</td>
|
64 | <td>String</td>
|
65 | <td></td>
|
66 | <td>prefix class name for notification container</td>
|
67 | </tr>
|
68 | <tr>
|
69 | <td>style</td>
|
70 | <td>Object</td>
|
71 | <td>{'top': 65, left: '50%'}</td>
|
72 | <td>additional style for notification container.</td>
|
73 | </tr>
|
74 | <tr>
|
75 | <td>getContainer</td>
|
76 | <td>getContainer(): HTMLElement</td>
|
77 | <td></td>
|
78 | <td>function returning html node which will act as notification container</td>
|
79 | </tr>
|
80 | <tr>
|
81 | <td>maxCount</td>
|
82 | <td>number</td>
|
83 | <td></td>
|
84 | <td>max notices show, drop first notice if exceed limit</td>
|
85 | </tr>
|
86 | </tbody>
|
87 | </table>
|
88 |
|
89 | ### notification.notice(props)
|
90 |
|
91 | props details:
|
92 |
|
93 | <table class="table table-bordered table-striped">
|
94 | <thead>
|
95 | <tr>
|
96 | <th style="width: 100px;">name</th>
|
97 | <th style="width: 50px;">type</th>
|
98 | <th style="width: 50px;">default</th>
|
99 | <th>description</th>
|
100 | </tr>
|
101 | </thead>
|
102 | <tbody>
|
103 | <tr>
|
104 | <td>content</td>
|
105 | <td>React.Element</td>
|
106 | <td></td>
|
107 | <td>content of notice</td>
|
108 | </tr>
|
109 | <tr>
|
110 | <td>key</td>
|
111 | <td>String</td>
|
112 | <td></td>
|
113 | <td>id of this notice</td>
|
114 | </tr>
|
115 | <tr>
|
116 | <td>closable</td>
|
117 | <td>Boolean</td>
|
118 | <td></td>
|
119 | <td>whether show close button</td>
|
120 | </tr>
|
121 | <tr>
|
122 | <td>onClose</td>
|
123 | <td>Function</td>
|
124 | <td></td>
|
125 | <td>called when notice close</td>
|
126 | </tr>
|
127 | <tr>
|
128 | <td>duration</td>
|
129 | <td>number</td>
|
130 | <td>1.5</td>
|
131 | <td>after duration of time, this notice will disappear.(seconds)</td>
|
132 | </tr>
|
133 | <tr>
|
134 | <td>showProgress</td>
|
135 | <td>boolean</td>
|
136 | <td>false</td>
|
137 | <td>show with progress bar for auto-closing notification</td>
|
138 | </tr>
|
139 | <tr>
|
140 | <td>pauseOnHover</td>
|
141 | <td>boolean</td>
|
142 | <td>true</td>
|
143 | <td>keep the timer running or not on hover</td>
|
144 | </tr>
|
145 | <tr>
|
146 | <td>style</td>
|
147 | <td>Object</td>
|
148 | <td> { right: '50%' } </td>
|
149 | <td>additional style for single notice node.</td>
|
150 | </tr>
|
151 | <tr>
|
152 | <td>closeIcon</td>
|
153 | <td>ReactNode</td>
|
154 | <td></td>
|
155 | <td>specific the close icon.</td>
|
156 | </tr>
|
157 | <tr>
|
158 | <td>props</td>
|
159 | <td>Object</td>
|
160 | <td></td>
|
161 | <td>An object that can contain <code>data-*</code>, <code>aria-*</code>, or <code>role</code> props, to be put on the notification <code>div</code>. This currently only allows <code>data-testid</code> instead of <code>data-*</code> in TypeScript. See https://github.com/microsoft/TypeScript/issues/28960.</td>
|
162 | </tr>
|
163 | </tbody>
|
164 | </table>
|
165 |
|
166 | ### notification.removeNotice(key:string)
|
167 |
|
168 | remove single notice with specified key
|
169 |
|
170 | ### notification.destroy()
|
171 |
|
172 | destroy current notification
|
173 |
|
174 | ## Test Case
|
175 |
|
176 | ```
|
177 | npm test
|
178 | npm run chrome-test
|
179 | ```
|
180 |
|
181 | ## Coverage
|
182 |
|
183 | ```
|
184 | npm run coverage
|
185 | ```
|
186 |
|
187 | open coverage/ dir
|
188 |
|
189 | ## License
|
190 |
|
191 | rc-notification is released under the MIT license.
|