Skip to content

Commit 1f2db70

Browse files
committed
toggle-switch: allows to be disabled
Signed-off-by: Louis Greiner <[email protected]>
1 parent 46c293c commit 1f2db70

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
<div class="toggle-switch-button-component">
2-
<span *ngIf="!!labelFalse" [ngClass]="createLabelCheckedTag(false)" (click)="onToggle(false)">{{
3-
labelFalse
4-
}}</span>
1+
<div class="toggle-switch-button-component" [ngClass]="{disabled: disabled}">
2+
<span
3+
*ngIf="labelFalse"
4+
[ngClass]="createLabelCheckedTag(false)"
5+
(click)="!disabled && onToggle(false)"
6+
[style.cursor]="disabled ? 'default' : 'pointer'"
7+
>{{ labelFalse }}</span
8+
>
59
<label class="toggle-switch">
610
<input
711
type="checkbox"
@@ -11,7 +15,11 @@
1115
/>
1216
<span class="slider"></span>
1317
</label>
14-
<span *ngIf="!!labelTrue" [ngClass]="createLabelCheckedTag(true)" (click)="onToggle(true)">{{
15-
labelTrue
16-
}}</span>
18+
<span
19+
*ngIf="labelTrue"
20+
[ngClass]="createLabelCheckedTag(true)"
21+
(click)="!disabled && onToggle(true)"
22+
[style.cursor]="disabled ? 'default' : 'pointer'"
23+
>{{ labelTrue }}</span
24+
>
1725
</div>

src/app/view/toggle-switch-button/toggle-switch-button.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,9 @@
101101
input.non-default + .slider:before {
102102
background: $COLOR_SBB_RED;
103103
}
104+
105+
&.disabled {
106+
opacity: 0.6;
107+
pointer-events: none;
108+
}
104109
}

src/app/view/toggle-switch-button/toggle-switch-button.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@ import {Component, EventEmitter, Input, Output} from "@angular/core";
88
export class ToggleSwitchButtonComponent {
99
@Output() checkedChanged = new EventEmitter<boolean>();
1010
@Input() checked = false;
11-
@Input() labelFalse: string = "";
12-
@Input() labelTrue: string = "";
13-
@Input() tagNonDefault: boolean = false;
11+
@Input() labelFalse = "";
12+
@Input() labelTrue = "";
13+
@Input() tagNonDefault = false;
14+
@Input() disabled = false;
1415

15-
onToggle(check: boolean) {
16+
onToggle(check: boolean): void {
1617
if (!this.labelTrue || !this.labelFalse) {
1718
this.onChange(!this.checked);
1819
return;
1920
}
2021
this.onChange(check);
2122
}
2223

23-
onChange(isChecked: boolean) {
24+
onChange(isChecked: boolean): void {
2425
if (this.checked !== isChecked) {
2526
this.checked = isChecked;
2627
this.checkedChanged.next(this.checked);

0 commit comments

Comments
 (0)