import * as i0 from '@angular/core'; import { ControlValueAccessor, NgControl, ValidatorFn } from '@angular/forms'; import { Controller, DisabledController, ReadonlyController } from '@odx/angular'; import * as rxjs from 'rxjs'; declare class ControlDirective { readonly element: i0.ElementRef; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * An abstract directive that serves as a base for custom form controls, integrating seamlessly with Angular Forms. * It incorporates common form control behaviors such as handling disabled and readonly states, validation, and more. * * This approach allows the creation of highly reusable and consistent form controls within Angular applications, * simplifying the integration with Angular Forms and the handling of common form behaviors. * * Extends Controller to provide a consistent API for managing state changes and subscriptions. * * @see {Controller} */ declare abstract class CustomFormControl extends Controller implements ControlValueAccessor { private static CURRENT_INDEX; private readonly requiredValidator; private internalValue; protected readonly disabledController: DisabledController | null; protected readonly readonlyController: ReadonlyController | null; protected readonly ngControl: NgControl | null; /** * A unique identifier for the custom form control. If not provided, a unique ID is generated automatically. * This can be useful for associating form control with a label. * * @type {string} */ id: string | null; /** * The name attribute for the custom form control. Defaults to a unique name if not provided. * This is useful when the form control is part of a form and needs to be identified. * * @type {string} */ name: string; /** * The tabindex attribute for the custom form control. Can be used to control the order of focus navigation. * * @type {string | null} */ tabindex: string | null; /** * An array of error codes to ignore. If an error code is included in this array, the form control will not * consider it as an error state. Useful for ignoring specific validation errors. * * @type {string[]} */ ignoreErrors: string[]; required: boolean; /** * The current value of the form control. Setting this value updates the internal state and marks the control * for checking changes. Getting this value returns the current internal value of the control. * * @example * ```ts * this.customInputControl.value = 'newValue'; // Sets the value * const currentValue = this.customInputControl.value; // Gets the current value * ``` */ set value(value: T); /** * Gets the value of the custom form control. * * @returns {T} - The value of the custom form control. */ get value(): T; /** * Indicates whether the form control currently has an error. This takes into account any ignored errors. * * @returns {boolean} - True if the form control has an error, false otherwise. * * @example * ```ts * if (this.customInputControl.hasError) { ... } * ``` */ get hasError(): boolean; /** * Indicates whether the form control is currently disabled. * * @returns {boolean} - True if the form control is disabled, false otherwise. * * @example * ```ts * if (this.customInputControl.isDisabled) { ... } * ``` */ get isDisabled(): boolean; /** * Indicates whether the form control is currently in a readonly state. * * @returns {boolean} - True if the form control is readonly, false otherwise. * * @example * ```ts * if (this.customInputControl.isReadonly) { ... } * ``` */ get isReadonly(): boolean; /** * Indicates whether the form control is marked as required, either through Validators.required, Validators.requiredTrue, * or by a required attribute on a parent form field. * * @returns {boolean} - True if the form control is required, false otherwise. * * @example * ````ts * if (this.customInputControl.isRequired) { ... } * ```` */ get isRequired(): boolean; /** * A reference to the `ControlDirective` if it exists within the same host. This allows for direct interaction * with the underlying form control directive. * * @type {ControlDirective | null} * * @example * ```ts * this.customInputControl.control?.focus(); * ``` */ readonly control: ControlDirective | null; constructor(initialValue: T); /** @internal */ onTouched(): void; /** @internal */ onChange(_value: T): void; /** @internal */ registerOnChange(fn: (value: T) => void): void; /** @internal */ registerOnTouched(fn: () => void): void; /** @internal */ setDisabledState(isDisabled: boolean): void; /** @internal */ writeValue(value: T): void; /** @internal */ updateValue(value: T): void; protected hasValidator(validator: ValidatorFn): boolean; private hasNonIgnoredError; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵdir: i0.ɵɵDirectiveDeclaration, never, never, { "id": { "alias": "id"; "required": false; }; "name": { "alias": "name"; "required": false; }; "tabindex": { "alias": "tabindex"; "required": false; }; "ignoreErrors": { "alias": "ignoreErrors"; "required": false; }; "required": { "alias": "required"; "required": false; }; }, {}, never, never, true, never>; static ngAcceptInputType_ignoreErrors: string | string[]; static ngAcceptInputType_required: unknown; } /** * An abstract directive that facilitates handling input changes, focusing, and blurring programmatically for input elements. * It provides a reactive `valueChange$` observable to subscribe to input changes. * This directive can be extended to create more specific input handlers. * * @example * Extending InputControlDirective in a custom directive: * ```ts * @Directive({ * selector: '[appCustomInput]', * standalone: true, * }) * export class CustomInputDirective extends InputControlDirective { * // Custom logic here * } * ``` * * Using the directive in a component template: * ```html * * ``` * * Subscribing to input changes in the component: * ```ts * @Component({...}) * export class MyComponent implements AfterViewInit { * @ViewChild(CustomInputDirective) customInputDirective!: CustomInputDirective; * * ngAfterViewInit(): void { * this.customInputDirective.valueChange$.subscribe(value => { * console.log('Input value changed to:', value); * }); * } * } * * // Focusing the input programmatically * this.customInputDirective.focus(); * * // Blurring the input programmatically * this.customInputDirective.blur(); * * // Resetting the input value programmatically * this.customInputDirective.reset(); * ``` */ declare abstract class InputControlDirective { protected readonly takeUntilDestroyed: () => rxjs.MonoTypeOperatorFunction; readonly element: i0.ElementRef; /** * Represents an observable stream of value changes for the input control. * * @emits {string} input value changes. */ valueChange$: rxjs.Observable; /** * Gets the current value of the input element. * * @type {string} The current value of the input element. */ get nativeElementValue(): string; /** * Sets the value of the input element. * * @param {string} value - The value to set. */ set nativeElementValue(value: string); /** * Sets focus on the input element. * * @returns {void} */ focus(): void; /** * Removes focus from the input element. * * @returns {void} */ blur(): void; /** * Resets the input element value to an empty string. * * @returns {void} */ reset(): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } export { ControlDirective, CustomFormControl, InputControlDirective };