1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import * as React from 'react';
|
10 |
|
11 | export type Mask = Array<string | RegExp> | false;
|
12 |
|
13 | export 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 |
|
23 | export type ConformToMaskConfig = Partial<Omit<PipeConfig, 'rawValue'>>;
|
24 |
|
25 | export 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 |
|
51 | export interface ConformToMaskResult {
|
52 | conformedValue: string;
|
53 | meta: {
|
54 | someCharsRejected: boolean;
|
55 | };
|
56 | }
|
57 |
|
58 | export default class MaskedInput extends React.Component<MaskedInputProps, any> {
|
59 | inputElement: HTMLElement;
|
60 | }
|
61 |
|
62 | export function conformToMask(
|
63 | text: string,
|
64 | mask: Mask | ((value: string) => Mask),
|
65 | config?: ConformToMaskConfig,
|
66 | ): ConformToMaskResult;
|