Compare commits

..

2 Commits

5 changed files with 80 additions and 4 deletions

View File

@@ -74,7 +74,16 @@
</app-input> </app-input>
<app-input <app-input
type="password" type="user"
placeholder="Nombre de usuario"
[value]="user"
(valueChange)="user = $event"
>
Usuario
</app-input>
<app-input
type="password-toggle"
placeholder="********" placeholder="********"
[value]="password" [value]="password"
(valueChange)="password = $event" (valueChange)="password = $event"

View File

@@ -12,6 +12,7 @@ export class ReutilizablesTestPageComponent {
protected textValue = 'Auriculares'; protected textValue = 'Auriculares';
protected numberValue = '24'; protected numberValue = '24';
protected email = 'usuario@empresa.com'; protected email = 'usuario@empresa.com';
protected user = 'Juan Perez';
protected password = '12345678'; protected password = '12345678';
protected date = '2026-06-24'; protected date = '2026-06-24';
protected amount = '125000'; protected amount = '125000';

View File

@@ -9,6 +9,7 @@
'input-control-percent': type() === 'percent', 'input-control-percent': type() === 'percent',
'input-control-file': type() === 'file', 'input-control-file': type() === 'file',
'input-control-editable': type() === 'editable', 'input-control-editable': type() === 'editable',
'input-control-password-toggle': type() === 'password-toggle',
'input-control-disabled': isInputDisabled(), 'input-control-disabled': isInputDisabled(),
'input-control-editable-active': isEditableActive() 'input-control-editable-active': isEditableActive()
}" }"
@@ -38,6 +39,28 @@
</span> </span>
} }
@if (type() === 'user') {
<span class="input-user-icon" aria-hidden="true">
<i class="fa-solid fa-user"></i>
</span>
}
@if (type() === 'password-toggle') {
<button
type="button"
class="input-icon"
[disabled]="disabled()"
[attr.aria-label]="isPasswordVisible() ? 'Ocultar contrasena' : 'Mostrar contrasena'"
(click)="togglePasswordVisibility()"
>
<i
class="fa-solid"
[ngClass]="isPasswordVisible() ? 'fa-eye' : 'fa-eye-slash'"
aria-hidden="true"
></i>
</button>
}
@if (type() === 'file') { @if (type() === 'file') {
<span class="input-file-name" [class.input-file-name-empty]="!resolvedFileName()"> <span class="input-file-name" [class.input-file-name-empty]="!resolvedFileName()">
{{ resolvedFileName() || 'Sin archivo...' }} {{ resolvedFileName() || 'Sin archivo...' }}

View File

@@ -14,7 +14,8 @@
position: relative; position: relative;
} }
.input-search-icon { .input-search-icon,
.input-user-icon {
position: absolute; position: absolute;
right: 1rem; right: 1rem;
top: 50%; top: 50%;
@@ -43,6 +44,10 @@
padding-right: 2.5rem; padding-right: 2.5rem;
} }
.input-with-action-icon {
padding-right: 2.5rem;
}
input[type='file'].form-control { input[type='file'].form-control {
padding-right: 1rem; padding-right: 1rem;
color: transparent; color: transparent;
@@ -100,7 +105,8 @@ input[type='file'].form-control {
} }
} }
.input-control-editable { .input-control-editable,
.input-control-password-toggle {
.input-icon { .input-icon {
position: absolute; position: absolute;
right: 0.875rem; right: 0.875rem;

View File

@@ -14,10 +14,12 @@ import { NgClass } from '@angular/common';
export type AppInputType = export type AppInputType =
| 'search' | 'search'
| 'user'
| 'text' | 'text'
| 'number' | 'number'
| 'email' | 'email'
| 'password' | 'password'
| 'password-toggle'
| 'currency' | 'currency'
| 'percent' | 'percent'
| 'date' | 'date'
@@ -28,10 +30,12 @@ export type AppInputType =
const DEFAULT_TYPE: AppInputType = 'text'; const DEFAULT_TYPE: AppInputType = 'text';
const INPUT_TYPES = new Set<AppInputType>([ const INPUT_TYPES = new Set<AppInputType>([
'search', 'search',
'user',
'text', 'text',
'number', 'number',
'email', 'email',
'password', 'password',
'password-toggle',
'currency', 'currency',
'percent', 'percent',
'date', 'date',
@@ -60,6 +64,7 @@ export class InputComponent {
private readonly inputElement = viewChild<ElementRef<HTMLInputElement>>('inputElement'); private readonly inputElement = viewChild<ElementRef<HTMLInputElement>>('inputElement');
private readonly selectedFileName = signal(''); private readonly selectedFileName = signal('');
private readonly editableDisabled = signal(false); private readonly editableDisabled = signal(false);
private readonly passwordVisible = signal(false);
private lastClearTrigger = 0; private lastClearTrigger = 0;
readonly invalid = input(false); readonly invalid = input(false);
@@ -70,6 +75,7 @@ export class InputComponent {
readonly fileName = input(''); readonly fileName = input('');
readonly clearTrigger = input(0); readonly clearTrigger = input(0);
readonly disabled = input(false); readonly disabled = input(false);
readonly visible = input<boolean | null>(null);
readonly type = input<AppInputType, AppInputType | string>(DEFAULT_TYPE, { readonly type = input<AppInputType, AppInputType | string>(DEFAULT_TYPE, {
transform: normalizeType transform: normalizeType
}); });
@@ -77,13 +83,24 @@ export class InputComponent {
readonly disabledChange = output<boolean>(); readonly disabledChange = output<boolean>();
readonly valueChange = output<string>(); readonly valueChange = output<string>();
readonly fileChange = output<File | null>(); readonly fileChange = output<File | null>();
readonly visibleChange = output<boolean>();
protected readonly id = `app-input-${globalThis.crypto.randomUUID()}`; protected readonly id = `app-input-${globalThis.crypto.randomUUID()}`;
protected readonly inputType = computed(() => { protected readonly inputType = computed(() => {
const type = this.type(); const type = this.type();
if (type === 'search' || type === 'currency' || type === 'percent' || type === 'editable') { if (type === 'password-toggle') {
return this.isPasswordVisible() ? 'text' : 'password';
}
if (
type === 'search' ||
type === 'user' ||
type === 'currency' ||
type === 'percent' ||
type === 'editable'
) {
return 'text'; return 'text';
} }
@@ -98,6 +115,7 @@ export class InputComponent {
'form-control': true, 'form-control': true,
'is-invalid': this.invalid(), 'is-invalid': this.invalid(),
'input-with-search-icon': this.type() === 'search', 'input-with-search-icon': this.type() === 'search',
'input-with-action-icon': this.type() === 'user' || this.type() === 'password-toggle',
'input-with-prefix': this.type() === 'currency', 'input-with-prefix': this.type() === 'currency',
'input-with-suffix': this.type() === 'percent', 'input-with-suffix': this.type() === 'percent',
'input-with-icon': this.type() === 'editable' 'input-with-icon': this.type() === 'editable'
@@ -111,6 +129,11 @@ export class InputComponent {
() => this.type() === 'editable' && !this.editableDisabled() () => this.type() === 'editable' && !this.editableDisabled()
); );
protected readonly isPasswordVisible = computed(() => {
const visible = this.visible();
return visible === null ? this.passwordVisible() : visible;
});
protected readonly resolvedFileName = computed( protected readonly resolvedFileName = computed(
() => this.selectedFileName() || this.fileName() || '' () => this.selectedFileName() || this.fileName() || ''
); );
@@ -163,6 +186,20 @@ export class InputComponent {
this.disabledChange.emit(nextState); this.disabledChange.emit(nextState);
} }
protected togglePasswordVisibility(): void {
if (this.type() !== 'password-toggle' || this.disabled()) {
return;
}
const nextState = !this.isPasswordVisible();
if (this.visible() === null) {
this.passwordVisible.set(nextState);
}
this.visibleChange.emit(nextState);
}
private clearFileInput(): void { private clearFileInput(): void {
this.inputElement()?.nativeElement && (this.inputElement()!.nativeElement.value = ''); this.inputElement()?.nativeElement && (this.inputElement()!.nativeElement.value = '');
this.selectedFileName.set(''); this.selectedFileName.set('');