feat(terminei): Feito todas as partes funcionais do shopping list

This commit is contained in:
Vinícius Gabriel 2022-11-13 10:35:37 -03:00
parent 6877840931
commit f481aad592
5 changed files with 82 additions and 13 deletions

View File

@ -19,7 +19,7 @@
<label class="shopping-form-label" for="item-name">Item name</label>
<input class="shopping-form-item-input" type="text" name="item-name" id="item-name">
</div>
<div class="shopping-form-quatity-warapper">
<button class="shopping-form-quatity-button shopping-form-decrement-button" type="button"></button>
<input class="shopping-form-quantity-input" name="item-quatity" type="text" value="1" disabled>
@ -31,13 +31,18 @@
<button class="shopping-form-submit-button" type="submit">Add to list</button>
</form>
<div class="shopping-result">
<div class="shopping-result-head">
<strong>Item</strong>
<strong>Quantity</strong>
</div>
<ul class="shopping-items"></ul>
</div>
</section>
<div>
<ul>
</ul>
</div>
</main>
<script src="scripts/app.js"></script>

View File

@ -1,13 +1,16 @@
document.addEventListener('DOMContentLoaded', function(){
const quantityInput = document.querySelector('.shopping-form-quantity-input');
const list = [];
const quantityInput = document.querySelector('.shopping-form-quantity-input');
const increment = document.querySelector('.shopping-form-increment-button');
const decrement = document.querySelector('.shopping-form-decrement-button');
const textValue = document.querySelector('.shopping-form-submit-button');
const form = document.querySelector('.shopping-form');
const itemInput = document.querySelector('.shopping-form-item-input');
const items = document.querySelector('.shopping-items')
increment.addEventListener('click', addIcrement)
decrement.addEventListener('click', addDecrement)
textValue.addEventListener('click', addTextValue)
increment.addEventListener('click', addIcrement);
decrement.addEventListener('click', addDecrement);
form.addEventListener('submit', addTextValue);
function addIcrement() {
const valueQuantityInput = Number(quantityInput.value);
@ -23,14 +26,49 @@ document.addEventListener('DOMContentLoaded', function(){
}
}
const ul = document.querySelector('ul')
const li = createElement('li');
function addTextValue () {
function addTextValue(event) {
event.preventDefault();
const itemName = event.target['item-name'].value
const itemQuantity = event.target['item-quatity'].value
if(itemName != "") {
const item = {
nome: itemName,
quantity: itemQuantity
};
list.push(item);
renderListItems()
resetInput()
}
}
function renderListItems() {
let itemStructure = "";
list.forEach(function (item) {
itemStructure += `
<li class="shopping-item">
<span>${item.nome}</span>
<span>${item.quantity}</span>
</li>
`;
})
items.innerHTML = itemStructure
}
function resetInput() {
itemInput.value = "";
quantityInput.value = 1;
}
})

View File

@ -1,7 +1,11 @@
.shopping-form {
margin-bottom: 32px;
}
.shopping-form-inputs {
display: flex;
align-items: flex-end;
margin-bottom: 24px;
}
.shopping-form-item-wrapper {

View File

@ -0,0 +1,21 @@
.shopping-result {
max-width: 416px;
}
.shopping-result-head, .shopping-item{
display: grid;
grid-template-columns: 3fr 1fr;
padding: 8px 16px;
border-radius: 5px;
}
.shopping-result-head {
background: var(--gray-100);
}
.shopping-items {
list-style: none;
}
.shopping-item:nth-child(even) {
background: var(--gray-100);
}

View File

@ -1,6 +1,7 @@
@import "global.css";
@import "variables.css";
@import "form.css";
@import "itens.css";
.shopping-container {
max-width: 500px;