about summary refs log tree commit diff
path: root/users/wpcarro/assessments/tt/client/src/UI.elm
blob: 7f8f379795f7b2f10c42eb0a4b8edfc9866eb104 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
module UI exposing (..)

import Date
import DatePicker exposing (defaultSettings)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import State
import Tailwind


label_ : { for_ : String, text_ : String } -> Html msg
label_ { for_, text_ } =
    label
        [ [ "block"
          , "text-gray-700"
          , "text-sm"
          , "font-bold"
          , "mb-2"
          ]
            |> Tailwind.use
            |> class
        , for for_
        ]
        [ text text_ ]


errorBanner : { title : String, body : String } -> Html msg
errorBanner { title, body } =
    div
        [ [ "text-left"
          , "fixed"
          , "container"
          , "top-0"
          , "mt-6"
          ]
            |> Tailwind.use
            |> class
        , style "left" "50%"

        -- TODO(wpcarro): Consider supporting breakpoints, but for now
        -- don't.
        , style "width" "800px"
        , style "margin-left" "-400px"
        ]
        [ div
            [ [ "bg-red-500"
              , "text-white"
              , "font-bold"
              , "rounded-t"
              , "px-4"
              , "py-2"
              ]
                |> Tailwind.use
                |> class
            ]
            [ text title ]
        , div
            [ [ "border"
              , "border-t-0"
              , "border-red-400"
              , "rounded-b"
              , "bg-red-100"
              , "px-4"
              , "py-3"
              , "text-red-700"
              ]
                |> Tailwind.use
                |> class
            ]
            [ p [] [ text body ] ]
        ]


baseButton :
    { label : String
    , enabled : Bool
    , handleClick : msg
    , extraClasses : List String
    }
    -> Html msg
baseButton { label, enabled, handleClick, extraClasses } =
    button
        [ [ if enabled then
                "bg-blue-500"

            else
                "bg-gray-500"
          , if enabled then
                "hover:bg-blue-700"

            else
                ""
          , if enabled then
                ""

            else
                "cursor-not-allowed"
          , "text-white"
          , "font-bold"
          , "py-1"
          , "shadow-lg"
          , "px-4"
          , "rounded"
          , "focus:outline-none"
          , "focus:shadow-outline"
          ]
            ++ extraClasses
            |> Tailwind.use
            |> class
        , onClick handleClick
        , disabled (not enabled)
        ]
        [ text label ]


simpleButton :
    { label : String
    , handleClick : msg
    }
    -> Html msg
simpleButton { label, handleClick } =
    baseButton
        { label = label
        , enabled = True
        , handleClick = handleClick
        , extraClasses = []
        }


disabledButton :
    { label : String }
    -> Html State.Msg
disabledButton { label } =
    baseButton
        { label = label
        , enabled = False
        , handleClick = State.DoNothing
        , extraClasses = []
        }


textButton :
    { label : String
    , handleClick : msg
    }
    -> Html msg
textButton { label, handleClick } =
    button
        [ [ "text-blue-600"
          , "hover:text-blue-500"
          , "font-bold"
          , "hover:underline"
          , "focus:outline-none"
          ]
            |> Tailwind.use
            |> class
        , onClick handleClick
        ]
        [ text label ]


textField :
    { pholder : String
    , inputId : String
    , handleInput : String -> msg
    , inputValue : String
    }
    -> Html msg
textField { pholder, inputId, handleInput, inputValue } =
    input
        [ [ "shadow"
          , "appearance-none"
          , "border"
          , "rounded"
          , "w-full"
          , "py-2"
          , "px-3"
          , "text-gray-700"
          , "leading-tight"
          , "focus:outline-none"
          , "focus:shadow-outline"
          ]
            |> Tailwind.use
            |> class
        , id inputId
        , value inputValue
        , placeholder pholder
        , onInput handleInput
        ]
        []


toggleButton :
    { toggled : Bool
    , label : String
    , handleEnable : msg
    , handleDisable : msg
    }
    -> Html msg
toggleButton { toggled, label, handleEnable, handleDisable } =
    button
        [ [ if toggled then
                "bg-blue-700"

            else
                "bg-blue-500"
          , "hover:bg-blue-700"
          , "text-white"
          , "font-bold"
          , "py-2"
          , "px-4"
          , "rounded"
          , "focus:outline-none"
          , "focus:shadow-outline"
          ]
            |> Tailwind.use
            |> class
        , onClick
            (if toggled then
                handleDisable

             else
                handleEnable
            )
        ]
        [ text label ]


paragraph : String -> Html msg
paragraph x =
    p [ [ "text-xl" ] |> Tailwind.use |> class ] [ text x ]


header : Int -> String -> Html msg
header which x =
    let
        hStyles =
            case which of
                1 ->
                    [ "text-6xl"
                    , "py-12"
                    ]

                2 ->
                    [ "text-3xl"
                    , "py-6"
                    ]

                _ ->
                    [ "text-2xl"
                    , "py-2"
                    ]
    in
    h1
        [ hStyles
            ++ [ "font-bold"
               , "text-gray-700"
               ]
            |> Tailwind.use
            |> class
        ]
        [ text x ]


link : String -> String -> Html msg
link path label =
    a
        [ href path
        , [ "underline"
          , "text-blue-600"
          , "text-xl"
          ]
            |> Tailwind.use
            |> class
        ]
        [ text label ]


absentData : { handleFetch : msg } -> Html msg
absentData { handleFetch } =
    div []
        [ paragraph "Welp... it looks like you've caught us in a state that we considered impossible: we did not fetch the data upon which this page depends. Maybe you can help us out by clicking the super secret, highly privileged \"Fetch data\" button below (we don't normally show people this)."
        , div [ [ "py-4" ] |> Tailwind.use |> class ]
            [ simpleButton
                { label = "Fetch data"
                , handleClick = handleFetch
                }
            ]
        ]


datePicker :
    { mDate : Maybe Date.Date
    , prompt : String
    , prefix : String
    , picker : DatePicker.DatePicker
    , onUpdate : DatePicker.Msg -> State.Msg
    }
    -> Html State.Msg
datePicker { mDate, prompt, prefix, picker, onUpdate } =
    let
        settings =
            { defaultSettings
                | placeholder = prompt
                , inputClassList =
                    [ ( "text-center", True )
                    , ( "py-2", True )
                    ]
            }
    in
    div [ [ "w-1/2", "py-4", "mx-auto" ] |> Tailwind.use |> class ]
        [ DatePicker.view mDate settings picker |> Html.map onUpdate ]


wrapNoPrint : Html State.Msg -> Html State.Msg
wrapNoPrint component =
    div [ [ "no-print" ] |> Tailwind.use |> class ] [ component ]