2018-03-30 19:03:16 +03:00
|
|
|
module Examples.SegmentedControl
|
|
|
|
exposing
|
|
|
|
( Msg
|
|
|
|
, State
|
|
|
|
, example
|
|
|
|
, init
|
|
|
|
, update
|
|
|
|
)
|
2018-03-24 05:05:34 +03:00
|
|
|
|
|
|
|
{-|
|
|
|
|
|
2018-03-30 19:03:16 +03:00
|
|
|
@docs Msg
|
|
|
|
@docs State
|
|
|
|
@docs example
|
|
|
|
@docs init
|
|
|
|
@docs styles
|
|
|
|
@docs update
|
2018-03-24 05:05:34 +03:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2018-03-30 19:03:16 +03:00
|
|
|
import Css
|
2018-09-10 17:31:25 +03:00
|
|
|
import Html.Styled as Html
|
|
|
|
import Html.Styled.Attributes exposing (css)
|
2018-03-24 05:05:34 +03:00
|
|
|
import ModuleExample exposing (Category(..), ModuleExample)
|
2018-09-10 17:56:26 +03:00
|
|
|
import Nri.Ui.SegmentedControl.V6 exposing (Width(..))
|
2018-03-24 05:05:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= Select Id
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
2018-09-10 17:04:29 +03:00
|
|
|
Nri.Ui.SegmentedControl.V6.Config Id Msg
|
2018-03-24 05:05:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
2018-03-29 13:58:41 +03:00
|
|
|
example : (Msg -> msg) -> State -> ModuleExample msg
|
|
|
|
example parentMessage state =
|
2018-09-10 17:04:29 +03:00
|
|
|
{ filename = "Nri/Ui/SegmentedControl/V6.elm"
|
2018-03-24 05:05:34 +03:00
|
|
|
, category = Behaviors
|
|
|
|
, content =
|
2018-09-10 17:56:26 +03:00
|
|
|
[ Nri.Ui.SegmentedControl.V6.view state
|
2018-09-10 17:31:25 +03:00
|
|
|
|> Html.map parentMessage
|
|
|
|
|> Html.toUnstyled
|
2018-03-24 05:05:34 +03:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
{ onClick = Select
|
|
|
|
, options =
|
2018-03-29 04:20:58 +03:00
|
|
|
[ { 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"
|
2018-09-10 17:56:26 +03:00
|
|
|
, 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
|