noredink-ui/styleguide-app/KeyboardSupport.elm

102 lines
1.7 KiB
Elm
Raw Normal View History

module KeyboardSupport exposing
( view
, KeyboardSupport
, Key(..), Direction(..)
)
{-|
@docs view
@docs KeyboardSupport
@docs Key, Direction
-}
2020-06-20 00:50:47 +03:00
import Css exposing (..)
import Html.Styled as Html exposing (..)
2020-06-20 00:50:47 +03:00
import Html.Styled.Attributes exposing (css)
{-| -}
type alias KeyboardSupport =
{ keys : List Key
, result : String
}
{-| -}
view : List KeyboardSupport -> Html msg
view keyboardSupport =
case keyboardSupport of
[] ->
text ""
_ ->
details []
[ summary [] [ text "Keyboard Support" ]
2020-06-20 00:50:47 +03:00
, ul
[ css [ listStyle none, margin2 (px 10) zero, padding zero ]
]
(List.map viewKeyboardActions keyboardSupport)
]
viewKeyboardActions : KeyboardSupport -> Html msg
viewKeyboardActions { keys, result } =
li []
2020-06-20 00:50:47 +03:00
[ strong [] [ text (String.join "+" (List.map keyToString keys) ++ ": ") ]
, text result
]
{-| -}
type Key
= Shift
| Enter
| Arrow Direction
| Tab
| Space
keyToString : Key -> String
keyToString key =
case key of
Shift ->
"Shift"
Enter ->
"Enter"
Arrow direction ->
directionToString direction ++ " arrow"
Tab ->
"Tab"
Space ->
"Space"
{-| -}
type Direction
= Up
| Right
| Down
| Left
directionToString : Direction -> String
directionToString direction =
case direction of
Up ->
"Up"
Right ->
"Right"
Down ->
"Down"
Left ->
"Left"