diff --git a/elm-package.json b/elm-package.json index 10341207..1a7bf00b 100644 --- a/elm-package.json +++ b/elm-package.json @@ -1,5 +1,5 @@ { - "version": "5.15.0", + "version": "5.16.0", "summary": "UI Widgets we use at NRI", "repository": "https://github.com/NoRedInk/noredink-ui.git", "license": "BSD3", @@ -30,6 +30,7 @@ "Nri.Ui.InputStyles", "Nri.Ui.Modal.V1", "Nri.Ui.Modal.V2", + "Nri.Ui.Modal.V3", "Nri.Ui.Outline.V1", "Nri.Ui.Page.V1", "Nri.Ui.Palette.V1", diff --git a/src/Nri/Ui/Modal/V3.elm b/src/Nri/Ui/Modal/V3.elm new file mode 100644 index 00000000..32c84307 --- /dev/null +++ b/src/Nri/Ui/Modal/V3.elm @@ -0,0 +1,245 @@ +module Nri.Ui.Modal.V3 + exposing + ( Model + , info + , warning + ) + +{-| Changes from V2: + + - Add assets for close button + +@docs Model +@docs info +@docs warning + +-} + +import Accessibility.Styled as Html exposing (..) +import Accessibility.Styled.Role as Role +import Accessibility.Styled.Widget as Widget +import Css +import Css.Foreign exposing (Snippet, body, children, descendants, everything, selector) +import Html.Styled +import Html.Styled.Events exposing (onClick) +import Nri.Ui +import Nri.Ui.AssetPath exposing (Asset(..)) +import Nri.Ui.Colors.Extra +import Nri.Ui.Colors.V1 +import Nri.Ui.Fonts.V1 as Fonts +import Nri.Ui.Icon.V3 as Icon + + +{-| + + - `onDismiss`: If `Nothing`, the modal will not be dismissable + - `visibleTitle`: If `False`, the title will still be used for screen readers + - `content`: This will be placed in a `width:100%` div in the main area of the modal + - `footerContent`: The optional items here will be stacked below the main content area and center-aligned. + Commonly you will either give a list of Nri.Ui.Buttons, + or an empty list. + +-} +type alias Model msg = + { title : String + , visibleTitle : Bool + , content : Html msg + , footerContent : List (Html msg) + , onDismiss : Maybe msg + , width : Maybe Int + } + + +type alias Assets r = + { r | icons_xBlue_svg : Asset } + + +type ModalType + = Info + | Warning + + +{-| -} +info : Assets r -> Model msg -> Html msg +info assets = + view assets Info + + +{-| -} +warning : Assets r -> Model msg -> Html msg +warning assets = + view assets Warning + + +view : Assets r -> ModalType -> Model msg -> Html msg +view assets modalType { title, visibleTitle, content, onDismiss, footerContent, width } = + Nri.Ui.styled div + "modal-backdrop-container" + ((case modalType of + Info -> + Css.backgroundColor (Nri.Ui.Colors.Extra.withAlpha 0.9 Nri.Ui.Colors.V1.navy) + + Warning -> + Css.backgroundColor (Nri.Ui.Colors.Extra.withAlpha 0.9 Nri.Ui.Colors.V1.gray20) + ) + :: [ Css.height (Css.vh 100) + , Css.left Css.zero + , Css.overflow Css.hidden + , Css.position Css.fixed + , Css.top Css.zero + , Css.width (Css.pct 100) + , Css.zIndex (Css.int 200) + , Css.displayFlex + , Css.alignItems Css.center + , Css.justifyContent Css.center + ] + ) + [ Role.dialog + , Widget.label title + , Widget.modal True + ] + [ Nri.Ui.styled Html.Styled.div + "modal-click-catcher" + [ Css.bottom Css.zero + , Css.left Css.zero + , Css.position Css.absolute + , Css.right Css.zero + , Css.top Css.zero + ] + (case onDismiss of + Nothing -> + [] + + Just msg -> + [ onClick msg ] + ) + [] + , Nri.Ui.styled div + "modal-container" + [ Css.width (Css.px 600) + , Css.maxHeight <| Css.calc (Css.vh 100) Css.minus (Css.px 100) + , Css.padding4 (Css.px 35) Css.zero (Css.px 25) Css.zero + , Css.margin2 (Css.px 75) Css.auto + , Css.backgroundColor Nri.Ui.Colors.V1.white + , Css.borderRadius (Css.px 20) + , Css.property "box-shadow" "0 1px 10px 0 rgba(0, 0, 0, 0.35)" + , Css.position Css.relative -- required for closeButtonContainer + , Css.displayFlex + , Css.alignItems Css.center + , Css.flexDirection Css.column + , Css.flexWrap Css.noWrap + , Fonts.baseFont + ] + [] + [ -- This global