1- import React from 'react' ;
1+ import React , { useRef } from 'react' ;
22import ReactDOM from 'react-dom/client' ;
33import './index.css' ;
4- import { IgrButton , IgrSnackbar , IgrButtonModule , IgrSnackbarModule } from 'igniteui-react' ;
4+ import { IgrButton , IgrSnackbar } from 'igniteui-react' ;
55import 'igniteui-webcomponents/themes/light/bootstrap.css' ;
66
7- IgrButtonModule . register ( ) ;
8- IgrSnackbarModule . register ( ) ;
9-
10- export default class SnackbarActionText extends React . Component < any , any > {
11-
12- public snackbarRef : IgrSnackbar ;
13-
14- constructor ( props : any ) {
15- super ( props ) ;
16- this . onShowButtonClicked = this . onShowButtonClicked . bind ( this ) ;
17- this . onSnackbarRef = this . onSnackbarRef . bind ( this ) ;
18- this . onSnackbarActionClicked = this . onSnackbarActionClicked . bind ( this ) ;
19- }
20-
21- public render ( ) : JSX . Element {
22- return (
23- < div className = "container sample" >
24- < IgrButton variant = "contained" onClick = { this . onShowButtonClicked } >
25- < span > Show Snackbar</ span >
26- </ IgrButton >
27-
28- < IgrSnackbar ref = { this . onSnackbarRef } keepOpen = { true } actionText = "Close" onAction = { this . onSnackbarActionClicked } >
29- < span > Snackbar with enabled keep-open option</ span >
30- </ IgrSnackbar >
31- </ div >
32- ) ;
33- }
34-
35- public onSnackbarRef ( snackbar : IgrSnackbar ) {
36- if ( ! snackbar ) { return ; }
37- this . snackbarRef = snackbar ;
38- }
39-
40- public onSnackbarActionClicked ( ) {
41- if ( this . snackbarRef ) {
42- this . snackbarRef . hide ( ) ;
43- }
44- }
45-
46- public onShowButtonClicked ( ) {
47- if ( this . snackbarRef ) {
48- this . snackbarRef . show ( ) ;
49- }
50- }
7+ export default function SnackbarActionText ( ) {
8+ const snackbarRef = useRef < IgrSnackbar > ( null ) ;
9+
10+ const onShowButtonClicked = ( ) => {
11+ snackbarRef . current ?. show ( ) ;
12+ } ;
13+
14+ const onSnackbarActionClicked = ( ) => {
15+ snackbarRef . current ?. hide ( ) ;
16+ } ;
17+
18+ return (
19+ < div className = "container sample" >
20+ < IgrButton variant = "contained" onClick = { onShowButtonClicked } >
21+ < span > Show Snackbar</ span >
22+ </ IgrButton >
23+
24+ < IgrSnackbar
25+ ref = { snackbarRef }
26+ keepOpen = { true }
27+ actionText = "Close"
28+ onAction = { onSnackbarActionClicked }
29+ >
30+ < span > Snackbar with enabled keep-open option</ span >
31+ </ IgrSnackbar >
32+ </ div >
33+ ) ;
5134}
5235
53- // rendering above class to the React DOM
36+ // rendering above function to the React DOM
5437const root = ReactDOM . createRoot ( document . getElementById ( 'root' ) ) ;
55- root . render ( < SnackbarActionText /> ) ;
38+ root . render ( < SnackbarActionText /> ) ;
0 commit comments