-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathtypes.ts
125 lines (108 loc) · 3.44 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React, { SyntheticEvent } from 'react';
export type Timeout = ReturnType<typeof setTimeout>;
export interface NumberFormatState {
value?: string;
numAsString?: string;
mounted: boolean;
}
export interface NumberFormatValues {
floatValue: number | undefined;
formattedValue: string;
value: string;
}
export enum SourceType {
event = 'event',
props = 'prop',
}
export interface SourceInfo {
event?: SyntheticEvent<HTMLInputElement>;
source: SourceType;
}
export type FormatInputValueFunction = (inputValue: string) => string;
export type RemoveFormattingFunction = (inputValue: string, changeMeta?: ChangeMeta) => string;
export interface SyntheticInputEvent extends React.SyntheticEvent<HTMLInputElement> {
readonly target: HTMLInputElement;
data: any;
}
export type ChangeMeta = {
from: {
start: number;
end: number;
};
to: {
start: number;
end: number;
};
lastValue: string;
};
export type InputAttributes = Omit<
React.InputHTMLAttributes<HTMLInputElement>,
'defaultValue' | 'value' | 'children'
>;
type NumberFormatProps<Props, BaseType = InputAttributes> = Props &
Omit<InputAttributes, keyof BaseType> &
Omit<BaseType, keyof Props | 'ref'> & {
customInput?: React.ComponentType<BaseType>;
};
export type OnValueChange = (values: NumberFormatValues, sourceInfo: SourceInfo) => void;
export type IsCharacterSame = (compareProps: {
currentValue: string;
lastValue: string;
formattedValue: string;
currentValueIndex: number;
formattedValueIndex: number;
}) => boolean;
type NumberFormatBase = {
type?: 'text' | 'tel' | 'password';
displayType?: 'input' | 'text';
inputMode?: InputAttributes['inputMode'];
renderText?: (formattedValue: string, otherProps: Partial<NumberFormatBase>) => React.ReactNode;
format?: FormatInputValueFunction;
removeFormatting?: RemoveFormattingFunction;
getInputRef?: ((el: HTMLInputElement) => void) | React.Ref<any>;
value?: number | string | null;
defaultValue?: number | string | null;
valueIsNumericString?: boolean;
onValueChange?: OnValueChange;
isAllowed?: (values: NumberFormatValues) => boolean;
onKeyDown?: InputAttributes['onKeyDown'];
onMouseUp?: InputAttributes['onMouseUp'];
onChange?: InputAttributes['onChange'];
onFocus?: InputAttributes['onFocus'];
onBlur?: InputAttributes['onBlur'];
getCaretBoundary?: (formattedValue: string) => boolean[];
isValidInputCharacter?: (character: string) => boolean;
isCharacterSame?: IsCharacterSame;
};
export type NumberFormatBaseProps<BaseType = InputAttributes> = NumberFormatProps<
NumberFormatBase,
BaseType
>;
export type InternalNumberFormatBase = Omit<
NumberFormatBase,
'format' | 'removeFormatting' | 'getCaretBoundary' | 'isValidInputCharacter' | 'isCharacterSame'
>;
export type NumericFormatProps<BaseType = InputAttributes> = NumberFormatProps<
InternalNumberFormatBase & {
thousandSeparator?: boolean | string;
decimalSeparator?: string;
allowedDecimalSeparators?: Array<string>;
thousandsGroupStyle?: 'thousand' | 'lakh' | 'wan' | 'none';
decimalScale?: number;
fixedDecimalScale?: boolean;
allowNegative?: boolean;
allowLeadingZeros?: boolean;
suffix?: string;
prefix?: string;
},
BaseType
>;
export type PatternFormatProps<BaseType = InputAttributes> = NumberFormatProps<
InternalNumberFormatBase & {
format: string;
mask?: string | string[];
allowEmptyFormatting?: boolean;
patternChar?: string;
},
BaseType
>;