-
-
Notifications
You must be signed in to change notification settings - Fork 664
/
Copy pathindex.tsx
86 lines (77 loc) · 1.96 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import X from "@modules/common/icons/x"
import { FormEvent } from "react"
import SearchBoxWrapper, {
ControlledSearchBoxProps,
} from "../search-box-wrapper"
const ControlledSearchBox = ({
inputRef,
isSearchStalled,
onChange,
onReset,
onSubmit,
placeholder,
value,
...props
}: ControlledSearchBoxProps) => {
const handleSubmit = (event: FormEvent) => {
event.preventDefault()
event.stopPropagation()
if (onSubmit) {
onSubmit(event)
}
if (inputRef.current) {
inputRef.current.blur()
}
}
const handleReset = (event: FormEvent) => {
event.preventDefault()
event.stopPropagation()
onReset(event)
if (inputRef.current) {
inputRef.current.focus()
}
}
return (
<div {...props} className="w-full">
<form action="" noValidate onSubmit={handleSubmit} onReset={handleReset}>
<div className="flex items-center justify-between">
<input
ref={inputRef}
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
placeholder={placeholder}
spellCheck={false}
type="search"
value={value}
onChange={onChange}
className="text-base-regular placeholder:transition-colors placeholder:text-gray-500 focus:placeholder:text-gray-900 focus:outline-none flex-1 bg-transparent text-[16px]"
/>
{value && (
<button
onClick={handleReset}
type="button"
className="h-5 w-5 rounded-full flex items-center justify-center text-gray-900 bg-gray-200"
>
<X size={12} />
</button>
)}
</div>
</form>
</div>
)
}
const SearchBox = () => {
return (
<SearchBoxWrapper>
{(props) => {
return (
<>
<ControlledSearchBox {...props} />
</>
)
}}
</SearchBoxWrapper>
)
}
export default SearchBox