@@ -2,33 +2,39 @@ module Yoga.Block.Atom.Select.View where
3import Yoga.Prelude.View
3import Yoga.Prelude.View
5+import Data.Array as Array
5import Effect.Unsafe (unsafePerformEffect)
6import Effect.Unsafe (unsafePerformEffect)
6−import Yoga.Block.Atom.Select.Style as Style
7import React.Basic.DOM as R
7import React.Basic.DOM as R
8import React.Basic.Hooks as React
8import React.Basic.Hooks as React
9+import Yoga.Block.Atom.Select.Style as Style
10−component ∷
11+type Props a =
13− ( { choice ∷ a
12+ { choice ∷ a
14− , choices ∷ Array a
13+ , choices ∷ Array a
15− , onChange ∷ Array a → Effect Unit
14+ , onChange ∷ a → Effect Unit
16− , toString ∷ a → String
15+ , toString ∷ a → String
17− , toValue ∷ a → String
16+ , toValue ∷ a → String
19+component ∷ ∀ a. ReactComponent (Props a)
20component = unsafePerformEffect do
20component = unsafePerformEffect do
21− React.reactComponent "Select" \{ toString, toValue, choices } → React.do
21+ React.reactComponent "Select" \{ toString, toValue, choices, onChange } →
23− div "input-container" Style.container
24+ div "input-container" Style.container
24− [ R.select'
25+ [ R.select'
26− { className: "select"
27+ { className: "select"
27− , role: "listbox"
28+ , role: "listbox"
28− , css: Style.select
29+ , css: Style.select
30+ , onChange: handler targetValue
31+ \maybeVal → traverse_ onChange do
33+ choices # Array.find (toString >>> (_ == val))
31− ( choices <#> \c → R.option' </ { value: toValue c } />
37+ ( choices <#> \c → R.option' </ { value: toValue c } />
32− [ R.text $ toString c ]
38+ [ R.text $ toString c ]