Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 62673e7

Browse files
chore: 🤖 release 1.0.0
1 parent 07827ff commit 62673e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1332
-720
lines changed

README.md

Lines changed: 151 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img width="20%" height="20%" src="./logo.svg">
2+
<img width="20%" height="20%" src="./logo.png">
33
</p>
44

55
<br />
@@ -12,22 +12,27 @@
1212
[![ngneat](https://img.shields.io/badge/@-ngneat-383636?style=flat-square&labelColor=8f68d4)](https://github.com/ngneat/)
1313
[![spectator](https://img.shields.io/badge/tested%20with-spectator-2196F3.svg?style=flat-square)](https://github.com/ngneat/spectator)
1414

15-
> The Library Slogan
15+
> Reactive forms validation for pros
1616
17-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid assumenda atque blanditiis cum delectus eligendi ipsam iste iure, maxime modi molestiae nihil obcaecati odit officiis pariatur quibusdam suscipit temporibus unde.
18-
Accusantium aliquid corporis cupiditate dolores eum exercitationem illo iure laborum minus nihil numquam odit officiis possimus quas quasi quos similique, temporibus veritatis? Exercitationem, iure magni nulla quo sapiente soluta. Esse?
17+
I solely missed `ng-messages` directive from AngularJs, so I created this one to use in Angular 2+.
18+
In contrast to the one from AngularJs, this one requires you to pass the control name to the directive, instead of its errors.
19+
This allowed me to hook in to the status of control, like its `dirty` state, and display validation messages according to that status.
20+
A nice side effect of that decision is less boilerplate code.
1921

2022
## Features
2123

22-
- ✅ One
23-
- ✅ Two
24-
- ✅ Three
24+
- ✅ Simple syntax that reduces boilerplate
25+
- ✅ Configure when to display error messages for an app further reducing boilerplate
26+
- ✅ Seamless integration with Reactive Forms
27+
- ✅ Works with nested forms
2528

2629
## Table of Contents
2730

2831
- [Installation](#installation)
2932
- [Usage](#usage)
30-
- [FAQ](#faq)
33+
- [Advanced configuration](#configuration)
34+
- [Styling](#styling)
35+
- [Development](#development)
3136

3237
## Installation
3338

@@ -41,17 +46,150 @@ Accusantium aliquid corporis cupiditate dolores eum exercitationem illo iure lab
4146

4247
## Usage
4348

44-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid assumenda atque blanditiis cum delectus eligendi ipsam iste iure, maxime modi molestiae nihil obcaecati odit officiis pariatur quibusdam suscipit temporibus unde.
49+
Import library into your application module:
4550

4651
```ts
47-
function helloWorld() {}
52+
import { NgxErrorsModule } from '@ngspot/ngx-errors'; // <-- import the module
53+
54+
@NgModule({
55+
imports: [
56+
NgxErrorsModule, // <-- include it in your app module
57+
],
58+
})
59+
export class MyAppModule {}
4860
```
4961

50-
## FAQ
62+
### Use-case with a form:
5163

52-
## How to ...
64+
```ts
65+
@Component({
66+
selector: 'my-component',
67+
template: `
68+
<form [formGroup]="myForm">
69+
<input formControlName="email" type="email" />
70+
71+
<div ngxErrors="email">
72+
<div ngxError="required">Email is required</div>
73+
</div>
74+
</form>
75+
`,
76+
})
77+
export class MyComponent implements OnInit {
78+
myForm: FormGroup;
79+
80+
constructor(private fb: FormBuilder) {
81+
this.myForm = this.fb.group({
82+
email: ['', Validators.required],
83+
});
84+
}
85+
}
86+
```
87+
88+
### Use-case with a simple FormControl:
89+
90+
```ts
91+
@Component({
92+
selector: 'my-component',
93+
template: `
94+
<input [formControl]="email" placeholder="Email" type="email" />
95+
96+
<div [ngxErrors]="email">
97+
<div ngxError="required">Email is required</div>
98+
</div>
99+
`,
100+
})
101+
export class MyComponent implements OnInit {
102+
email = new FormControl('', Validators.required);
103+
}
104+
```
105+
106+
## Configuration
107+
108+
You configure when to show messages for your whole module by using `.configure()` method:
109+
110+
```ts
111+
@NgModule({
112+
imports: [
113+
NgxErrorsModule.configure({ ... }) // <- provide configuration here
114+
],
115+
})
116+
export class MyAppModule {}
117+
```
118+
119+
Alternatively, use dependency injection to provide configuration at a component level:
120+
121+
```ts
122+
import { ErrorsConfiguration } from '@ngspot/ngx-errors';
123+
124+
const myConfig = { ... }; // <- specify your config
125+
126+
@Component({
127+
...
128+
providers: [
129+
{ provide: ErrorsConfiguration, useValue: myConfig }
130+
]
131+
})
132+
export class MyComponent { }
133+
```
134+
135+
Here's configuration object interface:
136+
137+
```ts
138+
interface IErrorsConfiguration {
139+
/**
140+
* Configure errors to show only when the corresponding input is dirty.
141+
*
142+
* Default is `true`.
143+
*/
144+
showErrorsOnlyIfInputDirty?: boolean;
145+
146+
/**
147+
* Configure errors to show only when form is submitted.
148+
* Upon form submission shows errors even if `showErrorsOnlyIfInputDirty = true`
149+
* and some of the inputs aren't dirty.
150+
* Takes effect only when ngxErrors directive is a child of a form.
151+
*
152+
* Default is `false`.
153+
*/
154+
showErrorsWhenFormSubmitted?: boolean;
155+
}
156+
```
157+
158+
## Styling
159+
160+
Just include something similar to the following in your global css file:
161+
162+
```css
163+
[ngxerrors] {
164+
color: red;
165+
}
166+
```
167+
168+
## Development
169+
170+
### Basic Workflow
171+
172+
1. Develop
173+
1. Write specs
174+
1. Run npm run test:lib,
175+
1. Run npm run commit, and choose fix or feature
176+
1. Run npm run release
177+
1. Run npm run build:lib
178+
1. Go to the dist directory, and run npm publish
179+
180+
### Scripts
181+
182+
- `build:lib` - Builds the library
183+
- `test:lib` - Runs tests
184+
- `test:lib:headless` - Runs tests in headless mode with Chrome
185+
- `release` - Releases a new version. This will bump the library's version, and update the `CHANGE_LOG` file based on the commit message
186+
- `release:first` - Creates the first release
187+
- `commit` - Creates a new commit message based on Angular commit messgae convention
188+
- `contributors:add` - Adds a new contributor to the `README` file
189+
190+
## License
53191

54-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid assumenda atque blanditiis cum delectus eligendi ips
192+
MIT © [Dmitry Efimenko](mailto:[email protected])
55193

56194
## Contributors ✨
57195

angular.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"projectType": "library",
88
"root": "projects/ngx-errors",
99
"sourceRoot": "projects/ngx-errors/src",
10-
"prefix": "lib",
10+
"prefix": "ngx",
1111
"architect": {
1212
"build": {
1313
"builder": "@angular-devkit/build-ng-packagr:build",
@@ -36,9 +36,7 @@
3636
"projects/ngx-errors/tsconfig.lib.json",
3737
"projects/ngx-errors/tsconfig.spec.json"
3838
],
39-
"exclude": [
40-
"**/node_modules/**"
41-
]
39+
"exclude": ["**/node_modules/**"]
4240
}
4341
}
4442
}
@@ -67,9 +65,7 @@
6765
"projects/playground/src/favicon.ico",
6866
"projects/playground/src/assets"
6967
],
70-
"styles": [
71-
"projects/playground/src/styles.scss"
72-
],
68+
"styles": ["projects/playground/src/styles.scss"],
7369
"scripts": []
7470
},
7571
"configurations": {
@@ -131,9 +127,7 @@
131127
"projects/playground/src/favicon.ico",
132128
"projects/playground/src/assets"
133129
],
134-
"styles": [
135-
"projects/playground/src/styles.scss"
136-
],
130+
"styles": ["projects/playground/src/styles.scss"],
137131
"scripts": []
138132
}
139133
},
@@ -145,9 +139,7 @@
145139
"projects/playground/tsconfig.spec.json",
146140
"projects/playground/e2e/tsconfig.json"
147141
],
148-
"exclude": [
149-
"**/node_modules/**"
150-
]
142+
"exclude": ["**/node_modules/**"]
151143
}
152144
},
153145
"e2e": {
@@ -163,7 +155,8 @@
163155
}
164156
}
165157
}
166-
}},
158+
}
159+
},
167160
"cli": {
168161
"analytics": "1fda32b1-7b29-416a-8ab5-4ab9bb640931"
169162
},

assets/logo.psd

390 KB
Binary file not shown.

logo.png

23.7 KB
Loading

logo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)