Skip to content

Instantly share code, notes, and snippets.

@crawftv
Created January 21, 2022 04:52
Show Gist options
  • Save crawftv/c35c6a64a0dd0faa6d0a494a69c67451 to your computer and use it in GitHub Desktop.
Save crawftv/c35c6a64a0dd0faa6d0a494a69c67451 to your computer and use it in GitHub Desktop.
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
type alias Model =
{
selectedGender : Gender
, selectedNumber : Number
, selectedCase : Case
}
type Number = NoNumber | Singular | Plural
type Gender = NoGender | Masculine | Feminine | Neuter
type Case = NoCase | Nominative | Genitive | Dative | Accusative | Vocative
initialModel : Model
initialModel =
{ selectedGender = NoGender
, selectedNumber = NoNumber
, selectedCase = NoCase
}
type Msg
= SelectGender Gender
| SelectNumber Number
| SelectCase Case
update : Msg -> Model -> Model
update msg model =
case msg of
SelectGender gender ->
{ model | selectedGender = gender }
SelectCase case_ ->
{ model | selectedCase = case_ }
SelectNumber number ->
{model | selectedNumber = number }
colorList =
[ ("#9b5de5", "white")
, ("#f15bb5","white")
, ("#ffe66d","black")
, ("#00bbf9","white")
, ("#00f5d4","black")
, ("#ff6b6b","white")
, ("#4f5d75","white")
]
genderList =
[ (Masculine, "masuline")
, (Feminine, "feminine")
, (Neuter, "neuter")
]
numberList =
[ (Singular, "singular")
, (Plural, "plural")
]
caseList =
[ (Nominative, "nominative")
, (Genitive, "genitive")
, (Dative, "dative")
, (Accusative, "accusative")
, (Vocative, "vocative")
]
zip x y = List.map2 Tuple.pair x y
view : Model -> Html Msg
view model =
div []
[ div []
(List.map (viewButtonColor model model.selectedGender SelectGender ) (zip genderList colorList))
, div []
(List.map (viewButtonColor model model.selectedNumber SelectNumber) (zip numberList colorList))
, div []
(List.map (viewButtonColor model model.selectedCase SelectCase) (zip caseList colorList))
]
-- viewTenseColor : Model -> ( ( Tense, String ), ( String, String ) ) -> Html Msg
viewButtonColor model selection message tup =
if Tuple.first (Tuple.first tup) == selection then
button
[ style "background-color" (Tuple.first (Tuple.second tup))
, style "color" (Tuple.second (Tuple.second tup))
]
[ text (Tuple.second (Tuple.first tup)) ]
else
button [ onClick (message (Tuple.first (Tuple.first tup) )) ]
[ text (Tuple.second (Tuple.first tup)) ]
main : Program () Model Msg
main =
Browser.sandbox
{ init = initialModel
, view = view
, update = update
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment