@@ -2,33 +2,18 @@ import React, { useEffect, useRef, useState } from 'react';
22import ReactDOM from 'react-dom/client' ;
33import {
44 IgrBanner ,
5- IgrBannerModule ,
65 IgrButton ,
7- IgrButtonModule ,
86 IgrCard ,
9- IgrCardModule ,
107 IgrIcon ,
11- IgrIconModule ,
128 IgrNavbar ,
13- IgrNavbarModule ,
149 IgrRipple ,
15- IgrRippleModule ,
1610 IgrToast ,
17- IgrToastModule ,
1811 registerIconFromText ,
19- } from 'igniteui-react' ;
12+ } from 'igniteui-react' ;
2013import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
2114import './BannerAdvancedSample.css' ;
2215import './index.css' ;
2316
24- IgrBannerModule . register ( ) ;
25- IgrNavbarModule . register ( ) ;
26- IgrIconModule . register ( ) ;
27- IgrCardModule . register ( ) ;
28- IgrButtonModule . register ( ) ;
29- IgrRippleModule . register ( ) ;
30- IgrToastModule . register ( ) ;
31-
3217const wifiOnIcon =
3318 '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M12.01 21.49L23.64 7c-.45-.34-4.93-4-11.64-4C5.28 3 .81 6.66.36 7l11.63 14.49.01.01.01-.01z"/></svg>' ;
3419const wifiOffIcon =
@@ -40,27 +25,29 @@ export default function BannerAdvancedSample() {
4025 const toastRef = useRef < IgrToast > ( null ) ;
4126
4227 const [ wifiState , setWifiState ] = useState ( false ) ;
28+ const [ iconName , setIconName ] = useState ( "signal_wifi_off" ) ;
4329
4430 useEffect ( ( ) => {
4531 registerIconFromText ( 'signal_wifi_off' , wifiOffIcon ) ;
4632 registerIconFromText ( 'signal_wifi_4_bar' , wifiOnIcon ) ;
4733 bannerRef . current . open = true ;
4834 } , [ ] ) ;
4935
50- function refreshBanner ( ) {
51- if ( ! wifiState ) {
52- iconRef . current . name = 'signal_wifi_4_bar' ;
36+ const refreshBanner = ( ) => {
37+ const nextWifiState = ! wifiState ;
38+ setWifiState ( nextWifiState ) ;
39+ setIconName ( nextWifiState ? "signal_wifi_4_bar" : "signal_wifi_off" ) ;
40+
41+ if ( nextWifiState ) {
5342 bannerRef . current . hide ( ) ;
5443 } else {
55- iconRef . current . name = 'signal_wifi_off' ;
5644 bannerRef . current . show ( ) ;
5745 }
5846
59- setWifiState ( current => ! current ) ;
6047 showToast ( ) ;
6148 }
6249
63- function showToast ( ) {
50+ const showToast = ( ) => {
6451 toastRef . current . open = false ;
6552 toastRef . current . show ( ) ;
6653 }
@@ -69,37 +56,37 @@ export default function BannerAdvancedSample() {
6956 < div className = "gallery__wrapper" >
7057 < div className = "gallery__content" >
7158 < IgrNavbar >
72- < h1 key = "header" > Gallery</ h1 >
73- < IgrIcon ref = { iconRef } key = "icon-wifi-off" name = "signal_wifi_off" slot = "end" onClick = { ( ) => refreshBanner ( ) } > </ IgrIcon >
59+ < h1 > Gallery</ h1 >
60+ < IgrIcon ref = { iconRef } name = { iconName } slot = "end" onClick = { refreshBanner } > </ IgrIcon >
7461 </ IgrNavbar >
7562
7663 < IgrBanner ref = { bannerRef } className = "offline-banner" >
77- < IgrIcon key = "icon-wifi-off" name = "signal_wifi_off" slot = "prefix" > </ IgrIcon >
78- < span key = "message" > You have lost connection to the internet. This app is offline.</ span >
79- < div key = "actions" slot = "actions" >
80- < IgrButton key = "button-offline" variant = "flat" onClick = { ( ) => bannerRef . current . hide ( ) } >
81- < IgrRipple key = "ripple-offline" />
82- < span key = "action-offline" > Continue Offline</ span >
64+ < IgrIcon name = "signal_wifi_off" slot = "prefix" > </ IgrIcon >
65+ < span > You have lost connection to the internet. This app is offline.</ span >
66+ < div slot = "actions" >
67+ < IgrButton variant = "flat" onClick = { ( ) => bannerRef . current . hide ( ) } >
68+ < IgrRipple />
69+ < span > Continue Offline</ span >
8370 </ IgrButton >
84- < IgrButton key = "button-wifi" variant = "flat" onClick = { ( ) => refreshBanner ( ) } >
85- < IgrRipple key = "ripple-wifi" />
86- < span key = "action-wifi" > Turn On Wifi</ span >
71+ < IgrButton variant = "flat" onClick = { refreshBanner } >
72+ < IgrRipple />
73+ < span > Turn On Wifi</ span >
8774 </ IgrButton >
8875 </ div >
8976 </ IgrBanner >
9077
9178 < IgrCard className = "gallery__item" elevated >
92- < div key = "img-forest" >
93- < img src = "https://www.infragistics.com/angular-demos-lob/assets/images/card/media/the_red_ice_forest.jpg" />
79+ < div >
80+ < img src = "https://www.infragistics.com/angular-demos-lob/assets/images/card/media/the_red_ice_forest.jpg" />
9481 </ div >
9582 </ IgrCard >
9683 < IgrCard className = "gallery__item" elevated >
97- < div key = "img-yosemite" >
98- < img src = "https://www.infragistics.com/angular-demos-lob/assets/images/card/media/yosemite.jpg" />
84+ < div >
85+ < img src = "https://www.infragistics.com/angular-demos-lob/assets/images/card/media/yosemite.jpg" />
9986 </ div >
10087 </ IgrCard >
10188 < IgrToast ref = { toastRef } position = "middle" >
102- < span key = "toast-message" > { `Wifi is now ${ wifiState ? 'on' : 'off' } ` } </ span >
89+ < span > { `Wifi is now ${ wifiState ? 'on' : 'off' } ` } </ span >
10390 </ IgrToast >
10491 </ div >
10592 </ div >
@@ -108,4 +95,4 @@ export default function BannerAdvancedSample() {
10895
10996// rendering above class to the React DOM
11097const root = ReactDOM . createRoot ( document . getElementById ( 'root' ) ) ;
111- root . render ( < BannerAdvancedSample /> ) ;
98+ root . render ( < BannerAdvancedSample /> ) ;
0 commit comments