Skip to content

Commit 1c5d952

Browse files
committed
feat(lib): added mat-select-icon.component the main component of the library
1 parent c127f87 commit 1c5d952

12 files changed

+143
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NgModule } from '@angular/core';
2+
import { MatSelectIconComponent } from './mat-select-icon/mat-select-icon.component';
3+
4+
5+
@NgModule({
6+
declarations: [MatSelectIconComponent],
7+
imports: [],
8+
exports: [MatSelectIconComponent]
9+
})
10+
export class MatSelectIconModule {
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="dep-img" fxLayout="row wrap">
2+
<button (click)="select(icon)"
3+
*ngFor="let icon of this.icons"
4+
[color]="icon?.color ? icon.color : 'accent'"
5+
class="dep-img"
6+
mat-icon-button
7+
type="button">
8+
<img [ngClass]="{'gray': this.value && this.value !== icon}"
9+
[src]="icon?.url"
10+
class="mat-icon">
11+
</button>
12+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.dep-img {
2+
.mat-icon-button {
3+
width: 80px;
4+
height: 80px;
5+
}
6+
7+
img.gray {
8+
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
9+
filter: grayscale(100%);
10+
}
11+
12+
img.mat-icon {
13+
width: 48px;
14+
height: 48px;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { MatSelectIconComponent } from './mat-select-icon.component';
4+
5+
describe('MatSelectIconComponent', () => {
6+
let component: MatSelectIconComponent;
7+
let fixture: ComponentFixture<MatSelectIconComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ MatSelectIconComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(MatSelectIconComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
2+
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
3+
import { ThemePalette } from '@angular/material/core';
4+
5+
export interface MatSelectIcon {
6+
url: string;
7+
selected?: boolean;
8+
color?: ThemePalette;
9+
tags?: string[];
10+
}
11+
12+
@Component({
13+
selector: 'mat-select-icon',
14+
templateUrl: './mat-select-icon.component.html',
15+
styleUrls: ['./mat-select-icon.component.scss'],
16+
providers: [
17+
{
18+
provide: NG_VALUE_ACCESSOR,
19+
useExisting: forwardRef(() => MatSelectIconComponent),
20+
multi: true
21+
}
22+
]
23+
})
24+
export class MatSelectIconComponent implements OnInit, ControlValueAccessor {
25+
26+
propagateChange = (_: any) => {
27+
};
28+
29+
@Input()
30+
icons: MatSelectIcon[];
31+
32+
@Output()
33+
onIconSelected: EventEmitter<MatSelectIcon> = new EventEmitter<MatSelectIcon>();
34+
35+
36+
constructor() {
37+
}
38+
39+
private _value: MatSelectIcon;
40+
41+
get value(): MatSelectIcon {
42+
return this._value;
43+
}
44+
45+
@Input()
46+
set value(value: MatSelectIcon) {
47+
this._value = value;
48+
this.propagateChange(this._value);
49+
}
50+
51+
ngOnInit(): void {
52+
}
53+
54+
select(icon: MatSelectIcon) {
55+
this.value = icon;
56+
this.onIconSelected.next(this.value);
57+
}
58+
59+
writeValue(value: MatSelectIcon) {
60+
if (value !== undefined) {
61+
this.value = value;
62+
}
63+
}
64+
65+
registerOnChange(fn: any): void {
66+
this.propagateChange = fn;
67+
}
68+
69+
registerOnTouched(fn: any): void {
70+
}
71+
72+
setDisabledState(isDisabled: boolean): void {
73+
}
74+
75+
}

projects/angular-material-extensions/select-icon/src/lib/select-icon.component.spec.ts

-25
This file was deleted.

projects/angular-material-extensions/select-icon/src/lib/select-icon.component.ts

-20
This file was deleted.

projects/angular-material-extensions/select-icon/src/lib/select-icon.module.ts

-12
This file was deleted.

projects/angular-material-extensions/select-icon/src/lib/select-icon.service.spec.ts

-16
This file was deleted.

projects/angular-material-extensions/select-icon/src/lib/select-icon.service.ts

-9
This file was deleted.

projects/angular-material-extensions/select-icon/src/public-api.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
* Public API Surface of select-icon
33
*/
44

5-
export * from './lib/select-icon.service';
6-
export * from './lib/select-icon.component';
7-
export * from './lib/select-icon.module';
5+
export * from './lib/mat-select-icon/mat-select-icon.component';
6+
export * from './lib/mat-select-icon.module';

projects/angular-material-extensions/select-icon/tslint.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"directive-selector": [
55
true,
66
"attribute",
7-
"lib",
7+
"mat",
88
"camelCase"
99
],
1010
"component-selector": [
1111
true,
1212
"element",
13-
"lib",
13+
"mat",
1414
"kebab-case"
1515
]
1616
}

0 commit comments

Comments
 (0)