1 | import { EventEmitter, Component, ChangeDetectionStrategy, forwardRef, ChangeDetectorRef, Input, Output, ViewChild, ElementRef, NgModule } from '@angular/core';
|
2 | import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
3 | import { CommonModule } from '@angular/common';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | class PasswordInputComponent {
|
13 | |
14 |
|
15 |
|
16 | constructor(_cdr) {
|
17 | this._cdr = _cdr;
|
18 | this.value = null;
|
19 | this.displayButton = true;
|
20 | this.hide = true;
|
21 | this.toggleHide = new EventEmitter();
|
22 | this.passwordChange = new EventEmitter();
|
23 | }
|
24 | |
25 |
|
26 |
|
27 |
|
28 | writeValue(value) {
|
29 | this.value = value;
|
30 | this._cdr.markForCheck();
|
31 | }
|
32 | |
33 |
|
34 |
|
35 |
|
36 | registerOnChange(fn) {
|
37 | this._onChangeCb = fn;
|
38 | }
|
39 | |
40 |
|
41 |
|
42 |
|
43 | registerOnTouched(fn) {
|
44 | this._onTouchCb = fn;
|
45 | }
|
46 | |
47 |
|
48 |
|
49 |
|
50 | setDisabledState(isDisabled) {
|
51 | this.disabled = isDisabled;
|
52 | }
|
53 | |
54 |
|
55 |
|
56 |
|
57 | onInputChange(e) {
|
58 | const { value } = ( (e.target));
|
59 | if (this._onChangeCb) {
|
60 | this._onChangeCb(value);
|
61 | }
|
62 | this.passwordChange.emit(value);
|
63 | }
|
64 | |
65 |
|
66 |
|
67 | onInputBlur() {
|
68 | if (this._onTouchCb) {
|
69 | this._onTouchCb();
|
70 | }
|
71 | }
|
72 | |
73 |
|
74 |
|
75 | focus() {
|
76 | if (this._input && this._input.nativeElement) {
|
77 | this._input.nativeElement.focus();
|
78 | }
|
79 | }
|
80 | |
81 |
|
82 |
|
83 |
|
84 | onToggleClick(e) {
|
85 | e.preventDefault();
|
86 | this.hide = !this.hide;
|
87 | this.toggleHide.emit(this.hide);
|
88 | }
|
89 | |
90 |
|
91 |
|
92 | getInputType() {
|
93 | return this.hide ? 'password' : 'text';
|
94 | }
|
95 | }
|
96 | PasswordInputComponent.decorators = [
|
97 | { type: Component, args: [{
|
98 | selector: 'bm-password',
|
99 | template: "<ng-template #shownPassword>\n <svg\n aria-hidden=\"true\"\n data-prefix=\"far\"\n data-icon=\"eye\"\n class=\"bm-password__svg\"\n role=\"img\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 576 512\"\n >\n <path\n fill=\"currentColor\"\n d=\"M569.354 231.631C512.97 135.949 407.81 72 288 72 168.14 72 63.004 135.994 6.646 231.631a47.999 47.999 0 0 0 0 48.739C63.031 376.051 168.19 440 288 440c119.86 0 224.996-63.994 281.354-159.631a47.997 47.997 0 0 0 0-48.738zM288 392c-102.556 0-192.091-54.701-240-136 44.157-74.933 123.677-127.27 216.162-135.007C273.958 131.078 280 144.83 280 160c0 30.928-25.072 56-56 56s-56-25.072-56-56l.001-.042C157.794 179.043 152 200.844 152 224c0 75.111 60.889 136 136 136s136-60.889 136-136c0-31.031-10.4-59.629-27.895-82.515C451.704 164.638 498.009 205.106 528 256c-47.908 81.299-137.444 136-240 136z\"\n ></path>\n </svg>\n</ng-template>\n<input\n #input\n class=\"bm-password__input bm-input\"\n [disabled]=\"disabled\"\n [value]=\"value\"\n [type]=\"getInputType()\"\n (change)=\"onInputChange($event)\"\n (blur)=\"onInputBlur()\"\n/>\n<button\n *ngIf=\"displayButton\"\n class=\"bm-password__toggle\"\n type=\"button\"\n i18n-title\n title=\"Toggle hidden password\"\n (click)=\"onToggleClick($event)\"\n>\n <i aria-hidden=\"true\">\n <svg\n *ngIf=\"hide; else shownPassword\"\n aria-hidden=\"true\"\n data-prefix=\"far\"\n data-icon=\"eye-slash\"\n class=\"bm-password__svg\"\n role=\"img\"\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 576 512\"\n >\n <path\n fill=\"currentColor\"\n d=\"M272.702 359.139c-80.483-9.011-136.212-86.886-116.93-167.042l116.93 167.042zM288 392c-102.556 0-192.092-54.701-240-136 21.755-36.917 52.1-68.342 88.344-91.658l-27.541-39.343C67.001 152.234 31.921 188.741 6.646 231.631a47.999 47.999 0 0 0 0 48.739C63.004 376.006 168.14 440 288 440a332.89 332.89 0 0 0 39.648-2.367l-32.021-45.744A284.16 284.16 0 0 1 288 392zm281.354-111.631c-33.232 56.394-83.421 101.742-143.554 129.492l48.116 68.74c3.801 5.429 2.48 12.912-2.949 16.712L450.23 509.83c-5.429 3.801-12.912 2.48-16.712-2.949L102.084 33.399c-3.801-5.429-2.48-12.912 2.949-16.712L125.77 2.17c5.429-3.801 12.912-2.48 16.712 2.949l55.526 79.325C226.612 76.343 256.808 72 288 72c119.86 0 224.996 63.994 281.354 159.631a48.002 48.002 0 0 1 0 48.738zM528 256c-44.157-74.933-123.677-127.27-216.162-135.007C302.042 131.078 296 144.83 296 160c0 30.928 25.072 56 56 56s56-25.072 56-56l-.001-.042c30.632 57.277 16.739 130.26-36.928 171.719l26.695 38.135C452.626 346.551 498.308 306.386 528 256z\"\n ></path>\n </svg>\n </i>\n</button>\n",
|
100 | changeDetection: ChangeDetectionStrategy.OnPush,
|
101 | providers: [
|
102 | {
|
103 | provide: NG_VALUE_ACCESSOR,
|
104 |
|
105 | useExisting: forwardRef(( |
106 |
|
107 |
|
108 | () => PasswordInputComponent)),
|
109 | multi: true,
|
110 | },
|
111 | ],
|
112 | styles: [":host{display:inline-block;position:relative}.bm-password__input{box-sizing:border-box;padding-right:2em;width:100%}.bm-password__toggle{background:0 0;border:0;display:block;position:absolute;right:.25em;top:calc(50% - .7em)}.bm-password__svg{display:inline-block;font-size:inherit;height:1em;overflow:visible;vertical-align:-.125em;width:1.125em}"]
|
113 | }] }
|
114 | ];
|
115 |
|
116 | PasswordInputComponent.ctorParameters = () => [
|
117 | { type: ChangeDetectorRef }
|
118 | ];
|
119 | PasswordInputComponent.propDecorators = {
|
120 | value: [{ type: Input }],
|
121 | disabled: [{ type: Input }],
|
122 | displayButton: [{ type: Input }],
|
123 | hide: [{ type: Input }],
|
124 | toggleHide: [{ type: Output }],
|
125 | passwordChange: [{ type: Output }],
|
126 | _input: [{ type: ViewChild, args: ['input', { read: ElementRef, static: true },] }]
|
127 | };
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | class PasswordInputComponentModule {
|
134 | }
|
135 | PasswordInputComponentModule.decorators = [
|
136 | { type: NgModule, args: [{
|
137 | imports: [CommonModule],
|
138 | declarations: [PasswordInputComponent],
|
139 | exports: [PasswordInputComponent],
|
140 | },] }
|
141 | ];
|
142 |
|
143 | export { PasswordInputComponent, PasswordInputComponentModule };
|
144 |
|