@seniorsistemas/angular-components 18.0.4 → 18.1.0-feature-sds-276-640ecaac
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/esm2022/form-dynamic/components/form-dynamic/form-dynamic.component.mjs +53 -0
- package/esm2022/form-dynamic/core/registry.mjs +10 -0
- package/esm2022/form-dynamic/fields-basic/boolean-field/boolean-field.component.mjs +15 -0
- package/esm2022/form-dynamic/fields-basic/string-field/string-field.component.mjs +15 -0
- package/esm2022/form-dynamic/lib/optional-fields/editor/editor-field/editor-field.component.mjs +30 -0
- package/esm2022/form-dynamic/lib/optional-fields/editor/editor-types.mjs +3 -0
- package/esm2022/form-dynamic/lib/optional-fields/editor/public-api.mjs +8 -0
- package/esm2022/form-dynamic/lib/optional-fields/editor/seniorsistemas-angular-components-form-dynamic-lib-optional-fields-editor.mjs +5 -0
- package/esm2022/form-dynamic/public-api.mjs +10 -0
- package/esm2022/form-dynamic/schemas/field-dynamic.mjs +2 -0
- package/esm2022/form-dynamic/schemas/form-dynamic-schema.mjs +2 -0
- package/esm2022/form-dynamic/seniorsistemas-angular-components-form-dynamic.mjs +5 -0
- package/esm2022/numeric-mask/lib/numeric-mask/numeric-mask.directive.mjs +10 -14
- package/esm2022/pin-code-field/lib/pin-code-field/pin-code-field.component.mjs +460 -0
- package/esm2022/pin-code-field/lib/pin-code-field.module.mjs +16 -0
- package/esm2022/pin-code-field/public-api.mjs +3 -0
- package/esm2022/pin-code-field/seniorsistemas-angular-components-pin-code-field.mjs +5 -0
- package/fesm2022/seniorsistemas-angular-components-form-dynamic-lib-optional-fields-editor.mjs +44 -0
- package/fesm2022/seniorsistemas-angular-components-form-dynamic-lib-optional-fields-editor.mjs.map +1 -0
- package/fesm2022/seniorsistemas-angular-components-form-dynamic.mjs +94 -0
- package/fesm2022/seniorsistemas-angular-components-form-dynamic.mjs.map +1 -0
- package/fesm2022/seniorsistemas-angular-components-numeric-mask.mjs +9 -13
- package/fesm2022/seniorsistemas-angular-components-numeric-mask.mjs.map +1 -1
- package/fesm2022/seniorsistemas-angular-components-pin-code-field.mjs +480 -0
- package/fesm2022/seniorsistemas-angular-components-pin-code-field.mjs.map +1 -0
- package/form-dynamic/components/form-dynamic/form-dynamic.component.d.ts +15 -0
- package/form-dynamic/core/registry.d.ts +7 -0
- package/form-dynamic/fields-basic/boolean-field/boolean-field.component.d.ts +9 -0
- package/form-dynamic/fields-basic/string-field/string-field.component.d.ts +9 -0
- package/form-dynamic/index.d.ts +5 -0
- package/form-dynamic/lib/optional-fields/editor/editor-field/editor-field.component.d.ts +15 -0
- package/form-dynamic/lib/optional-fields/editor/editor-types.d.ts +13 -0
- package/form-dynamic/lib/optional-fields/editor/index.d.ts +5 -0
- package/form-dynamic/lib/optional-fields/editor/public-api.d.ts +2 -0
- package/form-dynamic/public-api.d.ts +4 -0
- package/form-dynamic/schemas/field-dynamic.d.ts +20 -0
- package/form-dynamic/schemas/form-dynamic-schema.d.ts +4 -0
- package/numeric-mask/README.md +182 -154
- package/numeric-mask/lib/numeric-mask/numeric-mask.directive.d.ts +2 -7
- package/package.json +32 -14
- package/pin-code-field/README.md +366 -0
- package/pin-code-field/index.d.ts +5 -0
- package/pin-code-field/lib/pin-code-field/pin-code-field.component.d.ts +284 -0
- package/pin-code-field/lib/pin-code-field.module.d.ts +7 -0
- package/pin-code-field/public-api.d.ts +2 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# Pin Code Field
|
|
2
|
+
|
|
3
|
+
O `PinCodeFieldComponent` é um componente customizado que encapsula múltiplos inputs para entrada de códigos de autenticação (tokens, OTP, etc.). O componente implementa `ControlValueAccessor`, tornando-o totalmente compatível com formulários reativos e template-driven do Angular.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Compatível com `ngModel` e `ReactiveForms` (`ControlValueAccessor`)
|
|
8
|
+
- Validação flexível delegada ao `FormControl` do usuário
|
|
9
|
+
- Configuração flexível de comprimento do código
|
|
10
|
+
- Suporte a caracteres alfanuméricos e especiais (opcional)
|
|
11
|
+
- Navegação entre campos com setas (esquerda/direita)
|
|
12
|
+
- Suporte a colar código (trunca se maior que o comprimento)
|
|
13
|
+
- Suporte a backspace com navegação automática
|
|
14
|
+
- Estados visuais: normal, foco, desabilitado e erro
|
|
15
|
+
- Controle de estado de erro via input `invalid`
|
|
16
|
+
- Help text descritivo
|
|
17
|
+
- Acessibilidade completa (ARIA labels, roles, etc.)
|
|
18
|
+
- Integração com `s-control-errors` para exibição de mensagens de erro
|
|
19
|
+
|
|
20
|
+
## Dependências
|
|
21
|
+
|
|
22
|
+
Nenhuma dependência adicional além do Angular.
|
|
23
|
+
|
|
24
|
+
## Utilização
|
|
25
|
+
|
|
26
|
+
**[Exemplo completo de implementação](../../../../src/app/components/pin-code-field-showcase)**
|
|
27
|
+
|
|
28
|
+
- **Componente**: `PinCodeFieldComponent`
|
|
29
|
+
- **Seletor do componente**: `s-pin-code-field`
|
|
30
|
+
|
|
31
|
+
### Import
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { PinCodeFieldComponent } from '@seniorsistemas/angular-components/pin-code-field';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Exemplos de utilização
|
|
38
|
+
|
|
39
|
+
### Exemplo básico com template-driven forms
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<form #myForm="ngForm">
|
|
43
|
+
<s-pin-code-field
|
|
44
|
+
name="code"
|
|
45
|
+
[(ngModel)]="code"
|
|
46
|
+
[length]="6"
|
|
47
|
+
helpText="Digite o código enviado para seu email"
|
|
48
|
+
>
|
|
49
|
+
</s-pin-code-field>
|
|
50
|
+
</form>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Exemplo com formulário reativo
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { Component } from '@angular/core';
|
|
57
|
+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
58
|
+
|
|
59
|
+
@Component({
|
|
60
|
+
selector: 'app-auth-form',
|
|
61
|
+
template: `
|
|
62
|
+
<form [formGroup]="form">
|
|
63
|
+
<s-pin-code-field
|
|
64
|
+
formControlName="code"
|
|
65
|
+
[length]="6"
|
|
66
|
+
[alphanumeric]="false"
|
|
67
|
+
[invalid]="(form.get('code')?.invalid && form.get('code')?.dirty) || false"
|
|
68
|
+
helpText="Digite o código de 6 dígitos"
|
|
69
|
+
>
|
|
70
|
+
</s-pin-code-field>
|
|
71
|
+
<s-control-errors
|
|
72
|
+
[control]="form.get('code')"
|
|
73
|
+
[errorMessages]="errorMessages"
|
|
74
|
+
[displayErrors]="submitted"
|
|
75
|
+
>
|
|
76
|
+
</s-control-errors>
|
|
77
|
+
</form>
|
|
78
|
+
`,
|
|
79
|
+
})
|
|
80
|
+
export class AuthFormComponent {
|
|
81
|
+
form: FormGroup;
|
|
82
|
+
submitted = false;
|
|
83
|
+
errorMessages = {
|
|
84
|
+
required: 'Este campo é obrigatório e não foi preenchido.',
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
constructor(private fb: FormBuilder) {
|
|
88
|
+
this.form = this.fb.group({
|
|
89
|
+
code: ['', [Validators.required()]],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Exemplo com listener de preenchimento
|
|
96
|
+
|
|
97
|
+
```html
|
|
98
|
+
<s-pin-code-field
|
|
99
|
+
[(ngModel)]="code"
|
|
100
|
+
[length]="6"
|
|
101
|
+
(codeFilled)="onCodeFilled($event)"
|
|
102
|
+
>
|
|
103
|
+
</s-pin-code-field>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
export class MyComponent {
|
|
108
|
+
code: string = '';
|
|
109
|
+
|
|
110
|
+
onCodeFilled(code: string) {
|
|
111
|
+
console.log('Código completado:', code);
|
|
112
|
+
// Realizar verificação do código
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Exemplo com caracteres alfanuméricos
|
|
118
|
+
|
|
119
|
+
```html
|
|
120
|
+
<s-pin-code-field
|
|
121
|
+
[(ngModel)]="code"
|
|
122
|
+
[length]="8"
|
|
123
|
+
[alphanumeric]="true"
|
|
124
|
+
helpText="Código pode conter letras, números e caracteres especiais"
|
|
125
|
+
>
|
|
126
|
+
</s-pin-code-field>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Inputs
|
|
130
|
+
|
|
131
|
+
| Nome | Tipo | Valor Padrão | Obrigatório | Descrição |
|
|
132
|
+
| -------------- | ---------------- | ------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
133
|
+
| `length` | `input<number>` | 6 | Não | Quantidade de caracteres que o código deve ter. |
|
|
134
|
+
| `alphanumeric` | `input<boolean>` | false | Não | Se true, aceita letras, números e caracteres especiais. Se false, aceita apenas números. |
|
|
135
|
+
| `helpText` | `input<string>` | '' | Não | Texto de ajuda exibido abaixo dos campos. |
|
|
136
|
+
| `invalid` | `input<boolean>` | false | Não | Controla se o componente exibe estado de erro (borda vermelha). Use em conjunto com `FormControl.invalid && FormControl.dirty` para validação. |
|
|
137
|
+
| `disabled` | `model<boolean>` | false | Não | Desabilita todos os campos impedindo entrada de dados. Two-way binding. |
|
|
138
|
+
|
|
139
|
+
## Outputs
|
|
140
|
+
|
|
141
|
+
| Nome | Tipo | Descrição |
|
|
142
|
+
| ------------ | ---------------------- | -------------------------------------------------------------------------------------------------- |
|
|
143
|
+
| `codeFilled` | `EventEmitter<string>` | Emitido quando todos os caracteres do código são preenchidos. Emite o código completo como string. |
|
|
144
|
+
|
|
145
|
+
## Validators
|
|
146
|
+
|
|
147
|
+
O componente exporta dois validators personalizados que trabalham como `ValidatorFn` do Angular:
|
|
148
|
+
|
|
149
|
+
### `incomplete(length?: number)`
|
|
150
|
+
|
|
151
|
+
Valida se o código foi totalmente preenchido. Retorna erro `incomplete` se houver preenchimento parcial.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const control = new FormControl('', [Validators.required(), incomplete(6)]);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Parâmetro:**
|
|
158
|
+
|
|
159
|
+
- `length` (opcional): Comprimento esperado do código (padrão: 6)
|
|
160
|
+
|
|
161
|
+
**Retorna:**
|
|
162
|
+
|
|
163
|
+
- `{ incomplete: true }` se o valor parcial for preenchido
|
|
164
|
+
- `null` se o código estiver completo ou vazio
|
|
165
|
+
|
|
166
|
+
### `pasteError(component?: PinCodeFieldComponent)`
|
|
167
|
+
|
|
168
|
+
Valida se houve erro ao colar conteúdo inválido. Retorna erro `pasteError` quando um paste inválido é detectado.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const control = new FormControl('', [pasteError()]);
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Nota:** Este validator monitora o estado interno do componente para detectar tentativas de paste com conteúdo inválido.
|
|
175
|
+
|
|
176
|
+
## Comportamentos
|
|
177
|
+
|
|
178
|
+
### Navegação
|
|
179
|
+
|
|
180
|
+
- **Seta Direita**: Move o foco para o próximo campo
|
|
181
|
+
- **Seta Esquerda**: Move o foco para o campo anterior
|
|
182
|
+
- **Seta Para Cima/Baixo**: Sem efeito
|
|
183
|
+
|
|
184
|
+
### Entrada de Dados
|
|
185
|
+
|
|
186
|
+
- A digitação automática avança para o próximo campo quando um caractere é inserido
|
|
187
|
+
- No último campo, a digitação não causa mudança de foco
|
|
188
|
+
- Todos os campos são preenchidos ao colar um código válido
|
|
189
|
+
|
|
190
|
+
### Backspace
|
|
191
|
+
|
|
192
|
+
- **Campo preenchido**: Limpa o campo atual e mantém o foco
|
|
193
|
+
- **Campo vazio**: Move para o campo anterior, limpa-o e mantém o foco no anterior
|
|
194
|
+
|
|
195
|
+
### Paste (Colar)
|
|
196
|
+
|
|
197
|
+
- Filtra caracteres inválidos de acordo com a configuração `alphanumeric`
|
|
198
|
+
- Se o texto colado é maior que o comprimento, trunca automaticamente
|
|
199
|
+
- Preenche os campos disponíveis com o texto colado filtrado
|
|
200
|
+
- Emite o evento `codeFilled` quando todos os campos são preenchidos
|
|
201
|
+
- A validação de valores aceitáveis é responsabilidade do `FormControl` validator
|
|
202
|
+
|
|
203
|
+
### Estados Visuais
|
|
204
|
+
|
|
205
|
+
- **Normal**: Borda cinza, fundo branco
|
|
206
|
+
- **Foco**: Borda azul com ring de foco
|
|
207
|
+
- **Desabilitado**: Fundo cinza claro, texto cinza, sem interação
|
|
208
|
+
- **Erro**: Borda e ring vermelhos (quando `invalid` input é true)
|
|
209
|
+
|
|
210
|
+
## Validação
|
|
211
|
+
|
|
212
|
+
O componente **não exporta validators pré-construídos**. A validação é responsabilidade do usuário via `FormControl.validator`.
|
|
213
|
+
|
|
214
|
+
Exemplos de validators customizados:
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
// Validar que o código tem exatamente 6 dígitos
|
|
218
|
+
const requiredValidator = Validators.required();
|
|
219
|
+
|
|
220
|
+
// Validador customizado para rejeitar valor específico
|
|
221
|
+
const notBlacklisted: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
|
|
222
|
+
const value = control.value as string;
|
|
223
|
+
if (value === '123456') {
|
|
224
|
+
return { blacklisted: true };
|
|
225
|
+
}
|
|
226
|
+
return null;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const form = this.fb.group({
|
|
230
|
+
code: ['', [requiredValidator, notBlacklisted]],
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Mostrando Erros de Validação
|
|
235
|
+
|
|
236
|
+
Use o input `invalid` para controlar visualmente o estado de erro:
|
|
237
|
+
|
|
238
|
+
```html
|
|
239
|
+
<s-pin-code-field
|
|
240
|
+
formControlName="code"
|
|
241
|
+
[invalid]="(form.get('code')?.invalid && form.get('code')?.dirty) || false"
|
|
242
|
+
>
|
|
243
|
+
</s-pin-code-field>
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Acessibilidade
|
|
247
|
+
|
|
248
|
+
O componente implementa padrões de acessibilidade completos:
|
|
249
|
+
|
|
250
|
+
- Cada input tem um `aria-label` descritivo com sua posição no código
|
|
251
|
+
- O container tem `role="group"` e associação com help text
|
|
252
|
+
- `aria-invalid` é definido quando há erro
|
|
253
|
+
- `aria-describedby` conecta inputs ao help text
|
|
254
|
+
- `inputmode` é configurado corretamente (numeric/text)
|
|
255
|
+
- `autocomplete="off"` previne preenchimento automático indesejado
|
|
256
|
+
- Todos os estados visuais incluem indicadores para leitores de tela
|
|
257
|
+
|
|
258
|
+
## Exemplos Completos
|
|
259
|
+
|
|
260
|
+
### Integração com Reactive Forms e validação customizada
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { Component, OnInit } from '@angular/core';
|
|
264
|
+
import { FormBuilder, FormGroup, Validators, AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';
|
|
265
|
+
|
|
266
|
+
// Validador customizado que rejeita um valor específico
|
|
267
|
+
const notBlacklisted: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
|
|
268
|
+
const value = control.value as string;
|
|
269
|
+
if (value === '123456') {
|
|
270
|
+
return { blacklisted: true };
|
|
271
|
+
}
|
|
272
|
+
return null;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
@Component({
|
|
276
|
+
selector: 'app-verify-code',
|
|
277
|
+
template: `
|
|
278
|
+
<form [formGroup]="verifyForm">
|
|
279
|
+
<s-pin-code-field
|
|
280
|
+
formControlName="verificationCode"
|
|
281
|
+
[length]="6"
|
|
282
|
+
[alphanumeric]="false"
|
|
283
|
+
[invalid]="(control?.invalid && control?.dirty) || false"
|
|
284
|
+
helpText="Digite o código de 6 dígitos enviado"
|
|
285
|
+
(codeFilled)="verifyCode($event)"
|
|
286
|
+
>
|
|
287
|
+
</s-pin-code-field>
|
|
288
|
+
|
|
289
|
+
<s-control-errors
|
|
290
|
+
[control]="control"
|
|
291
|
+
[errorMessages]="errorMessages"
|
|
292
|
+
[displayErrors]="submitted"
|
|
293
|
+
>
|
|
294
|
+
</s-control-errors>
|
|
295
|
+
|
|
296
|
+
<button
|
|
297
|
+
[disabled]="!verifyForm.valid"
|
|
298
|
+
(click)="submit()"
|
|
299
|
+
>
|
|
300
|
+
Verificar
|
|
301
|
+
</button>
|
|
302
|
+
</form>
|
|
303
|
+
`,
|
|
304
|
+
})
|
|
305
|
+
export class VerifyCodeComponent implements OnInit {
|
|
306
|
+
verifyForm!: FormGroup;
|
|
307
|
+
submitted = false;
|
|
308
|
+
errorMessages = {
|
|
309
|
+
required: 'Código obrigatório',
|
|
310
|
+
blacklisted: 'Este código não é válido',
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
get control() {
|
|
314
|
+
return this.verifyForm.get('verificationCode');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
constructor(private fb: FormBuilder) {}
|
|
318
|
+
|
|
319
|
+
ngOnInit() {
|
|
320
|
+
this.verifyForm = this.fb.group({
|
|
321
|
+
verificationCode: ['', [Validators.required, notBlacklisted]],
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
verifyCode(code: string) {
|
|
326
|
+
console.log('Código completo:', code);
|
|
327
|
+
// Enviar para API de verificação
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
submit() {
|
|
331
|
+
this.submitted = true;
|
|
332
|
+
if (this.verifyForm.valid) {
|
|
333
|
+
this.verifyCode(this.verifyForm.value.verificationCode);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Com loading e desabilitação após envio
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
export class VerifyCodeComponent {
|
|
343
|
+
verifyForm!: FormGroup;
|
|
344
|
+
isLoading = false;
|
|
345
|
+
|
|
346
|
+
verifyCode(code: string) {
|
|
347
|
+
this.isLoading = true;
|
|
348
|
+
// Desabilita o campo durante a requisição
|
|
349
|
+
this.verifyForm.get('verificationCode')?.disable();
|
|
350
|
+
|
|
351
|
+
this.authService.verify(code).subscribe(
|
|
352
|
+
(response) => {
|
|
353
|
+
// Sucesso
|
|
354
|
+
this.isLoading = false;
|
|
355
|
+
},
|
|
356
|
+
(error) => {
|
|
357
|
+
// Erro - reabilita o formulário
|
|
358
|
+
this.isLoading = false;
|
|
359
|
+
this.verifyForm.get('verificationCode')?.enable();
|
|
360
|
+
this.verifyForm.get('verificationCode')?.reset();
|
|
361
|
+
},
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { ElementRef } from '@angular/core';
|
|
2
|
+
import { ControlValueAccessor } from '@angular/forms';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Pin Code Field Component
|
|
6
|
+
*
|
|
7
|
+
* A flexible, accessible PIN code input component that implements {@link ControlValueAccessor}
|
|
8
|
+
* for seamless integration with Angular Reactive Forms and Template-driven Forms.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Multiple input fields for PIN/OTP code entry
|
|
12
|
+
* - Configurable code length and character validation
|
|
13
|
+
* - Keyboard navigation (arrow keys, backspace)
|
|
14
|
+
* - Paste support with automatic truncation
|
|
15
|
+
* - Error state display via the `invalid` input
|
|
16
|
+
* - Full accessibility support (ARIA labels, semantic roles)
|
|
17
|
+
* - Signal-based state management
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```html
|
|
21
|
+
* <form [formGroup]="form">
|
|
22
|
+
* <s-pin-code-field
|
|
23
|
+
* formControlName="code"
|
|
24
|
+
* [length]="6"
|
|
25
|
+
* [alphanumeric]="false"
|
|
26
|
+
* [invalid]="(form.get('code')?.invalid && form.get('code')?.dirty) || false"
|
|
27
|
+
* helpText="Enter your 6-digit code"
|
|
28
|
+
* (codeFilled)="onCodeFilled($event)">
|
|
29
|
+
* </s-pin-code-field>
|
|
30
|
+
* </form>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* form = this.fb.group({
|
|
36
|
+
* code: ['', [Validators.required]],
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class PinCodeFieldComponent implements ControlValueAccessor {
|
|
41
|
+
private static readonly LAST_INDEX_OFFSET;
|
|
42
|
+
private static readonly EMPTY_VALUE;
|
|
43
|
+
/**
|
|
44
|
+
* Number of input fields (PIN code length).
|
|
45
|
+
* Must be at least 1.
|
|
46
|
+
*
|
|
47
|
+
* @default 6
|
|
48
|
+
*/
|
|
49
|
+
length: import("@angular/core").InputSignal<number>;
|
|
50
|
+
/**
|
|
51
|
+
* Allows alphanumeric and special characters input.
|
|
52
|
+
* When false, only numeric input (0-9) is accepted.
|
|
53
|
+
*
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
alphanumeric: import("@angular/core").InputSignal<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Help text displayed below the input fields.
|
|
59
|
+
*
|
|
60
|
+
* @default ''
|
|
61
|
+
*/
|
|
62
|
+
helpText: import("@angular/core").InputSignal<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Controls the error state visualization of the component.
|
|
65
|
+
* When true, displays red border on input fields.
|
|
66
|
+
* Typically bound to FormControl's invalid and dirty state.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```html
|
|
70
|
+
* [invalid]="(control?.invalid && control?.dirty) || false"
|
|
71
|
+
* ```
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
invalid: import("@angular/core").InputSignal<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Two-way binding for the disabled state of the component.
|
|
77
|
+
* Disables all input fields and prevents user interaction.
|
|
78
|
+
*
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
disabled: import("@angular/core").ModelSignal<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Emitted when all PIN code fields are filled.
|
|
84
|
+
* Emits the complete PIN code as a string.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```html
|
|
88
|
+
* (codeFilled)="onCodeFilled($event)"
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
codeFilled: import("@angular/core").OutputEmitterRef<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Signal containing the current values of each input field.
|
|
94
|
+
* Array length matches the `length` input value.
|
|
95
|
+
*/
|
|
96
|
+
inputs: import("@angular/core").WritableSignal<string[]>;
|
|
97
|
+
/**
|
|
98
|
+
* Signal tracking whether the component has been touched by the user.
|
|
99
|
+
* Set to true when the last input field loses focus (blur event).
|
|
100
|
+
*/
|
|
101
|
+
touched: import("@angular/core").WritableSignal<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Computed signal indicating whether all PIN code fields are filled.
|
|
104
|
+
* True only when every field contains a non-empty value.
|
|
105
|
+
*/
|
|
106
|
+
isComplete: import("@angular/core").Signal<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* Computed signal containing the complete PIN code as a joined string.
|
|
109
|
+
* Returns empty string if no inputs are filled.
|
|
110
|
+
*/
|
|
111
|
+
currentValue: import("@angular/core").Signal<string>;
|
|
112
|
+
/**
|
|
113
|
+
* Signal tracking if the component host has the ng-invalid class from FormControl validators.
|
|
114
|
+
* Updated reactively whenever the invalid state changes.
|
|
115
|
+
*/
|
|
116
|
+
private hasNgInvalidClass;
|
|
117
|
+
/**
|
|
118
|
+
* Signal tracking if the FormControl is dirty.
|
|
119
|
+
* Updated reactively whenever the dirty state changes.
|
|
120
|
+
*/
|
|
121
|
+
private isControlDirty;
|
|
122
|
+
/**
|
|
123
|
+
* Computed signal indicating if the component should show error state.
|
|
124
|
+
* Returns true if:
|
|
125
|
+
* - The `invalid` input is true, OR
|
|
126
|
+
* - The component has the `ng-invalid` class AND the FormControl is dirty (touched/modified)
|
|
127
|
+
* This ensures errors are only shown to the user after they've interacted with the field.
|
|
128
|
+
*/
|
|
129
|
+
hasError: import("@angular/core").Signal<boolean>;
|
|
130
|
+
/**
|
|
131
|
+
* ViewChildren reference to all input DOM elements.
|
|
132
|
+
* Used for DOM manipulation (focus, selection).
|
|
133
|
+
*/
|
|
134
|
+
pinInputs: import("@angular/core").Signal<readonly ElementRef<any>[]>;
|
|
135
|
+
private readonly elementRef;
|
|
136
|
+
private readonly destroyRef;
|
|
137
|
+
private onChange;
|
|
138
|
+
private onTouched;
|
|
139
|
+
constructor();
|
|
140
|
+
/**
|
|
141
|
+
* Handles input event on PIN code fields.
|
|
142
|
+
* Validates character input, prevents multiple characters per field,
|
|
143
|
+
* auto-advances to next field when character is entered.
|
|
144
|
+
*
|
|
145
|
+
* @param index - The input field index (0-based)
|
|
146
|
+
* @param event - The input event
|
|
147
|
+
*/
|
|
148
|
+
onInput(index: number, event: Event): void;
|
|
149
|
+
/**
|
|
150
|
+
* Handles keyboard events on PIN code fields.
|
|
151
|
+
* Supports arrow navigation (left/right) and backspace key.
|
|
152
|
+
*
|
|
153
|
+
* Keyboard behavior:
|
|
154
|
+
* - ArrowRight: Move focus to next field
|
|
155
|
+
* - ArrowLeft: Move focus to previous field
|
|
156
|
+
* - Backspace: Clear current or previous field and adjust focus
|
|
157
|
+
*
|
|
158
|
+
* @param index - The input field index (0-based)
|
|
159
|
+
* @param event - The keyboard event
|
|
160
|
+
*/
|
|
161
|
+
onKeyDown(index: number, event: KeyboardEvent): void;
|
|
162
|
+
/**
|
|
163
|
+
* Handles paste (clipboard) events on PIN code fields.
|
|
164
|
+
* Extracts valid characters from pasted content, filters by character type,
|
|
165
|
+
* and automatically truncates to match field length.
|
|
166
|
+
*
|
|
167
|
+
* Behavior:
|
|
168
|
+
* - Filters characters based on `alphanumeric` setting
|
|
169
|
+
* - Truncates to maximum field count
|
|
170
|
+
* - Fills available fields with pasted content
|
|
171
|
+
* - Emits codeFilled event if all fields are filled
|
|
172
|
+
*
|
|
173
|
+
* @param event - The clipboard event
|
|
174
|
+
*/
|
|
175
|
+
onPaste(event: ClipboardEvent): void;
|
|
176
|
+
/**
|
|
177
|
+
* Handles focus event on PIN code fields.
|
|
178
|
+
* Selects all text in the input field when focused.
|
|
179
|
+
*
|
|
180
|
+
* @param index - The input field index (0-based)
|
|
181
|
+
*/
|
|
182
|
+
onFocus(index: number): void;
|
|
183
|
+
/**
|
|
184
|
+
* Handles blur event on PIN code fields.
|
|
185
|
+
* Marks the component as touched when the last input field loses focus.
|
|
186
|
+
* Also notifies the registered onTouched callback for FormControl integration.
|
|
187
|
+
*
|
|
188
|
+
* @param index - The input field index (0-based)
|
|
189
|
+
*/
|
|
190
|
+
onBlur(index: number): void;
|
|
191
|
+
/**
|
|
192
|
+
* Clears the input value at specified index and adjusts focus accordingly.
|
|
193
|
+
* If current field is empty, moves to previous field and clears it.
|
|
194
|
+
*
|
|
195
|
+
* @private
|
|
196
|
+
* @param index - The input field index (0-based)
|
|
197
|
+
*/
|
|
198
|
+
private handleBackspace;
|
|
199
|
+
/**
|
|
200
|
+
* Sets the value at a specific input field index and updates the form value.
|
|
201
|
+
* Updates the signal and triggers the change detection via onChange callback.
|
|
202
|
+
*
|
|
203
|
+
* @private
|
|
204
|
+
* @param index - The input field index (0-based)
|
|
205
|
+
* @param value - The value to set in the field
|
|
206
|
+
*/
|
|
207
|
+
private setInputAtIndex;
|
|
208
|
+
/**
|
|
209
|
+
* Focuses on and selects text in the input field at the specified index.
|
|
210
|
+
* Uses queueMicrotask to ensure DOM is updated before focusing.
|
|
211
|
+
*
|
|
212
|
+
* @private
|
|
213
|
+
* @param index - The input field index (0-based)
|
|
214
|
+
*/
|
|
215
|
+
private focusAndSelectInput;
|
|
216
|
+
/**
|
|
217
|
+
* Clears the value of an input element.
|
|
218
|
+
* Used for input validation to reject invalid characters.
|
|
219
|
+
*
|
|
220
|
+
* @private
|
|
221
|
+
* @param target - The HTML input element to clear
|
|
222
|
+
*/
|
|
223
|
+
private clearInput;
|
|
224
|
+
/**
|
|
225
|
+
* Extracts valid characters from pasted content.
|
|
226
|
+
* Filters based on alphanumeric setting and limits to component's length.
|
|
227
|
+
*
|
|
228
|
+
* @private
|
|
229
|
+
* @param event - The clipboard event
|
|
230
|
+
* @returns Array of valid characters from the pasted content
|
|
231
|
+
*/
|
|
232
|
+
private extractValidCharactersFromPaste;
|
|
233
|
+
/**
|
|
234
|
+
* Validates if a character is acceptable based on component configuration.
|
|
235
|
+
* For numeric mode, accepts only digits 0-9.
|
|
236
|
+
* For alphanumeric mode, accepts any non-whitespace character.
|
|
237
|
+
*
|
|
238
|
+
* @private
|
|
239
|
+
* @param char - The character to validate
|
|
240
|
+
* @returns true if character is valid, false otherwise
|
|
241
|
+
*/
|
|
242
|
+
private isValidCharacter;
|
|
243
|
+
/**
|
|
244
|
+
* Updates the form value by calling the onChange callback registered by FormControl.
|
|
245
|
+
* This ensures the reactive form stays synchronized with component state.
|
|
246
|
+
*
|
|
247
|
+
* @private
|
|
248
|
+
*/
|
|
249
|
+
private updateValue;
|
|
250
|
+
/**
|
|
251
|
+
* Implements ControlValueAccessor interface.
|
|
252
|
+
* Called by the FormControl to write a value to the component.
|
|
253
|
+
* Only accepts string values with length matching the component's length setting.
|
|
254
|
+
*
|
|
255
|
+
* @param value - The value to write (typically from the FormControl)
|
|
256
|
+
*/
|
|
257
|
+
writeValue(value: any): void;
|
|
258
|
+
/**
|
|
259
|
+
* Implements ControlValueAccessor interface.
|
|
260
|
+
* Called by the FormControl when value changes.
|
|
261
|
+
* Registers the callback to be called when the component value changes.
|
|
262
|
+
*
|
|
263
|
+
* @param fn - Callback function to invoke when component value changes
|
|
264
|
+
*/
|
|
265
|
+
registerOnChange(fn: (value: string) => void): void;
|
|
266
|
+
/**
|
|
267
|
+
* Implements ControlValueAccessor interface.
|
|
268
|
+
* Called by the FormControl to register the touched callback.
|
|
269
|
+
* The callback is invoked when the last input field loses focus.
|
|
270
|
+
*
|
|
271
|
+
* @param fn - Callback function to invoke when component is touched
|
|
272
|
+
*/
|
|
273
|
+
registerOnTouched(fn: () => void): void;
|
|
274
|
+
/**
|
|
275
|
+
* Implements ControlValueAccessor interface.
|
|
276
|
+
* Called by the FormControl to set the disabled state of the component.
|
|
277
|
+
* Updates the disabled model to reflect the form's disabled state.
|
|
278
|
+
*
|
|
279
|
+
* @param isDisabled - Whether the component should be disabled
|
|
280
|
+
*/
|
|
281
|
+
setDisabledState(isDisabled: boolean): void;
|
|
282
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<PinCodeFieldComponent, never>;
|
|
283
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<PinCodeFieldComponent, "s-pin-code-field", never, { "length": { "alias": "length"; "required": false; "isSignal": true; }; "alphanumeric": { "alias": "alphanumeric"; "required": false; "isSignal": true; }; "helpText": { "alias": "helpText"; "required": false; "isSignal": true; }; "invalid": { "alias": "invalid"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; }, { "disabled": "disabledChange"; "codeFilled": "codeFilled"; }, never, never, true, never>;
|
|
284
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import * as i1 from "./pin-code-field/pin-code-field.component";
|
|
3
|
+
export declare class PinCodeFieldModule {
|
|
4
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<PinCodeFieldModule, never>;
|
|
5
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<PinCodeFieldModule, never, [typeof i1.PinCodeFieldComponent], [typeof i1.PinCodeFieldComponent]>;
|
|
6
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<PinCodeFieldModule>;
|
|
7
|
+
}
|