Skip to content

Instantly share code, notes, and snippets.

@Chadtech
Created June 24, 2019 16:16
Show Gist options
  • Save Chadtech/672b32e44015f9169d01165734021e2a to your computer and use it in GitHub Desktop.
Save Chadtech/672b32e44015f9169d01165734021e2a to your computer and use it in GitHub Desktop.
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