Skip to content

Commit b92ba04

Browse files
Add files via upload
1 parent 837ea5d commit b92ba04

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

Backdrop.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function Backdrop(props) {
2+
return <div className="backdrop" onClick={props.onCancel} />;
3+
}
4+
5+
export default Backdrop;

Model.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function Model(props) {
2+
function cancelHandler() {
3+
props.onCancel();
4+
}
5+
function confirmHandler() {
6+
props.onConfirm();
7+
}
8+
9+
return (
10+
<div className="modal">
11+
<p>Are you sure?</p>
12+
<button className="btn btn--alt" onClick={cancelHandler}>
13+
Cancel
14+
</button>
15+
<button className="btn" onClick={confirmHandler}>
16+
Confirm
17+
</button>
18+
</div>
19+
);
20+
}
21+
22+
export default Model;

Todo.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useState } from "react";
2+
3+
import Backdrop from "./Backdrop";
4+
import Model from "./Model";
5+
6+
function Todo(props) {
7+
const [modalIsOpen, setModalIsOpen] = useState(false);
8+
9+
function deleteHandler() {
10+
setModalIsOpen(true);
11+
}
12+
13+
function closeModalHandler() {
14+
setModalIsOpen(false);
15+
}
16+
17+
return (
18+
<div className="card">
19+
<h2>{props.text}</h2>
20+
<div className="actions">
21+
<button className="btn" onClick={deleteHandler}>
22+
Delete
23+
</button>
24+
</div>
25+
{modalIsOpen && (
26+
<Model onCancel={closeModalHandler} onConfirm={closeModalHandler} />
27+
)}
28+
{modalIsOpen && <Backdrop onCancel={closeModalHandler} />}
29+
</div>
30+
);
31+
}
32+
33+
export default Todo;

0 commit comments

Comments
 (0)