Created
June 24, 2019 16:16
-
-
Save Chadtech/672b32e44015f9169d01165734021e2a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Modal exposing | |
( view | |
, headerView | |
, Msg(..) | |
) | |
import Html.Styled exposing (Html) | |
import Html.Styled.Attributes as Attrs | |
type alias ViewParams msg = | |
{ style : List Style | |
, onClickOutside : msg | |
, children : List (Html msg) | |
} | |
view : ViewParams msg -> Html msg | |
view params = | |
Html.div | |
[ Attrs.css | |
[ defaultStyles | |
, params.style | |
] | |
, customOutsideClickHandler params.onClickOutside | |
] | |
params.children | |
type alias HeaderViewParams msg = | |
{ style : List Style | |
, onClickClose : msg | |
, title : String | |
} | |
headerView : HeaderViewParams msg -> Html msg | |
headerView params = | |
Html.div | |
[ Attr.css | |
[ defaultHeaderStyles | |
, params.style | |
] | |
] | |
[ headerTitle params.title | |
, headerCloseButton params.onClickClose | |
] | |
-- Useage -- | |
type alias Model = | |
{ showConfirmation : Bool } | |
type Msg | |
= ClickedOutsideModal | |
| ClickedModalCloseButton | |
view model = | |
-- .. | |
Modal.view | |
{ style = [] | |
, onClickOutside = ClickedOutsideModal | |
, children = | |
[ Modal.headerView | |
{ style = [] | |
, onClickClose = ClickedModalCloseButton | |
, title = "Confirm" | |
} | |
, Html.p | |
[] | |
[ Html.text "Are you sure you would like to quit?"] | |
, Button.view [] [ Html.text "Yes"] | |
, Button.view [] [ html.text "No"] | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment