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

86 lines
1.4 KiB
Elm
Raw Normal View History

module Examples.SegmentedControl
exposing
( Msg
, State
, example
, init
, update
)
2018-03-24 05:05:34 +03:00
{-|
@docs Msg
@docs State
@docs example
@docs init
@docs styles
@docs update
2018-03-24 05:05:34 +03:00
-}
import Css
import Html.Styled as Html
import Html.Styled.Attributes exposing (css)
2018-03-24 05:05:34 +03:00
import ModuleExample exposing (Category(..), ModuleExample)
import Nri.Ui.SegmentedControl.V6 exposing (Width(..))
2018-03-24 05:05:34 +03:00
{-| -}
type Msg
= Select Id
{-| -}
type alias State =
Nri.Ui.SegmentedControl.V6.Config Id Msg
2018-03-24 05:05:34 +03:00
{-| -}
example : (Msg -> msg) -> State -> ModuleExample msg
example parentMessage state =
{ filename = "Nri/Ui/SegmentedControl/V6.elm"
2018-03-24 05:05:34 +03:00
, category = Behaviors
, content =
[ Nri.Ui.SegmentedControl.V6.view state
|> Html.map parentMessage
|> Html.toUnstyled
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"
, width = FitContent
2018-03-24 05:05:34 +03:00
}
{-| -}
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
case msg of
Select id ->
( { state | selected = id }, Cmd.none )
-- INTERNAL
type alias Id =
String