Skip to content

Commit 11ec470

Browse files
committed
Add a modal for books removal
1 parent 584c870 commit 11ec470

File tree

3 files changed

+113
-13
lines changed

3 files changed

+113
-13
lines changed

css/styles.css

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/* FONT FOR BODY TEXT*/
1+
/* BODY TEXT FONT */
22
@font-face {
33
font-family: "Montserrat-Regular";
44
src: url("../fonts/Montserrat-Regular.ttf");
55
}
6-
/* FONT FOR H1 (LOGO) TEXT */
6+
/* H1 (LOGO) TEXT FONT */
77
@font-face {
88
font-family: "MarcellusSC-Regular";
99
src: url("../fonts/MarcellusSC-Regular.ttf");
@@ -36,7 +36,7 @@
3636
background-color: var(--cream);
3737
}
3838

39-
/* COLOR FOR LIBRARY LOGO */
39+
/* LIBRARY LOGO COLOR */
4040
.theme-books {
4141
--fa-secondary-color: var(--white);
4242
--fa-secondary-opacity: 1.0;
@@ -66,7 +66,7 @@
6666
outline: none;
6767
}
6868

69-
/* STYLE FOR FLOATING INPUT PLACEHOLDER */
69+
/* FLOATING INPUT PLACEHOLDER STYLE */
7070
div.input-block {
7171
position: relative;
7272
}
@@ -86,7 +86,7 @@ div.input-block input:focus {
8686
border-bottom: 2px dotted var(--white) !important;
8787
}
8888

89-
/* STYLE FOR NUMBER INPUT */
89+
/* NUMBER INPUT STYLE */
9090
/* Chrome, Safari, Edge, Opera */
9191
input::-webkit-outer-spin-button,
9292
input::-webkit-inner-spin-button {
@@ -98,7 +98,7 @@ input[type=number] {
9898
-moz-appearance: textfield;
9999
}
100100

101-
/* STYLE FOR CHECKBOX INPUT */
101+
/* CHECKBOX INPUT STYLE */
102102
.checkbox {
103103
display: grid;
104104
grid-template-columns: min-content auto;
@@ -135,7 +135,7 @@ input[type=number] {
135135
color: var(--white);
136136
}
137137

138-
/* STYLE FOR 'ADD BOOK' BUTTON */
138+
/* 'ADD BOOK' BUTTON STYLE */
139139
#add-book {
140140
width: 200px;
141141
height: 50px;
@@ -148,7 +148,7 @@ input[type=number] {
148148
}
149149
#add-book:hover {
150150
cursor: pointer;
151-
border: 1px solid var(--dark-blue);
151+
border-color: var(--dark-blue);
152152
background-color: var(--dark-blue);
153153
transition: 0.3s;
154154
}
@@ -158,7 +158,7 @@ input[type=number] {
158158
bottom: 0;
159159
padding: 0 0 30px 0;
160160
}
161-
/* STYLE FOR TOOLTIP */
161+
/* TOOLTIP STYLE */
162162
.project-info .tooltip-text {
163163
visibility: hidden;
164164
padding: 10px;
@@ -211,10 +211,11 @@ input[type=number] {
211211
color: var(--white);
212212
transition: 0.3s;
213213
}
214-
#delete-all-btn:hover {
215-
border: 1px solid var(--dark-red);
216-
background-color: var(--dark-red);
214+
#delete-all-btn:hover,
215+
.confirm-removal:hover {
217216
cursor: pointer;
217+
border-color: var(--dark-red);
218+
background-color: var(--dark-red);
218219
}
219220

220221
#books-list {
@@ -254,3 +255,70 @@ input[type=number] {
254255
.fa-trash-alt:hover {
255256
color: var(--dark-red);
256257
}
258+
259+
/* MODAL STYLE */
260+
#modal {
261+
display: none;
262+
position: fixed;
263+
padding-top: 50px;
264+
left: 0;
265+
top: 0;
266+
width: 100%;
267+
height: 100%;
268+
background-color: rgba(0, 0, 0, 0.5);
269+
}
270+
.modal-card {
271+
position: relative;
272+
margin: auto;
273+
width: 30%;
274+
border: 2px solid var(--blue);
275+
border-radius: 2px;
276+
}
277+
.modal-header {
278+
display: flex;
279+
justify-content: space-between;
280+
background-color: var(--blue);
281+
color: var(--white);
282+
}
283+
.modal-header h2 {
284+
margin: 0;
285+
padding: 20px;
286+
}
287+
.close-modal {
288+
align-self: flex-start;
289+
padding: 0 20px 0 0;
290+
color: var(--white);
291+
font-size: 30px;
292+
font-weight: 900;
293+
}
294+
.close-modal:hover,
295+
.cancel-removal:hover {
296+
cursor: pointer;
297+
}
298+
.modal-content {
299+
display: flex;
300+
flex-direction: column;
301+
padding: 20px;
302+
background-color: var(--white);
303+
}
304+
.modal-content p {
305+
margin: 0;
306+
font-size: 20px;
307+
font-weight: 900;
308+
}
309+
.modal-options {
310+
display: flex;
311+
justify-content: end;
312+
align-items: center;
313+
margin-top: 20px;
314+
}
315+
.confirm-removal {
316+
margin-left: 15px;
317+
height: 40px;
318+
background-color: var(--red);
319+
color: var(--white);
320+
border: 1px solid var(--red);
321+
border-radius: 2px;
322+
transition: 0.3s;
323+
font-weight: 900;
324+
}

index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ <h1 id="logo"><i class="fad fa-books theme-books"></i> Library</i></h1>
9797
</tbody>
9898
</table>
9999

100+
<!-- MODAL -->
101+
<div id="modal" class="close">
102+
<div class="modal-card">
103+
<div class="modal-header">
104+
<h2>BOOKS REMOVAL</h2>
105+
<span class="close-modal close">&times;</span>
106+
</div>
107+
<div class="modal-content">
108+
<p>Do you really want to delete all the books from your library?</p>
109+
<div class="modal-options">
110+
<p class="cancel-removal close">Cancel</p>
111+
<button class="confirm-removal">DELETE ALL</button>
112+
</div>
113+
</div>
114+
</div>
115+
</div>
100116
</main>
101117

102118
<script type="text/javascript" src="scripts.js"></script>

scripts.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,28 @@ function addBookToLibrary(title, author, pages, status) {
7272
showBooksInLibrary();
7373
}
7474

75+
// MODAL FOR BOOKS REMOVAL
76+
function showModal() {
77+
const modal = document.querySelector('#modal');
78+
const closeModal = document.querySelectorAll('.close');
79+
const deleteBooks = document.querySelector('.confirm-removal');
80+
modal.style.display = 'block';
81+
closeModal.forEach((btn) => {
82+
btn.addEventListener('click', () => {
83+
modal.style.display = 'none';
84+
});
85+
});
86+
deleteBooks.addEventListener('click', () => {
87+
myLibrary = [];
88+
});
89+
}
90+
7591
function listenClicks() {
7692
document.addEventListener('click', (event) => {
7793
const { target } = event;
7894
const tr = target.parentNode.parentNode.rowIndex - 1;
7995
if (target.id === 'delete-all-btn') {
80-
myLibrary = [];
96+
showModal();
8197
} else if (target.classList.contains('fa-trash-alt')) {
8298
myLibrary.splice(tr, 1);
8399
} else if (target.classList.contains('fa-check')) {

0 commit comments

Comments
 (0)