Skip to content

Commit

Permalink
Add Form.CheckboxField
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Oct 20, 2023
1 parent 0d7dc57 commit d78d41a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/UI/Form/CheckboxField.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module UI.Form.CheckboxField exposing (..)

import Html exposing (Html, div, input, label, small, text)
import Html.Attributes exposing (checked, class, type_)
import Maybe.Extra as MaybeE
import UI
import UI.Click as Click


type alias CheckboxField msg =
{ label : String
, helpText : Maybe String
, onChange : msg
, checked : Bool
}



-- CREATE


field : String -> Maybe String -> msg -> Bool -> CheckboxField msg
field =
CheckboxField



-- VIEW


view : CheckboxField msg -> Html msg
view checkboxField =
Click.view [ class "form-field checkbox-field" ]
[ div [ class "checkbox-field_checkbox" ]
[ input
[ type_ "checkbox"
, checked checkboxField.checked
]
[]
]
, div
[ class "label-and-help-text" ]
[ label [ class "label" ] [ text checkboxField.label ]
, MaybeE.unwrap UI.nothing (\ht -> small [ class "help-text" ] [ text ht ]) checkboxField.helpText
]
]
(Click.onClick checkboxField.onChange)

0 comments on commit d78d41a

Please sign in to comment.