123 lines
4.2 KiB
JavaScript
123 lines
4.2 KiB
JavaScript
import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Input, Output, NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
|
|
const TRISTATECHECKBOX_VALUE_ACCESSOR = {
|
|
provide: NG_VALUE_ACCESSOR,
|
|
useExisting: forwardRef(() => TriStateCheckbox),
|
|
multi: true
|
|
};
|
|
class TriStateCheckbox {
|
|
constructor(cd) {
|
|
this.cd = cd;
|
|
this.onChange = new EventEmitter();
|
|
this.onModelChange = () => { };
|
|
this.onModelTouched = () => { };
|
|
}
|
|
onClick(event, input) {
|
|
if (!this.disabled && !this.readonly) {
|
|
this.toggle(event);
|
|
this.focused = true;
|
|
input.focus();
|
|
}
|
|
}
|
|
onKeydown(event) {
|
|
if (event.keyCode == 32) {
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
onKeyup(event) {
|
|
if (event.keyCode == 32 && !this.readonly) {
|
|
this.toggle(event);
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
toggle(event) {
|
|
if (this.value == null || this.value == undefined)
|
|
this.value = true;
|
|
else if (this.value == true)
|
|
this.value = false;
|
|
else if (this.value == false)
|
|
this.value = null;
|
|
this.onModelChange(this.value);
|
|
this.onChange.emit({
|
|
originalEvent: event,
|
|
value: this.value
|
|
});
|
|
}
|
|
onFocus() {
|
|
this.focused = true;
|
|
}
|
|
onBlur() {
|
|
this.focused = false;
|
|
this.onModelTouched();
|
|
}
|
|
registerOnChange(fn) {
|
|
this.onModelChange = fn;
|
|
}
|
|
registerOnTouched(fn) {
|
|
this.onModelTouched = fn;
|
|
}
|
|
writeValue(value) {
|
|
this.value = value;
|
|
this.cd.markForCheck();
|
|
}
|
|
setDisabledState(disabled) {
|
|
this.disabled = disabled;
|
|
this.cd.markForCheck();
|
|
}
|
|
}
|
|
TriStateCheckbox.decorators = [
|
|
{ type: Component, args: [{
|
|
selector: 'p-triStateCheckbox',
|
|
template: `
|
|
<div [ngStyle]="style" [ngClass]="{'p-checkbox p-component': true,'p-checkbox-disabled': disabled, 'p-checkbox-focused': focused}" [class]="styleClass">
|
|
<div class="p-hidden-accessible">
|
|
<input #input type="text" [attr.id]="inputId" [name]="name" [attr.tabindex]="tabindex" [readonly]="readonly" [disabled]="disabled" (keyup)="onKeyup($event)" (keydown)="onKeydown($event)" (focus)="onFocus()" (blur)="onBlur()" [attr.aria-labelledby]="ariaLabelledBy" inputmode="none">
|
|
</div>
|
|
<div class="p-checkbox-box" (click)="onClick($event,input)" role="checkbox" [attr.aria-checked]="value === true"
|
|
[ngClass]="{'p-highlight':value!=null,'p-disabled':disabled,'p-focus':focused}">
|
|
<span class="p-checkbox-icon pi" [ngClass]="{'pi-check':value==true,'pi-times':value==false}"></span>
|
|
</div>
|
|
</div>
|
|
<label class="p-checkbox-label" (click)="onClick($event,input)"
|
|
[ngClass]="{'p-checkbox-label-active':value!=null, 'p-disabled':disabled, 'p-checkbox-label-focus':focused}"
|
|
*ngIf="label" [attr.for]="inputId">{{label}}</label>
|
|
`,
|
|
providers: [TRISTATECHECKBOX_VALUE_ACCESSOR],
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
encapsulation: ViewEncapsulation.None
|
|
},] }
|
|
];
|
|
TriStateCheckbox.ctorParameters = () => [
|
|
{ type: ChangeDetectorRef }
|
|
];
|
|
TriStateCheckbox.propDecorators = {
|
|
disabled: [{ type: Input }],
|
|
name: [{ type: Input }],
|
|
ariaLabelledBy: [{ type: Input }],
|
|
tabindex: [{ type: Input }],
|
|
inputId: [{ type: Input }],
|
|
style: [{ type: Input }],
|
|
styleClass: [{ type: Input }],
|
|
label: [{ type: Input }],
|
|
readonly: [{ type: Input }],
|
|
onChange: [{ type: Output }]
|
|
};
|
|
class TriStateCheckboxModule {
|
|
}
|
|
TriStateCheckboxModule.decorators = [
|
|
{ type: NgModule, args: [{
|
|
imports: [CommonModule],
|
|
exports: [TriStateCheckbox],
|
|
declarations: [TriStateCheckbox]
|
|
},] }
|
|
];
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { TRISTATECHECKBOX_VALUE_ACCESSOR, TriStateCheckbox, TriStateCheckboxModule };
|
|
//# sourceMappingURL=primeng-tristatecheckbox.js.map
|