about summary refs log tree commit diff
path: root/website/habit-screens/src/Utils.elm
blob: 23b13c224c68eb4ecb7a2933379aeefb101126af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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