Skip to content

Commit b83e000

Browse files
authored
add config for disabled styles (#52)
1 parent 59fd9e8 commit b83e000

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

projects/demo/src/app/app.component.html

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ <h2 class="subtitle">
3131
<h2 class="subtitle">
3232
Disabled
3333
</h2>
34+
<ng-toggle
35+
[value]="false"
36+
[disabled]="true"
37+
[color]="{checked: '#00FF00', unchecked: 'red', disabled: '#ddd'}"
38+
[labels]="{checked: 'si', unchecked: 'no'}"
39+
></ng-toggle>
3440
<ng-toggle
3541
[value]="false"
3642
[disabled]="true"
37-
[color]="{checked: '#00FF00', unchecked: 'red', disabled: '#ddd'}"
43+
[color]="{checked: '#00FF00', unchecked: 'red', disabled: '#eee'}"
44+
[switchColor]="{disabled: '#ddd', checked: '#000', unchecked: '#000'}"
45+
[fontColor]="{ checked: '#fff', unchecked :'#fff', disabled: '#aaa'}"
3846
[labels]="{checked: 'si', unchecked: 'no'}"
3947
></ng-toggle>
4048

@@ -284,6 +292,17 @@ <h2 class="subtitle">
284292
</div>
285293
</div>
286294

295+
<div class="field is-horizontal">
296+
<div class="field-label">
297+
<label class="label">disabled color: </label>
298+
</div>
299+
<div class="field-body">
300+
<div class="control">
301+
<input type="color" [(ngModel)]="config.color.disabled" aria-label="color disabled">
302+
</div>
303+
</div>
304+
</div>
305+
287306
<div class="field is-horizontal">
288307
<div class="field-label">
289308
<label class="label">checked switchColor: </label>
@@ -306,6 +325,17 @@ <h2 class="subtitle">
306325
</div>
307326
</div>
308327

328+
<div class="field is-horizontal">
329+
<div class="field-label">
330+
<label class="label">disabled switchColor: </label>
331+
</div>
332+
<div class="field-body">
333+
<div class="control">
334+
<input type="color" [(ngModel)]="config.switchColor.disabled" aria-label="color disabled">
335+
</div>
336+
</div>
337+
</div>
338+
309339
<div class="field is-horizontal">
310340
<div class="field-label">
311341
<label class="label">checked fontColor: </label>
@@ -328,6 +358,17 @@ <h2 class="subtitle">
328358
</div>
329359
</div>
330360

361+
<div class="field is-horizontal">
362+
<div class="field-label">
363+
<label class="label">disabled fontColor: </label>
364+
</div>
365+
<div class="field-body">
366+
<div class="control">
367+
<input type="color" [(ngModel)]="config.fontColor.disabled" aria-label="fontColor disabled">
368+
</div>
369+
</div>
370+
</div>
371+
331372
</div>
332373
</div>
333374
</section>

projects/demo/src/app/app.component.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ export class AppComponent {
2525
color: {
2626
unchecked: '#BFCBD9',
2727
checked: '#BFCBD9',
28+
disabled: '#DBDBDB',
29+
},
30+
switchColor: {
31+
checked: '#00a388',
32+
unchecked: 'red',
33+
disabled: '#c0c0c0'
2834
},
29-
switchColor: {checked: '#00a388', unchecked: 'red'},
3035
labels: {
3136
unchecked: 'off',
3237
checked: 'on',
@@ -35,7 +40,11 @@ export class AppComponent {
3540
unchecked: 0,
3641
checked: 1,
3742
},
38-
fontColor: {checked: '#fafafa', unchecked: '#f45a32'}
43+
fontColor: {
44+
checked: '#fafafa',
45+
unchecked: '#f45a32',
46+
disabled: '#ffffff'
47+
}
3948
}
4049
myForm: FormGroup;
4150
constructor() {

projects/ng-toggle/src/lib/ng-toggle.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor, OnChange
4444
@Input('aria-labelledby') ariaLabelledby: string | null = null;
4545
@Input('aria-describedby') ariaDescribedby: string;
4646
cssColors: boolean = false
47-
47+
4848
@Output() change = new EventEmitter()
4949
@Output() valueChange = new EventEmitter()
5050
toggled: boolean
@@ -69,7 +69,6 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor, OnChange
6969

7070
onInput(value: boolean) {
7171
this.value = value;
72-
console.log(this.value, value, 'calue')
7372
this.onTouch();
7473
this.onChange(this.value);
7574
}
@@ -130,7 +129,7 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor, OnChange
130129
let background = this.switchColor
131130
? this.switchColorCurrent
132131
: null
133-
background = this.disabled ? DISABLED_BUTTON_COLOR : background
132+
background = this.disabled ? this.switchColorDisabled : background
134133
return {
135134
width: px(this.buttonRadius),
136135
height: px(this.buttonRadius),
@@ -177,6 +176,10 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor, OnChange
177176
get switchColorUnchecked () {
178177
return get(this.switchColor, 'unchecked', DEFAULT_SWITCH_COLOR)
179178
}
179+
get switchColorDisabled(){
180+
return get(this.switchColor, 'disabled', DISABLED_BUTTON_COLOR)
181+
}
182+
180183
get switchColorCurrent () {
181184
if (!isObject(this.switchColor)) {
182185
return this.switchColor || DEFAULT_SWITCH_COLOR
@@ -192,10 +195,17 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor, OnChange
192195
get fontColorUnchecked () {
193196
return get(this.fontColor, 'unchecked', DEFAULT_SWITCH_COLOR)
194197
}
198+
199+
get fontColorDisabled(){
200+
return get(this.fontColor, 'disabled', DEFAULT_SWITCH_COLOR)
201+
}
195202
get fontColorCurrent () {
196203
if (!isObject(this.fontColor)) {
197204
return this.fontColor || DEFAULT_SWITCH_COLOR
198205
}
206+
if(this.disabled){
207+
return this.fontColorDisabled
208+
}
199209
return this.toggled
200210
? this.fontColorChecked
201211
: this.fontColorUnchecked
@@ -227,7 +237,7 @@ export class NgToggleComponent implements OnInit, ControlValueAccessor, OnChange
227237
this.focused = true;
228238
}
229239
}
230-
240+
231241
onFocusout(event: FocusEvent) {
232242
if (!this._elementRef.nativeElement.contains(event.relatedTarget as Element)) {
233243
this.focused = false;

0 commit comments

Comments
 (0)