ngx-form-stepper 0.0.11 β 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[π«π· Lire la version franΓ§aise](https://github.com/rayaneriahi/ngx-form-stepper/blob/main/README.fr.md)
|
|
4
4
|
|
|
5
|
-
**ngx-form-stepper** is an Angular library to create multi-step forms with field-level
|
|
5
|
+
**ngx-form-stepper** is an Angular library that allows you to create multi-step forms with field-level validation, **extremely strongly typed**.
|
|
6
6
|
|
|
7
7
|
It prevents creating invalid states **at development time**, not at runtime.
|
|
8
8
|
|
|
@@ -62,26 +62,6 @@ onComplete() {
|
|
|
62
62
|
|
|
63
63
|
## Input
|
|
64
64
|
|
|
65
|
-
Each `Input` type only accepts compatible `validators`.
|
|
66
|
-
|
|
67
|
-
Examples :
|
|
68
|
-
|
|
69
|
-
- `email` β forbidden on `number`
|
|
70
|
-
- `minLength` β forbidden on `checkbox`
|
|
71
|
-
- `confirm` β forbidden on `select`
|
|
72
|
-
|
|
73
|
-
And only default values that are compatible.
|
|
74
|
-
|
|
75
|
-
Examples :
|
|
76
|
-
|
|
77
|
-
- `string` β forbidden on `number`
|
|
78
|
-
- `number` β forbidden on `checkbox`
|
|
79
|
-
- `string | number` β forbidden on `select`
|
|
80
|
-
|
|
81
|
-
Return key must be camelCase.
|
|
82
|
-
|
|
83
|
-
Duplicating a `validator` is impossible.
|
|
84
|
-
|
|
85
65
|
```typescript
|
|
86
66
|
export class Input<
|
|
87
67
|
T extends InputType,
|
|
@@ -116,6 +96,28 @@ export enum InputType {
|
|
|
116
96
|
}
|
|
117
97
|
```
|
|
118
98
|
|
|
99
|
+
Each `Input` type only accepts compatible default values.
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
export type InputDefaultValue<T extends InputType> = T extends InputType.Text
|
|
103
|
+
? string | null
|
|
104
|
+
: T extends InputType.Password
|
|
105
|
+
? string | null
|
|
106
|
+
: T extends InputType.Email
|
|
107
|
+
? string | null
|
|
108
|
+
: T extends InputType.Number
|
|
109
|
+
? number | null
|
|
110
|
+
: T extends InputType.Tel
|
|
111
|
+
? string | null
|
|
112
|
+
: T extends InputType.Checkbox
|
|
113
|
+
? boolean | null
|
|
114
|
+
: T extends InputType.Date
|
|
115
|
+
? Date | null
|
|
116
|
+
: T extends InputType.Select
|
|
117
|
+
? Select<SelectItemTuple, number | null>
|
|
118
|
+
: never;
|
|
119
|
+
```
|
|
120
|
+
|
|
119
121
|
## Validator
|
|
120
122
|
|
|
121
123
|
A `validator` is a function that can be passed to an `Input`. It takes different arguments like conditional values or error text.
|
|
@@ -156,20 +158,38 @@ export type ValidatorsNames =
|
|
|
156
158
|
| 'maxDate';
|
|
157
159
|
```
|
|
158
160
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
**ngx-form-stepper** allows you to factor them while keeping strict typing based on the `Input` type.
|
|
161
|
+
Each `Input` type only accepts compatible validators.
|
|
162
162
|
|
|
163
163
|
```typescript
|
|
164
|
-
|
|
164
|
+
export type ValidatorsNamesOfType<T extends InputType> = T extends InputType.Text
|
|
165
|
+
? 'required' | 'confirm' | 'minLength' | 'maxLength' | 'pattern'
|
|
166
|
+
: T extends InputType.Password
|
|
167
|
+
? 'required' | 'confirm' | 'strongPassword' | 'pattern'
|
|
168
|
+
: T extends InputType.Email
|
|
169
|
+
? 'required' | 'confirm' | 'email'
|
|
170
|
+
: T extends InputType.Number
|
|
171
|
+
? 'required' | 'confirm' | 'min' | 'max' | 'integer'
|
|
172
|
+
: T extends InputType.Tel
|
|
173
|
+
? 'required' | 'confirm' | 'phone'
|
|
174
|
+
: T extends InputType.Checkbox
|
|
175
|
+
? 'check'
|
|
176
|
+
: T extends InputType.Date
|
|
177
|
+
? 'required' | 'confirm' | 'minDate' | 'maxDate'
|
|
178
|
+
: T extends InputType.Select
|
|
179
|
+
? 'required'
|
|
180
|
+
: never;
|
|
165
181
|
```
|
|
166
182
|
|
|
167
|
-
|
|
183
|
+
## Reusing typed validators
|
|
184
|
+
|
|
185
|
+
**ngx-form-stepper** allows you to factor them out, then create groups of `validators` that are compatible only with a given `Input` type:
|
|
168
186
|
|
|
169
187
|
```typescript
|
|
170
|
-
|
|
188
|
+
reqVal: Validator<'required'> = required('Field is required');
|
|
189
|
+
|
|
190
|
+
emailValidators: ValidatorTuple<ValidatorsNamesOfType<InputType.Email>> = [
|
|
171
191
|
reqVal,
|
|
172
|
-
email(
|
|
192
|
+
email('E-mail is not valid'),
|
|
173
193
|
];
|
|
174
194
|
```
|
|
175
195
|
|
|
@@ -218,9 +238,25 @@ export type SelectItem = {
|
|
|
218
238
|
};
|
|
219
239
|
```
|
|
220
240
|
|
|
221
|
-
|
|
241
|
+
Assigning an invalid currentIndex is impossible.
|
|
222
242
|
|
|
223
|
-
|
|
243
|
+
```typescript
|
|
244
|
+
// β Compilation error
|
|
245
|
+
invalid = new Input(
|
|
246
|
+
InputType.Select,
|
|
247
|
+
new Select(
|
|
248
|
+
[
|
|
249
|
+
{ label: 'Male', value: 'male' },
|
|
250
|
+
{ label: 'Female', value: 'female' },
|
|
251
|
+
],
|
|
252
|
+
5
|
|
253
|
+
),
|
|
254
|
+
'gender',
|
|
255
|
+
'Gender'
|
|
256
|
+
);
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Step
|
|
224
260
|
|
|
225
261
|
Tuple of one or more `Inputs`.
|
|
226
262
|
|
|
@@ -251,8 +287,6 @@ new Step([
|
|
|
251
287
|
|
|
252
288
|
Impossible to duplicate an `Input` return key between two `Steps`.
|
|
253
289
|
|
|
254
|
-
Configuration object depending on the number of `Steps`.
|
|
255
|
-
|
|
256
290
|
Tuple of one or more `Steps`.
|
|
257
291
|
|
|
258
292
|
```typescript
|
|
@@ -268,7 +302,11 @@ export class FormStepper<T extends StepTuple> {
|
|
|
268
302
|
) as FormStepperValues<T>;
|
|
269
303
|
}
|
|
270
304
|
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Configuration object depending on the number of `Steps`.
|
|
271
308
|
|
|
309
|
+
```typescript
|
|
272
310
|
export type SingleStepConfig = Readonly<{
|
|
273
311
|
title?: string;
|
|
274
312
|
actionText?: RedirectItem[];
|
|
@@ -291,7 +329,7 @@ export type MultiStepConfig = Readonly<{
|
|
|
291
329
|
A `RedirectItem[]` is an array of strings or `RedirectUrl` objects, a kind of mini TS language to create texts with clickable links.
|
|
292
330
|
|
|
293
331
|
```typescript
|
|
294
|
-
actionText = ['You already have an account
|
|
332
|
+
actionText = ['You already have an account?', { url: '/signin', urlText: 'Sign in' }];
|
|
295
333
|
|
|
296
334
|
export type RedirectUrl = Readonly<{ url: string; urlText: string }>;
|
|
297
335
|
|