onasty/web/src/Components/Form.elm (view raw)
Olexandr Smirnov
Olexandr Smirnov
ss2316544@gmail.com web: general refactor (#158)..., 11 months ago
ss2316544@gmail.com web: general refactor (#158)..., 11 months ago
| 1 | module Components.Form exposing (input) |
| 2 | |
| 3 | import Html as H exposing (Html) |
| 4 | import Html.Attributes as A |
| 5 | import Html.Events as E |
| 6 | |
| 7 | |
| 8 | input : |
| 9 | -- TODO: add `error : Maybe String`, to input to show that field is not correct and message |
| 10 | { id : String |
| 11 | , field : field |
| 12 | , label : String |
| 13 | , type_ : String |
| 14 | , value : String |
| 15 | , placeholder : String |
| 16 | , required : Bool |
| 17 | , helpText : Maybe String |
| 18 | , prefix : Maybe String |
| 19 | , onInput : String -> msg |
| 20 | } |
| 21 | -> Html msg |
| 22 | input opts = |
| 23 | H.div [ A.class "space-y-2" ] |
| 24 | [ H.label |
| 25 | [ A.for opts.id |
| 26 | , A.class "block text-sm font-medium text-gray-700" |
| 27 | ] |
| 28 | [ H.text opts.label ] |
| 29 | , H.div |
| 30 | [ A.class |
| 31 | (if opts.prefix /= Nothing then |
| 32 | "flex items-center" |
| 33 | |
| 34 | else |
| 35 | "" |
| 36 | ) |
| 37 | ] |
| 38 | [ case opts.prefix of |
| 39 | Just prefix -> |
| 40 | H.span [ A.class "text-gray-500 text-md mr-2 whitespace-nowrap" ] [ H.text prefix ] |
| 41 | |
| 42 | Nothing -> |
| 43 | H.text "" |
| 44 | , H.input |
| 45 | [ A.class "w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-black focus:border-transparent" |
| 46 | , A.type_ opts.type_ |
| 47 | , A.value opts.value |
| 48 | , A.id opts.id |
| 49 | , A.placeholder opts.placeholder |
| 50 | , A.required opts.required |
| 51 | , E.onInput opts.onInput |
| 52 | ] |
| 53 | [] |
| 54 | ] |
| 55 | , case opts.helpText of |
| 56 | Just help -> |
| 57 | H.p [ A.class "text-xs text-gray-500 mt-1" ] [ H.text help ] |
| 58 | |
| 59 | Nothing -> |
| 60 | H.text "" |
| 61 | ] |