mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-04-18 15:31:17 -04:00
feat: modal added
This commit is contained in:
parent
ba35554e0e
commit
104849154f
3 changed files with 66 additions and 27 deletions
|
@ -1,16 +1,22 @@
|
|||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
:root {
|
||||
--background-color: #000000;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
margin-top: 20px;
|
||||
margin-bottom: 100px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
align-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navbar ul {
|
||||
|
@ -18,16 +24,22 @@
|
|||
gap: 20px;
|
||||
}
|
||||
|
||||
.content {
|
||||
min-height: 1000px;
|
||||
min-width: 1000px;
|
||||
}
|
||||
|
||||
.book-cards {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
}
|
||||
|
||||
.card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
min-width: 200px;
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet"
|
||||
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
<title>Anonymous Library</title>
|
||||
</head>
|
||||
|
@ -12,29 +14,31 @@
|
|||
<div class="container">
|
||||
<nav class="navbar">
|
||||
<h1 class="header">Anonymous BookClub</h1>
|
||||
<ul>
|
||||
<li>Add Book</li>
|
||||
</ul>
|
||||
<button class="show-modal btn">Add Book</button>
|
||||
</nav>
|
||||
<div class="content">
|
||||
<div class="form">
|
||||
<form action="" >
|
||||
<input type="text" name="title" id="title">
|
||||
<input type="text" name="author" id="author">
|
||||
<button type="submit" id="btn">Submit</button>
|
||||
</form>
|
||||
<div class="book-cards">
|
||||
</div>
|
||||
|
||||
<div class="book-cards">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<footer>
|
||||
<div class="contact"></div>
|
||||
<div class="icons"></div>
|
||||
</footer>
|
||||
</div>
|
||||
<dialog class="modal">
|
||||
<main>
|
||||
<div class="form">
|
||||
<form action="" >
|
||||
<input type="text" name="title" id="title">
|
||||
<input type="text" name="author" id="author">
|
||||
<button type="submit" id="submit-btn" class="btn">Submit</button>
|
||||
</form>
|
||||
<button class="btn close-btn">
|
||||
<span class="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
</dialog>
|
||||
<script src="js/script.js"></script>
|
||||
</body>
|
||||
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
const myLibrary = [];
|
||||
const submitButton = document.querySelector('#submit-btn');
|
||||
|
||||
const booksDiv = document.querySelector('.book-cards');
|
||||
const defaultData = new Book('James Clear', 'Atomic Habits', true);
|
||||
const dialog = document.querySelector("dialog");
|
||||
const addBookButton = document.querySelector(".show-modal");
|
||||
const closeDialogButton = document.querySelector(".close-btn");
|
||||
|
||||
|
||||
|
||||
const defaultData = new Book('Atomic Habits', 'James Clear', false);
|
||||
|
||||
|
||||
function Book(title, author, read) {
|
||||
this.title = title;
|
||||
|
@ -40,9 +49,8 @@ function displayBooks(books) {
|
|||
});
|
||||
}
|
||||
|
||||
const button = document.querySelector('#btn');
|
||||
|
||||
button.addEventListener('click', event => {
|
||||
submitButton.addEventListener('click', event => {
|
||||
const author = document.querySelector('#author').value;
|
||||
const title = document.querySelector('#title').value;
|
||||
const newBook = new Book(title, author, false);
|
||||
|
@ -50,7 +58,22 @@ button.addEventListener('click', event => {
|
|||
addBookToLibrary(newBook);
|
||||
displayBooks(myLibrary);
|
||||
event.preventDefault();
|
||||
})
|
||||
});
|
||||
|
||||
addBookButton.addEventListener('click', () => {
|
||||
dialog.showModal();
|
||||
});
|
||||
|
||||
closeDialogButton.addEventListener('click', () => {
|
||||
dialog.close();
|
||||
});
|
||||
|
||||
// document.addEventListener('click', e => {
|
||||
// if (!e.target.closest("dialog")) {
|
||||
// dialog.showModal();
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
// default data
|
||||
myLibrary.push(defaultData)
|
||||
|
|
Loading…
Add table
Reference in a new issue