about summary refs log tree commit diff
path: root/scratch
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-10-11T09·15+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-10-11T09·15+0100
commit0a15ea736611b60a2e30001a03c85c9940584494 (patch)
tree6ee3b6b633115c6f844231b768fb56d13b905926 /scratch
parent106457de4b5fc8172ce302eaa61c7625150e67a1 (diff)
Create UI module for common components
Create UI.elm to house components like `button`, which is a simple HTML button
with `focus:outline-none` applied as a `class`, which is an accessibility
feature that I don't need for this touch-screen application.

I like this pattern more than my more opinionated patterns for UI modules in Elm
where I'd define all of the arguments as a record type (i.e. kwargs).
Diffstat (limited to 'scratch')
-rw-r--r--scratch/habit-screens/client/src/Habits.elm35
-rw-r--r--scratch/habit-screens/client/src/UI.elm9
2 files changed, 27 insertions, 17 deletions
diff --git a/scratch/habit-screens/client/src/Habits.elm b/scratch/habit-screens/client/src/Habits.elm
index 88a3d686912f..a24b6d772f11 100644
--- a/scratch/habit-screens/client/src/Habits.elm
+++ b/scratch/habit-screens/client/src/Habits.elm
@@ -7,6 +7,7 @@ import Html.Events exposing (..)
 import Set
 import State
 import Time exposing (Weekday(..))
+import UI
 
 
 morning : List State.Habit
@@ -154,7 +155,7 @@ render { today, visibleDayOfWeek, completed } =
                         div [ class "text-center w-full bg-blue-600 text-white fixed top-0 left-0 px-3 py-4" ]
                             [ p [ class "py-2 inline pr-5" ]
                                 [ text "As you are not viewing today's habits, the UI is in read-only mode" ]
-                            , button
+                            , UI.button
                                 [ class "bg-blue-200 px-4 py-2 rounded text-blue-600 text-xs font-bold"
                                 , onClick State.ViewToday
                                 ]
@@ -164,40 +165,40 @@ render { today, visibleDayOfWeek, completed } =
                       else
                         text ""
                     , div [ class "flex center" ]
-                        [ button
+                        [ UI.button
                             [ class "w-1/4 text-gray-500"
                             , onClick State.ViewPrevious
                             ]
                             [ text "‹ previous" ]
                         , h1 [ class "font-bold text-gray-500 text-3xl text-center w-full" ]
                             [ text (weekdayName weekday) ]
-                        , button
+                        , UI.button
                             [ class "w-1/4 text-gray-500"
                             , onClick State.ViewNext
                             ]
                             [ text "next ›" ]
                         ]
                     ]
-                , ul []
+                , ul [ class "pt-6" ]
                     (weekday
                         |> habitsFor
                         |> List.indexedMap
                             (\i x ->
                                 li [ class "text-xl list-disc ml-6" ]
-                                    [ button
-                                        [ class "py-5 px-3"
-                                        , tailwind
-                                            [ ( "line-through", today == visibleDayOfWeek && Set.member i completed )
+                                    [ if today == visibleDayOfWeek then
+                                        UI.button
+                                            [ class "py-5 px-3"
+                                            , tailwind [ ( "line-through", Set.member i completed ) ]
+                                            , onClick (State.ToggleHabit i)
                                             ]
-                                        , onClick
-                                            (if today /= visibleDayOfWeek then
-                                                State.DoNothing
-
-                                             else
-                                                State.ToggleHabit i
-                                            )
-                                        ]
-                                        [ text x ]
+                                            [ text x ]
+
+                                      else
+                                        UI.button
+                                            [ class "py-5 px-3 cursor-not-allowed"
+                                            , onClick State.DoNothing
+                                            ]
+                                            [ text x ]
                                     ]
                             )
                     )
diff --git a/scratch/habit-screens/client/src/UI.elm b/scratch/habit-screens/client/src/UI.elm
new file mode 100644
index 000000000000..5b5426913570
--- /dev/null
+++ b/scratch/habit-screens/client/src/UI.elm
@@ -0,0 +1,9 @@
+module UI exposing (..)
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+
+
+button : List (Attribute msg) -> List (Html msg) -> Html msg
+button attrs children =
+    Html.button ([ class "focus:outline-none" ] ++ attrs) children