Skip to content

Instantly share code, notes, and snippets.

@noobymatze
Last active March 14, 2023 10:52
Show Gist options
  • Save noobymatze/4e6600ea69d7812af6ab to your computer and use it in GitHub Desktop.
Save noobymatze/4e6600ea69d7812af6ab to your computer and use it in GitHub Desktop.
{- Can be tested at: http://elm-lang.org/try
-}
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Signal exposing (Signal, Address)
import Random exposing (generate, int, Seed)
import String exposing (concat)
rotate : List a -> List a
rotate xs =
let first =
case List.head xs of
Just a -> [a]
Nothing -> []
in
(Maybe.withDefault [] (List.tail xs)) ++ first
wuensche =
[ "Herzlichen Glückwunsch und alles, alles Gute zum Geburtstag!!"
, "Happy Birthday too youuu, happy birthday to youu, happy birthday Timo, happy birthday too you!!"
, "Alles Gute zum Geburtstag und einen schönen Tag wünsche ich dir!"
]
type alias Model =
{ wuensche : List String
, text : String
}
type Action
= NoOp
| Next
update : Action -> Model -> Model
update action model =
case action of
NoOp -> model
Next ->
let next = Maybe.withDefault "Happy Birthday!" (List.head model.wuensche)
in
{ model | text <- next, wuensche <- rotate model.wuensche }
alignCenter =
[ ("display","flex")
, ("align-items", "center")
, ("justify-content", "center")
]
itemStyle =
[ ("max-width", "50%")
, ("font", "Georgia 16/24px")
]
buttonStyle =
[ ("position", "absolute")
, ("top", "0")
, ("right", "0")
, ("width", "100%")
, ("height", "30px")
, ("background", "lightgray")
, ("border", "none")
, ("cursor", "pointer")
]
view : Address Action -> Model -> Html
view address model =
div
[ style alignCenter ]
[ h1
[ style itemStyle ]
[ text model.text ]
, button
[ style buttonStyle, onClick address Next ]
[ text "Next" ]
]
actions : Signal.Mailbox Action
actions =
Signal.mailbox NoOp
initialModel : Model
initialModel =
let text = (Maybe.withDefault "" (List.head wuensche))
in
{ text = text
, wuensche = rotate wuensche
}
model : Signal Model
model =
Signal.foldp update initialModel actions.signal
main : Signal Html
main =
Signal.map (view actions.address) model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment