1 | import { trigger, state, style, transition, animate } from '@angular/animations';
|
2 | import { Component, ViewEncapsulation, forwardRef, Renderer2, ViewChild, HostBinding, Input, NgModule } from '@angular/core';
|
3 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
4 | import { CommonModule } from '@angular/common';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | class BMRadioComponent {
|
11 | |
12 |
|
13 |
|
14 | constructor(_renderer) {
|
15 | this._renderer = _renderer;
|
16 | |
17 |
|
18 |
|
19 | this.name = '';
|
20 | this.value = '';
|
21 | this.tabIndex = 0;
|
22 | }
|
23 | |
24 |
|
25 |
|
26 | get isFocused() {
|
27 | return this._focused;
|
28 | }
|
29 | |
30 |
|
31 |
|
32 |
|
33 | set checked(checked) {
|
34 | if (checked !== this.checked) {
|
35 | this._renderer.setProperty(this.input.nativeElement, 'checked', checked);
|
36 | }
|
37 | }
|
38 | |
39 |
|
40 |
|
41 | get checked() {
|
42 | return this.input.nativeElement.checked;
|
43 | }
|
44 | |
45 |
|
46 |
|
47 | inputFocus() {
|
48 | this._focused = true;
|
49 | }
|
50 | |
51 |
|
52 |
|
53 | inputBlur() {
|
54 | this._focused = false;
|
55 | if (this._onTouchedCb) {
|
56 | this._onTouchedCb();
|
57 | }
|
58 | }
|
59 |
|
60 | |
61 |
|
62 |
|
63 |
|
64 | writeValue(value) {
|
65 | this.checked = value === this.value;
|
66 | }
|
67 |
|
68 | |
69 |
|
70 |
|
71 |
|
72 | registerOnChange(fn) {
|
73 | this._onChangeCb = fn;
|
74 | }
|
75 |
|
76 | |
77 |
|
78 |
|
79 |
|
80 | registerOnTouched(fn) {
|
81 | this._onTouchedCb = fn;
|
82 | }
|
83 | |
84 |
|
85 |
|
86 | inputChange() {
|
87 | if (this._onChangeCb && this.checked) {
|
88 | this._onChangeCb(this.value);
|
89 | }
|
90 | }
|
91 | |
92 |
|
93 |
|
94 | focus() {
|
95 | this.input.nativeElement.focus();
|
96 | }
|
97 | }
|
98 | BMRadioComponent.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 |
|
107 | useExisting: forwardRef(( |
108 |
|
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 |
|
134 | BMRadioComponent.ctorParameters = () => [
|
135 | { type: Renderer2 }
|
136 | ];
|
137 | BMRadioComponent.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 |
|
153 |
|
154 |
|
155 | class BMRadioComponentModule {
|
156 | }
|
157 | BMRadioComponentModule.decorators = [
|
158 | { type: NgModule, args: [{
|
159 | imports: [CommonModule],
|
160 | declarations: [BMRadioComponent],
|
161 | exports: [BMRadioComponent],
|
162 | },] }
|
163 | ];
|
164 |
|
165 | export { BMRadioComponent, BMRadioComponentModule };
|
166 |
|