Skip to content

Commit

Permalink
Close modals with Escape
Browse files Browse the repository at this point in the history
  • Loading branch information
Ascani Carlo committed Jan 17, 2024
1 parent 50ad452 commit d6e0435
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/Umbra.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module Umbra exposing (main)

import Browser
import Browser.Events exposing (onKeyUp)
import FeatherIcons
import Hex
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick, onInput)
import Json.Decode as Decode
import Random


Expand Down Expand Up @@ -52,6 +54,8 @@ type Msg
| Guybrush
| CloseExportModal
| GotRandomColor Color
| PressedLetter Char
| PressedControl String


type ShadowParam
Expand Down Expand Up @@ -146,6 +150,20 @@ update msg model =
, Cmd.none
)

PressedControl "Escape" ->
( { model
| css = Nothing
, selectedShadowId = ""
}
, Cmd.none
)

PressedControl _ ->
( model, Cmd.none )

PressedLetter _ ->
( model, Cmd.none )



----------------------------------------------
Expand Down Expand Up @@ -212,7 +230,7 @@ main =
{ init = \_ -> ( initialModel, Cmd.none )
, view = view
, update = update
, subscriptions = \_ -> Sub.none
, subscriptions = \_ -> onKeyUp keyDecoder
}


Expand Down Expand Up @@ -610,3 +628,18 @@ randomColor =
colorToString : Color -> String
colorToString c =
"#" ++ Hex.toString c.r ++ Hex.toString c.g ++ Hex.toString c.b


keyDecoder : Decode.Decoder Msg
keyDecoder =
Decode.map toKey (Decode.field "key" Decode.string)


toKey : String -> Msg
toKey string =
case String.uncons string of
Just ( char, "" ) ->
PressedLetter char

_ ->
PressedControl string

0 comments on commit d6e0435

Please sign in to comment.