UNPKG

1.93 kBTypeScriptView Raw
1// Type definitions for react-text-mask 5.4
2// Project: https://github.com/text-mask/text-mask/tree/master/react
3// Definitions by: Guilherme Hübner <https://github.com/guilhermehubner>
4// Deividi Cavarzan <https://github.com/cavarzan>
5// Artem Lyubchuk <https://github.com/needpower>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7// Minimum TypeScript Version: 3.9
8
9import * as React from 'react';
10
11export type Mask = Array<string | RegExp> | false;
12
13export interface PipeConfig {
14 placeholder: string;
15 placeholderChar: string;
16 currentCaretPosition: number;
17 keepCharPositions: boolean;
18 rawValue: string;
19 guide: boolean | undefined;
20 previousConformedValue: string | undefined;
21}
22
23export type ConformToMaskConfig = Partial<Omit<PipeConfig, 'rawValue'>>;
24
25export interface MaskedInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
26 mask: Mask | ((value: string) => Mask);
27
28 guide?: boolean;
29
30 placeholderChar?: string;
31
32 keepCharPositions?: boolean;
33
34 pipe?: (
35 conformedValue: string,
36 config: PipeConfig,
37 ) => false | string | { value: string; indexesOfPipedChars: number[] };
38
39 showMask?: boolean;
40
41 render?: (
42 ref: (inputElement: HTMLElement) => void,
43 props: {
44 onChange: (event: React.ChangeEvent<HTMLElement>) => void;
45 onBlur: (event: React.FocusEvent<HTMLElement>) => void;
46 defaultValue: string | undefined;
47 },
48 ) => React.ReactNode;
49}
50
51export interface ConformToMaskResult {
52 conformedValue: string;
53 meta: {
54 someCharsRejected: boolean;
55 };
56}
57
58export default class MaskedInput extends React.Component<MaskedInputProps, any> {
59 inputElement: HTMLElement;
60}
61
62export function conformToMask(
63 text: string,
64 mask: Mask | ((value: string) => Mask),
65 config?: ConformToMaskConfig,
66): ConformToMaskResult;