2020-12-10 20:56:52 +03:00
|
|
|
module Examples.Switch exposing (Msg, State, example)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs Msg, State, example
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
2021-11-06 00:35:09 +03:00
|
|
|
import Accessibility.Styled.Key as Key
|
2020-12-10 20:56:52 +03:00
|
|
|
import Category
|
|
|
|
import Example exposing (Example)
|
|
|
|
import Html.Styled as Html
|
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
2022-04-19 03:40:39 +03:00
|
|
|
import Nri.Ui.Switch.V2 as Switch
|
2020-12-10 20:56:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
Bool
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= Switch Bool
|
|
|
|
|
|
|
|
|
|
|
|
example : Example State Msg
|
|
|
|
example =
|
|
|
|
{ name = "Switch"
|
|
|
|
, version = 1
|
|
|
|
, state = True
|
|
|
|
, update = \(Switch new) _ -> ( new, Cmd.none )
|
|
|
|
, subscriptions = \_ -> Sub.none
|
2021-11-05 23:55:44 +03:00
|
|
|
, preview =
|
2021-11-06 00:35:09 +03:00
|
|
|
[ Switch.view
|
2022-04-19 04:20:22 +03:00
|
|
|
[ Switch.label "Toggle Off"
|
|
|
|
, Switch.selected False
|
2021-11-06 00:42:34 +03:00
|
|
|
, Switch.custom [ Key.tabbable False ]
|
2021-11-06 00:35:09 +03:00
|
|
|
]
|
|
|
|
, Switch.view
|
2022-04-19 04:20:22 +03:00
|
|
|
[ Switch.label "Toggle On"
|
|
|
|
, Switch.selected True
|
2021-11-06 00:42:34 +03:00
|
|
|
, Switch.custom [ Key.tabbable False ]
|
2021-11-06 00:35:09 +03:00
|
|
|
]
|
2021-11-05 23:55:44 +03:00
|
|
|
]
|
2020-12-10 20:56:52 +03:00
|
|
|
, view =
|
2022-03-29 20:19:32 +03:00
|
|
|
\ellieLinkConfig interactiveIsOn ->
|
2022-04-14 23:38:33 +03:00
|
|
|
[ Heading.h2 [ Heading.style Heading.Subhead ] [ Html.text "Interactive" ]
|
2021-11-05 23:55:44 +03:00
|
|
|
, Switch.view
|
|
|
|
[ Switch.onSwitch Switch
|
|
|
|
, Switch.id "switch-interactive"
|
|
|
|
, Switch.label
|
|
|
|
(if interactiveIsOn then
|
2022-04-19 04:01:51 +03:00
|
|
|
"On"
|
2020-12-10 20:56:52 +03:00
|
|
|
|
2021-11-05 23:55:44 +03:00
|
|
|
else
|
2022-04-19 04:01:51 +03:00
|
|
|
"Off"
|
2021-11-05 23:55:44 +03:00
|
|
|
)
|
2022-04-19 04:20:22 +03:00
|
|
|
, Switch.selected interactiveIsOn
|
2020-12-10 20:56:52 +03:00
|
|
|
]
|
2022-04-14 23:38:33 +03:00
|
|
|
, Heading.h2 [ Heading.style Heading.Subhead ] [ Html.text "Disabled (On)" ]
|
2021-11-05 23:55:44 +03:00
|
|
|
, Switch.view
|
|
|
|
[ Switch.disabled
|
|
|
|
, Switch.id "switch-disabled-on"
|
2022-04-19 04:01:51 +03:00
|
|
|
, Switch.label "Permanently on"
|
2022-04-19 04:20:22 +03:00
|
|
|
, Switch.selected True
|
2020-12-10 20:56:52 +03:00
|
|
|
]
|
2022-04-14 23:38:33 +03:00
|
|
|
, Heading.h2 [ Heading.style Heading.Subhead ] [ Html.text "Disabled (Off)" ]
|
2021-11-05 23:55:44 +03:00
|
|
|
, Switch.view
|
|
|
|
[ Switch.disabled
|
|
|
|
, Switch.id "switch-disabled-off"
|
2022-04-19 04:01:51 +03:00
|
|
|
, Switch.label "Permanently off"
|
2022-04-19 04:20:22 +03:00
|
|
|
, Switch.selected False
|
2020-12-10 20:56:52 +03:00
|
|
|
]
|
|
|
|
]
|
|
|
|
, categories = [ Category.Inputs ]
|
|
|
|
, keyboardSupport = [{- TODO -}]
|
|
|
|
}
|