feat(index.html,script.js,form.css,items.css,style.css)finalizando projeto shopping-list

This commit is contained in:
wellington carlos 2022-11-14 18:09:48 -03:00
parent 76e4dcff10
commit bd73e5f9fa
5 changed files with 148 additions and 25 deletions

View File

@ -9,7 +9,7 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style/style.css"> <link rel="stylesheet" href="style/style.css">
<link rel="stylesheet" href="..script/script.js" defender>
<title>Document</title> <title>Document</title>
</head> </head>
@ -19,7 +19,7 @@
<section class="shopping-container"> <section class="shopping-container">
<h2 class="shopping-title"> shopping list</h2> <h2 class="shopping-title"> shopping list</h2>
<form class="shoppinh-form"> <form class="shopping-form">
<div class="shopping-form-inputs"> <div class="shopping-form-inputs">
<div class="shopping-form-item-wraper"> <div class="shopping-form-item-wraper">
<label class="shopping-form-label" for="item-name">item name</label> <label class="shopping-form-label" for="item-name">item name</label>
@ -40,8 +40,21 @@
<button class="shopping-form-submit-button" type="submit"> add to list</button> <button class="shopping-form-submit-button" type="submit"> add to list</button>
</form> </form>
<div class="shopping-result">
<div class="shopping-result-head">
<strong>item</strong>
<strong>quantity</strong>
</div>
<ul class="shopping-items">
</ul>
</div>
</section> </section>
</main> </main>
<script src="script/script.js"></script>
</body> </body>
</html> </html>

View File

@ -0,0 +1,82 @@
document.addEventListener('DOMContentLoaded', function () {
const quantidade = document.querySelector('.shopping-form-quantity-input')
const adicionar = document.querySelector('.shopping-form-increment-button')
const remover = document.querySelector('.shopping-form-decrement-button')
adicionar.addEventListener('click', adicionarMaisUm)
function adicionarMaisUm() {
const valorAtual = Number(quantidade.value)
const novoValor = valorAtual + 1
quantidade.value = novoValor
}
remover.addEventListener('click', menosUm)
function menosUm() {
const valorAtual = Number(quantidade.value)
const novoValor = valorAtual - 1
if (novoValor > 0) {
quantidade.value = novoValor
}
}
const lista = []
const formulario = document.querySelector('.shopping-form')
const produtosDoFormulario = document.querySelector('.shopping-form-item-input')
formulario.addEventListener('submit', adicionarProdutoNaLista)
function adicionarProdutoNaLista(event) {
event.preventDefault()
const nomeDoProduto = event.target['item-name'].value
const quantidadeDeProdutos = event.target['item-quantity'].value
if (nomeDoProduto != '') {
const carrinho = {
nome: nomeDoProduto,
quantidade: quantidadeDeProdutos
}
lista.push(carrinho)
mostrarLista()
resetar()
}
}
const produtos = document.querySelector('.shopping-items')
function mostrarLista() {
let estruturaDosProdutos = ''
lista.forEach(function (carrinho) {
estruturaDosProdutos += `
<li class="shopping-item">
<span>${carrinho.nome}</span>
<span>${carrinho.quantidade}</span>
</li>
`
})
produtos.innerHTML = estruturaDosProdutos
}
function resetar() {
produtosDoFormulario.value = ''
quantidade.value = 1
}
})

View File

@ -1,4 +1,9 @@
.shopping-form-inputs{ .shopping-form {
margin-bottom: 32px;
}
.shopping-form-inputs {
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
@ -7,40 +12,40 @@
} }
.shopping-form-item-wraper{ .shopping-form-item-wraper {
flex: 1; flex: 1;
max-width: 256px; max-width: 256px;
} }
.shopping-form-label{ .shopping-form-label {
display: block; display: block;
margin-bottom: 4px; margin-bottom: 4px;
} }
.shopping-form-item-input, .shopping-form-item-input,
.shopping-form-quantity-input{ .shopping-form-quantity-input {
width: 100%; width: 100%;
height: 32px; height: 32px;
padding: 0 12px; padding: 0 12px;
border: 1px solid var(--gray-300) ; border: 1px solid var(--gray-300);
border-radius: 4px; border-radius: 4px;
background: var(--white); background: var(--white);
} }
.shopping-form-quantity-wrapper{ .shopping-form-quantity-wrapper {
display: flex; display: flex;
align-items: center; align-items: center;
margin-left: 24px; margin-left: 24px;
} }
.shopping-form-quantity-input{ .shopping-form-quantity-input {
max-width: 64px; max-width: 64px;
text-align: center; text-align: center;
margin: 0 4px; margin: 0 4px;
} }
.shopping-form-quantity-button{ .shopping-form-quantity-button {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@ -52,16 +57,18 @@
transition: background-color 0.2s linear; transition: background-color 0.2s linear;
} }
.shopping-form-quantity-button:hover{
.shopping-form-quantity-button:hover {
background: var(--orange-500); background: var(--orange-500);
} }
.shopping-form-quantity-button:active{
.shopping-form-quantity-button:active {
background: var(--orange-300); background: var(--orange-300);
} }
.shopping-form-quantity-button::before, .shopping-form-quantity-button::before,
.shopping-form-increment-button::after{ .shopping-form-increment-button::after {
content:''; content: '';
position: absolute; position: absolute;
width: 16px; width: 16px;
height: 4px; height: 4px;
@ -70,11 +77,11 @@
} }
.shopping-form-increment-button::after{ .shopping-form-increment-button::after {
transform: rotate(90deg); transform: rotate(90deg);
} }
.shopping-form-submit-button{ .shopping-form-submit-button {
width: 100%; width: 100%;
max-width: 128px; max-width: 128px;
height: 32px; height: 32px;
@ -85,16 +92,11 @@
background: var(--orange-500); background: var(--orange-500);
} }
.shopping-form-submit-button:hover{ .shopping-form-submit-button:hover {
background: var(--gray-300); background: var(--gray-300);
transition: backgound 0.2s linear; transition: backgound 0.2s linear;
} }
.shopping-form-submit-button:active{ .shopping-form-submit-button:active {
background: var(--orange-500); background: var(--orange-500);
} }

25
style/items.css Normal file
View File

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

View File

@ -1,6 +1,7 @@
@import "global.css"; @import "global.css";
@import "varibles.css"; @import "varibles.css";
@import "form.css"; @import "form.css";
@import "items.css";