UNPKG

9.24 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/forms')) :
3 typeof define === 'function' && define.amd ? define('primeng/checkbox', ['exports', '@angular/core', '@angular/common', '@angular/forms'], factory) :
4 (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.checkbox = {}), global.ng.core, global.ng.common, global.ng.forms));
5}(this, (function (exports, core, common, forms) { 'use strict';
6
7 var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11 return c > 3 && r && Object.defineProperty(target, key, r), r;
12 };
13 var __read = (this && this.__read) || function (o, n) {
14 var m = typeof Symbol === "function" && o[Symbol.iterator];
15 if (!m) return o;
16 var i = m.call(o), r, ar = [], e;
17 try {
18 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19 }
20 catch (error) { e = { error: error }; }
21 finally {
22 try {
23 if (r && !r.done && (m = i["return"])) m.call(i);
24 }
25 finally { if (e) throw e.error; }
26 }
27 return ar;
28 };
29 var __spread = (this && this.__spread) || function () {
30 for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31 return ar;
32 };
33 var CHECKBOX_VALUE_ACCESSOR = {
34 provide: forms.NG_VALUE_ACCESSOR,
35 useExisting: core.forwardRef(function () { return Checkbox; }),
36 multi: true
37 };
38 var Checkbox = /** @class */ (function () {
39 function Checkbox(cd) {
40 this.cd = cd;
41 this.checkboxIcon = 'pi pi-check';
42 this.onChange = new core.EventEmitter();
43 this.onModelChange = function () { };
44 this.onModelTouched = function () { };
45 this.focused = false;
46 this.checked = false;
47 }
48 Checkbox.prototype.onClick = function (event, checkbox, focus) {
49 event.preventDefault();
50 if (this.disabled || this.readonly) {
51 return;
52 }
53 this.checked = !this.checked;
54 this.updateModel(event);
55 if (focus) {
56 checkbox.focus();
57 }
58 };
59 Checkbox.prototype.updateModel = function (event) {
60 if (!this.binary) {
61 if (this.checked)
62 this.addValue();
63 else
64 this.removeValue();
65 this.onModelChange(this.model);
66 if (this.formControl) {
67 this.formControl.setValue(this.model);
68 }
69 }
70 else {
71 this.onModelChange(this.checked);
72 }
73 this.onChange.emit({ checked: this.checked, originalEvent: event });
74 };
75 Checkbox.prototype.handleChange = function (event) {
76 if (!this.readonly) {
77 this.checked = event.target.checked;
78 this.updateModel(event);
79 }
80 };
81 Checkbox.prototype.isChecked = function () {
82 if (this.binary)
83 return this.model;
84 else
85 return this.model && this.model.indexOf(this.value) > -1;
86 };
87 Checkbox.prototype.removeValue = function () {
88 var _this = this;
89 this.model = this.model.filter(function (val) { return val !== _this.value; });
90 };
91 Checkbox.prototype.addValue = function () {
92 if (this.model)
93 this.model = __spread(this.model, [this.value]);
94 else
95 this.model = [this.value];
96 };
97 Checkbox.prototype.onFocus = function () {
98 this.focused = true;
99 };
100 Checkbox.prototype.onBlur = function () {
101 this.focused = false;
102 this.onModelTouched();
103 };
104 Checkbox.prototype.focus = function () {
105 this.inputViewChild.nativeElement.focus();
106 };
107 Checkbox.prototype.writeValue = function (model) {
108 this.model = model;
109 this.checked = this.isChecked();
110 this.cd.markForCheck();
111 };
112 Checkbox.prototype.registerOnChange = function (fn) {
113 this.onModelChange = fn;
114 };
115 Checkbox.prototype.registerOnTouched = function (fn) {
116 this.onModelTouched = fn;
117 };
118 Checkbox.prototype.setDisabledState = function (val) {
119 this.disabled = val;
120 };
121 Checkbox.ctorParameters = function () { return [
122 { type: core.ChangeDetectorRef }
123 ]; };
124 __decorate([
125 core.Input()
126 ], Checkbox.prototype, "value", void 0);
127 __decorate([
128 core.Input()
129 ], Checkbox.prototype, "name", void 0);
130 __decorate([
131 core.Input()
132 ], Checkbox.prototype, "disabled", void 0);
133 __decorate([
134 core.Input()
135 ], Checkbox.prototype, "binary", void 0);
136 __decorate([
137 core.Input()
138 ], Checkbox.prototype, "label", void 0);
139 __decorate([
140 core.Input()
141 ], Checkbox.prototype, "ariaLabelledBy", void 0);
142 __decorate([
143 core.Input()
144 ], Checkbox.prototype, "tabindex", void 0);
145 __decorate([
146 core.Input()
147 ], Checkbox.prototype, "inputId", void 0);
148 __decorate([
149 core.Input()
150 ], Checkbox.prototype, "style", void 0);
151 __decorate([
152 core.Input()
153 ], Checkbox.prototype, "styleClass", void 0);
154 __decorate([
155 core.Input()
156 ], Checkbox.prototype, "labelStyleClass", void 0);
157 __decorate([
158 core.Input()
159 ], Checkbox.prototype, "formControl", void 0);
160 __decorate([
161 core.Input()
162 ], Checkbox.prototype, "checkboxIcon", void 0);
163 __decorate([
164 core.Input()
165 ], Checkbox.prototype, "readonly", void 0);
166 __decorate([
167 core.Input()
168 ], Checkbox.prototype, "required", void 0);
169 __decorate([
170 core.ViewChild('cb')
171 ], Checkbox.prototype, "inputViewChild", void 0);
172 __decorate([
173 core.Output()
174 ], Checkbox.prototype, "onChange", void 0);
175 Checkbox = __decorate([
176 core.Component({
177 selector: 'p-checkbox',
178 template: "\n <div [ngStyle]=\"style\" [ngClass]=\"{'ui-chkbox ui-widget': true,'ui-chkbox-readonly': readonly}\" [class]=\"styleClass\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #cb type=\"checkbox\" [attr.id]=\"inputId\" [attr.name]=\"name\" [readonly]=\"readonly\" [value]=\"value\" [checked]=\"checked\" (focus)=\"onFocus()\" (blur)=\"onBlur()\"\n [ngClass]=\"{'ui-state-focus':focused}\" (change)=\"handleChange($event)\" [disabled]=\"disabled\" [attr.tabindex]=\"tabindex\" [attr.aria-labelledby]=\"ariaLabelledBy\" [attr.required]=\"required\">\n </div>\n <div class=\"ui-chkbox-box ui-widget ui-corner-all ui-state-default\" (click)=\"onClick($event,cb,true)\"\n [ngClass]=\"{'ui-state-active':checked,'ui-state-disabled':disabled,'ui-state-focus':focused}\" role=\"checkbox\" [attr.aria-checked]=\"checked\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"checked ? checkboxIcon : null\"></span>\n </div>\n </div>\n <label (click)=\"onClick($event,cb,true)\" [class]=\"labelStyleClass\"\n [ngClass]=\"{'ui-chkbox-label': true, 'ui-label-active':checked, 'ui-label-disabled':disabled, 'ui-label-focus':focused}\"\n *ngIf=\"label\" [attr.for]=\"inputId\">{{label}}</label>\n ",
179 providers: [CHECKBOX_VALUE_ACCESSOR],
180 changeDetection: core.ChangeDetectionStrategy.Default
181 })
182 ], Checkbox);
183 return Checkbox;
184 }());
185 var CheckboxModule = /** @class */ (function () {
186 function CheckboxModule() {
187 }
188 CheckboxModule = __decorate([
189 core.NgModule({
190 imports: [common.CommonModule],
191 exports: [Checkbox],
192 declarations: [Checkbox]
193 })
194 ], CheckboxModule);
195 return CheckboxModule;
196 }());
197
198 exports.CHECKBOX_VALUE_ACCESSOR = CHECKBOX_VALUE_ACCESSOR;
199 exports.Checkbox = Checkbox;
200 exports.CheckboxModule = CheckboxModule;
201
202 Object.defineProperty(exports, '__esModule', { value: true });
203
204})));
205//# sourceMappingURL=primeng-checkbox.umd.js.map