2018-09-26 17:02:10 +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 update
|
2018-03-24 05:05:34 +03:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2018-09-10 18:19:15 +03:00
|
|
|
import Accessibility.Styled
|
|
|
|
import Html.Styled as Html exposing (Html)
|
|
|
|
import Html.Styled.Attributes as Attr
|
|
|
|
import Html.Styled.Events as Events
|
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
|
2018-09-10 18:19:15 +03:00
|
|
|
| SetFillContainer Bool
|
2018-03-24 05:05:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
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-10-23 19:55:30 +03:00
|
|
|
List.map (Html.map parentMessage)
|
2018-09-10 18:19:15 +03:00
|
|
|
[ fillContainerCheckbox state.width
|
|
|
|
, Nri.Ui.SegmentedControl.V6.view state
|
|
|
|
]
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-10 18:19:15 +03:00
|
|
|
fillContainerCheckbox : Width -> Html Msg
|
|
|
|
fillContainerCheckbox currentOption =
|
|
|
|
let
|
|
|
|
id =
|
|
|
|
"SegmentedControl-fill-container-checkbox"
|
|
|
|
|
|
|
|
isChecked =
|
|
|
|
case currentOption of
|
|
|
|
FitContent ->
|
|
|
|
Just False
|
|
|
|
|
|
|
|
FillContainer ->
|
|
|
|
Just True
|
|
|
|
in
|
|
|
|
Html.div []
|
|
|
|
[ Accessibility.Styled.checkbox "Fill container"
|
|
|
|
isChecked
|
|
|
|
[ Attr.id id
|
|
|
|
, Events.onCheck SetFillContainer
|
|
|
|
]
|
|
|
|
, Html.label
|
|
|
|
[ Attr.for id
|
|
|
|
]
|
|
|
|
[ Html.text "Fill Container" ]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
|
2018-09-10 18:19:15 +03:00
|
|
|
SetFillContainer fillContainer ->
|
|
|
|
( { state
|
|
|
|
| width =
|
|
|
|
if fillContainer then
|
|
|
|
FillContainer
|
2018-09-26 17:02:10 +03:00
|
|
|
|
2018-09-10 18:19:15 +03:00
|
|
|
else
|
|
|
|
FitContent
|
|
|
|
}
|
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
|
2018-03-24 05:05:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
-- INTERNAL
|
|
|
|
|
|
|
|
|
|
|
|
type alias Id =
|
|
|
|
String
|