Skip to content

Commit

Permalink
Improving animation states (#5329)
Browse files Browse the repository at this point in the history
* AnimationEnd | Null check SelectedSlide (#5312)

* SnackbarInfo Initialize IntervalBeforeClose correctly (#5313)

* ModalService | Refactor to capture the Action<ModalProviderParameterBuilder<TComponent>> and re-evaluate to sync with any user parameter changes (#5322)

* wip hiding and showing states

* Refactorting modal animations

* Use keyframes for BS5 and BS5 modal animation

* Combine animations for centered modals

* Fix Tailwind

* Reformat merge conflict

* Add comments

---------

Co-authored-by: David Moreira <[email protected]>
  • Loading branch information
stsrki and David-Moreira authored Feb 27, 2024
1 parent ff0567e commit da543e1
Show file tree
Hide file tree
Showing 37 changed files with 595 additions and 120 deletions.
4 changes: 1 addition & 3 deletions Source/Blazorise.AntDesign/AntDesignClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,9 +877,7 @@ public override string Display( DisplayType displayType, DisplayDefinition displ

public override string Modal() => "ant-modal-root";

public override string ModalFade() => Fade();

public override string ModalFade( bool animation ) => animation ? Fade() : null;
public override string ModalFade( bool showing, bool hiding ) => showing || hiding ? Fade() : null;

public override string ModalVisible( bool visible ) => null;

Expand Down
8 changes: 7 additions & 1 deletion Source/Blazorise.AntDesign/AntDesignStyleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ public class AntDesignStyleProvider : StyleProvider

public override int DefaultModalBackdropZIndex => 1000;

public override string ModalShow() => "display: block;";
public override string ModalShow( bool visible ) => visible ? "display: block" : null;

public override string ModalFade( bool showing, bool hiding ) => null;

public override string ModalAnimationDuration( bool animated, int animationDuration ) => animated
? $"--modal-animation-duration: {animationDuration}ms"
: "--modal-animation-duration: 0ms";

int ModalZIndexDiff => DefaultModalZIndex - DefaultModalBackdropZIndex;

Expand Down
8 changes: 5 additions & 3 deletions Source/Blazorise.Bootstrap/BootstrapClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,11 @@ public override string Display( DisplayType displayType, DisplayDefinition displ

public override string Modal() => "modal";

public override string ModalFade() => Fade();

public override string ModalFade( bool animation ) => animation ? Fade() : null;
public override string ModalFade( bool showing, bool hiding ) => showing
? "showing"
: hiding
? "hiding"
: null;

public override string ModalVisible( bool visible ) => visible ? Show() : null;

Expand Down
8 changes: 7 additions & 1 deletion Source/Blazorise.Bootstrap/BootstrapStyleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ public class BootstrapStyleProvider : StyleProvider

public override int DefaultModalBackdropZIndex => 1040;

public override string ModalShow() => "display: block";
public override string ModalShow( bool visible ) => null;

public override string ModalFade( bool showing, bool hiding ) => null;

public override string ModalAnimationDuration( bool animated, int animationDuration ) => animated
? $"--modal-animation-duration: {animationDuration}ms"
: "--modal-animation-duration: 0ms";

int ModalZIndexDiff => DefaultModalZIndex - DefaultModalBackdropZIndex;

Expand Down
90 changes: 86 additions & 4 deletions Source/Blazorise.Bootstrap/Styles/components/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,94 @@
}
}

&.fade {
transition: opacity var(--modal-animation-duration, 300ms) linear;
&.show {
display: block;

.modal-dialog {
transition: -webkit-transform var(--modal-animation-duration, 300ms) ease-out;
transition: transform var(--modal-animation-duration, 300ms) ease-out;
&:not(.modal-dialog-centered) {
animation: modal-slidein var(--modal-animation-duration, 300ms) ease-out;
}

&.modal-dialog-centered {
animation: modal-slidein, modal-slidein-centered var(--modal-animation-duration, 300ms) ease-out;
}
}
}

&:not(.show) {
display: none;
animation: modal-slideaway var(--modal-animation-duration, 300ms) linear;

.modal-dialog {
&:not(.modal-dialog-centered) {
animation: modal-slideaway var(--modal-animation-duration, 300ms) ease-out;
}

&.modal-dialog-centered {
animation: modal-slideaway, modal-slideaway-centered var(--modal-animation-duration, 300ms) ease-out;
}
}
}
}

.modal-backdrop.fade {
transition-property: opacity;
transition-duration: var(--modal-animation-duration, 300ms);
transition-timing-function: linear;
}

@keyframes modal-slidein {
0% {
display: none;
opacity: 0;
transform: $modal-fade-transform;
}

1% {
display: block;
opacity: 0;
}

100% {
opacity: 1;
}
}

@keyframes modal-slidein-centered {
0% {
display: none;
opacity: 0;
transform: $modal-fade-transform;
}

100% {
display: flex;
align-items: center;
opacity: 1;
}
}

@keyframes modal-slideaway {
from {
display: block;
opacity: 1;
}

to {
transform: $modal-fade-transform;
opacity: 0;
}
}

@keyframes modal-slideaway-centered {
from {
display: flex;
align-items: center;
opacity: 1;
}

to {
transform: $modal-fade-transform;
opacity: 0;
}
}
75 changes: 70 additions & 5 deletions Source/Blazorise.Bootstrap/wwwroot/blazorise.bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,79 @@ li.list-group-item-action {
.modal .modal-fullscreen .modal-footer {
border-radius: 0;
}
.modal.fade {
transition: opacity var(--modal-animation-duration, 300ms) linear;
.modal.show {
display: block;
}
.modal.show .modal-dialog:not(.modal-dialog-centered) {
animation: modal-slidein var(--modal-animation-duration, 300ms) ease-out;
}
.modal.show .modal-dialog.modal-dialog-centered {
animation: modal-slidein, modal-slidein-centered var(--modal-animation-duration, 300ms) ease-out;
}
.modal:not(.show) {
display: none;
animation: modal-slideaway var(--modal-animation-duration, 300ms) linear;
}
.modal.fade .modal-dialog {
transition: -webkit-transform var(--modal-animation-duration, 300ms) ease-out;
transition: transform var(--modal-animation-duration, 300ms) ease-out;
.modal:not(.show) .modal-dialog:not(.modal-dialog-centered) {
animation: modal-slideaway var(--modal-animation-duration, 300ms) ease-out;
}
.modal:not(.show) .modal-dialog.modal-dialog-centered {
animation: modal-slideaway, modal-slideaway-centered var(--modal-animation-duration, 300ms) ease-out;
}

.modal-backdrop.fade {
transition-property: opacity;
transition-duration: var(--modal-animation-duration, 300ms);
transition-timing-function: linear;
}

@keyframes modal-slidein {
0% {
display: none;
opacity: 0;
transform: translate(0, -50px);
}
1% {
display: block;
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes modal-slidein-centered {
0% {
display: none;
opacity: 0;
transform: translate(0, -50px);
}
100% {
display: flex;
align-items: center;
opacity: 1;
}
}
@keyframes modal-slideaway {
from {
display: block;
opacity: 1;
}
to {
transform: translate(0, -50px);
opacity: 0;
}
}
@keyframes modal-slideaway-centered {
from {
display: flex;
align-items: center;
opacity: 1;
}
to {
transform: translate(0, -50px);
opacity: 0;
}
}
.offcanvas, .offcanvas-xl, .offcanvas-lg, .offcanvas-md, .offcanvas-sm {
--offcanvas-zindex: 1045;
--offcanvas-width: 400px;
Expand Down

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Source/Blazorise.Bootstrap5/Bootstrap5ClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,11 @@ public override string Display( DisplayType displayType, DisplayDefinition displ

public override string Modal() => "modal";

public override string ModalFade() => Fade();

public override string ModalFade( bool animation ) => animation ? Fade() : null;
public override string ModalFade( bool showing, bool hiding ) => showing
? "showing"
: hiding
? "hiding"
: null;

public override string ModalVisible( bool visible ) => visible ? Show() : null;

Expand Down
8 changes: 7 additions & 1 deletion Source/Blazorise.Bootstrap5/Bootstrap5StyleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ public class Bootstrap5StyleProvider : StyleProvider

public override int DefaultModalBackdropZIndex => 1050;

public override string ModalShow() => "display: block;";
public override string ModalShow( bool visible ) => null;

public override string ModalFade( bool showing, bool hiding ) => null;

public override string ModalAnimationDuration( bool animated, int animationDuration ) => animated
? $"--modal-animation-duration: {animationDuration}ms"
: "--modal-animation-duration: 0ms";

int ModalZIndexDiff => DefaultModalZIndex - DefaultModalBackdropZIndex;

Expand Down
90 changes: 86 additions & 4 deletions Source/Blazorise.Bootstrap5/Styles/components/_modal.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,92 @@
.modal {
&.fade {
transition: opacity var(--modal-animation-duration, 300ms) linear;
&.show {
display: block;

.modal-dialog {
transition: -webkit-transform var(--modal-animation-duration, 300ms) ease-out;
transition: transform var(--modal-animation-duration, 300ms) ease-out;
&:not(.modal-dialog-centered) {
animation: modal-slidein var(--modal-animation-duration, 300ms) ease-out;
}

&.modal-dialog-centered {
animation: modal-slidein, modal-slidein-centered var(--modal-animation-duration, 300ms) ease-out;
}
}
}

&:not(.show) {
display: none;
animation: modal-slideaway var(--modal-animation-duration, 300ms) linear;

.modal-dialog {
&:not(.modal-dialog-centered) {
animation: modal-slideaway var(--modal-animation-duration, 300ms) ease-out;
}

&.modal-dialog-centered {
animation: modal-slideaway, modal-slideaway-centered var(--modal-animation-duration, 300ms) ease-out;
}
}
}
}

.modal-backdrop.fade {
transition-property: opacity;
transition-duration: var(--modal-animation-duration, 300ms);
transition-timing-function: linear;
}

@keyframes modal-slidein {
0% {
display: none;
opacity: 0;
transform: $modal-fade-transform;
}

1% {
display: block;
opacity: 0;
}

100% {
opacity: 1;
}
}

@keyframes modal-slidein-centered {
0% {
display: none;
opacity: 0;
transform: $modal-fade-transform;
}

100% {
display: flex;
align-items: center;
opacity: 1;
}
}

@keyframes modal-slideaway {
from {
display: block;
opacity: 1;
}

to {
transform: $modal-fade-transform;
opacity: 0;
}
}

@keyframes modal-slideaway-centered {
from {
display: flex;
align-items: center;
opacity: 1;
}

to {
transform: $modal-fade-transform;
opacity: 0;
}
}
Loading

0 comments on commit da543e1

Please sign in to comment.