UNPKG

6.36 kBJavaScriptView Raw
1import { Component, ChangeDetectionStrategy, ViewEncapsulation, forwardRef, Renderer2, ChangeDetectorRef, ViewChild, HostBinding, Input, NgModule } from '@angular/core';
2import { NG_VALUE_ACCESSOR } from '@angular/forms';
3import { trigger, state, style, transition, animate } from '@angular/animations';
4import { CommonModule } from '@angular/common';
5
6/**
7 * @fileoverview added by tsickle
8 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
9 */
10class CheckboxComponent {
11 /**
12 * @param {?} _renderer
13 * @param {?} _changeDetectorRef
14 */
15 constructor(_renderer, _changeDetectorRef) {
16 this._renderer = _renderer;
17 this._changeDetectorRef = _changeDetectorRef;
18 /**
19 * Input values to directly copy to inner checkbox
20 */
21 this.name = '';
22 this.tabIndex = 0;
23 }
24 /**
25 * @return {?}
26 */
27 get isFocused() {
28 return this._focused;
29 }
30 /**
31 * @return {?}
32 */
33 get checked() {
34 return this.input.nativeElement.checked;
35 }
36 /**
37 * @param {?} checked
38 * @return {?}
39 */
40 set checked(checked) {
41 this._renderer.setProperty(this.input.nativeElement, 'checked', checked);
42 }
43 // Focus Blur Handle
44 /**
45 * @return {?}
46 */
47 inputFocus() {
48 this._focused = true;
49 }
50 /**
51 * @return {?}
52 */
53 inputBlur() {
54 this._focused = false;
55 if (this._onTouchedCb) {
56 this._onTouchedCb();
57 }
58 }
59 /**
60 * @param {?} value
61 * @return {?}
62 */
63 writeValue(value) {
64 this.checked = !!value;
65 this._changeDetectorRef.markForCheck();
66 }
67 // tslint:disable-next-line:no-any
68 /**
69 * @param {?} fn
70 * @return {?}
71 */
72 registerOnChange(fn) {
73 this._onChangeCb = fn;
74 }
75 /**
76 * @param {?} fn
77 * @return {?}
78 */
79 registerOnTouched(fn) {
80 this._onTouchedCb = fn;
81 }
82 /**
83 * @param {?} event
84 * @return {?}
85 */
86 inputChange(event) {
87 const { checked } = (/** @type {?} */ (event.target));
88 if (this._onChangeCb) {
89 this._onChangeCb(checked);
90 }
91 }
92 /**
93 * @return {?}
94 */
95 focus() {
96 if (this.input && this.input.nativeElement) {
97 this.input.nativeElement.focus();
98 }
99 }
100}
101CheckboxComponent.decorators = [
102 { type: Component, args: [{
103 selector: 'bm-checkbox',
104 template: "<label class=\"bm-checkbox__label-container\">\n <input\n #input\n type=\"checkbox\"\n class=\"bm-visual-hidden\"\n [checked]=\"checked\"\n [required]=\"required\"\n [disabled]=\"disabled\"\n [name]=\"name\"\n [tabIndex]=\"tabIndex\"\n [readonly]=\"readonly\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n (change)=\"inputChange($event)\"\n (focus)=\"inputFocus()\"\n (blur)=\"inputBlur()\"\n />\n <div class=\"bm-checkbox__container\">\n <svg\n *ngIf=\"checked\"\n [@fadeInOut]=\"'in'\"\n class=\"bm-checkbox__tick\"\n xml:space=\"preserve\"\n version=\"1.1\"\n viewBox=\"0 0 24 24\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <path\n class=\"bm-checkbox__tick-path\"\n d=\"M4.1,12.7 9,17.6 20.3,6.3\"\n fill=\"none\"\n stroke=\"white\"\n ></path>\n </svg>\n </div>\n <span class=\"bm-checkbox__label\"><ng-content></ng-content></span>\n</label>\n",
105 changeDetection: ChangeDetectionStrategy.OnPush,
106 encapsulation: ViewEncapsulation.None,
107 providers: [
108 {
109 provide: NG_VALUE_ACCESSOR,
110 // tslint:disable-next-line:no-forward-ref
111 useExisting: forwardRef((/**
112 * @return {?}
113 */
114 () => CheckboxComponent)),
115 multi: true,
116 },
117 ],
118 animations: [
119 trigger('fadeInOut', [
120 state('in', style({ opacity: 1 })),
121 transition('void => *', [
122 style({
123 opacity: 0,
124 }),
125 animate('0.2s ease-in'),
126 ]),
127 transition('* => void', [
128 animate('0.2s ease-out', style({
129 opacity: 0,
130 })),
131 ]),
132 ]),
133 ],
134 styles: [".bm-checkbox--focused .bm-checkbox-container{border-color:var(--bm-checkbox-path-color,#4399fd)}.bm-checkbox__container{border:1px solid var(--secondary-color,#bcbcbc);border-radius:3px;display:inline-block;width:1em;height:1em;position:relative;vertical-align:middle}.bm-checkbox__tick{position:absolute}.bm-checkbox__tick-path{stroke:var(--bm-checkbox-path-color,#4399fd);stroke-width:5px;vertical-align:middle}"]
135 }] }
136];
137/** @nocollapse */
138CheckboxComponent.ctorParameters = () => [
139 { type: Renderer2 },
140 { type: ChangeDetectorRef }
141];
142CheckboxComponent.propDecorators = {
143 input: [{ type: ViewChild, args: ['input', { static: true },] }],
144 isFocused: [{ type: HostBinding, args: ['class.bm-checkbox--focused',] }],
145 name: [{ type: Input }],
146 tabIndex: [{ type: Input }],
147 required: [{ type: Input }],
148 disabled: [{ type: Input }],
149 readonly: [{ type: Input }],
150 ariaLabel: [{ type: Input, args: ['aria-label',] }],
151 ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
152 checked: [{ type: Input }]
153};
154
155/**
156 * @fileoverview added by tsickle
157 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
158 */
159class CheckboxComponentModule {
160}
161CheckboxComponentModule.decorators = [
162 { type: NgModule, args: [{
163 imports: [CommonModule],
164 declarations: [CheckboxComponent],
165 exports: [CheckboxComponent],
166 },] }
167];
168
169export { CheckboxComponent, CheckboxComponentModule };
170//# sourceMappingURL=bmat-angular-forms-bm-checkbox.js.map