Skip to content

Commit 9a67a57

Browse files
sirajalam04940818419
authored andcommitted
Typings added for the component (#77)
1 parent 8059859 commit 9a67a57

4 files changed

Lines changed: 83 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const ReactCodeInput = dynamic(import('react-code-input'));
8787
|:---|:---|:---|
8888
| type | string | Only types like: `text`, `number`, `password` and `tel` are accepted.|
8989
| fields | number | Allowed amount of characters to enter. |
90-
| value | string | Setting the initial value of code input field. |
90+
| value | string | Setting the value of code input field. |
9191
| name | string | Setting the name of component. |
9292
| onChange | func | Function, which is called whenever there is a change of value in the input box. |
9393
| touch | func | Marks the given fields as "touched" to show errors. |

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-code-input",
3-
"version": "3.8.1",
3+
"version": "3.8.2",
44
"description": "React component for entering and validating numbers, text or password.",
55
"main": "dist/ReactCodeInput.js",
66
"scripts": {
@@ -121,4 +121,4 @@
121121
"react": "^15.5.4 || ^16.2.0",
122122
"react-dom": "^15.5.4 || ^16.2.0"
123123
}
124-
}
124+
}

src/ReactCodeInput.d.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Type definitions for react-code-input 3.8.2
2+
// Project: React Code Input
3+
// Definitions by: Siraj Alam https://github.com/sirajalam049
4+
5+
import React, { Component } from 'react';
6+
7+
export type InputModeTypes =
8+
'verbatim' | 'latin' | 'latin-name' | 'latin-prose' |
9+
'full-width-latin' | 'kana' | 'kana-name' | 'katakana' |
10+
'numeric' | 'tel' | 'email' | 'url'
11+
12+
export interface ReactCodeInputProps {
13+
14+
// Type of input accept
15+
type?: 'text' | 'number' | 'password' | 'tel'
16+
17+
// Allowed amount of characters to enter.
18+
fields?: number
19+
20+
// Value of the input
21+
value?: string
22+
23+
// Get the full value of the input on every change
24+
onChange?: (value: string) => void
25+
26+
// Setting the name of component.
27+
name: string
28+
29+
// Marks the given fields as "touched" to show errors.
30+
touch?: (name: string) => void
31+
32+
// Clears the "touched" flag for the given fields.
33+
untouch?: (name: string) => void
34+
35+
// Add classname to the root element.
36+
className?: string
37+
38+
isValid?: boolean
39+
40+
// When present, it specifies that the element should be disabled.
41+
disabled?: boolean
42+
43+
// Setting the styles of container element.
44+
style?: React.CSSProperties
45+
46+
// Setting the styles of each input field.
47+
inputStyle?: React.CSSProperties
48+
49+
// Setting the styles of each input field if isValid prop is false.
50+
inputStyleInvalid?: React.CSSProperties
51+
52+
// Setup autofocus on the first input, true by default.
53+
autoFocus?: boolean
54+
55+
//
56+
forceUppercase?: boolean
57+
58+
// Filter characters on key down.
59+
filterKeyCodes?: Array<number>
60+
61+
// Filter characters.
62+
filterChars?: Array<string>
63+
64+
// The pattern prop specifies a regular expression that the element's value is checked against.
65+
pattern?: string
66+
67+
// The inputMode prop tells the browser on devices with dynamic keyboards which keyboard to display.
68+
inputMode: InputModeTypes
69+
70+
}
71+
72+
declare class ReactCodeInput extends Component<ReactCodeInputProps, any> {
73+
constructor(props: ReactCodeInputProps);
74+
}
75+
76+
export default ReactCodeInput

src/ReactCodeInput.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ class ReactCodeInput extends Component {
6565

6666
UNSAFE_componentWillReceiveProps(nextProps) {
6767
this.setState({
68-
isValid: nextProps.isValid,
69-
value: nextProps.value,
70-
disabled: nextProps.disabled,
71-
});
68+
isValid: nextProps.isValid,
69+
value: nextProps.value,
70+
disabled: nextProps.disabled,
71+
});
7272
}
7373

7474
handleBlur(e) {

0 commit comments

Comments
 (0)