[59329aa] | 1 | import * as i0 from '@angular/core';
|
---|
| 2 | import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, Output, NgModule } from '@angular/core';
|
---|
| 3 | import * as i1 from '@angular/common';
|
---|
| 4 | import { CommonModule } from '@angular/common';
|
---|
| 5 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
---|
| 6 |
|
---|
| 7 | const TRISTATECHECKBOX_VALUE_ACCESSOR = {
|
---|
| 8 | provide: NG_VALUE_ACCESSOR,
|
---|
| 9 | useExisting: forwardRef(() => TriStateCheckbox),
|
---|
| 10 | multi: true
|
---|
| 11 | };
|
---|
| 12 | class TriStateCheckbox {
|
---|
| 13 | constructor(cd) {
|
---|
| 14 | this.cd = cd;
|
---|
| 15 | this.checkboxTrueIcon = 'pi pi-check';
|
---|
| 16 | this.checkboxFalseIcon = 'pi pi-times';
|
---|
| 17 | this.onChange = new EventEmitter();
|
---|
| 18 | this.onModelChange = () => { };
|
---|
| 19 | this.onModelTouched = () => { };
|
---|
| 20 | }
|
---|
| 21 | onClick(event, input) {
|
---|
| 22 | if (!this.disabled && !this.readonly) {
|
---|
| 23 | this.toggle(event);
|
---|
| 24 | this.focused = true;
|
---|
| 25 | input.focus();
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 | onKeydown(event) {
|
---|
| 29 | if (event.keyCode == 32) {
|
---|
| 30 | event.preventDefault();
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 | onKeyup(event) {
|
---|
| 34 | if (event.keyCode == 32 && !this.readonly) {
|
---|
| 35 | this.toggle(event);
|
---|
| 36 | event.preventDefault();
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | toggle(event) {
|
---|
| 40 | if (this.value == null || this.value == undefined)
|
---|
| 41 | this.value = true;
|
---|
| 42 | else if (this.value == true)
|
---|
| 43 | this.value = false;
|
---|
| 44 | else if (this.value == false)
|
---|
| 45 | this.value = null;
|
---|
| 46 | this.onModelChange(this.value);
|
---|
| 47 | this.onChange.emit({
|
---|
| 48 | originalEvent: event,
|
---|
| 49 | value: this.value
|
---|
| 50 | });
|
---|
| 51 | }
|
---|
| 52 | onFocus() {
|
---|
| 53 | this.focused = true;
|
---|
| 54 | }
|
---|
| 55 | onBlur() {
|
---|
| 56 | this.focused = false;
|
---|
| 57 | this.onModelTouched();
|
---|
| 58 | }
|
---|
| 59 | registerOnChange(fn) {
|
---|
| 60 | this.onModelChange = fn;
|
---|
| 61 | }
|
---|
| 62 | registerOnTouched(fn) {
|
---|
| 63 | this.onModelTouched = fn;
|
---|
| 64 | }
|
---|
| 65 | writeValue(value) {
|
---|
| 66 | this.value = value;
|
---|
| 67 | this.cd.markForCheck();
|
---|
| 68 | }
|
---|
| 69 | setDisabledState(disabled) {
|
---|
| 70 | this.disabled = disabled;
|
---|
| 71 | this.cd.markForCheck();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | TriStateCheckbox.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TriStateCheckbox, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
---|
| 75 | TriStateCheckbox.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: TriStateCheckbox, selector: "p-triStateCheckbox", inputs: { disabled: "disabled", name: "name", ariaLabelledBy: "ariaLabelledBy", tabindex: "tabindex", inputId: "inputId", style: "style", styleClass: "styleClass", label: "label", readonly: "readonly", checkboxTrueIcon: "checkboxTrueIcon", checkboxFalseIcon: "checkboxFalseIcon" }, outputs: { onChange: "onChange" }, host: { classAttribute: "p-element" }, providers: [TRISTATECHECKBOX_VALUE_ACCESSOR], ngImport: i0, template: `
|
---|
| 76 | <div [ngStyle]="style" [ngClass]="{'p-checkbox p-component': true,'p-checkbox-disabled': disabled, 'p-checkbox-focused': focused}" [class]="styleClass">
|
---|
| 77 | <div class="p-hidden-accessible">
|
---|
| 78 | <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">
|
---|
| 79 | </div>
|
---|
| 80 | <div class="p-checkbox-box" (click)="onClick($event,input)" role="checkbox" [attr.aria-checked]="value === true"
|
---|
| 81 | [ngClass]="{'p-highlight':value!=null,'p-disabled':disabled,'p-focus':focused}">
|
---|
| 82 | <span class="p-checkbox-icon" [ngClass]="value === true ? checkboxTrueIcon : value === false ? checkboxFalseIcon : ''"></span>
|
---|
| 83 | </div>
|
---|
| 84 | </div>
|
---|
| 85 | <label class="p-checkbox-label" (click)="onClick($event,input)"
|
---|
| 86 | [ngClass]="{'p-checkbox-label-active':value!=null, 'p-disabled':disabled, 'p-checkbox-label-focus':focused}"
|
---|
| 87 | *ngIf="label" [attr.for]="inputId">{{label}}</label>
|
---|
| 88 | `, isInline: true, directives: [{ type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
---|
| 89 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TriStateCheckbox, decorators: [{
|
---|
| 90 | type: Component,
|
---|
| 91 | args: [{
|
---|
| 92 | selector: 'p-triStateCheckbox',
|
---|
| 93 | template: `
|
---|
| 94 | <div [ngStyle]="style" [ngClass]="{'p-checkbox p-component': true,'p-checkbox-disabled': disabled, 'p-checkbox-focused': focused}" [class]="styleClass">
|
---|
| 95 | <div class="p-hidden-accessible">
|
---|
| 96 | <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">
|
---|
| 97 | </div>
|
---|
| 98 | <div class="p-checkbox-box" (click)="onClick($event,input)" role="checkbox" [attr.aria-checked]="value === true"
|
---|
| 99 | [ngClass]="{'p-highlight':value!=null,'p-disabled':disabled,'p-focus':focused}">
|
---|
| 100 | <span class="p-checkbox-icon" [ngClass]="value === true ? checkboxTrueIcon : value === false ? checkboxFalseIcon : ''"></span>
|
---|
| 101 | </div>
|
---|
| 102 | </div>
|
---|
| 103 | <label class="p-checkbox-label" (click)="onClick($event,input)"
|
---|
| 104 | [ngClass]="{'p-checkbox-label-active':value!=null, 'p-disabled':disabled, 'p-checkbox-label-focus':focused}"
|
---|
| 105 | *ngIf="label" [attr.for]="inputId">{{label}}</label>
|
---|
| 106 | `,
|
---|
| 107 | providers: [TRISTATECHECKBOX_VALUE_ACCESSOR],
|
---|
| 108 | changeDetection: ChangeDetectionStrategy.OnPush,
|
---|
| 109 | encapsulation: ViewEncapsulation.None,
|
---|
| 110 | host: {
|
---|
| 111 | 'class': 'p-element'
|
---|
| 112 | }
|
---|
| 113 | }]
|
---|
| 114 | }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { disabled: [{
|
---|
| 115 | type: Input
|
---|
| 116 | }], name: [{
|
---|
| 117 | type: Input
|
---|
| 118 | }], ariaLabelledBy: [{
|
---|
| 119 | type: Input
|
---|
| 120 | }], tabindex: [{
|
---|
| 121 | type: Input
|
---|
| 122 | }], inputId: [{
|
---|
| 123 | type: Input
|
---|
| 124 | }], style: [{
|
---|
| 125 | type: Input
|
---|
| 126 | }], styleClass: [{
|
---|
| 127 | type: Input
|
---|
| 128 | }], label: [{
|
---|
| 129 | type: Input
|
---|
| 130 | }], readonly: [{
|
---|
| 131 | type: Input
|
---|
| 132 | }], checkboxTrueIcon: [{
|
---|
| 133 | type: Input
|
---|
| 134 | }], checkboxFalseIcon: [{
|
---|
| 135 | type: Input
|
---|
| 136 | }], onChange: [{
|
---|
| 137 | type: Output
|
---|
| 138 | }] } });
|
---|
| 139 | class TriStateCheckboxModule {
|
---|
| 140 | }
|
---|
| 141 | TriStateCheckboxModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TriStateCheckboxModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 142 | TriStateCheckboxModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TriStateCheckboxModule, declarations: [TriStateCheckbox], imports: [CommonModule], exports: [TriStateCheckbox] });
|
---|
| 143 | TriStateCheckboxModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TriStateCheckboxModule, imports: [[CommonModule]] });
|
---|
| 144 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: TriStateCheckboxModule, decorators: [{
|
---|
| 145 | type: NgModule,
|
---|
| 146 | args: [{
|
---|
| 147 | imports: [CommonModule],
|
---|
| 148 | exports: [TriStateCheckbox],
|
---|
| 149 | declarations: [TriStateCheckbox]
|
---|
| 150 | }]
|
---|
| 151 | }] });
|
---|
| 152 |
|
---|
| 153 | /**
|
---|
| 154 | * Generated bundle index. Do not edit.
|
---|
| 155 | */
|
---|
| 156 |
|
---|
| 157 | export { TRISTATECHECKBOX_VALUE_ACCESSOR, TriStateCheckbox, TriStateCheckboxModule };
|
---|