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

79 lines
2.0 KiB
Elm
Raw Normal View History

2020-12-10 20:56:52 +03:00
module Examples.Switch exposing (Msg, State, example)
{-|
@docs Msg, State, example
-}
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
, preview =
[ Switch.view
[ Switch.label "Toggle On"
, Switch.custom [ Key.tabbable False ]
]
False
, Switch.view
[ Switch.label "Toggle Off"
, Switch.custom [ Key.tabbable False ]
]
True
]
2020-12-10 20:56:52 +03:00
, view =
\ellieLinkConfig interactiveIsOn ->
2022-04-14 23:38:33 +03:00
[ Heading.h2 [ Heading.style Heading.Subhead ] [ Html.text "Interactive" ]
, Switch.view
[ Switch.onSwitch Switch
, Switch.id "switch-interactive"
, Switch.label
(if interactiveIsOn then
"On"
2020-12-10 20:56:52 +03:00
else
"Off"
)
2020-12-10 20:56:52 +03:00
]
interactiveIsOn
2022-04-14 23:38:33 +03:00
, Heading.h2 [ Heading.style Heading.Subhead ] [ Html.text "Disabled (On)" ]
, Switch.view
[ Switch.disabled
, Switch.id "switch-disabled-on"
, Switch.label "Permanently on"
2020-12-10 20:56:52 +03:00
]
True
2022-04-14 23:38:33 +03:00
, Heading.h2 [ Heading.style Heading.Subhead ] [ Html.text "Disabled (Off)" ]
, Switch.view
[ Switch.disabled
, Switch.id "switch-disabled-off"
, Switch.label "Permanently off"
2020-12-10 20:56:52 +03:00
]
False
2020-12-10 20:56:52 +03:00
]
, categories = [ Category.Inputs ]
, keyboardSupport = [{- TODO -}]
}