UNPKG

tristate-checkbox

Version:

Do not download. It will not work for you. This is a test. This is a tristate checkbox that exists in three states, all items checked, some items checked, and no items checked

37 lines (31 loc) 1.1 kB
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { asEnumerable } from 'linq-es5'; @Component({ selector: 'tristate-checkbox', templateUrl: './tristate-checkbox.component.html' }) export class TriStateCheckboxComponent implements OnInit { @Input() listItems: any[]; @Output() onSelected = new EventEmitter<string>(); constructor() { } public get allSelected(): boolean { return asEnumerable(this.listItems).All(i => i.isSelected); } public get noneSelected(): boolean { return asEnumerable(this.listItems).All(i => !i.isSelected); } public get someSelected(): boolean { return asEnumerable(this.listItems).Any(i => i.isSelected) && !this.allSelected; } public onClick(): void { if (this.allSelected) { this.listItems.forEach(i => i.isSelected = false); return; } if (this.noneSelected || this.someSelected) this.listItems.forEach(i => i.isSelected = true); } ngOnInit() { } }