-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathInput.res
More file actions
101 lines (96 loc) · 2.55 KB
/
Copy pathInput.res
File metadata and controls
101 lines (96 loc) · 2.55 KB
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
open RecoilAtoms
@react.component
let make = (
~isValid=None,
~id="",
~setIsValid=?,
~value,
~onChange,
~onBlur=?,
~onKeyDown=?,
~onFocus=?,
~rightIcon=React.null,
~errorString=?,
~fieldName="",
~type_="text",
~maxLength=?,
~pattern=?,
~placeholder="",
~className="",
~inputRef,
) => {
let options = Recoil.useRecoilValueFromAtom(elementOptions)
let {themeObj} = Recoil.useRecoilValueFromAtom(configAtom)
let (_inputFocused, setInputFocused) = React.useState(_ => false)
let {parentURL, iframeId} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys)
let elementType = PaymentTypeContext.usePaymentType()->CardThemeType.getPaymentModeToString
let setFocus = (val: bool) => {
switch onFocus {
| Some(fn) => fn(val)
| None => ()
}
}
let setValid = val => {
switch setIsValid {
| Some(fn) => fn(_ => val)
| None => ()
}
}
let handleFocus = _ => {
setFocus(true)
setValid(None)
setInputFocused(_ => true)
Utils.handleOnFocusPostMessage(~iframeId, ~elementType, ~targetOrigin=parentURL)
}
let handleBlur = ev => {
setFocus(false)
switch onBlur {
| Some(fn) => fn(ev)
| None => ()
}
}
let direction = if type_ == "password" || type_ == "tel" {
"ltr"
} else {
""
}
<div className={` flex flex-col w-full`} style={color: themeObj.colorText}>
<RenderIf condition={fieldName->String.length > 0}>
<div> {React.string(fieldName)} </div>
</RenderIf>
<div className="flex flex-row " style={direction: direction}>
<input
id
style={
background: themeObj.colorBackground,
padding: themeObj.spacingUnit,
width: "100%",
}
disabled=options.disabled
ref={inputRef->ReactDOM.Ref.domRef}
type_
?onKeyDown
?maxLength
?pattern
className={`Input ${className} focus:outline-none transition-shadow ease-out duration-200 border border-gray-300 focus:border-[#006DF9] rounded-md text-sm`}
placeholder
value
onChange
onBlur=handleBlur
onFocus=handleFocus
ariaLabel={`Type to fill ${fieldName} input`}
/>
<div className={`flex -ml-10 items-center`}> {rightIcon} </div>
</div>
{switch errorString {
| Some(val) =>
<RenderIf condition={val->String.length > 0}>
<div
className="py-1 text-xs text-red-600 transition-colors transition-border ease-out duration-200">
{React.string(val)}
</div>
</RenderIf>
| None => React.null
}}
</div>
}