@@ -39,13 +39,11 @@ First, you need to the install the corresponding {ProductName} npm package by ru
39
39
npm install igniteui-react
40
40
```
41
41
42
- You will then need to import the ` Banner ` , its necessary CSS, and register its module , like so:
42
+ You will then need to import the ` Banner ` and its necessary CSS, like so:
43
43
44
44
``` tsx
45
- import { IgrBannerModule , IgrBanner } from ' igniteui-react' ;
45
+ import { IgrBanner } from ' igniteui-react' ;
46
46
import ' igniteui-webcomponents/themes/light/bootstrap.css' ;
47
-
48
- IgrBannerModule .register ();
49
47
```
50
48
<!-- end: React -->
51
49
@@ -80,12 +78,12 @@ In order to display the banner component, use its `Show` method and call it on a
80
78
```
81
79
82
80
``` tsx
83
- <IgrButton clicked = { () => bannerRef .current .show ()} >
81
+ <IgrButton onClick = { () => bannerRef .current .show ()} >
84
82
<span >Show Banner</span >
85
83
</IgrButton >
86
84
87
85
<IgrBanner ref = { bannerRef } >
88
- <span key = " message " >You are currently offline.</span >
86
+ <span >You are currently offline.</span >
89
87
</IgrBanner >
90
88
```
91
89
@@ -126,7 +124,7 @@ Configuring the message displayed in the banner is easy - just change the conten
126
124
127
125
``` tsx
128
126
<IgrBanner ref = { bannerRef } >
129
- <span key = " message " >You have lost connection to the internet. This app is offline.</span >
127
+ <span >You have lost connection to the internet. This app is offline.</span >
130
128
</IgrBanner >
131
129
```
132
130
@@ -154,8 +152,8 @@ To pass an `Icon` to your banner, use the `prefix` slot:
154
152
155
153
``` tsx
156
154
<IgrBanner ref = { bannerRef } >
157
- <IgrIcon key = " icon " slot = " prefix" name = " signal_wifi_off" ></IgrIcon >
158
- <span key = " message " >You have lost connection to the internet. This app is offline.</span >
155
+ <IgrIcon slot = " prefix" name = " signal_wifi_off" ></IgrIcon >
156
+ <span >You have lost connection to the internet. This app is offline.</span >
159
157
</IgrBanner >
160
158
```
161
159
@@ -177,8 +175,8 @@ If you want to use an `Icon` in your banner message, simply insert it in the ban
177
175
178
176
``` tsx
179
177
<IgrBanner ref = { bannerRef } >
180
- <span key = " message " >You have lost connection to the internet. This app is offline.</span >
181
- <IgrIcon key = " icon " name = " signal_wifi_off" ></IgrIcon >
178
+ <span >You have lost connection to the internet. This app is offline.</span >
179
+ <IgrIcon name = " signal_wifi_off" ></IgrIcon >
182
180
</IgrBanner >
183
181
```
184
182
@@ -208,12 +206,12 @@ The `Banner` exposes the `actions` slot for templating the banner buttons. This
208
206
209
207
``` tsx
210
208
<IgrBanner ref = { bannerRef } >
211
- <IgrIcon key = " icon " slot = " prefix" name = " signal_wifi_off" ></IgrIcon >
212
- <span key = " message " >You have lost connection to the internet. This app is offline.</span >
213
- <div key = " actions " slot = " actions" >
214
- <IgrButton key = " button " variant = " flat" clicked = { () => bannerRef .current .toggle ()} >
215
- <IgrRipple key = " ripple " />
216
- <span key = " action-text " >Toggle Banner</span >
209
+ <IgrIcon slot = " prefix" name = " signal_wifi_off" ></IgrIcon >
210
+ <span >You have lost connection to the internet. This app is offline.</span >
211
+ <div slot = " actions" >
212
+ <IgrButton variant = " flat" onClick = { () => bannerRef .current .toggle ()} >
213
+ <IgrRipple />
214
+ <span >Toggle Banner</span >
217
215
</IgrButton >
218
216
</div >
219
217
</IgrBanner >
@@ -245,7 +243,7 @@ The `Banner` exposes the `actions` slot for templating the banner buttons. This
245
243
246
244
### Binding to events
247
245
248
- The banner component emits the ` igcClosing ` and ` igcClosed ` events when being closed. The ` igcClosing ` event is cancelable - it uses the [ ` CustomEvent ` ] ( https://developer.mozilla.org/docs/Web/API/CustomEvent ) interface and the emitted object has its ` cancelable ` property set to ** true** . If we cancel the ` igcClosing ` event, the corresponding end action and event will not be triggered - the banner will not be closed and the ` igcClosed ` event will not be emitted.
246
+ The banner component emits the ` Closing ` and ` Closed ` events when being closed. The ` Closing ` event is cancelable - it uses the [ ` CustomEvent ` ] ( https://developer.mozilla.org/docs/Web/API/CustomEvent ) interface and the emitted object has its ` cancelable ` property set to ** true** . If we cancel the ` Closing ` event, the corresponding end action and event will not be triggered - the banner will not be closed and the ` Closed ` event will not be emitted.
249
247
250
248
To cancel the closing event, call the [ ` preventDefault ` ] ( https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault ) method.
251
249
@@ -263,17 +261,9 @@ banner.addEventListener('igcClosing', (event) => {
263
261
```
264
262
265
263
``` tsx
266
- <IgrBanner ref = { bannerRef } >
264
+ <IgrBanner onClosing = { ( event ) => event . preventDefault () } >
267
265
...
268
266
</IgrBanner >
269
-
270
- const bannerRef = useRef <IgrBanner >(null );
271
-
272
- useEffect (() => {
273
- bannerRef .current .nativeElement .addEventListener (' igcClosing' , (event ) => {
274
- event .preventDefault ();
275
- });
276
- }, [])
277
267
```
278
268
279
269
``` razor
@@ -328,16 +318,16 @@ Let's create a banner with two custom buttons - one for dismissing the notificat
328
318
329
319
``` tsx
330
320
<IgrBanner ref = { bannerRef } >
331
- <IgrIcon key = " icon " slot = " prefix" name = " signal_wifi_off" ></IgrIcon >
332
- <span key = " message " >You have lost connection to the internet. This app is offline.</span >
333
- <div key = " actions " slot = " actions" >
334
- <IgrButton key = " button-offline " variant = " flat" clicked = { () => bannerRef .current .hide ()} >
335
- <IgrRipple key = " ripple-offline " />
336
- <span key = " action-offline " >Continue Offline</span >
321
+ <IgrIcon slot = " prefix" name = " signal_wifi_off" ></IgrIcon >
322
+ <span >You have lost connection to the internet. This app is offline.</span >
323
+ <div slot = " actions" >
324
+ <IgrButton variant = " flat" onClick = { () => bannerRef .current .hide ()} >
325
+ <IgrRipple />
326
+ <span >Continue Offline</span >
337
327
</IgrButton >
338
- <IgrButton key = " button-wifi " variant = " flat" clicked = { () => refreshBanner () } >
339
- <IgrRipple key = " ripple-wifi " />
340
- <span key = " action-wifi " >Turn On Wifi</span >
328
+ <IgrButton variant = " flat" onClick = { refreshBanner } >
329
+ <IgrRipple />
330
+ <span >Turn On Wifi</span >
341
331
</IgrButton >
342
332
</div >
343
333
</IgrBanner >
@@ -423,37 +413,43 @@ public refreshBanner() {
423
413
```
424
414
425
415
``` tsx
426
- <IgrNavbar >
427
- <h1 key = " header" >Gallery</h1 >
428
- <IgrIcon ref = { iconRef } key = " icon" name = " signal_wifi_off" slot = " end" onClick = { () => refreshBanner ()} ></IgrIcon >
429
- </IgrNavbar >
430
-
431
- <IgrBanner ref = { bannerRef } >
432
- ...
433
- <div key = " actions" slot = " actions" >
434
- ...
435
- <IgrButton key = " button-wifi" variant = " flat" clicked = { () => refreshBanner ()} >
436
- <IgrRipple key = " ripple-wifi" />
437
- <span key = " action-wifi" >Turn On Wifi</span >
438
- </IgrButton >
439
- </div >
440
- </IgrBanner >
441
-
442
416
const bannerRef = useRef <IgrBanner >(null );
443
417
const iconRef = useRef <IgrIcon >(null );
444
418
445
419
const [wifiState, setWifiState] = useState (false );
420
+ const [iconName, setIconName] = useState (" signal_wifi_off" );
446
421
447
- function refreshBanner() {
448
- if (! wifiState ) {
449
- iconRef .current .name = ' signal_wifi_4_bar' ;
422
+ const refreshBanner = () => {
423
+ const nextWifiState = ! wifiState ;
424
+ setWifiState (nextWifiState );
425
+ setIconName (nextWifiState ? " signal_wifi_4_bar" : " signal_wifi_off" );
426
+
427
+ if (nextWifiState ) {
450
428
bannerRef .current .hide ();
451
429
} else {
452
- iconRef .current .name = ' signal_wifi_off' ;
453
430
bannerRef .current .show ();
454
431
}
455
- setWifiState (current => ! current );
456
432
}
433
+
434
+ return (
435
+ <>
436
+ <IgrNavbar >
437
+ <h1 >Gallery</h1 >
438
+ <IgrIcon ref = { iconRef } name = { iconName } slot = " end" onClick = { refreshBanner } ></IgrIcon >
439
+ </IgrNavbar >
440
+
441
+ <IgrBanner ref = { bannerRef } >
442
+ ...
443
+ <div slot = " actions" >
444
+ ...
445
+ <IgrButton variant = " flat" onClick = { refreshBanner } >
446
+ <IgrRipple />
447
+ <span >Turn On Wifi</span >
448
+ </IgrButton >
449
+ </div >
450
+ </IgrBanner >
451
+ </>
452
+ );
457
453
```
458
454
459
455
``` razor
0 commit comments