-
Notifications
You must be signed in to change notification settings - Fork 3
/
Slider.elm
39 lines (33 loc) · 851 Bytes
/
Slider.elm
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
module Slider where
import Html
import Json.Decode exposing ((:=))
import Html.Attributes exposing (type', value, class)
import Html.Events exposing (on)
valueDecoder =
"target" := ("valueAsNumber" := Json.Decode.float)
type alias Options =
{ min : Float
, max : Float
, step : Maybe Float
, value : Float
}
stepString : Maybe Float -> String
stepString mx =
case mx of
Just x ->
toString x
Nothing ->
"any"
slider : Options -> (Float -> Signal.Message) -> Html.Html
slider options f =
Html.input
[ type' "range"
, class "mdl-slider mdl-js-slider"
, Html.Attributes.tabindex 10
, value (toString options.value)
, Html.Attributes.max (toString options.max)
, Html.Attributes.min (toString options.min)
, Html.Attributes.step (stepString options.step)
, on "input" valueDecoder f
]
[]