File

src/app/todo/todo.component.ts

Metadata

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(TodosService: TodosService)
Parameters :
Name Type Optional
TodosService TodosService No

Inputs

completed
Type : boolean
favorite
Type : boolean | undefined
id
Type : number
todo
Type : string
userId
Type : number

Outputs

deleteEvent
Type : EventEmitter
loveEvent
Type : EventEmitter
toggleEvent
Type : EventEmitter

Methods

deleteTodo
deleteTodo()
Returns : void
loveTodo
loveTodo()
Returns : void
toggleCompleted
toggleCompleted()
Returns : void

Properties

statusSelected$
Type : Observable<string>
Default value : this.TodosService.statusSelected
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Todo } from '../Todo';
import { TodosService } from '../todos.service'
import { Observable } from 'rxjs';


@Component({
  selector: 'app-todo',
  templateUrl: './todo.component.html',
  styleUrls: ['./todo.component.css']
})
export class TodoComponent {
  @Input() 
  id!: number;
  @Input() 
  todo!: string;
  @Input() 
  completed!: boolean;
  @Input()
  userId!: number;
  @Input()
  favorite!: boolean | undefined;
  
  @Output() deleteEvent = new EventEmitter<number>();
  @Output() toggleEvent = new EventEmitter<Todo>();
  @Output() loveEvent = new EventEmitter<number>();
  
  statusSelected$: Observable<string> =this.TodosService.statusSelected;
  constructor(private TodosService: TodosService) { }

  deleteTodo() {
    this.deleteEvent.emit(this.id)
  }

  loveTodo() {
    this.loveEvent.emit(this.id)
  }

  toggleCompleted() {
    this.toggleEvent.emit({id: this.id, todo: this.todo, completed: this.completed, userId: this.userId})
  }

}
<li class="task">
    <label for="0">
        <input type="checkbox" id={{id}} [(ngModel)]="completed" (change)="toggleCompleted()"
            *ngIf="(statusSelected$ | async) != 'deleted'">
        <p [ngClass]="{'checked': completed}">{{id}} - {{todo}}</p>

    </label>
    <div class="settings">
        <i class="bi" [ngClass]="favorite ? 'bi-heart-fill' : 'bi-heart'" (click)="loveTodo()"
            *ngIf="(statusSelected$ | async) != 'deleted'"></i>
        <i class="bi bi-trash" (click)="deleteTodo()" *ngIf="(statusSelected$ | async) != 'deleted'"></i>
        <i class="bi bi-info-circle" routerLink="/todos/{{id}}" *ngIf="(statusSelected$ | async) != 'deleted'"></i>
    </div>
</li>

./todo.component.css

@import "~bootstrap-icons/font/bootstrap-icons.css";

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Poppins", sans-serif;
}

.controls,
li {
    display: flex;
    align-items: center;
    justify-content: space-between;
}


.clear-btn {
    border: none;
    opacity: 0.6;
    outline: none;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    padding: 7px 13px;
    border-radius: 4px;
    letter-spacing: 0.3px;
    transition: transform 0.25s ease;
    background: linear-gradient(135deg, #f5af19 0%, #f12711 100%);
}



.task {
    list-style: none;
    font-size: 17px;
    margin-bottom: 18px;
    padding-bottom: 16px;
    align-items: flex-start;
    border-bottom: 1px solid #ccc;
}

.task label {
    display: flex;
    align-items: flex-start;
    max-width: 75%;
}

.task label input {
    margin-top: 7px;
    accent-color: #cbccc8;
}

.task label p {
    user-select: none;
    margin-left: 12px;
    word-wrap: break-word;
}

.task label p.checked {
    text-decoration: line-through;
}

.settings {
    position: relative;
}

.settings :where(i, li) {
    cursor: pointer;
}

.settings .task-menu {
    position: absolute;
    right: -5px;
    bottom: -65px;
    padding: 5px 0;
    background: #fff;
    border-radius: 4px;
    transform: scale(0);
    transform-origin: top right;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
    z-index: 10;
}

.task:last-child .task-menu {
    bottom: 0;
    transform-origin: bottom right;
}

.task:first-child .task-menu {
    bottom: -65px;
    transform-origin: top right;
}

.task-menu.show {
    transform: scale(1);
}

.task-menu li {
    height: 25px;
    font-size: 16px;
    margin-bottom: 2px;
    padding: 17px 15px;
    cursor: pointer;
    justify-content: flex-start;
}

.task-menu li:last-child {
    margin-bottom: 0;
}

.settings li:hover {
    background: #f5f5f5;
}

.settings li i {
    padding-right: 8px;
}

.settings button {
    margin-left: 5px;
}

i.bi-trash:hover {
    color: red;
}

i {
    margin-left: 5px;
}

i.bi-info-circle:hover {
    color: #0077c2;
}

i.bi-heart:hover {
    color: orange;
}

i.bi-heart-fill {
    color: #f8b574;
}

@media (max-width: 400px) {
    body {
        padding: 0 10px;
    }

    .wrapper {
        padding: 20px 0;
    }

    .filters span {
        margin: 0 5px;
    }

    .task-input {
        padding: 0 20px;
    }

    .controls {
        padding: 18px 20px;
    }

    .task-box {
        margin-top: 20px;
        margin-right: 5px;
        padding: 0 15px 10px 20px;
    }

    .task label input {
        margin-top: 4px;
    }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""