diff --git a/src/Modal.elm b/src/Modal.elm index c998b99..e6e2d7d 100755 --- a/src/Modal.elm +++ b/src/Modal.elm @@ -1,14 +1,13 @@ module Modal exposing ( ClosingAnimation(..) - , ClosingEffect(..) , Config , Model(..) , Msg , OpenedAnimation(..) , OpeningAnimation(..) , animationEnd - , closeModal , cancelModal + , closeModal , cmdGetWindowSize , initModel , newConfig @@ -20,7 +19,6 @@ module Modal exposing , setBodyHeight , setBodyWidth , setClosingAnimation - , setClosingEffect , setFooter , setFooterCss , setHeader @@ -108,6 +106,7 @@ type OpeningAnimation | FromRight | FromBottom | FromLeft + | FromNone type OpenedAnimation @@ -122,11 +121,7 @@ type ClosingAnimation | ToRight | ToBottom | ToLeft - - -type ClosingEffect - = WithoutAnimate - | WithAnimate + | ToNone type BodySettings @@ -163,7 +158,6 @@ type Config msg { openingAnimation : OpeningAnimation , openedAnimation : OpenedAnimation , closingAnimation : ClosingAnimation - , closingEffect : ClosingEffect , headerCss : String , header : Header msg , bodyCss : String @@ -186,7 +180,6 @@ newConfig tagger = { openingAnimation = FromTop , openedAnimation = OpenFromTop , closingAnimation = ToTop - , closingEffect = WithAnimate , headerCss = "" , header = text "" , bodyCss = "" @@ -215,10 +208,12 @@ closeModal : (Msg msg -> msg) -> msg closeModal fn = fn CloseModal + cancelModal : (Msg msg -> msg) -> msg cancelModal fn = fn CancelModal + animationEnd : (Msg msg -> msg) -> msg animationEnd fn = fn AnimationEnd @@ -237,11 +232,11 @@ just add Modal.update modalMsg model.modal in case updatedModal of - Canceled -> + Canceled -> ( { model | modal = updatedModal } -- Model was canceled , Cmd.batch [Cmd.map ModalMsg cmdModal] ) - Closed -> + Closed -> ( { model | modal = updatedModal, confirmed = True } -- Modal was confirmed/acknowledged , Cmd.batch [Cmd.map ModalMsg cmdModal] ) @@ -295,7 +290,7 @@ view modal = case modal of Opening (Config config) -> div [ modalFade ] - [ modalBodyView + [ modalBodyView (Just AnimationEnd) (openingAnimationClass config.openingAnimation config.modalBodySettings) (Config config) @@ -313,7 +308,6 @@ view modal = div [ modalFade , modalClose - , closingEffectClass config.closingEffect ] [ modalBodyView (Just AnimationEnd) @@ -328,7 +322,6 @@ view modal = div [ modalFade , modalClose - , closingEffectClass config.closingEffect ] [ modalBodyView (Just AnimationEnd) @@ -467,15 +460,6 @@ setClosingAnimation closing config = mapConfig fn config -setClosingEffect : ClosingEffect -> Config msg -> Config msg -setClosingEffect newClosingEffect config = - let - fn (Config c) = - Config { c | closingEffect = newClosingEffect } - in - mapConfig fn config - - setBodyWidth : Float -> Config msg -> Config msg setBodyWidth width config = let @@ -532,7 +516,7 @@ openingAnimationClass animation bodySettings = modalTopOpening bodySettings FromRight -> - modalRigthOpening bodySettings + modalRightOpening bodySettings FromBottom -> modalBottomOpening bodySettings @@ -540,6 +524,9 @@ openingAnimationClass animation bodySettings = FromLeft -> modalLeftOpening bodySettings + FromNone -> + modalNoneOpening bodySettings + openedAnimationClass : OpenedAnimation -> BodySettings -> Attribute msg openedAnimationClass animation bodySettings = @@ -548,7 +535,7 @@ openedAnimationClass animation bodySettings = modalOpenFromTop bodySettings OpenFromRight -> - modalOpenFromRigth bodySettings + modalOpenFromRight bodySettings OpenFromBottom -> modalOpenFromBottom bodySettings @@ -572,16 +559,8 @@ closingAnimationClass animation bodySettings = ToLeft -> modalLeftClosing bodySettings - -closingEffectClass : ClosingEffect -> Attribute msg -closingEffectClass animation = - case animation of - WithoutAnimate -> - css [ Css.display Css.none ] - - WithAnimate -> - css [] - + ToNone -> + modalNoneClosing bodySettings -- Private css style and animations for modal window @@ -646,8 +625,8 @@ modalTopOpening (BodySettings body) = ] -modalRigthOpening : BodySettings -> Attribute msg -modalRigthOpening (BodySettings body) = +modalRightOpening : BodySettings -> Attribute msg +modalRightOpening (BodySettings body) = css [ Css.animationName (Animations.keyframes @@ -724,6 +703,27 @@ modalLeftOpening (BodySettings body) = ] +modalNoneOpening : BodySettings -> Attribute msg +modalNoneOpening (BodySettings body) = + css + [ Css.animationName + (Animations.keyframes + [ ( 0 + , [ Animations.property "opacity" "0" + ] + ) + , ( 75 + , [ Animations.property "opacity" "1" + ] + ) + ] + ) + , Css.property "animation-duration" "0s" + , Css.property "top" body.center.value + , Css.position Css.absolute + ] + + -- Open animations @@ -754,8 +754,8 @@ modalOpenFromTop (BodySettings body) = ] -modalOpenFromRigth : BodySettings -> Attribute msg -modalOpenFromRigth (BodySettings body) = +modalOpenFromRight : BodySettings -> Attribute msg +modalOpenFromRight (BodySettings body) = css [ Css.property "right" body.center.value , Css.top body.fromTop @@ -892,6 +892,32 @@ modalLeftClosing (BodySettings body) = ] +modalNoneClosing : BodySettings -> Attribute msg +modalNoneClosing (BodySettings body) = + css + [ Css.animationName + (Animations.keyframes + [ ( 0 + , [ Animations.property "opacity" "1" + , Animations.property "left" body.center.value + , Animations.property "top" body.fromTop.value + ] + ) + , ( 100 + , [ Animations.property "opacity" "0" + , Animations.property "left" "0" + , Animations.property "top" body.fromTop.value + ] + ) + ] + ) + , Css.property "animation-duration" "0.0s" + , Css.opacity (Css.int 0) + , Css.position Css.absolute + , Css.top body.fromTop + ] + + -- Modal close animation @@ -991,7 +1017,7 @@ setModalState msg modal = if msg == CancelModal then Canceling config - else + else Closing config Closing _ -> @@ -1006,6 +1032,7 @@ setModalState msg modal = Canceled -> Canceled + {-| @priv Centering and adaptive width for modal body -}