noredink-ui/styleguide-app/Examples/SegmentedControl.elm

70 lines
1.2 KiB
Elm
Raw Normal View History

2018-03-24 05:05:34 +03:00
module Examples.SegmentedControl exposing (Msg, State, example, init, update)
{-|
@docs Msg, State, example, init, update,
-}
import Html
import ModuleExample exposing (Category(..), ModuleExample)
import Nri.Ui.Icon.V1
import Nri.Ui.SegmentedControl.V3
2018-03-24 05:05:34 +03:00
{-| -}
type Msg
= Select Id
{-| -}
type alias State =
Nri.Ui.SegmentedControl.V3.Config Id Msg
2018-03-24 05:05:34 +03:00
{-| -}
example : Nri.Ui.Icon.V1.Assets r -> (Msg -> msg) -> State -> ModuleExample msg
example assets parentMessage state =
{ filename = "Nri/Ui/SegmentedControl/V3.elm"
2018-03-24 05:05:34 +03:00
, category = Behaviors
, content =
[ Html.map parentMessage (Nri.Ui.SegmentedControl.V3.view assets state)
2018-03-24 05:05:34 +03:00
]
}
{-| -}
init : State
init =
{ onClick = Select
, options =
[ { icon = Nothing
, id = "a"
, label = "Option A"
, value = "a"
}
, { icon = Nothing
, id = "b"
, label = "Option B"
, value = "b"
}
2018-03-24 05:05:34 +03:00
]
, selected = "a"
}
{-| -}
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
case msg of
Select id ->
( { state | selected = id }, Cmd.none )
-- INTERNAL
type alias Id =
String