-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSelect.scala
66 lines (57 loc) · 1.74 KB
/
Select.scala
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
package weatherApp.components
import scalajs.js
import scalajs.js.annotation._
import japgolly.scalajs.react._
object Select {
@JSImport("react-select", JSImport.Default)
@js.native
object JsComp extends js.Any
@JSImport("react-select/dist/react-select.css", JSImport.Namespace)
@js.native
object CSS extends js.Any
CSS
@ScalaJSDefined
trait Options extends js.Object {
val value: String
val label: String
}
object Options {
def apply(value: String, label: String) = js.Dynamic.literal(value = value, label = label).asInstanceOf[Options]
}
@ScalaJSDefined
trait Props extends js.Object {
val name: String
val options: js.Array[Options]
val value: String
val onInputChange: js.Function1[String, Unit]
val onChange: js.Function1[Options, Unit]
val isLoading: Boolean
val backspaceRemoves: Boolean
}
val Component = JsFnComponent[Props, Children.Varargs](JsComp)
def props(
pName: String,
pOptions: js.Array[Options],
pValue: String,
pOnInputChange: js.Function1[String, Unit],
pOnChange: js.Function1[Options, Unit],
pIsLoading: Boolean = false
): Props = {
new Props {
val name = pName
val options = pOptions
val value = pValue
val onInputChange = pOnInputChange
val onChange = pOnChange
val isLoading = pIsLoading
val backspaceRemoves = false
}
}
def apply( pName: String,
pOptions: js.Array[Options],
pValue: String,
pOnInputChange: js.Function1[String, Unit],
pOnChange: js.Function1[Options, Unit],
pIsLoading: Boolean = false
) = Component(props(pName, pOptions, pValue, pOnInputChange, pOnChange, pIsLoading))()
}