rundis/elm-bootstrap/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Bootstrap.Modal

Modals are streamlined, but flexible dialog prompts. They support a number of use cases from user notifications to completely custom content and feature a handful of helpful subcomponents, sizes, and more.

type alias Model =
    { modalState : Modal.State }




init : ( Model, Cmd Msg )
init =
    ( { modalState : Modal.initalState}, Cmd.none )




type Msg
    = ModalMsg Modal.State




update : Msg -> Model -> ( Model, Cmd msg )
update msg model =
    case msg of
        ModelMsg state ->
            ( { model | modalState = state }
            , Cmd.none
            )


view : Model -> Html msg
view model =
    Grid.container []
        [ Button.button
            [ Button.attrs [ onClick ModalMsg Modal.visibleState ] ]
            [ text "Show modal" ]


        , Modal.config ModalMsg
            |> Modal.small
            |> Modal.h5 [] [ text "Modal header" ]
            |> Modal.body []
                [ Grid.containerFluid []
                    [ Grid.simpleRow
                        [ Grid.col
                            [ Grid.colWidth Grid.colXsSix ]
                            [ text "Col 1" ]
                        , Grid.col
                            [ Grid.colWidth Grid.colXsSix ]
                            [ text "Col 2" ]
                        ]
                    ]
                ]
            |> Modal.footer []
                [ Button.button
                    [ Button.outlinePrimary
                    , Button.attr <| onClick <| ModalMsg Modal.hiddenState
                    ]
                    [ text "Close" ]
                ]
            |> Modal.view
        ]

NOTE: Don't try to open several modals at the same time. It probably won't end well.

Modal

view : State -> Config msg -> Html msg

Create a modal for your application

  • state The current view state of the modal. You need to keep track of this state in your model
  • config View configuration
config : (State -> msg) -> Config msg

Create an initial modal config. You can enrich the config by using the header, body, footer and option related functions.

type Config msg

Opaque type representing the view config for a model. Use the config function to create an inital config.

State

hiddenState : State

Ensures the modal is not displayed (it's still in the DOM though !)

visibleState : State

In this state the modal will be displayed

type State

Opaque representation of the view state of a modal

small : Config msg -> Config msg

Option to make a modal smaller than the default

large : Config msg -> Config msg

Option to make a modal larger than the default

type Option

Opaque type representing configuration options

h1 : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Creates a modal header with a h1 title child element

  • attributes List of attributes
  • children List of child elements
  • config configuration settings to configure header for
h2 : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Creates a modal header with a h2 title child element

  • attributes List of attributes
  • children List of child elements
  • config configuration settings to configure header for
h3 : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Creates a modal header with a h3 title child element

  • attributes List of attributes
  • children List of child elements
  • config configuration settings to configure header for
h4 : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Creates a modal header with a h4 title child element

  • attributes List of attributes
  • children List of child elements
  • config configuration settings to configure header for
h5 : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Creates a modal header with a h5 title child element

  • attributes List of attributes
  • children List of child elements
  • config configuration settings to configure header for
h6 : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Creates a modal header with a h6 title child element

  • attributes List of attributes
  • children List of child elements
  • config configuration settings to configure header for

Body

body : List (Attribute msg) -> List (Html msg) -> Config msg -> Config msg

Create a body for a modal, you would typically always create a body for a modal

  • attributes List of attributes
  • children List of child elements
  • config configuration settings to configure body for
type Body msg

Opaque type represetning a modal body