Skip to content

Commit aee18be

Browse files
authored
Update banner topic for React 19 (#1603)
1 parent 0ed5f9c commit aee18be

File tree

1 file changed

+53
-57
lines changed

1 file changed

+53
-57
lines changed

doc/en/components/notifications/banner.md

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ First, you need to the install the corresponding {ProductName} npm package by ru
3939
npm install igniteui-react
4040
```
4141

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:
4343

4444
```tsx
45-
import { IgrBannerModule, IgrBanner } from 'igniteui-react';
45+
import { IgrBanner } from 'igniteui-react';
4646
import 'igniteui-webcomponents/themes/light/bootstrap.css';
47-
48-
IgrBannerModule.register();
4947
```
5048
<!-- end: React -->
5149

@@ -80,12 +78,12 @@ In order to display the banner component, use its `Show` method and call it on a
8078
```
8179

8280
```tsx
83-
<IgrButton clicked={() => bannerRef.current.show()}>
81+
<IgrButton onClick={() => bannerRef.current.show()}>
8482
<span>Show Banner</span>
8583
</IgrButton>
8684

8785
<IgrBanner ref={bannerRef}>
88-
<span key="message">You are currently offline.</span>
86+
<span>You are currently offline.</span>
8987
</IgrBanner>
9088
```
9189

@@ -126,7 +124,7 @@ Configuring the message displayed in the banner is easy - just change the conten
126124

127125
```tsx
128126
<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>
130128
</IgrBanner>
131129
```
132130

@@ -154,8 +152,8 @@ To pass an `Icon` to your banner, use the `prefix` slot:
154152

155153
```tsx
156154
<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>
159157
</IgrBanner>
160158
```
161159

@@ -177,8 +175,8 @@ If you want to use an `Icon` in your banner message, simply insert it in the ban
177175

178176
```tsx
179177
<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>
182180
</IgrBanner>
183181
```
184182

@@ -208,12 +206,12 @@ The `Banner` exposes the `actions` slot for templating the banner buttons. This
208206

209207
```tsx
210208
<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>
217215
</IgrButton>
218216
</div>
219217
</IgrBanner>
@@ -245,7 +243,7 @@ The `Banner` exposes the `actions` slot for templating the banner buttons. This
245243

246244
### Binding to events
247245

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.
249247

250248
To cancel the closing event, call the [`preventDefault`](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault) method.
251249

@@ -263,17 +261,9 @@ banner.addEventListener('igcClosing', (event) => {
263261
```
264262

265263
```tsx
266-
<IgrBanner ref={bannerRef}>
264+
<IgrBanner onClosing={(event) => event.preventDefault()}>
267265
...
268266
</IgrBanner>
269-
270-
const bannerRef = useRef<IgrBanner>(null);
271-
272-
useEffect(() => {
273-
bannerRef.current.nativeElement.addEventListener('igcClosing', (event) => {
274-
event.preventDefault();
275-
});
276-
}, [])
277267
```
278268

279269
```razor
@@ -328,16 +318,16 @@ Let's create a banner with two custom buttons - one for dismissing the notificat
328318

329319
```tsx
330320
<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>
337327
</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>
341331
</IgrButton>
342332
</div>
343333
</IgrBanner>
@@ -423,37 +413,43 @@ public refreshBanner() {
423413
```
424414

425415
```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-
442416
const bannerRef = useRef<IgrBanner>(null);
443417
const iconRef = useRef<IgrIcon>(null);
444418

445419
const [wifiState, setWifiState] = useState(false);
420+
const [iconName, setIconName] = useState("signal_wifi_off");
446421

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) {
450428
bannerRef.current.hide();
451429
} else {
452-
iconRef.current.name = 'signal_wifi_off';
453430
bannerRef.current.show();
454431
}
455-
setWifiState(current => !current);
456432
}
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+
);
457453
```
458454

459455
```razor

0 commit comments

Comments
 (0)