Skip to content

Commit fded067

Browse files
new feature added
1 parent f99ad31 commit fded067

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

project-1/project-app/src/App.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@ import TextForm from './components/TextForm';
77

88
function 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"/> */}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import 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;

0 commit comments

Comments
 (0)