react-text-mask-modern
Version:
A modern, React 19+ compatible input masking component using hooks and TypeScript.
74 lines (68 loc) • 3 kB
text/typescript
import React, { InputHTMLAttributes, FocusEvent, ChangeEvent } from 'react';
interface MaskedInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange' | 'onBlur'> {
mask: any;
guide?: boolean;
value?: string | number;
pipe?: any;
placeholderChar?: string;
keepCharPositions?: boolean;
showMask?: boolean;
onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
}
declare const MaskedInput: React.ForwardRefExoticComponent<MaskedInputProps & React.RefAttributes<HTMLInputElement>>;
type Mask = Array<string | RegExp> | ((value: string, config?: any) => Array<string | RegExp> | false);
interface ConformToMaskConfig {
guide?: boolean;
previousConformedValue?: string;
placeholderChar?: string;
placeholder?: string;
currentCaretPosition?: number;
keepCharPositions?: boolean;
}
interface ConformToMaskResult {
conformedValue: string;
meta: {
someCharsRejected: boolean;
};
}
declare function conformToMask(rawValue: string | undefined, mask: Mask, config?: ConformToMaskConfig): ConformToMaskResult;
interface AdjustCaretPositionArgs {
previousConformedValue?: string;
previousPlaceholder?: string;
currentCaretPosition?: number;
conformedValue: string;
rawValue: string;
placeholderChar: string;
placeholder: string;
indexesOfPipedChars?: number[];
caretTrapIndexes?: number[];
}
declare function adjustCaretPosition({ previousConformedValue, previousPlaceholder, currentCaretPosition, conformedValue, rawValue, placeholderChar, placeholder, indexesOfPipedChars, caretTrapIndexes, }: AdjustCaretPositionArgs): number;
interface CreateTextMaskInputElementConfig {
inputElement: HTMLInputElement;
mask: Array<string | RegExp> | ((value: string, config?: any) => Array<string | RegExp> | false) | boolean | {
mask: Array<string | RegExp> | ((value: string, config?: any) => Array<string | RegExp> | false);
pipe?: (conformedValue: string, config: any) => false | string | {
value: string;
[key: string]: any;
};
};
guide?: boolean;
pipe?: (conformedValue: string, config: any) => false | string | {
value: string;
[key: string]: any;
};
placeholderChar?: string;
keepCharPositions?: boolean;
showMask?: boolean;
}
interface TextMaskInputElement {
state: {
previousConformedValue?: string;
previousPlaceholder?: string;
};
update: (rawValue?: string | number, configOverride?: Partial<CreateTextMaskInputElementConfig>) => void;
}
declare function createTextMaskInputElement(config: CreateTextMaskInputElementConfig): TextMaskInputElement;
export { AdjustCaretPositionArgs, ConformToMaskConfig, ConformToMaskResult, CreateTextMaskInputElementConfig, Mask, MaskedInput, MaskedInputProps, TextMaskInputElement, adjustCaretPosition, conformToMask, createTextMaskInputElement };