relay-rw.component.ts raw
1 import {
2 Component,
3 EventEmitter,
4 HostBinding,
5 HostListener,
6 Input,
7 Output,
8 } from '@angular/core';
9
10 @Component({
11 // eslint-disable-next-line @angular-eslint/component-selector
12 selector: 'lib-relay-rw',
13 imports: [],
14 templateUrl: './relay-rw.component.html',
15 styleUrl: './relay-rw.component.scss',
16 })
17 export class RelayRwComponent {
18 @Input({ required: true }) type!: 'read' | 'write';
19 @Input({ required: true }) model!: boolean;
20 @Input() readonly = false;
21 @Output() modelChange = new EventEmitter<boolean>();
22
23 @HostBinding('class.read') get isRead() {
24 return this.type === 'read';
25 }
26
27 @HostBinding('class.is-selected') get isSelected() {
28 return this.model;
29 }
30
31 @HostBinding('class.is-readonly') get isReadonly() {
32 return this.readonly;
33 }
34
35 @HostListener('click') onClick() {
36 if (this.readonly) {
37 return;
38 }
39 this.model = !this.model;
40 this.modelChange.emit(this.model);
41 }
42 }
43