Skip to content

Commit 7389d99

Browse files
committed
add standalone and upgrade
1 parent 4538e01 commit 7389d99

31 files changed

+9542
-15365
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.0.0] - 2025-05-25
6+
7+
### Added
8+
9+
- Improved README.md
10+
- Added `minusComponent`, `plusComponent` inputs to set custom component template content to minus and plus buttons.
11+
- Added `NgxInputCounterService` to set config.
12+
- Added Standalone
13+
- Upgraded to Angular 18
14+
515
## [0.0.3]
616

717
### Added

README.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The input number with counter for Angular
1717

1818
| Angular | ngx-input-counter |
1919
| -------- |:------:|
20+
| >=16.0.0 | v1.0.x |
2021
| >=15.0.0 | v0.0.x |
2122

2223
### Instalation
@@ -27,7 +28,7 @@ npm i ngx-input-counter
2728

2829
## Usage
2930

30-
Import the module
31+
NgModule: Import the module
3132

3233
```typescript
3334
import { NgxInputCounterModule } from 'ngx-input-counter';
@@ -40,6 +41,21 @@ import { NgxInputCounterModule } from 'ngx-input-counter';
4041
})
4142
```
4243

44+
Standalone: Import the component, optional: if you are using the directives
45+
46+
```ts
47+
import { NgxInputCounterComponent } from 'ngx-input-counter';
48+
@NgModule({
49+
...
50+
imports: [
51+
...,
52+
NgxInputCounterComponent,
53+
PlusContentDirective,
54+
MinusContentDirective,
55+
],
56+
})
57+
```
58+
4359
Use in your components
4460

4561
```html
@@ -56,6 +72,8 @@ Use in your components
5672
| step | `number` | `1` | Transition time for the animation |
5773
| minusTemplate | `TemplateRef` | `-` | Pass a TemplateRef to replace the minus button content |
5874
| plusTemplate | `TemplateRef` | `+` | Pass a TemplateRef to replace the plus button content |
75+
| minusComponent | `Type` | `undefined` | Pass a Component to replace the minus button content |
76+
| plusComponent | `Type` | `undefined` | Pass a Component to replace the plus button content |
5977
| minusClass | `string` | `'ngx-input-counter-button'` | Classes of the minus button |
6078
| plusClass | `string` | `'ngx-input-counter-button'` | Classes of the plus button |
6179
| valueClass | `string` | `'ngx-input-counter-value'` | Classes of value text |
@@ -171,6 +189,110 @@ When you use the slot template you can pass classes to override the button class
171189
</ng-template>
172190
```
173191

192+
## Global Configuration
193+
194+
You can configure all `ngx-input-counter` components in your app using the `NgxInputCounterService` provider.
195+
This allows you to set default values for all instances of `ngx-input-counter` throughout your application.
196+
197+
```ts
198+
constructor (private config: NgxInputCounterService) {
199+
this.config.min = 0
200+
this.config.valueClass = 'p-2 border border-gray-400 font-monospace'
201+
this.config.minusClass = 'btn border-gray-400 rounded-l-md opacity-50 hover:opacity-40'
202+
this.config.plusClass = 'btn border-gray-400 rounded-r-md opacity-50 hover:opacity-40'
203+
}
204+
```
205+
206+
These settings will apply to all `ngx-input-counter` components in your application. However, you can still override individual values
207+
directly through their input properties in your templates.
208+
209+
### Advanced Customization
210+
211+
For more advanced use cases, you can use the plusComponent and minusComponent properties to define custom components for the plus and minus buttons:
212+
213+
```ts
214+
constructor (private config: NgxInputCounterService) {
215+
...
216+
this.config.minusComponent = MinusTemplateComponent;
217+
this.config.plusComponent = PlusTemplateComponent;
218+
}
219+
```
220+
221+
This is useful when you have dynamic or reusable templates for your button content and want to configure them globally via the service.
222+
223+
### Extending the Component
224+
225+
Another powerful way to customize `ngx-input-counter` is by extending the `NgxInputCounterComponent` itself.
226+
This allows you to create your own custom input counter component, add new properties, and directly modify the button content templates within your extended component.
227+
228+
```ts
229+
@Component({
230+
selector: 'app-input-counter',
231+
standalone: true,
232+
imports: [NgxInputCounterComponent],
233+
template: `
234+
<ng-template #plusTemplateIcon>
235+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
236+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
237+
</svg>
238+
</ng-template>
239+
<ng-template #minusTemplateIcon let-step="step" let-min="min" let-value="value">
240+
@if (value !== min + step) {
241+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
242+
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 12h-15" />
243+
</svg>
244+
} @else {
245+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="#EF2F35">
246+
<path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
247+
</svg>
248+
}
249+
</ng-template>
250+
<ngx-input-counter class="custom-plus" style="margin: auto;"
251+
[plusTemplate]="plusTemplateIcon"
252+
[minusTemplate]="minusTemplateIcon"
253+
[min]="min"
254+
[max]="max"
255+
[step]="step"
256+
[value]="value"
257+
[disabled]="disabled"
258+
(change)="onInput($event)"
259+
>
260+
</ngx-input-counter>
261+
`,
262+
providers: [
263+
{
264+
provide: NG_VALUE_ACCESSOR,
265+
useExisting: forwardRef(() => AppCounterComponent),
266+
multi: true
267+
}
268+
]
269+
})
270+
export class AppCounterComponent extends NgxInputCounterComponent {}
271+
```
272+
273+
By creating your own component that extends the original, you can:
274+
275+
- Add custom inputs and behavior
276+
- Override the button content templates
277+
- Fully customize the appearance and functionality
278+
279+
You can then use `<app-input-counter>` instead of `<ngx-input-counter>` in your templates.
280+
281+
> ![NOTE]
282+
> If you plan to use your extended component with Angular Forms, don't forget to provide the `NG_VALUE_ACCESSOR`
283+
284+
```ts
285+
providers: [
286+
{
287+
provide: NG_VALUE_ACCESSOR,
288+
useExisting: forwardRef(() => AppCounterComponent),
289+
multi: true
290+
}
291+
]
292+
```
293+
294+
This ensures your custom counter component works properly with ngModel or reactive forms.
295+
174296
## Development
175297

176298
Clone this repo and install the dependencies. Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.

angular.json

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,21 @@
4848
"prefix": "app",
4949
"architect": {
5050
"build": {
51-
"builder": "@angular-devkit/build-angular:browser",
51+
"builder": "@angular-devkit/build-angular:application",
5252
"options": {
5353
"outputPath": "dist/demo",
5454
"index": "projects/demo/src/index.html",
55-
"main": "projects/demo/src/main.ts",
55+
"browser": "projects/demo/src/main.ts",
5656
"polyfills": [
5757
"zone.js"
5858
],
5959
"tsConfig": "projects/demo/tsconfig.app.json",
6060
"inlineStyleLanguage": "scss",
6161
"assets": [
62-
"projects/demo/src/favicon.ico",
63-
"projects/demo/src/assets"
62+
{
63+
"glob": "**/*",
64+
"input": "projects/demo/public"
65+
}
6466
],
6567
"styles": [
6668
"projects/demo/src/styles.scss"
@@ -72,24 +74,21 @@
7274
"budgets": [
7375
{
7476
"type": "initial",
75-
"maximumWarning": "500kb",
76-
"maximumError": "1mb"
77+
"maximumWarning": "500kB",
78+
"maximumError": "1MB"
7779
},
7880
{
7981
"type": "anyComponentStyle",
80-
"maximumWarning": "2kb",
81-
"maximumError": "4kb"
82+
"maximumWarning": "2kB",
83+
"maximumError": "4kB"
8284
}
8385
],
8486
"outputHashing": "all"
8587
},
8688
"development": {
87-
"buildOptimizer": false,
8889
"optimization": false,
89-
"vendorChunk": true,
9090
"extractLicenses": false,
91-
"sourceMap": true,
92-
"namedChunks": true
91+
"sourceMap": true
9392
}
9493
},
9594
"defaultConfiguration": "production"
@@ -98,19 +97,16 @@
9897
"builder": "@angular-devkit/build-angular:dev-server",
9998
"configurations": {
10099
"production": {
101-
"browserTarget": "demo:build:production"
100+
"buildTarget": "demo:build:production"
102101
},
103102
"development": {
104-
"browserTarget": "demo:build:development"
103+
"buildTarget": "demo:build:development"
105104
}
106105
},
107106
"defaultConfiguration": "development"
108107
},
109108
"extract-i18n": {
110-
"builder": "@angular-devkit/build-angular:extract-i18n",
111-
"options": {
112-
"browserTarget": "demo:build"
113-
}
109+
"builder": "@angular-devkit/build-angular:extract-i18n"
114110
},
115111
"test": {
116112
"builder": "@angular-devkit/build-angular:karma",
@@ -122,8 +118,10 @@
122118
"tsConfig": "projects/demo/tsconfig.spec.json",
123119
"inlineStyleLanguage": "scss",
124120
"assets": [
125-
"projects/demo/src/favicon.ico",
126-
"projects/demo/src/assets"
121+
{
122+
"glob": "**/*",
123+
"input": "projects/demo/public"
124+
}
127125
],
128126
"styles": [
129127
"projects/demo/src/styles.scss"

0 commit comments

Comments
 (0)