UNPKG

5.77 kBJavaScriptView Raw
1import { trigger, state, style, transition, animate } from '@angular/animations';
2import { Component, ViewEncapsulation, forwardRef, Renderer2, ViewChild, HostBinding, Input, NgModule } from '@angular/core';
3import { NG_VALUE_ACCESSOR } from '@angular/forms';
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 BMRadioComponent {
11 /**
12 * @param {?} _renderer
13 */
14 constructor(_renderer) {
15 this._renderer = _renderer;
16 /**
17 * Input values to directly copy to inner radio
18 */
19 this.name = '';
20 this.value = '';
21 this.tabIndex = 0;
22 }
23 /**
24 * @return {?}
25 */
26 get isFocused() {
27 return this._focused;
28 }
29 /**
30 * @param {?} checked
31 * @return {?}
32 */
33 set checked(checked) {
34 if (checked !== this.checked) {
35 this._renderer.setProperty(this.input.nativeElement, 'checked', checked);
36 }
37 }
38 /**
39 * @return {?}
40 */
41 get checked() {
42 return this.input.nativeElement.checked;
43 }
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 // tslint:disable-next-line:no-any
60 /**
61 * @param {?} value
62 * @return {?}
63 */
64 writeValue(value) {
65 this.checked = value === this.value;
66 }
67 // tslint:disable-next-line:no-any
68 /**
69 * @param {?} fn
70 * @return {?}
71 */
72 registerOnChange(fn) {
73 this._onChangeCb = fn;
74 }
75 // tslint:disable-next-line:no-any
76 /**
77 * @param {?} fn
78 * @return {?}
79 */
80 registerOnTouched(fn) {
81 this._onTouchedCb = fn;
82 }
83 /**
84 * @return {?}
85 */
86 inputChange() {
87 if (this._onChangeCb && this.checked) {
88 this._onChangeCb(this.value);
89 }
90 }
91 /**
92 * @return {?}
93 */
94 focus() {
95 this.input.nativeElement.focus();
96 }
97}
98BMRadioComponent.decorators = [
99 { type: Component, args: [{
100 selector: 'bm-radio',
101 template: "<label class=\"bm-radio__label_container\">\n <input\n (blur)=\"inputBlur()\"\n (change)=\"inputChange()\"\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 #input\n class=\"bm-visual-hidden\"\n type=\"radio\"\n />\n <div class=\"bm-radio__container\">\n <span class=\"bm-radio__checked-mark\" *ngIf=\"checked\" [@fadeInOut]=\"'in'\">\n </span>\n </div>\n <span class=\"bm-radio__label\"><ng-content></ng-content></span>\n</label>\n",
102 encapsulation: ViewEncapsulation.None,
103 providers: [
104 {
105 provide: NG_VALUE_ACCESSOR,
106 // tslint:disable-next-line:no-forward-ref
107 useExisting: forwardRef((/**
108 * @return {?}
109 */
110 () => BMRadioComponent)),
111 multi: true,
112 },
113 ],
114 animations: [
115 trigger('fadeInOut', [
116 state('in', style({ opacity: 1 })),
117 transition('void => *', [
118 style({
119 opacity: 0,
120 }),
121 animate('0.2s ease-in'),
122 ]),
123 transition('* => void', [
124 animate('0.2s ease-out', style({
125 opacity: 0,
126 })),
127 ]),
128 ]),
129 ],
130 styles: [".bm-radio--focused .bm-radio-container{border-color:var(--bm-checkbox-path-color,#4399fd)}.bm-radio__container{border:1px solid var(--secondary-color-hover,#959494);border-radius:50%;display:inline-block;width:1em;height:1em;position:relative;text-align:center;vertical-align:middle}.bm-radio__checked-mark{background-color:var(--bm-checkbox-path-color,#4399fd);box-sizing:border-box;border:2px solid #fff;border-radius:50%;width:100%;height:100%;display:block}"]
131 }] }
132];
133/** @nocollapse */
134BMRadioComponent.ctorParameters = () => [
135 { type: Renderer2 }
136];
137BMRadioComponent.propDecorators = {
138 input: [{ type: ViewChild, args: ['input', { static: true },] }],
139 isFocused: [{ type: HostBinding, args: ['class.bm-radio--focused',] }],
140 name: [{ type: Input }],
141 value: [{ type: Input }],
142 tabIndex: [{ type: Input }],
143 required: [{ type: Input }],
144 disabled: [{ type: Input }],
145 readonly: [{ type: Input }],
146 ariaLabel: [{ type: Input, args: ['aria-label',] }],
147 ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }],
148 checked: [{ type: Input }]
149};
150
151/**
152 * @fileoverview added by tsickle
153 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
154 */
155class BMRadioComponentModule {
156}
157BMRadioComponentModule.decorators = [
158 { type: NgModule, args: [{
159 imports: [CommonModule],
160 declarations: [BMRadioComponent],
161 exports: [BMRadioComponent],
162 },] }
163];
164
165export { BMRadioComponent, BMRadioComponentModule };
166//# sourceMappingURL=bmat-angular-forms-bm-radio.js.map