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.
This commit is contained in:
parent
1c8a8f5d2c
commit
5684608fed
2 changed files with 63 additions and 17 deletions
|
|
@ -8,6 +8,7 @@ import Set
|
||||||
import State
|
import State
|
||||||
import Time exposing (Weekday(..))
|
import Time exposing (Weekday(..))
|
||||||
import UI
|
import UI
|
||||||
|
import Utils exposing (Strategy(..))
|
||||||
|
|
||||||
|
|
||||||
morning : List State.Habit
|
morning : List State.Habit
|
||||||
|
|
@ -201,14 +202,6 @@ habitsFor weekday =
|
||||||
toHabit saturday
|
toHabit saturday
|
||||||
|
|
||||||
Sun ->
|
Sun ->
|
||||||
|
|
||||||
tailwind : List ( String, Bool ) -> Attribute msg
|
|
||||||
tailwind classes =
|
|
||||||
classes
|
|
||||||
|> List.filter (\( k, v ) -> v)
|
|
||||||
|> List.map (\( k, v ) -> k)
|
|
||||||
|> String.join " "
|
|
||||||
|> class
|
|
||||||
toHabit sunday
|
toHabit sunday
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -220,8 +213,10 @@ render { today, visibleDayOfWeek, completed } =
|
||||||
|
|
||||||
Just weekday ->
|
Just weekday ->
|
||||||
div
|
div
|
||||||
[ class "container mx-auto py-6 px-6"
|
[ Utils.class
|
||||||
, tailwind [ ( "pt-20", today /= visibleDayOfWeek ) ]
|
[ Always "container mx-auto py-6 px-6"
|
||||||
|
, When (today /= visibleDayOfWeek) "pt-20"
|
||||||
|
]
|
||||||
]
|
]
|
||||||
[ header []
|
[ header []
|
||||||
[ if today /= visibleDayOfWeek then
|
[ if today /= visibleDayOfWeek then
|
||||||
|
|
@ -256,25 +251,39 @@ render { today, visibleDayOfWeek, completed } =
|
||||||
(weekday
|
(weekday
|
||||||
|> habitsFor
|
|> habitsFor
|
||||||
|> List.indexedMap
|
|> List.indexedMap
|
||||||
(\i x ->
|
(\i { label, minutesDuration } ->
|
||||||
|
let
|
||||||
|
isCompleted =
|
||||||
|
Set.member i completed
|
||||||
|
in
|
||||||
li [ class "text-xl list-disc ml-6" ]
|
li [ class "text-xl list-disc ml-6" ]
|
||||||
[ if today == visibleDayOfWeek then
|
[ if today == visibleDayOfWeek then
|
||||||
UI.button
|
UI.button
|
||||||
[ class "py-5 px-3"
|
[ class "py-5 px-3"
|
||||||
, tailwind
|
|
||||||
[ ( "line-through", Set.member i completed )
|
|
||||||
, ( "text-gray-400", Set.member i completed )
|
|
||||||
]
|
|
||||||
, onClick (State.ToggleHabit i)
|
, onClick (State.ToggleHabit i)
|
||||||
]
|
]
|
||||||
[ text x ]
|
[ span
|
||||||
|
[ Utils.class
|
||||||
|
[ Always "text-white pt-1 px-2 rounded"
|
||||||
|
, If isCompleted "bg-gray-400" "bg-blue-500"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
[ text (String.fromInt minutesDuration ++ " mins") ]
|
||||||
|
, p
|
||||||
|
[ Utils.class
|
||||||
|
[ Always "inline pl-3"
|
||||||
|
, When isCompleted "line-through text-gray-400"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
[ text label ]
|
||||||
|
]
|
||||||
|
|
||||||
else
|
else
|
||||||
UI.button
|
UI.button
|
||||||
[ class "py-5 px-3 cursor-not-allowed"
|
[ class "py-5 px-3 cursor-not-allowed"
|
||||||
, onClick State.DoNothing
|
, onClick State.DoNothing
|
||||||
]
|
]
|
||||||
[ text x ]
|
[ text label ]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
37
scratch/habit-screens/client/src/Utils.elm
Normal file
37
scratch/habit-screens/client/src/Utils.elm
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue