Skip to content

Commit c022666

Browse files
authored
Merge pull request #77 from edcarroll/develop
v0.7.0 into master
2 parents fe27e2b + 76ab3a8 commit c022666

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+831
-629
lines changed
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import {NgModule} from '@angular/core';
2-
import {FormsModule} from "@angular/forms";
3-
import {SUI_CHECKBOX_DIRECTIVES} from "./checkbox";
4-
import {SUI_RADIOBUTTON_DIRECTIVES} from "./radiobutton";
52
import {CommonModule} from "@angular/common";
3+
import {FormsModule} from "@angular/forms";
4+
import {SuiCheckbox, SuiCheckboxValueAccessor} from './checkbox';
5+
import {SuiRadioButton, SuiRadioButtonValueAccessor} from './radiobutton';
66

77
@NgModule({
8-
imports: [CommonModule, FormsModule],
9-
declarations: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES],
10-
exports: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES]
8+
imports: [
9+
CommonModule,
10+
FormsModule
11+
],
12+
declarations: [
13+
SuiCheckbox,
14+
SuiCheckboxValueAccessor,
15+
SuiRadioButton,
16+
SuiRadioButtonValueAccessor
17+
],
18+
exports: [
19+
SuiCheckbox,
20+
SuiCheckboxValueAccessor,
21+
SuiRadioButton,
22+
SuiRadioButtonValueAccessor
23+
]
1124
})
1225
export class SuiCheckboxModule {}

components/checkbox/checkbox.ts

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,84 @@
11
import {Component, Directive, Input, Output, HostListener, HostBinding, EventEmitter, forwardRef} from '@angular/core';
2-
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
2+
import {CustomValueAccessorHost, customValueAccessorFactory, CustomValueAccessor} from '../util/custom-value-accessor';
33

44
@Component({
55
selector: 'sui-checkbox',
66
exportAs: 'suiCheckbox',
77
template: `
8-
<input class="hidden" type="checkbox" [attr.name]="name" [attr.checked]="checkedAttribute" [attr.disabled]="isDisabledAttribute" [(ngModel)]="isChecked">
8+
<input class="hidden"
9+
type="checkbox"
10+
[attr.name]="name"
11+
[attr.checked]="checkedAttribute"
12+
[attr.disabled]="isDisabledAttribute"
13+
[(ngModel)]="isChecked">
914
<label>
1015
<ng-content></ng-content>
1116
</label>
1217
`
1318
})
14-
export class SuiCheckbox {
19+
export class SuiCheckbox implements CustomValueAccessorHost<boolean> {
1520
@HostBinding('class.ui')
1621
@HostBinding('class.checkbox')
17-
private _classes = true;
22+
private _checkboxClasses:boolean;
1823

1924
@Input()
2025
public name:string;
2126

2227
@HostBinding('class.checked')
23-
public isChecked:boolean = false;
28+
public isChecked:boolean;
2429

2530
@Output()
26-
public checkChange:EventEmitter<boolean> = new EventEmitter<boolean>(false);
31+
public checkChange:EventEmitter<boolean>;
2732

2833
@Input()
29-
public isDisabled:boolean = false;
34+
public isDisabled:boolean;
3035

3136
@HostBinding('class.read-only')
3237
@Input()
33-
public isReadonly:boolean = false;
38+
public isReadonly:boolean;
3439

35-
public get checkedAttribute():string {
40+
public get checkedAttribute() {
3641
return this.isChecked ? "" : null;
3742
}
3843

39-
public get isDisabledAttribute():string {
44+
public get isDisabledAttribute() {
4045
return this.isDisabled ? "disabled" : null;
4146
}
4247

48+
constructor() {
49+
this.isChecked = false;
50+
this.checkChange = new EventEmitter<boolean>();
51+
52+
this.isDisabled = false;
53+
this.isReadonly = false;
54+
55+
this._checkboxClasses = true;
56+
}
57+
4358
@HostListener('click')
44-
public onClick():void {
59+
public onClick() {
4560
if (!this.isDisabled && !this.isReadonly) {
4661
this.toggle();
4762
}
4863
}
4964

50-
public toggle():void {
65+
public toggle() {
5166
this.isChecked = !this.isChecked;
5267
this.checkChange.emit(this.isChecked);
5368
}
5469

5570
public writeValue(value:boolean) {
56-
setTimeout(() => {
57-
this.isChecked = value;
58-
});
71+
this.isChecked = value;
5972
}
6073
}
6174

62-
export const CUSTOM_VALUE_ACCESSOR: any = {
63-
provide: NG_VALUE_ACCESSOR,
64-
useExisting: forwardRef(() => SuiCheckboxValueAccessor),
65-
multi: true
66-
};
67-
6875
@Directive({
6976
selector: 'sui-checkbox',
70-
host: {'(checkChange)': 'onChange($event)'},
71-
providers: [CUSTOM_VALUE_ACCESSOR]
77+
host: { '(checkChange)': 'onChange($event)' },
78+
providers: [customValueAccessorFactory(SuiCheckboxValueAccessor)]
7279
})
73-
export class SuiCheckboxValueAccessor implements ControlValueAccessor {
74-
onChange = () => {};
75-
onTouched = () => {};
76-
77-
constructor(private host: SuiCheckbox) { }
78-
79-
writeValue(value: any): void {
80-
this.host.writeValue(!!value);
80+
export class SuiCheckboxValueAccessor extends CustomValueAccessor<boolean, SuiCheckbox> {
81+
constructor(host:SuiCheckbox) {
82+
super(host);
8183
}
82-
83-
registerOnChange(fn: () => void): void { this.onChange = fn; }
84-
registerOnTouched(fn: () => void): void { this.onTouched = fn; }
8584
}
86-
87-
export const SUI_CHECKBOX_DIRECTIVES = [SuiCheckbox, SuiCheckboxValueAccessor];

components/checkbox/radiobutton.ts

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, Directive, Input, Output, HostListener, HostBinding, EventEmitter, forwardRef} from '@angular/core';
2-
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
2+
import {CustomValueAccessorHost, customValueAccessorFactory, CustomValueAccessor} from '../util/custom-value-accessor';
33

44
@Component({
55
selector: 'sui-radio-button[ngModel]',
@@ -17,32 +17,32 @@ import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms';
1717
</label>
1818
`
1919
})
20-
export class SuiRadioButton {
20+
export class SuiRadioButton<T> implements CustomValueAccessorHost<T> {
2121
@HostBinding('class.ui')
2222
@HostBinding('class.radio')
2323
@HostBinding('class.checkbox')
24-
private _classes = true;
24+
private _radioClasses = true;
2525

2626
@Input()
2727
public name:string;
2828

2929
@Input()
30-
public value:any = "";
31-
32-
@Input()
33-
public isDisabled:boolean = false;
34-
35-
@HostBinding('class.read-only')
36-
@Input()
37-
public isReadonly:boolean = false;
30+
public value:T;
3831

3932
@HostBinding('class.checked')
40-
public isChecked:boolean = false;
33+
public isChecked:boolean;
4134

42-
public currentValue:any;
35+
public currentValue:T;
4336

4437
@Output()
45-
public currentValueChange:EventEmitter<any> = new EventEmitter<boolean>(false);
38+
public currentValueChange:EventEmitter<T>;
39+
40+
@Input()
41+
public isDisabled:boolean;
42+
43+
@HostBinding('class.read-only')
44+
@Input()
45+
public isReadonly:boolean;
4646

4747
public get checkedAttribute():string {
4848
return this.isChecked ? "" : null;
@@ -52,51 +52,42 @@ export class SuiRadioButton {
5252
return this.isDisabled ? "disabled" : null;
5353
}
5454

55+
constructor() {
56+
this.isChecked = false;
57+
this.currentValueChange = new EventEmitter<T>();
58+
59+
this.isDisabled = false;
60+
this.isReadonly = false;
61+
62+
this._radioClasses = true;
63+
}
64+
5565
@HostListener('click')
56-
public onClick():void {
66+
public onClick() {
5767
if (!this.isDisabled && !this.isReadonly) {
5868
this.currentValue = this.value;
5969
this.currentValueChange.emit(this.currentValue);
6070
this.update();
6171
}
6272
}
6373

64-
public update():void {
65-
//This is a horrible hack - need to rewrite!
66-
setTimeout(() => {
67-
this.isChecked = this.currentValue == this.value;
68-
});
74+
public update() {
75+
this.isChecked = this.currentValue == this.value;
6976
}
7077

71-
public writeValue(value:any) {
78+
public writeValue(value:T) {
7279
this.currentValue = value;
7380
this.update();
7481
}
7582
}
7683

77-
export const CUSTOM_VALUE_ACCESSOR: any = {
78-
provide: NG_VALUE_ACCESSOR,
79-
useExisting: forwardRef(() => SuiRadioButtonValueAccessor),
80-
multi: true
81-
};
82-
8384
@Directive({
8485
selector: 'sui-radio-button',
85-
host: {'(currentValueChange)': 'onChange($event)'},
86-
providers: [CUSTOM_VALUE_ACCESSOR]
86+
host: { '(currentValueChange)': 'onChange($event)' },
87+
providers: [customValueAccessorFactory(SuiRadioButtonValueAccessor)]
8788
})
88-
export class SuiRadioButtonValueAccessor implements ControlValueAccessor {
89-
onChange = () => {};
90-
onTouched = () => {};
91-
92-
constructor(private host: SuiRadioButton) { }
93-
94-
writeValue(value: any): void {
95-
this.host.writeValue(value);
89+
export class SuiRadioButtonValueAccessor<T> extends CustomValueAccessor<T, SuiRadioButton<T>> {
90+
constructor(host:SuiRadioButton<T>) {
91+
super(host);
9692
}
97-
98-
registerOnChange(fn: () => void): void { this.onChange = fn; }
99-
registerOnTouched(fn: () => void): void { this.onTouched = fn; }
100-
}
101-
102-
export const SUI_RADIOBUTTON_DIRECTIVES = [SuiRadioButton, SuiRadioButtonValueAccessor];
93+
}

components/collapse/collapse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Directive, ElementRef, Input, HostBinding, Renderer} from '@angular/core';
2+
import "web-animations-js";
23

34
@Directive({
45
selector: '[suiCollapse]'

0 commit comments

Comments
 (0)