NoRedInk/noredink-ui/7.18.1

NOTE: the latest version is 35.9.3

Nri.Ui.Modal.V8

Changes from V7:

  • More customizable attributes
  • Rather than accepting any number of attributes, Modal provides one callback that returns a focusable
  • viewFooter has been merged into viewContent
  • viewContent and closeButton are now callbacks that are pre-configured with settings (previously you passed config through)
    import Html.Styled exposing (..)
    import Nri.Ui.Button.V9 as Button
    import Nri.Ui.Modal.V8 as Modal

    type Msg
        = ModalMsg Modal.Msg
        | DoSomething

    view : Modal.Model -> Html Msg
    view state =
        Modal.info
            { title = "Modal Header"
            , wrapMsg = ModalMsg
            , visibleTitle = True
            }
            (\{viewContent, closeButton} ->
                Modal.onlyFocusableElementView
                    (\{ onlyFocusableElement } ->
                        div []
                            [ viewContent {
                                , content = [ text "Content goes here!" ]
                                , footer =
                                    [ Button.button "Continue"
                                        [ Button.primary
                                        , Button.onClick DoSomething
                                        , Button.custom onlyFocusableElement
                                        ]
                                    , text "`onlyFocusableElement` will trap the focus on the 'Continue' button."
                                    ]
                                }
                                visibleTitle
                            ]
                    )
            )
            state

    subscriptions : Modal.Model -> Sub Msg
    subscriptions state =
        Modal.subscriptions state

    view init
    --> text ""  -- a closed modal

State and updates

type alias Model =
Model
init : Model
type alias Msg =
Msg
{ dismissOnEscAndOverlayClick : Bool }
-> Msg
-> Model
-> ( Model, Cmd Msg )
subscriptions : Model -> Sub Msg

Include the subscription if you want the modal to dismiss on Esc.

open : String -> Msg

Pass the id of the element that focus should return to when the modal closes.

close : Msg

Views

Modals

info : Config msg -> (ViewFuncs msg -> Focusable msg) -> Model -> Html msg
warning : Config msg -> (ViewFuncs msg -> Focusable msg) -> Model -> Html msg
type alias ViewFuncs msg =
{ viewContent :
{ content : List (Html msg)
, footer : List (Html msg)
}
-> Html msg
, closeButton : List (Attribute msg) -> Html msg
}

Focusable

type Focusable msg
( { firstFocusableElement : List (Attribute msg)
, lastFocusableElement : List (Attribute msg)
, autofocusElement : Attribute msg
}
-> Html msg
)
-> Focusable msg
onlyFocusableElementView : (List (Attribute msg) -> Html msg) -> Focusable msg

Modules