Skip to content

Commit

Permalink
Merge pull request #58 from IvanPerez9/feature/groceryList
Browse files Browse the repository at this point in the history
Init groceryList - Test
  • Loading branch information
IvanPerez9 authored Oct 27, 2023
2 parents ef91a10 + e676c84 commit 36e6452
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
27 changes: 27 additions & 0 deletions GroceryList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width"/>
<title>Grocery List</title>
<link rel="stylesheet" href="assets/css/grocery.css">
</head>
<body>

<div class="container">
<div class="grocery-list">
<h2> Mi lista de la compra <img src="assets/images/icon.png" alt="" ></h2>
<div class="row">
<input type="text" id="input-box" placeholder="Añadir producto">
<button onclick="addTask()">+</button>
</div>
<ul id="list-container"">
<li class="checked">Ejemplo</li>
</ul>
</div>
</div>

<script src="assets/js/grocery.js"></script>
</body>
</html>
116 changes: 116 additions & 0 deletions assets/css/grocery.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
*{
margin: 0;
padding: 0;
font-family: 'Poppins', sans-serif;
box-sizing: border-box;
}

.container{
width: 100%;
min-height: 100vh;
background: linear-gradient(135deg, #153677, #4e085f);
padding: 10px;
}

.grocery-list{
width: 100%;
max-width: 540px;
background: #fff;
margin: 80px auto 20px;
padding: 40px 30px 70px;
border-radius: 10px;
}

.grocery-list h2{
color: #002765;
display: flex;
align-items: center;
margin-bottom: 20px;
}

.grocery-list h2 img{
width: 30px;
margin-left: 10px;
}

.row{
display: flex;
align-items: center;
justify-content: space-between;
background: #edeef0;
border-radius: 30px;
padding-left: 20px;
margin-bottom: 20px;
}

input{
flex: 1;
border: none;
outline: none;
background: transparent;
padding: 8px;
font-weight: 14px;
}

button{
border: none;
outline: none;
padding: 16px 30px;
/*background: #ff5954;*/
background: #f0575f;
color: #fff;
font-size: 17px;
font-weight: bolder;
cursor: pointer;
border-radius: 40px;
}

ul li {
list-style: none;
font-size: 16px;
padding: 12px 8px 12px 40px;
user-select: none;
cursor: pointer;
position: relative;
}

ul li::before{
content: '';
position: absolute;
height: 22px;
width: 22px;
border-radius: 50%;
background-image: url(../images/unchecked.png);
background-size: cover;
background-position: ccenter;
top:12px;
left: 8px;
}

/*Tacha cuando checked*/
ul li.checked{
color: #555;
text-decoration: line-through;
}

/*Rellena el circulo con una imagen si checked*/
ul li.checked::before{
background-image: url(../images/checked.png);;
}

ul li span{
position: absolute;
right: 0;
top: 5px;
width: 40px;
height: 40px;
font-size: 22px;
color: #555;
line-height: 40px;
text-align: center;
border-radius: 50%;
}

ul li span:hover{
background: #edeef0;
}
Binary file added assets/images/checked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/unchecked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions assets/js/grocery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const inputBox = document.getElementById("input-box")
const listContainer = document.getElementById("list-container")

/*
Funcion que controla el añadido a la lista
*/
function addTask(){
// Si no he escrito nada, no hacer nada
if(inputBox.value === ''){

} else {
// Crea el elemento de la lista
let li = document.createElement("li");
li.innerHTML = inputBox.value;
listContainer.appendChild(li);
// Le añade una cruz para el borrado
let span = document.createElement("span");
span.innerHTML = "\u00d7";
li.appendChild(span)
}

// Limpiar la entrada despues de añadir
inputBox.value = "";
// Almacena lo añadido
saveData();
}

/*
Funciona para escuchar distintos click en la app
*/
listContainer.addEventListener("click", function(e){
// Mira si hacemos click en un LI
// Cambiamos o quitamos el checked
if(e.target.tagName === "LI"){
e.target.classList.toggle("checked");
saveData();
// Si hacemos click en un SPAN
// Borra el elemento
} else if (e.target.tagName === "SPAN"){
e.target.parentElement.remove();
saveData();
}

} , false);

/*
Funciona para almacenar lo escrito en sesiones
Lo guardamos en local como "data"
*/
function saveData(){
localStorage.setItem("data", listContainer.innerHTML);
}

/*
Funcion para ver siempre "data" cuando recargemos la web
*/
function showDataList(){
listContainer.innerHTML = localStorage.getItem("data");
}

// Llamada para recuperar siempre los datos
showDataList();

0 comments on commit 36e6452

Please sign in to comment.