about summary refs log tree commit diff
path: root/scratch/habit-screens/client/src/Utils.elm
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-10-11T13·59+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-10-11T13·59+0100
commit5684608fedaf7d5cf0bebdb9494b5f6565e42e9c (patch)
treec5a18688a65ed9e60e88236bd45cd63f8ed621d8 /scratch/habit-screens/client/src/Utils.elm
parent1c8a8f5d2c2b9a20f679fa3bead491948571d5f2 (diff)
Move tailwind function into Utils module
Instead of accepting `List (String, Int)`, accept `List Strategy` where
`Strategy` defines whether or not the string of selectors should be applied to
the element.

I'm also renaming it `class` so I can just use `Utils.class`; `tailwind` has
little to do with the function itself.
Diffstat (limited to 'scratch/habit-screens/client/src/Utils.elm')
-rw-r--r--scratch/habit-screens/client/src/Utils.elm37
1 files changed, 37 insertions, 0 deletions
diff --git a/scratch/habit-screens/client/src/Utils.elm b/scratch/habit-screens/client/src/Utils.elm
new file mode 100644
index 000000000000..23b13c224c68
--- /dev/null
+++ b/scratch/habit-screens/client/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