Skip to content

Commit f1603bd

Browse files
committed
feat(lib): enhanced the lib
1 parent b3f213f commit f1603bd

8 files changed

+92
-31
lines changed

Diff for: projects/angular-material-extensions/input-counter/package.json

+34-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,42 @@
4444
},
4545
"peerDependencies": {
4646
"@angular/common": "^9.1.11",
47-
"@angular/core": "^9.1.11"
47+
"@angular/core": "^9.1.11",
48+
"@angular/flex-layout": "^9.0.0-beta.31",
49+
"@angular/cdk": "^9.2.0",
50+
"@angular/material": "^9.2.0"
4851
},
4952
"dependencies": {
5053
"tslib": "^1.10.0"
54+
},
55+
"engines": {
56+
"node": ">=10.0.0"
57+
},
58+
"release-it": {
59+
"github": {
60+
"release": true
61+
},
62+
"npm": {
63+
"publish": true,
64+
"publishPath": "../../../dist/angular-material-extensions/google-maps-autocomplete"
65+
},
66+
"publishConfig": {
67+
"access": "public"
68+
},
69+
"plugins": {
70+
"@release-it/conventional-changelog": {
71+
"preset": "angular",
72+
"infile": "../../../CHANGELOG.md"
73+
}
74+
},
75+
"hooks": {
76+
"before:init": [
77+
"npm run clean"
78+
],
79+
"after:bump": "echo \"building lib v${version}... \" && npm run build",
80+
"before:git:release": "echo \"Updating CHANGELOG.md for v${version} \" && git commit -a -m \"docs(project): Updating CHANGELOG.md for v${version} \" && git push",
81+
"after:release": "echo Successfully released ${name} v${version} to ${repo.repository}.",
82+
"before:npm": "echo building the library..."
83+
}
5184
}
5285
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div fxLayout="row" fxLayoutGap="5px" fxLayoutAlign="center center">
2+
<button mat-mini-fab (click)="decrement()" [disabled]="value - step < min">
3+
<mat-icon>remove</mat-icon>
4+
</button>
5+
<mat-form-field [appearance]="appearance">
6+
<mat-label>
7+
{{label}}
8+
</mat-label>
9+
<input #input matInput [placeholder]="placeholder" type="number" [(ngModel)]="value">
10+
</mat-form-field>
11+
<button mat-mini-fab (click)="increment()" [disabled]="value + step > max">
12+
<mat-icon>add</mat-icon>
13+
</button>
14+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
input {
2+
text-align: center;
3+
}

Diff for: projects/angular-material-extensions/input-counter/src/lib/input-counter.component.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, EventEmitter, forwardRef, Input, OnInit, Output} from '@angular/core';
22
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
3+
import {MatFormFieldAppearance} from '@angular/material/form-field';
34

45
@Component({
56
selector: 'mat-input-counter',
@@ -16,7 +17,7 @@ import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
1617
export class InputCounterComponent implements OnInit, ControlValueAccessor {
1718

1819
@Input()
19-
value: number;
20+
_value: number;
2021

2122
@Input()
2223
max: number;
@@ -25,23 +26,50 @@ export class InputCounterComponent implements OnInit, ControlValueAccessor {
2526
min: number;
2627

2728
@Input()
28-
step: number;
29+
step = 1;
30+
31+
@Input()
32+
appearance: MatFormFieldAppearance = 'standard';
2933

3034
@Input()
3135
placeholder: string;
3236

3337
@Input()
34-
label: string;
38+
label = 'Number';
3539

3640
@Output()
3741
change: EventEmitter<number> = new EventEmitter<number>();
3842

3943
propagateChange = (_: any) => {
4044
};
4145

46+
get value() {
47+
return this._value;
48+
}
49+
50+
set value(val) {
51+
this._value = val;
52+
this.propagateChange(this._value);
53+
}
54+
4255
ngOnInit(): void {
4356
}
4457

58+
increment() {
59+
console.log('incr', this.value);
60+
if (!this.value) {
61+
this.value = 0;
62+
}
63+
this.value += this.step;
64+
}
65+
66+
decrement() {
67+
if (!this.value) {
68+
this.value = 0;
69+
}
70+
this.value -= this.step;
71+
}
72+
4573
writeValue(obj: any): void {
4674
if (obj) {
4775
this.value = obj;

Diff for: projects/angular-material-extensions/input-counter/src/lib/input-counter.service.spec.ts

-16
This file was deleted.

Diff for: projects/angular-material-extensions/input-counter/src/lib/input-counter.service.ts

-9
This file was deleted.

Diff for: projects/angular-material-extensions/input-counter/src/lib/mat-input-counter.module.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { NgModule } from '@angular/core';
22
import { InputCounterComponent } from './input-counter.component';
3+
import {MatButtonModule} from '@angular/material/button';
4+
import {MatIconModule} from '@angular/material/icon';
5+
import {MatInputModule} from '@angular/material/input';
6+
import {FlexModule} from '@angular/flex-layout';
7+
import {FormsModule} from '@angular/forms';
38

49

510

611
@NgModule({
712
declarations: [InputCounterComponent],
813
imports: [
14+
MatButtonModule,
15+
MatIconModule,
16+
MatInputModule,
17+
FlexModule,
18+
FormsModule
919
],
1020
exports: [InputCounterComponent]
1121
})
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/*
22
* Public API Surface of input-counter
33
*/
4-
5-
export * from './lib/input-counter.service';
64
export * from './lib/input-counter.component';
75
export * from './lib/mat-input-counter.module';

0 commit comments

Comments
 (0)