Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Todo App</title> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| :root { | |
| --primary: #6366f1; | |
| --primary-dark: #4f46e5; | |
| --secondary: #f1f5f9; | |
| --accent: #10b981; | |
| --danger: #ef4444; | |
| --text-primary: #1e293b; | |
| --text-secondary: #64748b; | |
| --background: #f8fafc; | |
| --card-bg: #ffffff; | |
| --shadow: 0 10px 40px rgba(0, 0, 0, 0.1); | |
| --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.05); | |
| } | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| padding: 20px; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| } | |
| header { | |
| text-align: center; | |
| margin-bottom: 30px; | |
| } | |
| .built-with { | |
| font-size: 0.85rem; | |
| color: rgba(255, 255, 255, 0.8); | |
| margin-bottom: 10px; | |
| } | |
| .built-with a { | |
| color: #ffffff; | |
| text-decoration: none; | |
| font-weight: 600; | |
| transition: all 0.3s ease; | |
| } | |
| .built-with a:hover { | |
| text-decoration: underline; | |
| color: #fbbf24; | |
| } | |
| h1 { | |
| color: #ffffff; | |
| font-size: 2.5rem; | |
| font-weight: 700; | |
| text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); | |
| } | |
| .container { | |
| width: 100%; | |
| max-width: 600px; | |
| background: var(--card-bg); | |
| border-radius: 24px; | |
| box-shadow: var(--shadow); | |
| overflow: hidden; | |
| } | |
| .input-section { | |
| padding: 30px; | |
| background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%); | |
| border-bottom: 1px solid #e2e8f0; | |
| } | |
| .input-wrapper { | |
| display: flex; | |
| gap: 12px; | |
| } | |
| .input-wrapper input { | |
| flex: 1; | |
| padding: 16px 20px; | |
| border: 2px solid #e2e8f0; | |
| border-radius: 12px; | |
| font-size: 1rem; | |
| transition: all 0.3s ease; | |
| outline: none; | |
| } | |
| .input-wrapper input:focus { | |
| border-color: var(--primary); | |
| box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1); | |
| } | |
| .input-wrapper input::placeholder { | |
| color: var(--text-secondary); | |
| } | |
| .add-btn { | |
| padding: 16px 24px; | |
| background: var(--primary); | |
| color: white; | |
| border: none; | |
| border-radius: 12px; | |
| font-size: 1rem; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| display: flex; | |
| align-items: center; | |
| gap: 8px; | |
| } | |
| .add-btn:hover { | |
| background: var(--primary-dark); | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4); | |
| } | |
| .add-btn:active { | |
| transform: translateY(0); | |
| } | |
| .filters { | |
| display: flex; | |
| gap: 10px; | |
| padding: 20px 30px; | |
| background: #f8fafc; | |
| border-bottom: 1px solid #e2e8f0; | |
| flex-wrap: wrap; | |
| } | |
| .filter-btn { | |
| padding: 10px 20px; | |
| border: none; | |
| background: transparent; | |
| color: var(--text-secondary); | |
| font-size: 0.9rem; | |
| font-weight: 500; | |
| cursor: pointer; | |
| border-radius: 8px; | |
| transition: all 0.3s ease; | |
| } | |
| .filter-btn:hover { | |
| background: #e2e8f0; | |
| color: var(--text-primary); | |
| } | |
| .filter-btn.active { | |
| background: var(--primary); | |
| color: white; | |
| } | |
| .stats { | |
| margin-left: auto; | |
| display: flex; | |
| align-items: center; | |
| gap: 15px; | |
| font-size: 0.85rem; | |
| color: var(--text-secondary); | |
| } | |
| .stat-item { | |
| display: flex; | |
| align-items: center; | |
| gap: 5px; | |
| } | |
| .stat-item i { | |
| font-size: 0.8rem; | |
| } | |
| .todo-list { | |
| list-style: none; | |
| max-height: 500px; | |
| overflow-y: auto; | |
| } | |
| .todo-list::-webkit-scrollbar { | |
| width: 6px; | |
| } | |
| .todo-list::-webkit-scrollbar-track { | |
| background: #f1f5f9; | |
| } | |
| .todo-list::-webkit-scrollbar-thumb { | |
| background: #cbd5e1; | |
| border-radius: 3px; | |
| } | |
| .todo-item { | |
| display: flex; | |
| align-items: center; | |
| padding: 20px 30px; | |
| border-bottom: 1px solid #f1f5f9; | |
| transition: all 0.3s ease; | |
| animation: slideIn 0.3s ease; | |
| } | |
| @keyframes slideIn { | |
| from { | |
| opacity: 0; | |
| transform: translateX(-20px); | |
| } | |
| to { | |
| opacity: 1; | |
| transform: translateX(0); | |
| } | |
| } | |
| .todo-item:hover { | |
| background: #fafbfc; | |
| } | |
| .todo-item.completed .todo-text { | |
| text-decoration: line-through; | |
| color: var(--text-secondary); | |
| } | |
| .todo-item.completed .checkbox { | |
| background: var(--accent); | |
| border-color: var(--accent); | |
| } | |
| .todo-item.completed .checkbox i { | |
| opacity: 1; | |
| } | |
| .checkbox { | |
| width: 24px; | |
| height: 24px; | |
| border: 2px solid #e2e8f0; | |
| border-radius: 6px; | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: all 0.3s ease; | |
| flex-shrink: 0; | |
| } | |
| .checkbox i { | |
| color: white; | |
| font-size: 0.75rem; | |
| opacity: 0; | |
| transition: all 0.3s ease; | |
| } | |
| .checkbox:hover { | |
| border-color: var(--accent); | |
| } | |
| .todo-text { | |
| flex: 1; | |
| margin-left: 15px; | |
| font-size: 1rem; | |
| color: var(--text-primary); | |
| word-break: break-word; | |
| } | |
| .todo-date { | |
| font-size: 0.75rem; | |
| color: var(--text-secondary); | |
| margin-left: 10px; | |
| white-space: nowrap; | |
| } | |
| .todo-actions { | |
| display: flex; | |
| gap: 8px; | |
| margin-left: 15px; | |
| opacity: 0; | |
| transition: all 0.3s ease; | |
| } | |
| .todo-item:hover .todo-actions { | |
| opacity: 1; | |
| } | |
| .action-btn { | |
| width: 36px; | |
| height: 36px; | |
| border: none; | |
| border-radius: 8px; | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: all 0.3s ease; | |
| } | |
| .edit-btn { | |
| background: #e0f2fe; | |
| color: #0284c7; | |
| } | |
| .edit-btn:hover { | |
| background: #0284c7; | |
| color: white; | |
| } | |
| .delete-btn { | |
| background: #fee2e2; | |
| color: var(--danger); | |
| } | |
| .delete-btn:hover { | |
| background: var(--danger); | |
| color: white; | |
| } | |
| .empty-state { | |
| text-align: center; | |
| padding: 60px 30px; | |
| color: var(--text-secondary); | |
| } | |
| .empty-state i { | |
| font-size: 4rem; | |
| margin-bottom: 20px; | |
| color: #e2e8f0; | |
| } | |
| .empty-state h3 { | |
| font-size: 1.25rem; | |
| margin-bottom: 10px; | |
| color: var(--text-primary); | |
| } | |
| .empty-state p { | |
| font-size: 0.9rem; | |
| } | |
| .clear-completed { | |
| padding: 15px 30px; | |
| background: #f8fafc; | |
| border-top: 1px solid #e2e8f0; | |
| display: flex; | |
| justify-content: flex-end; | |
| } | |
| .clear-btn { | |
| padding: 10px 20px; | |
| background: transparent; | |
| border: 1px solid #e2e8f0; | |
| border-radius: 8px; | |
| color: var(--text-secondary); | |
| font-size: 0.85rem; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| } | |
| .clear-btn:hover { | |
| background: var(--danger); | |
| color: white; | |
| border-color: var(--danger); | |
| } | |
| /* Edit Modal */ | |
| .modal-overlay { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| bottom: 0; | |
| background: rgba(0, 0, 0, 0.5); | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| opacity: 0; | |
| visibility: hidden; | |
| transition: all 0.3s ease; | |
| z-index: 1000; | |
| padding: 20px; | |
| } | |
| .modal-overlay.active { | |
| opacity: 1; | |
| visibility: visible; | |
| } | |
| .modal { | |
| background: white; | |
| border-radius: 16px; | |
| padding: 30px; | |
| width: 100%; | |
| max-width: 400px; | |
| transform: scale(0.9); | |
| transition: all 0.3s ease; | |
| } | |
| .modal-overlay.active .modal { | |
| transform: scale(1); | |
| } | |
| .modal h2 { | |
| margin-bottom: 20px; | |
| color: var(--text-primary); | |
| } | |
| .modal input { | |
| width: 100%; | |
| padding: 14px 18px; | |
| border: 2px solid #e2e8f0; | |
| border-radius: 10px; | |
| font-size: 1rem; | |
| margin-bottom: 20px; | |
| outline: none; | |
| transition: all 0.3s ease; | |
| } | |
| .modal input:focus { | |
| border-color: var(--primary); | |
| } | |
| .modal-actions { | |
| display: flex; | |
| gap: 10px; | |
| justify-content: flex-end; | |
| } | |
| .modal-btn { | |
| padding: 12px 24px; | |
| border: none; | |
| border-radius: 8px; | |
| font-size: 0.9rem; | |
| font-weight: 500; | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| } | |
| .cancel-btn { | |
| background: #f1f5f9; | |
| color: var(--text-secondary); | |
| } | |
| .cancel-btn:hover { | |
| background: #e2e8f0; | |
| } | |
| .save-btn { | |
| background: var(--primary); | |
| color: white; | |
| } | |
| .save-btn:hover { | |
| background: var(--primary-dark); | |
| } | |
| /* Priority badges */ | |
| .priority-badge { | |
| font-size: 0.7rem; | |
| padding: 4px 8px; | |
| border-radius: 4px; | |
| margin-left: 10px; | |
| font-weight: 600; | |
| } | |
| .priority-high { | |
| background: #fee2e2; | |
| color: #dc2626; | |
| } | |
| .priority-medium { | |
| background: #fef3c7; | |
| color: #d97706; | |
| } | |
| .priority-low { | |
| background: #d1fae5; | |
| color: #059669; | |
| } | |
| @media (max-width: 600px) { | |
| body { | |
| padding: 15px; | |
| } | |
| h1 { | |
| font-size: 2rem; | |
| } | |
| .input-wrapper { | |
| flex-direction: column; | |
| } | |
| .add-btn { | |
| justify-content: center; | |
| } | |
| .filters { | |
| padding: 15px 20px; | |
| } | |
| .stats { | |
| width: 100%; | |
| margin-left: 0; | |
| margin-top: 10px; | |
| justify-content: center; | |
| } | |
| .todo-item { | |
| padding: 15px 20px; | |
| } | |
| .todo-actions { | |
| opacity: 1; | |
| } | |
| .todo-date { | |
| display: none; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <p class="built-with">Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" | |
| target="_blank">anycoder</a></p> | |
| <h1><i class="fas fa-check-circle"></i> Todo App</h1> | |
| </header> | |
| <div class="container"> | |
| <div class="input-section"> | |
| <div class="input-wrapper"> | |
| <input type="text" id="todoInput" placeholder="What needs to be done?" autofocus> | |
| <button class="add-btn" onclick="addTodo()"> | |
| <i class="fas fa-plus"></i> | |
| <span>Add</span> | |
| </button> | |
| </div> | |
| </div> | |
| <div class="filters"> | |
| <button class="filter-btn active" data-filter="all" onclick="filterTodos('all')">All</button> | |
| <button class="filter-btn" data-filter="active" onclick="filterTodos('active')">Active</button> | |
| <button class="filter-btn" data-filter="completed" onclick="filterTodos('completed')">Completed</button> | |
| <div class="stats"> | |
| <span class="stat-item"><i class="fas fa-tasks"></i> <span id="totalCount">0</span> total</span> | |
| <span class="stat-item"><i class="fas fa-check"></i> <span id="completedCount">0</span> done</span> | |
| </div> | |
| </div> | |
| <ul class="todo-list" id="todoList"> | |
| <!-- Todos will be rendered here --> | |
| </ul> | |
| <div class="clear-completed" id="clearSection" style="display: none;"> | |
| <button class="clear-btn" onclick="clearCompleted()"> | |
| <i class="fas fa-trash-alt"></i> Clear Completed | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Edit Modal --> | |
| <div class="modal-overlay" id="editModal"> | |
| <div class="modal"> | |
| <h2><i class="fas fa-edit"></i> Edit Task</h2> | |
| <input type="text" id="editInput" placeholder="Update your task"> | |
| <div class="modal-actions"> | |
| <button class="modal-btn cancel-btn" onclick="closeModal()">Cancel</button> | |
| <button class="modal-btn save-btn" onclick="saveEdit()">Save</button> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| let todos = JSON.parse(localStorage.getItem('todos')) || []; | |
| let currentFilter = 'all'; | |
| let editingId = null; | |
| // Initialize | |
| document.addEventListener('DOMContentLoaded', () => { | |
| renderTodos(); | |
| document.getElementById('todoInput').addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') addTodo(); | |
| }); | |
| document.getElementById('editInput').addEventListener('keypress', (e) => { | |
| if (e.key === 'Enter') saveEdit(); | |
| }); | |
| }); | |
| function generateId() { | |
| return Date.now().toString(36) + Math.random().toString(36).substr(2); | |
| } | |
| function formatDate(date) { | |
| const options = { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }; | |
| return new Date(date).toLocaleDateString('en-US', options); | |
| } | |
| function addTodo() { | |
| const input = document.getElementById('todoInput'); | |
| const text = input.value.trim(); | |
| if (!text) { | |
| input.classList.add('shake'); | |
| setTimeout(() => input.classList.remove('shake'), 500); | |
| return; | |
| } | |
| const todo = { | |
| id: generateId(), | |
| text: text, | |
| completed: false, | |
| createdAt: new Date().toISOString() | |
| }; | |
| todos.unshift(todo); | |
| saveTodos(); | |
| renderTodos(); | |
| input.value = ''; | |
| input.focus(); | |
| } | |
| function toggleTodo(id) { | |
| todos = todos.map(todo => | |
| todo.id === id ? { ...todo, completed: !todo.completed } : todo | |
| ); | |
| saveTodos(); | |
| renderTodos(); | |
| } | |
| function deleteTodo(id) { | |
| const todoElement = document.querySelector(`[data-id="${id}"]`); | |
| todoElement.style.animation = 'slideOut 0.3s ease forwards'; | |
| setTimeout(() => { | |
| todos = todos.filter(todo => todo.id !== id); | |
| saveTodos(); | |
| renderTodos(); | |
| }, 300); | |
| } | |
| function editTodo(id) { | |
| editingId = id; | |
| const todo = todos.find(t => t.id === id); | |
| document.getElementById('editInput').value = todo.text; | |
| document.getElementById('editModal').classList.add('active'); | |
| document.getElementById('editInput').focus(); | |
| } | |
| function closeModal() { | |
| document.getElementById('editModal').classList.remove('active'); | |
| editingId = null; | |
| } | |
| function saveEdit() { | |
| const text = document.getElementById('editInput').value.trim(); | |
| if (!text) return; | |
| todos = todos.map(todo => | |
| todo.id === editingId ? { ...todo, text: text } : todo | |
| ); | |
| saveTodos(); | |
| renderTodos(); | |
| closeModal(); | |
| } | |
| function filterTodos(filter) { | |
| currentFilter = filter; | |
| document.querySelectorAll('.filter-btn').forEach(btn => { | |
| btn.classList.toggle('active', btn.dataset.filter === filter); | |
| }); | |
| renderTodos(); | |
| } | |
| function clearCompleted() { | |
| todos = todos.filter(todo => !todo.completed); | |
| saveTodos(); | |
| renderTodos(); | |
| } | |
| function saveTodos() { | |
| localStorage.setItem('todos', JSON.stringify(todos)); | |
| } | |
| function getFilteredTodos() { | |
| switch (currentFilter) { | |
| case 'active': | |
| return todos.filter(todo => !todo.completed); | |
| case 'completed': | |
| return todos.filter(todo => todo.completed); | |
| default: | |
| return todos; | |
| } | |
| } | |
| function renderTodos() { | |
| const todoList = document.getElementById('todoList'); | |
| const filteredTodos = getFilteredTodos(); | |
| const completedCount = todos.filter(t => t.completed).length; | |
| document.getElementById('totalCount').textContent = todos.length; | |
| document.getElementById('completedCount').textContent = completedCount; | |
| document.getElementById('clearSection').style.display = | |
| completedCount > 0 ? 'flex' : 'none'; | |
| if (filteredTodos.length === 0) { | |
| todoList.innerHTML = ` | |
| <div class="empty-state"> | |
| <i class="fas fa-clipboard-list"></i> | |
| <h3>${currentFilter === 'all' ? 'No tasks yet' : `No ${currentFilter} tasks`}</h3> | |
| <p>${currentFilter === 'all' ? 'Add a task to get started!' : 'Check your other filters.'}</p> | |
| </div> | |
| `; | |
| return; | |
| } | |
| todoList.innerHTML = filteredTodos.map(todo => ` | |
| <li class="todo-item ${todo.completed ? 'completed' : ''}" data-id="${todo.id}"> | |
| <div class="checkbox" onclick="toggleTodo('${todo.id}')"> | |
| <i class="fas fa-check"></i> | |
| </div> | |
| <span class="todo-text">${escapeHtml(todo.text)}</span> | |
| <span class="todo-date">${formatDate(todo.createdAt)}</span> | |
| <div class="todo-actions"> | |
| <button class="action-btn edit-btn" onclick="editTodo('${todo.id}')" title="Edit"> | |
| <i class="fas fa-pen"></i> | |
| </button> | |
| <button class="action-btn delete-btn" onclick="deleteTodo('${todo.id}')" title="Delete"> | |
| <i class="fas fa-trash"></i> | |
| </button> | |
| </div> | |
| </li> | |
| `).join(''); | |
| } | |
| function escapeHtml(text) { | |
| const div = document.createElement('div'); | |
| div.textContent = text; | |
| return div.innerHTML; | |
| } | |
| // Close modal when clicking outside | |
| document.getElementById('editModal').addEventListener('click', (e) => { | |
| if (e.target.classList.contains('modal-overlay')) { | |
| closeModal(); | |
| } | |
| }); | |
| // Add animation keyframes | |
| const style = document.createElement('style'); | |
| style.textContent = ` | |
| @keyframes slideOut { | |
| to { | |
| opacity: 0; | |
| transform: translateX(100px); | |
| } | |
| } | |
| @keyframes shake { | |
| 0%, 100% { transform: translateX(0); } | |
| 25% { transform: translateX(-5px); } | |
| 75% { transform: translateX(5px); } | |
| } | |
| .shake { | |
| animation: shake 0.3s ease; | |
| border-color: var(--danger) !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| </script> | |
| </body> | |
| </html> |