-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextInput.tsx
65 lines (55 loc) · 2.42 KB
/
TextInput.tsx
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
import * as React from "react";
import { action } from "mobx";
import { observer } from "mobx-react";
import { BoxedValue } from "boxm";
import { FormElementProps, removeProps, StyleComponent } from "./FormElementProps";
import * as Rules from "../rules"
export type AutoComplete = "off"|"on"|"name"|"honorific-prefix"|"given-name"|"additional-name"|
"family-name"|"honorific-suffix"|"nickname"|"email"|"username"|"new-password"|
"current-password"|"organization-title"|"organization"|"street-address"|
"address-line1"|"address-line2"|"address-line3"|"address-level4"|"address-level3"|
"address-level2"|"address-level1"|"country"|"country-name"|"postal-code"|
"cc-name"|"cc-given-name"|"cc-additional-name"|"cc-family-name"|"cc-number"|
"cc-exp"|"cc-exp-month"|"cc-exp-year"|"cc-csc"|"cc-type"|"transaction-currency"|
"transaction-amount"|"language"|"bday"|"bday-day"|"bday-month"|"bday-year"|"sex"|
"tel"|"url";
export type InputMode = "verbatim"|"latin"|"latin-name"|"latin-prose"|"full-width-latin"|
"kana"|"katakana"|"numeric"|"tel"|"email"|"url";
export type SelectionDirection = "forward"|"backward"|"none";
export interface StandardTextInputProps extends FormElementProps {
autocomplete?: AutoComplete,
inputmode?: InputMode;
list?: string;
maxlength?: number;
minlength?: number;
pattern?: string;
placeholder?: string;
selectionDirection?: SelectionDirection;
size?: number;
spellcheck?: boolean;
}
export interface TextInputProps extends StandardTextInputProps {
value: BoxedValue<string> & Rules.Rule;
errorClass?: string;
component?: StyleComponent<HTMLInputElement>;
}
@observer
export class TextInput extends React.Component<TextInputProps, {}> {
@action.bound
changed(e: React.FormEvent<HTMLInputElement>) {
this.props.value.set(e.currentTarget.value);
}
render() {
const { component: InputComponent = "input" } = this.props;
return (
<InputComponent type="text"
{...removeProps(this.props, "value")}
{...Rules.props(this.props.value, this.props)}
value={this.props.value.get()}
onChange={this.changed} />
);
}
}
export function TextInputUsing(component: StyleComponent<HTMLInputElement>) {
return (props: TextInputProps) => <TextInput component={component} {...props}/>;
}