Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<prizm-input-layout label="Заголовок">
<prizm-input-layout-date [formControl]="control"></prizm-input-layout-date>
<prizm-input-layout-date [formControl]="control" [min]="min" [max]="max"></prizm-input-layout-date>
</prizm-input-layout>

<pre>
min: {{ min.toLocalNativeDate() | date : 'shortDate' }}
max: {{ max.toLocalNativeDate() | date : 'shortDate' }}
value: {{ control.value }}
</pre>
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ import { PrizmDay } from '@prizm-ui/components';
})
export class PrizmInputLayoutDateBaseExampleComponent {
public readonly control = new UntypedFormControl(new PrizmDay(2017, 0, 15));
readonly min = new PrizmDay(2000, 2, 20);

readonly max = new PrizmDay(2040, 2, 20);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectorRef, Directive, ElementRef, inject, Injector, OnInit } from '@angular/core';
import { ChangeDetectorRef, Directive, ElementRef, inject, Injector, OnInit, Renderer2 } from '@angular/core';
import { AbstractControl, ControlValueAccessor, NgControl, NgModel, Validators } from '@angular/forms';
import { PrizmInputControl } from './input-control.class';
import { PrizmDestroyService } from '@prizm-ui/helpers';
Expand All @@ -18,7 +18,7 @@ export abstract class PrizmInputNgControl<T>
ngControl!: NgControl;
readonly changeDetectorRef!: ChangeDetectorRef;
readonly layoutComponent?: PrizmInputLayoutComponent | null;
private previousInternalValue$$ = new BehaviorSubject<T | null>(null);
protected previousInternalValue$$ = new BehaviorSubject<T | null>(null);
onChange: (val: T) => void = PRIZM_EMPTY_FUNCTION;
onTouch: () => void = PRIZM_EMPTY_FUNCTION;
protected readonly focusableElement?: ElementRef<HTMLInputElement> | any;
Expand Down Expand Up @@ -74,6 +74,7 @@ export abstract class PrizmInputNgControl<T>
return !!this.ngControl?.touched;
}

public readonly renderer2 = inject(Renderer2);
protected constructor(
protected readonly injector: Injector,
readonly valueTransformer?: PrizmControlValueTransformer<T> | null
Expand Down Expand Up @@ -118,7 +119,7 @@ export abstract class PrizmInputNgControl<T>
}

protected updateValue(value: T): void {
if (this.disabled || this.valueIdenticalComparator(this.value, value)) {
if (this.disabled /*|| this.valueIdenticalComparator(this.value, value)*/) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужен ли этот код?

return;
}
this.onChange(value);
Expand All @@ -131,6 +132,10 @@ export abstract class PrizmInputNgControl<T>
}

public setDisabledState(isDisabled: boolean) {
if (this.focusableElement?.nativeElement) {
this.renderer2.setProperty(this.focusableElement.nativeElement, 'disabled', isDisabled);
}

this.checkControlUpdate();
this.stateChanges.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<input
class="input-search"
#focusableElementRef
#mask="mask"
[mask]="computedMask"
[showMaskTyped]="focusableElementRef.focused"
[dropSpecialCharacters]="false"
[placeholder]="placeholder"
[disabled]="!!disabled"
[ngModelOptions]="{ standalone: true }"
[ngModel]="stringValue"
(ngModelChange)="onValueChange($event || '')"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
afterRender,
ChangeDetectionStrategy,
Component,
ElementRef,
Expand All @@ -9,6 +10,7 @@ import {
Injector,
Input,
Optional,
Renderer2,
ViewChild,
} from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
Expand Down Expand Up @@ -59,6 +61,7 @@ import { PrizmLinkComponent } from '../../link';
import { PrizmDropdownHostComponent } from '../../dropdowns/dropdown-host';
import { PrizmIconsFullRegistry } from '@prizm-ui/icons/core';
import { prizmIconsCalendarBlank } from '@prizm-ui/icons/full/source';
import { NgxMaskDirective } from 'ngx-mask';

@Component({
selector: `prizm-input-layout-date`,
Expand Down Expand Up @@ -98,6 +101,9 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl<PrizmDay
@ViewChild('focusableElementRef', { read: ElementRef })
public override readonly focusableElement?: ElementRef<HTMLInputElement>;

@ViewChild('mask', { read: NgxMaskDirective })
public textMask?: NgxMaskDirective;

private month: PrizmMonth | null = null;

public mask = prizmCreateDateNgxMask(this.dateFormat, this.dateSeparator);
Expand Down Expand Up @@ -146,6 +152,7 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl<PrizmDay
public rightButtons$!: BehaviorSubject<PrizmDateButton[]>;

private readonly iconsFullRegistry = inject(PrizmIconsFullRegistry);
private readonly render2 = inject(Renderer2);

constructor(
@Inject(Injector) injector: Injector,
Expand All @@ -164,6 +171,18 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl<PrizmDay
this.extraButtonInjector = injector;

this.iconsFullRegistry.registerIcons(prizmIconsCalendarBlank);

// TODO after v5 released devide and move to abstract layer for all component
afterRender(() => {
if (this.focusableElement?.nativeElement && !this.focused) {
this.render2.setProperty(
this.focusableElement.nativeElement,
'value',
this.previousInternalValue$$.value ?? ''
);
this.textMask?.writeValue(this.previousInternalValue$$.value?.toString() ?? '');
}
});
}

public override ngOnInit(): void {
Expand Down Expand Up @@ -198,7 +217,7 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl<PrizmDay
return;
}

this.updateValue(
this.updateWithCorrectDate(
value.length !== PRIZM_DATE_FILLER_LENGTH ? null : PrizmDay.normalizeParse(value, this.dateFormat)
);
}
Expand All @@ -220,6 +239,9 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl<PrizmDay

public override writeValue(value: PrizmDay | null): void {
super.writeValue(value);
if (this.focusableElement) {
this.render2.setProperty(this.focusableElement.nativeElement, 'value', value ?? '');
}
}

public get nativeFocusableElement(): HTMLInputElement | null {
Expand All @@ -238,4 +260,15 @@ export class PrizmInputLayoutDateComponent extends PrizmInputNgControl<PrizmDay
this.markAsTouched();
this.changeDetectorRef.markForCheck();
}

private updateWithCorrectDate(date: PrizmDay | null): void {
if (!date) return;
// correct min max date
if (date) date = date.dayLimit(this.min, this.max);
if (this.focusableElement) {
// this.focusableElement.nativeElement.value = date?.toString();
}

this.updateValue(date);
}
}