UNPKG

7.59 kBJavaScriptView Raw
1import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, forwardRef, ChangeDetectorRef, Renderer2, ViewChild, HostBinding, Input, Output, NgModule } from '@angular/core';
2import { NG_VALUE_ACCESSOR } from '@angular/forms';
3import { CommonModule } from '@angular/common';
4
5/**
6 * @fileoverview added by tsickle
7 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
8 */
9class BMSwitchCheckboxComponent {
10 /**
11 * @param {?} _changeDetectorRef
12 * @param {?} _renderer
13 */
14 constructor(_changeDetectorRef, _renderer) {
15 this._changeDetectorRef = _changeDetectorRef;
16 this._renderer = _renderer;
17 this.tabIndex = 0;
18 this.switchChange = new EventEmitter();
19 }
20 /**
21 * @return {?}
22 */
23 get isFocused() {
24 return this._focused;
25 }
26 /**
27 * @param {?} checked
28 * @return {?}
29 */
30 set checked(checked) {
31 this._renderer.setProperty(this.input.nativeElement, 'checked', checked);
32 }
33 /**
34 * @return {?}
35 */
36 get checked() {
37 if (this.input && this.input.nativeElement) {
38 return this.input.nativeElement.checked;
39 }
40 return false;
41 }
42 // Focus Blur Handle
43 /**
44 * @return {?}
45 */
46 inputFocus() {
47 this._focused = true;
48 }
49 /**
50 * @return {?}
51 */
52 inputBlur() {
53 this._focused = false;
54 if (this._onTouched) {
55 this._onTouched();
56 }
57 }
58 /**
59 * @param {?} value
60 * @return {?}
61 */
62 writeValue(value) {
63 this.checked = value;
64 this._changeDetectorRef.markForCheck();
65 }
66 /**
67 * @param {?} fn
68 * @return {?}
69 */
70 registerOnChange(fn) {
71 this._propagateChange = fn;
72 }
73 /**
74 * @param {?} fn
75 * @return {?}
76 */
77 registerOnTouched(fn) {
78 this._onTouched = fn;
79 }
80 /**
81 * @param {?} isDisabled
82 * @return {?}
83 */
84 setDisabledState(isDisabled) {
85 this.disabled = isDisabled;
86 this._changeDetectorRef.markForCheck();
87 }
88 /**
89 * @param {?} event
90 * @return {?}
91 */
92 inputChange(event) {
93 if (this._propagateChange) {
94 this._propagateChange(((/** @type {?} */ (event.target))).checked);
95 }
96 this.switchChange.emit({
97 checked: ((/** @type {?} */ (event.target))).checked,
98 source: this,
99 });
100 }
101 /**
102 * @return {?}
103 */
104 focus() {
105 if (this.input && this.input.nativeElement) {
106 this.input.nativeElement.focus();
107 }
108 }
109}
110BMSwitchCheckboxComponent.decorators = [
111 { type: Component, args: [{
112 selector: 'bm-switch-checkbox',
113 template: "<label class=\"bm-switch-checkbox__label-container\">\n <input\n #input\n type=\"checkbox\"\n class=\"bm-switch-checkbox__checkbox\"\n (blur)=\"inputBlur()\"\n (change)=\"inputChange($event)\"\n (focus)=\"inputFocus()\"\n [attr.aria-label]=\"ariaLabel\"\n [attr.aria-labelledby]=\"ariaLabelledby\"\n [disabled]=\"disabled\"\n [name]=\"name\"\n [readonly]=\"readonly\"\n [required]=\"required\"\n [tabIndex]=\"tabIndex\"\n />\n <span\n class=\"bm-switch-checkbox__container\"\n [ngClass]=\"{\n 'bm-switch-checkbox__container--checked': checked,\n 'bm-switch-checkbox__container--disabled': disabled\n }\"\n >\n <span\n class=\"bm-switch-checkbox__thumb\"\n [ngClass]=\"{ 'bm-switch-checkbox__thumb--checked': checked }\"\n ></span>\n </span>\n <span class=\"bm-switch-checkbox__label\"><ng-content></ng-content></span>\n</label>\n",
114 changeDetection: ChangeDetectionStrategy.OnPush,
115 encapsulation: ViewEncapsulation.None,
116 providers: [
117 {
118 provide: NG_VALUE_ACCESSOR,
119 // tslint:disable-next-line:no-forward-ref
120 useExisting: forwardRef((/**
121 * @return {?}
122 */
123 () => BMSwitchCheckboxComponent)),
124 multi: true,
125 },
126 ],
127 styles: ["bm-switch-checkbox{border:1px solid transparent;border-radius:.2em;display:inline-block}.bm-switch-checkbox__checkbox{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;text-transform:none;width:1px}.bm-switch-checkbox--focused,.bm-switch-checkbox--focused .bm-switch-checkbox-container{border-color:var(--anchor-color,#4399fd)}.bm-switch-checkbox__container{align-items:center;background-color:var(--bm-switch-unchecked-color,#dadfea);border-color:var(--bm-switch-unchecked-color,#dadfea);border-radius:.2em;border:1px solid var(--secondary-color,#dadfea);display:inline-flex;height:1.5em;overflow:hidden;position:relative;transition:.2s ease-in;vertical-align:middle;width:3em}.bm-switch-checkbox__container--checked{background-color:var(--bm-switch-checked-color,#4dbd74);border-color:var(--bm-switch-checked-border-color,#3a9d5d)}.bm-switch-checkbox__container--disabled{opacity:.6;cursor:not-allowed}.bm-switch-checkbox__thumb{background-color:#fff;border-radius:.2em;border:1px solid var(--secondary-color,#bcbcbc);bottom:.1em;display:inline-block;margin:0 .1em;position:absolute;top:.1em;-webkit-transform:translateX(0);transform:translateX(0);transition:transform .2s ease-in;transition:transform .2s ease-in,-webkit-transform .2s ease-in;vertical-align:middle;width:calc(1.5em - .2em)}.bm-switch-checkbox__thumb::after,.bm-switch-checkbox__thumb::before{align-items:center;bottom:0;display:flex;font-size:.6em;font-weight:600;position:absolute;top:0}.bm-switch-checkbox__thumb::before{color:#fff;content:var(--switch-checked-label, \"Y\");left:-1.6em}.bm-switch-checkbox__thumb::after{color:#80838a;content:var(--switch-unchecked-label, \"N\");right:-1.6em}.bm-switch-checkbox__thumb--checked{border-color:var(--bm-switch-checked-border-color,#3a9d5d);-webkit-transform:translateX(100%);transform:translateX(100%)}.bm-switch-checkbox__tick-path{stroke:var(--bm-checkbox-path-color,#4399fd);stroke-width:.2em;vertical-align:middle}"]
128 }] }
129];
130/** @nocollapse */
131BMSwitchCheckboxComponent.ctorParameters = () => [
132 { type: ChangeDetectorRef },
133 { type: Renderer2 }
134];
135BMSwitchCheckboxComponent.propDecorators = {
136 input: [{ type: ViewChild, args: ['input', { static: true },] }],
137 isFocused: [{ type: HostBinding, args: ['class.bm-switch-checkbox--focused',] }],
138 ariaLabel: [{ type: Input, args: ['aria-label',] }],
139 ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
140 disabled: [{ type: Input }],
141 name: [{ type: Input }],
142 readonly: [{ type: Input }],
143 required: [{ type: Input }],
144 tabIndex: [{ type: Input }],
145 checked: [{ type: Input }],
146 switchChange: [{ type: Output }]
147};
148
149/**
150 * @fileoverview added by tsickle
151 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
152 */
153/**
154 * Module of the Switch Component
155 */
156class BMSwitchCheckboxModule {
157}
158BMSwitchCheckboxModule.decorators = [
159 { type: NgModule, args: [{
160 imports: [CommonModule],
161 declarations: [BMSwitchCheckboxComponent],
162 exports: [BMSwitchCheckboxComponent],
163 },] }
164];
165
166export { BMSwitchCheckboxComponent, BMSwitchCheckboxModule };
167//# sourceMappingURL=bmat-angular-forms-bm-switch-checkbox.js.map