-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from edcarroll/develop
v0.7.0 into master
- Loading branch information
Showing
54 changed files
with
831 additions
and
629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {FormsModule} from "@angular/forms"; | ||
import {SUI_CHECKBOX_DIRECTIVES} from "./checkbox"; | ||
import {SUI_RADIOBUTTON_DIRECTIVES} from "./radiobutton"; | ||
import {CommonModule} from "@angular/common"; | ||
import {FormsModule} from "@angular/forms"; | ||
import {SuiCheckbox, SuiCheckboxValueAccessor} from './checkbox'; | ||
import {SuiRadioButton, SuiRadioButtonValueAccessor} from './radiobutton'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, FormsModule], | ||
declarations: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES], | ||
exports: [SUI_CHECKBOX_DIRECTIVES, SUI_RADIOBUTTON_DIRECTIVES] | ||
imports: [ | ||
CommonModule, | ||
FormsModule | ||
], | ||
declarations: [ | ||
SuiCheckbox, | ||
SuiCheckboxValueAccessor, | ||
SuiRadioButton, | ||
SuiRadioButtonValueAccessor | ||
], | ||
exports: [ | ||
SuiCheckbox, | ||
SuiCheckboxValueAccessor, | ||
SuiRadioButton, | ||
SuiRadioButtonValueAccessor | ||
] | ||
}) | ||
export class SuiCheckboxModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,84 @@ | ||
import {Component, Directive, Input, Output, HostListener, HostBinding, EventEmitter, forwardRef} from '@angular/core'; | ||
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from '@angular/forms'; | ||
import {CustomValueAccessorHost, customValueAccessorFactory, CustomValueAccessor} from '../util/custom-value-accessor'; | ||
|
||
@Component({ | ||
selector: 'sui-checkbox', | ||
exportAs: 'suiCheckbox', | ||
template: ` | ||
<input class="hidden" type="checkbox" [attr.name]="name" [attr.checked]="checkedAttribute" [attr.disabled]="isDisabledAttribute" [(ngModel)]="isChecked"> | ||
<input class="hidden" | ||
type="checkbox" | ||
[attr.name]="name" | ||
[attr.checked]="checkedAttribute" | ||
[attr.disabled]="isDisabledAttribute" | ||
[(ngModel)]="isChecked"> | ||
<label> | ||
<ng-content></ng-content> | ||
</label> | ||
` | ||
}) | ||
export class SuiCheckbox { | ||
export class SuiCheckbox implements CustomValueAccessorHost<boolean> { | ||
@HostBinding('class.ui') | ||
@HostBinding('class.checkbox') | ||
private _classes = true; | ||
private _checkboxClasses:boolean; | ||
|
||
@Input() | ||
public name:string; | ||
|
||
@HostBinding('class.checked') | ||
public isChecked:boolean = false; | ||
public isChecked:boolean; | ||
|
||
@Output() | ||
public checkChange:EventEmitter<boolean> = new EventEmitter<boolean>(false); | ||
public checkChange:EventEmitter<boolean>; | ||
|
||
@Input() | ||
public isDisabled:boolean = false; | ||
public isDisabled:boolean; | ||
|
||
@HostBinding('class.read-only') | ||
@Input() | ||
public isReadonly:boolean = false; | ||
public isReadonly:boolean; | ||
|
||
public get checkedAttribute():string { | ||
public get checkedAttribute() { | ||
return this.isChecked ? "" : null; | ||
} | ||
|
||
public get isDisabledAttribute():string { | ||
public get isDisabledAttribute() { | ||
return this.isDisabled ? "disabled" : null; | ||
} | ||
|
||
constructor() { | ||
this.isChecked = false; | ||
this.checkChange = new EventEmitter<boolean>(); | ||
|
||
this.isDisabled = false; | ||
this.isReadonly = false; | ||
|
||
this._checkboxClasses = true; | ||
} | ||
|
||
@HostListener('click') | ||
public onClick():void { | ||
public onClick() { | ||
if (!this.isDisabled && !this.isReadonly) { | ||
this.toggle(); | ||
} | ||
} | ||
|
||
public toggle():void { | ||
public toggle() { | ||
this.isChecked = !this.isChecked; | ||
this.checkChange.emit(this.isChecked); | ||
} | ||
|
||
public writeValue(value:boolean) { | ||
setTimeout(() => { | ||
this.isChecked = value; | ||
}); | ||
this.isChecked = value; | ||
} | ||
} | ||
|
||
export const CUSTOM_VALUE_ACCESSOR: any = { | ||
provide: NG_VALUE_ACCESSOR, | ||
useExisting: forwardRef(() => SuiCheckboxValueAccessor), | ||
multi: true | ||
}; | ||
|
||
@Directive({ | ||
selector: 'sui-checkbox', | ||
host: {'(checkChange)': 'onChange($event)'}, | ||
providers: [CUSTOM_VALUE_ACCESSOR] | ||
host: { '(checkChange)': 'onChange($event)' }, | ||
providers: [customValueAccessorFactory(SuiCheckboxValueAccessor)] | ||
}) | ||
export class SuiCheckboxValueAccessor implements ControlValueAccessor { | ||
onChange = () => {}; | ||
onTouched = () => {}; | ||
|
||
constructor(private host: SuiCheckbox) { } | ||
|
||
writeValue(value: any): void { | ||
this.host.writeValue(!!value); | ||
export class SuiCheckboxValueAccessor extends CustomValueAccessor<boolean, SuiCheckbox> { | ||
constructor(host:SuiCheckbox) { | ||
super(host); | ||
} | ||
|
||
registerOnChange(fn: () => void): void { this.onChange = fn; } | ||
registerOnTouched(fn: () => void): void { this.onTouched = fn; } | ||
} | ||
|
||
export const SUI_CHECKBOX_DIRECTIVES = [SuiCheckbox, SuiCheckboxValueAccessor]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.