File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
project-1/project-app/src Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -7,22 +7,32 @@ import TextForm from './components/TextForm';
77
88function App ( ) {
99 const [ mode , setMode ] = useState ( 'light' ) ;
10+ const [ alert , setAlert ] = useState ( null ) ;
11+
12+ const showAlert = ( message , type ) => {
13+ setAlert ( {
14+ msg : message ,
15+ type : type
16+ } )
17+ }
1018
1119 const toggleMode = ( ) => {
1220 if ( mode === 'light' ) {
1321 setMode ( 'dark' ) ;
1422 document . body . style . backgroundColor = 'black' ;
23+ showAlert ( "Dark mode has been enabled" , "success" ) ;
1524 }
1625 else {
1726 setMode ( 'light' ) ;
1827 document . body . style . backgroundColor = 'white' ;
28+ showAlert ( "light mode has been enabled" , "success" ) ;
1929 }
2030 }
2131
2232 return (
2333 < >
2434 < Navbar title = "TextUtils" aboutText = "About" mode = { mode } toggleMode = { toggleMode } />
25- < Alert Alert = "This is alert" />
35+ < Alert alert = { alert } />
2636 { /* <Navbar title = "textUtils" aboutText = "About textUtils"/> */ }
2737 < div className = "container my-3" >
2838 { /* <TextForm heading = "Enter the text to analyze below"/> */ }
Original file line number Diff line number Diff line change 11import React from 'react' ;
22
3- export default function Alert ( props ) {
3+ function Alert ( props ) {
44 return (
5- < >
6- < div className = "alert alert-warning alert-dismissible fade show" role = "alert" >
7- < strong > { props . Alert } </ strong >
8- < button type = "button" className = "btn-close" data-bs-dismiss = "alert" aria-label = "Close" > </ button >
9- </ div >
10- </ >
5+ props . alert && < div className = "alert alert-warning alert-dismissible fade show" role = "alert" >
6+ < strong > { props . alert . type } </ strong > : { props . alert . msg }
7+ < button type = "button" className = "btn-close" data-bs-dismiss = "alert" aria-label = "Close" > </ button >
8+ </ div >
119 )
12- }
10+ }
11+
12+ export default Alert ;
You can’t perform that action at this time.
0 commit comments