UNPKG

2.31 kBTypeScriptView Raw
1// Type definitions for react-input-mask 3.0
2// Project: https://github.com/sanniassin/react-input-mask
3// Definitions by: Alexandre Paré <https://github.com/apare>
4// Dima Danylyuk <https://github.com/dima7a14>
5// Lucas Rêgo <https://github.com/lucasraziel>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7// TypeScript Version: 2.9
8
9import * as React from 'react';
10
11export interface Selection {
12 start: number;
13 end: number;
14}
15
16export interface InputState {
17 value: string;
18 selection: Selection | null;
19}
20
21export interface BeforeMaskedStateChangeStates {
22 previousState: InputState;
23 currentState: InputState;
24 nextState: InputState;
25}
26
27export interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
28 /**
29 * Mask string. Format characters are:
30 * * `9`: `0-9`
31 * * `a`: `A-Z, a-z`
32 * * `\*`: `A-Z, a-z, 0-9`
33 *
34 * Any character can be escaped with backslash, which usually will appear as double backslash in JS strings.
35 * For example, German phone mask with unremoveable prefix +49 will look like `mask="+4\\9 99 999 99"` or `mask={"+4\\\\9 99 999 99"}`
36 */
37 mask: string | Array<(string | RegExp)>;
38 /**
39 * Character to cover unfilled editable parts of mask. Default character is "_". If set to null, unfilled parts will be empty, like in ordinary input.
40 */
41 maskPlaceholder?: string | null | undefined;
42 /**
43 * Show mask even in empty input without focus.
44 */
45 alwaysShowMask?: boolean | undefined;
46 /**
47 * Use inputRef instead of ref if you need input node to manage focus, selection, etc.
48 */
49 inputRef?: React.Ref<HTMLInputElement> | undefined;
50 /**
51 * In case you need to implement more complex masking behavior, you can provide
52 * beforeMaskedStateChange function to change masked value and cursor position
53 * before it will be applied to the input.
54 *
55 * * previousState: Input state before change. Only defined on change event.
56 * * currentState: Current raw input state. Not defined during component render.
57 * * nextState: Input state with applied mask. Contains value and selection fields.
58 */
59 beforeMaskedStateChange?(states: BeforeMaskedStateChangeStates): InputState;
60}
61
62export class ReactInputMask extends React.Component<Props> {
63}
64
65export default ReactInputMask;