UNPKG

ngx-payment-inputs

Version:

A set of Angular Directives to validate and format credit card inputs.

80 lines (79 loc) 2.66 kB
import { AfterViewInit, ElementRef, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { AbstractControl, ControlValueAccessor, NgControl } from '@angular/forms'; import { CardTypeService } from '../services/card-type.service'; /** * Directive to format and validate a card CVC */ export declare class CardCvvDirective implements ControlValueAccessor, OnInit, AfterViewInit, OnDestroy { private _renderer; private _elementRef; private _ngControl; private _cardTypeService; onChange?: (event: any) => void; onTouched?: (event: any) => void; private _rendererTimeout; private _cvvMaskLength; /** * attr for stop all subscribes */ private readonly _destroy$; constructor(_renderer: Renderer2, _elementRef: ElementRef<HTMLInputElement>, _ngControl: NgControl, _cardTypeService: CardTypeService); ngOnInit(): void; ngAfterViewInit(): void; ngOnDestroy(): void; /** * get the current html input from element ref * @returns The native element from ref * @private */ get _el(): HTMLInputElement; /** * get the control of the current element ref * @returns return the control of element * @private */ get _control(): AbstractControl; /** * listener the input event from html input element * @param event - the keyboard event */ onCardChanges(event: KeyboardEvent): void; /** * listener the input blur event to update input mask * @param event - the keyboard event */ onCardBlur(event: KeyboardEvent): void; /** * Listener the keydown to check when backspace is pressed * @param event {KeyboardEvent} - The keyboard event */ onKeyDown(event: KeyboardEvent): void; /** * Writes a new value to the element. * @param rawValue - value from input */ writeValue(rawValue: KeyboardEvent): void; /** * Registers a callback function that is called when the control's value changes in the UI. * @param onChange - {fn} */ registerOnChange(onChange: any): void; /** * Registers a callback function that is called by the forms API on initialization to update the form model on blur. * @param onTouched - {fn} */ registerOnTouched(onTouched: any): void; /** * set element ref as disabled * @param isDisabled - set element as disabled */ setDisabledState?(isDisabled: boolean): void; /** * Set the mask size based on card type (from card BIN) */ private _setCardCvcMask; /** * setup input with some attrs for better user experience */ private _setupInput; }