about summary refs log tree commit diff
path: root/users/wpcarro/website/habit-screens/src/Utils.elm
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/website/habit-screens/src/Utils.elm')
-rw-r--r--users/wpcarro/website/habit-screens/src/Utils.elm37
1 files changed, 37 insertions, 0 deletions
diff --git a/users/wpcarro/website/habit-screens/src/Utils.elm b/users/wpcarro/website/habit-screens/src/Utils.elm
new file mode 100644
index 0000000000..23b13c224c
--- /dev/null
+++ b/users/wpcarro/website/habit-screens/src/Utils.elm
@@ -0,0 +1,37 @@
+module Utils exposing (..)
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Maybe.Extra
+
+
+type Strategy
+    = Always String
+    | When Bool String
+    | If Bool String String
+
+
+class : List Strategy -> Attribute msg
+class classes =
+    classes
+        |> List.map
+            (\strategy ->
+                case strategy of
+                    Always x ->
+                        Just x
+
+                    When True x ->
+                        Just x
+
+                    When False _ ->
+                        Nothing
+
+                    If True x _ ->
+                        Just x
+
+                    If False _ x ->
+                        Just x
+            )
+        |> Maybe.Extra.values
+        |> String.join " "
+        |> Html.Attributes.class