@@ -123,105 +123,6 @@ module Resource = {
123
123
}
124
124
}
125
125
126
- module SearchBox = {
127
- @bs. send external focus : Dom .element => unit = "focus"
128
-
129
- type state =
130
- | Active
131
- | Inactive
132
-
133
- @react.component
134
- let make = (
135
- ~completionValues : array <string >= [], // set of possible values
136
- ~value : string ,
137
- ~onClear : unit => unit ,
138
- ~placeholder : string = "" ,
139
- ~onValueChange : string => unit ,
140
- ) => {
141
- let (state , setState ) = React .useState (_ => Inactive )
142
- let textInput = React .useRef (Js .Nullable .null )
143
-
144
- let onMouseDownClear = evt => {
145
- ReactEvent .Mouse .preventDefault (evt )
146
- onClear ()
147
- }
148
-
149
- let focusInput = () =>
150
- textInput .current -> Js .Nullable .toOption -> Belt .Option .forEach (el => el -> focus )
151
-
152
- let onAreaFocus = evt => {
153
- let el = ReactEvent .Focus .target (evt )
154
- let isDiv = Js .Null_undefined .isNullable (el ["type" ])
155
-
156
- if isDiv && state === Inactive {
157
- focusInput ()
158
- }
159
- }
160
-
161
- let onFocus = _ => {
162
- setState (_ => Active )
163
- }
164
-
165
- let onBlur = _ => {
166
- setState (_ => Inactive )
167
- }
168
-
169
- let onKeyDown = evt => {
170
- let key = ReactEvent .Keyboard .key (evt )
171
- let ctrlKey = ReactEvent .Keyboard .ctrlKey (evt )
172
-
173
- let full = (ctrlKey ? "CTRL+" : "" ) ++ key
174
-
175
- switch full {
176
- | "Escape" => onClear ()
177
- | "Tab" =>
178
- if Js .Array .length (completionValues ) === 1 {
179
- let targetValue = Belt .Array .getExn (completionValues , 0 )
180
-
181
- if targetValue !== value {
182
- ReactEvent .Keyboard .preventDefault (evt )
183
- onValueChange (targetValue )
184
- } else {
185
- ()
186
- }
187
- }
188
- | _ => ()
189
- }
190
- }
191
-
192
- let onChange = evt => {
193
- ReactEvent .Form .preventDefault (evt )
194
- let value = ReactEvent .Form .target (evt )["value" ]
195
- onValueChange (value )
196
- }
197
-
198
- <div
199
- tabIndex = {- 1 }
200
- onFocus = onAreaFocus
201
- onBlur
202
- className = {(
203
- state === Active ? "border-fire" : "border-fire-40"
204
- ) ++ " flex items-center border rounded-lg py-4 px-5" }>
205
- <Icon .MagnifierGlass
206
- className = {(state === Active ? "text-fire" : "text-fire-80" ) ++ " w-4 h-4" }
207
- />
208
- <input
209
- value
210
- ref = {ReactDOM .Ref .domRef (textInput )}
211
- onFocus
212
- onKeyDown
213
- onChange = {onChange }
214
- placeholder
215
- className = "text-16 outline-none ml-4 w-full"
216
- type_ = "text"
217
- />
218
- <button onFocus className = {value === "" ? "hidden" : "block" } onMouseDown = onMouseDownClear >
219
- <Icon .Close className = "w-4 h-4 text-fire" />
220
- </button >
221
- </div >
222
- }
223
- }
224
-
225
126
module Card = {
226
127
@react.component
227
128
let make = (~value : Resource .t , ~onKeywordSelect : option <string => unit >= ?) => {
0 commit comments