Skip to content

Commit f966b1c

Browse files
committed
feat(package): added mat-pass-toggle-visibility component #153
1 parent 17d98ea commit f966b1c

File tree

5 files changed

+72
-8
lines changed

5 files changed

+72
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<button (click)="isVisible = !isVisible" class="mat-icon-button cdk-focused cdk-mouse-focused" mat-icon-button matRipple
2+
matRippleCentered="true"
3+
matSuffix>
4+
<mat-icon>{{isVisible ? 'visibility' : 'visibility_off' }}</mat-icon>
5+
</button>
6+

src/module/component/mat-pass-toggle-visibility/mat-pass-toggle-visibility.component.scss

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2+
3+
import {MatPassToggleVisibilityComponent} from './mat-pass-toggle-visibility.component';
4+
import {MatButtonModule, MatIconModule} from '@angular/material';
5+
6+
describe('MatPassToggleVisibilityComponent', () => {
7+
let component: MatPassToggleVisibilityComponent;
8+
let fixture: ComponentFixture<MatPassToggleVisibilityComponent>;
9+
10+
beforeEach(async(() => {
11+
TestBed.configureTestingModule({
12+
imports: [MatIconModule, MatButtonModule],
13+
declarations: [MatPassToggleVisibilityComponent]
14+
})
15+
.compileComponents();
16+
}));
17+
18+
beforeEach(() => {
19+
fixture = TestBed.createComponent(MatPassToggleVisibilityComponent);
20+
component = fixture.componentInstance;
21+
fixture.detectChanges();
22+
});
23+
24+
it('should create', () => {
25+
expect(component).toBeTruthy();
26+
});
27+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {Component, ViewEncapsulation} from '@angular/core';
2+
3+
type Type = 'text' | 'password' ;
4+
5+
@Component({
6+
selector: 'mat-pass-toggle-visibility',
7+
templateUrl: './mat-pass-toggle-visibility.component.html',
8+
styleUrls: ['./mat-pass-toggle-visibility.component.scss'],
9+
encapsulation: ViewEncapsulation.None
10+
})
11+
export class MatPassToggleVisibilityComponent {
12+
13+
isVisible: boolean;
14+
_type: Type = 'text';
15+
16+
get type() {
17+
return this.isVisible ? 'text' : 'password';
18+
}
19+
20+
}

src/module/mat-password-strength.module.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
import {CommonModule} from '@angular/common';
2-
import {NgModule, ModuleWithProviders} from '@angular/core';
3-
import {MatCardModule, MatIconModule, MatProgressBarModule} from '@angular/material';
2+
import {ModuleWithProviders, NgModule} from '@angular/core';
3+
import {MatCardModule, MatIconModule, MatInputModule, MatProgressBarModule, MatRippleModule} from '@angular/material';
44

55
import {MatPasswordStrengthComponent} from './component/mat-password-strength/mat-password-strength.component';
6-
import {
7-
MatPasswordStrengthInfoComponent
8-
} from './component/mat-password-strength-info/mat-password-strength-info.component';
6+
import {MatPasswordStrengthInfoComponent} from './component/mat-password-strength-info/mat-password-strength-info.component';
7+
import {MatPassToggleVisibilityComponent} from './component/mat-pass-toggle-visibility/mat-pass-toggle-visibility.component';
98

109
// Export module's public API
1110
export {MatPasswordStrengthComponent} from './component/mat-password-strength/mat-password-strength.component';
1211
export {
1312
MatPasswordStrengthInfoComponent
1413
} from './component/mat-password-strength-info/mat-password-strength-info.component';
14+
export {MatPassToggleVisibilityComponent} from './component/mat-pass-toggle-visibility/mat-pass-toggle-visibility.component';
1515

1616
@NgModule({
1717
imports: [
1818
CommonModule,
1919
MatProgressBarModule,
2020
MatCardModule,
21-
MatIconModule
21+
MatIconModule,
22+
MatInputModule,
23+
MatRippleModule
24+
],
25+
exports: [
26+
MatPasswordStrengthComponent,
27+
MatPasswordStrengthInfoComponent,
28+
MatPassToggleVisibilityComponent
29+
],
30+
declarations: [
31+
MatPasswordStrengthComponent,
32+
MatPasswordStrengthInfoComponent,
33+
MatPassToggleVisibilityComponent
2234
],
23-
exports: [MatPasswordStrengthComponent, MatPasswordStrengthInfoComponent],
24-
declarations: [MatPasswordStrengthComponent, MatPasswordStrengthInfoComponent]
35+
entryComponents: [MatPassToggleVisibilityComponent]
2536
})
2637
export class MatPasswordStrengthModule {
2738
static forRoot(): ModuleWithProviders {

0 commit comments

Comments
 (0)