2020-06-20 00:35:53 +03:00
|
|
|
module KeyboardShortcuts exposing
|
|
|
|
( view
|
|
|
|
, KeyboardShortcut
|
|
|
|
, Key(..), Direction(..)
|
|
|
|
)
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs view
|
|
|
|
@docs KeyboardShortcut
|
|
|
|
@docs Key, Direction
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
import Html.Styled as Html exposing (..)
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias KeyboardShortcut =
|
|
|
|
{ keys : List Key
|
|
|
|
, result : String
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-20 00:42:28 +03:00
|
|
|
{-| -}
|
|
|
|
view : List KeyboardShortcut -> Html msg
|
|
|
|
view keyboardShortcuts =
|
|
|
|
case keyboardShortcuts of
|
|
|
|
[] ->
|
|
|
|
text ""
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
details []
|
|
|
|
[ summary [] [ text "Keyboard Support" ]
|
|
|
|
, ul [] (List.map viewKeyboardActions keyboardShortcuts)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
viewKeyboardActions : KeyboardShortcut -> Html msg
|
|
|
|
viewKeyboardActions { keys, result } =
|
|
|
|
li []
|
|
|
|
[ strong [] [ text (String.join "+" (List.map keyToString keys)) ]
|
|
|
|
, text result
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-06-20 00:35:53 +03:00
|
|
|
{-| -}
|
|
|
|
type Key
|
|
|
|
= Shift
|
|
|
|
| Enter
|
|
|
|
| Arrow Direction
|
|
|
|
| Tab
|
|
|
|
|
|
|
|
|
2020-06-20 00:42:28 +03:00
|
|
|
keyToString : Key -> String
|
|
|
|
keyToString key =
|
|
|
|
case key of
|
|
|
|
Shift ->
|
|
|
|
"Shift"
|
|
|
|
|
|
|
|
Enter ->
|
|
|
|
"Enter"
|
|
|
|
|
|
|
|
Arrow direction ->
|
|
|
|
directionToString direction ++ " arrow"
|
|
|
|
|
|
|
|
Tab ->
|
|
|
|
"Tab"
|
|
|
|
|
|
|
|
|
2020-06-20 00:35:53 +03:00
|
|
|
{-| -}
|
|
|
|
type Direction
|
|
|
|
= Up
|
|
|
|
| Right
|
|
|
|
| Down
|
|
|
|
| Left
|
|
|
|
|
|
|
|
|
2020-06-20 00:42:28 +03:00
|
|
|
directionToString : Direction -> String
|
|
|
|
directionToString direction =
|
|
|
|
case direction of
|
|
|
|
Up ->
|
|
|
|
"Up"
|
|
|
|
|
|
|
|
Right ->
|
|
|
|
"Right"
|
|
|
|
|
|
|
|
Down ->
|
|
|
|
"Down"
|
|
|
|
|
|
|
|
Left ->
|
|
|
|
"Left"
|