From d78d41a8e1b8959485597a7e4c1c97ade56f9bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Fri, 20 Oct 2023 13:25:08 -0400 Subject: [PATCH] Add Form.CheckboxField --- src/UI/Form/CheckboxField.elm | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/UI/Form/CheckboxField.elm diff --git a/src/UI/Form/CheckboxField.elm b/src/UI/Form/CheckboxField.elm new file mode 100644 index 00000000..4a83e78d --- /dev/null +++ b/src/UI/Form/CheckboxField.elm @@ -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)