nixCodeX/elm-bootstrap/2.0.1

NOTE: the latest version is 3.1.1

Renamed to aDifferentJT/elm-bootstrap. That is where the repository lives now. It has not been published as a package under the new name.

Versions published as nixCodeX/elm-bootstrap still install under that name. 13 versions of 13 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/aDifferentJT/elm-bootstrap.

What we checked: The repo moved to github.com/aDifferentJT/elm-bootstrap. Rebuilt with git archive from commit 77a30ed727b0 of https://github.com/aDifferentJT/elm-bootstrap (zip prefix nixCodeX-elm-bootstrap-77a30ed/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 d4637469f6c86d5f9055b35cec2e56a92970c868.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/nixCodeX/elm-bootstrap/zipball/2.0.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 =
    { modalVisibility : Modal.Visibility }


init : ( Model, Cmd Msg )
init =
    ( { modalVisibility = Modal.hidden }, Cmd.none )


type Msg
    = CloseModal
    | ShowModal


update : Msg -> Model -> ( Model, Cmd msg )
update msg model =
    case msg of
        CloseModal ->
            ( { model | modalVisibility = Modal.hidden }
            , Cmd.none
            )


        ShowModal ->
            ( { model | modalVisibility = Modal.shown }
            , Cmd.none
            )


view : Model -> Html msg
view model =
    Grid.container []
        [ Button.button
            [ Button.attrs [ onClick ShowModal ] ]
            [ text "Show modal" ]
        , Modal.config CloseModal
            |> Modal.small
            |> Modal.h5 [] [ text "Modal header" ]
            |> Modal.body []
                [ Grid.containerFluid []
                    [ Grid.row []
                        [ Grid.col
                            [ Col.xs6 ]
                            [ text "Col 1" ]
                        , Grid.col
                            [ Col.xs6 ]
                            [ text "Col 2" ]
                        ]
                    ]
                ]
            |> Modal.footer []
                [ Button.button
                    [ Button.outlinePrimary
                    , Button.attrs [ onClick CloseModal ]
                    ]
                    [ text "Close" ]
                ]
            |> Modal.view model.modalVisibility
        ]

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

Modal

view : Visibility -> Config msg -> Html msg

Create a modal for your application

  • show Whether to display the modal or not (if False the content is still in the dom, but hidden). You need to keep track of this state in your model
  • config View configuration
config : 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 initial config.

State

The modal should be hidden

The modal should be made visible.

Visibility state for the modal

Modal options

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

centered : Bool -> Config msg -> Config msg

If you don't like the modal vertically centered, override with False here!

hideOnBackdropClick : Bool -> Config msg -> Config msg

Option to trigger close message when the user clicks on the modal backdrop. Default True.

scrollableBody : Bool -> Config msg -> Config msg

Use this function to make the Modal body scrollable.

attrs : List (Attribute msg) -> Config msg -> Config msg

Use this function to add any Html.Attribute options you wish to the Modal

Header

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 representing a modal body

Footer

Animated Modals

When you want your modal to support an animation when displayed and closed. There is a few more things you must wire-up and keep in mind.

withAnimation : (Visibility -> msg) -> Config msg -> Config msg

Configure the modal to support fade-in/out animations. You'll need to provide a message to handle animation.

subscriptions : Visibility -> (Visibility -> msg) -> Sub msg

Subscription for handling animations

When using animations use this state for handling custom close buttons etc.

Button.button
    [ Button.outlinePrimary
    , Button.attrs [ onClick <| CloseModalAnimated Modal.hiddenAnimated ]
    ]
    [ text "Close" ]

Example

type Msg
    = ShowModal
      -- Note the extra msg constructor needed
    | AnimateModal Modal.Visibility
    | CloseModal


update : Msg -> State -> State
update msg state =
    case msg of
        CloseModal ->
            { state | modalVisibility = Modal.hidden }


        ShowModal ->
            { state | modalVisibility = Modal.shown }


        -- You need to handle the extra animation message
        AnimateModal visibility ->
            { state | modalVisibility = visibility }


-- Animations for modal doesn't work without a subscription.
-- DON´T forget this !
subscriptions : Model -> Sub msg
subscriptions model =
    Sub.batch
        [ Modal.subscriptions model.modalVisibility AnimateModal ]


view : Model -> Html msg
view model =
    Grid.container []
        [ Button.button
            [ Button.attrs [ onClick ShowModal ] ]
            [ text "Show modal" ]
        , Modal.config CloseModal
            |> Modal.h5 [] [ text "Modal header" ]
            |> Modal.body [] [ text "Modal body" ]
            |> Modal.footer []
                [ Button.button
                    [ Button.outlinePrimary
                    , Button.attrs [ onClick <| AnimateModal Modal.hiddenAnimated ]
                    ]
                    [ text "Close" ]
                ]
            |> Modal.view model.modalVisibility
        ]