Skip to content

Commit

Permalink
Added two new animation types (#453)
Browse files Browse the repository at this point in the history
* added two new animation types

* Update samples/BlazorWebAssembly/Pages/Animation.razor

Co-authored-by: Lars Koopmans <[email protected]>

---------

Co-authored-by: Lars Koopmans <[email protected]>
Co-authored-by: Chris Sainty <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2024
1 parent ccba267 commit 898e88d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
18 changes: 17 additions & 1 deletion samples/BlazorWebAssembly/Pages/Animation.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
</div>

<button @onclick="AnimationDefault" class="btn btn-primary">Fade-in Fade-Out (Default)</button>
<button @onclick="AnimationPopInOut" class="btn btn-primary">Pop-in Pop-Out</button>
<button @onclick="AnimationPopIn" class="btn btn-primary">Pop-in</button>
<button @onclick="NoAnimation" class="btn btn-secondary">None</button>

<p>
Expand All @@ -49,6 +51,20 @@
Modal.Show<Confirm>("Default Animation");
}

void AnimationPopInOut()
{
var options = new ModalOptions { AnimationType = ModalAnimationType.PopInOut };

Modal.Show<Confirm>("Animation Type: PopInOut", options);
}

void AnimationPopIn()
{
var options = new ModalOptions { AnimationType = ModalAnimationType.PopIn };

Modal.Show<Confirm>("Animation Type: PopIn", options);
}

void NoAnimation()
{
var options = new ModalOptions { AnimationType = ModalAnimationType.None };
Expand All @@ -65,4 +81,4 @@

Modal.Show<YesNoPromptAnimation>("Multiple Modals", options);
}
}
}
15 changes: 13 additions & 2 deletions src/Blazored.Modal/BlazoredModalInstance.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ public async Task CloseAsync(ModalResult modalResult)

await Task.Delay(400); // Needs to be a bit more than the animation time because of delays in the animation being applied between server and client (at least when using blazor server side), I think.
}
else if (AnimationType is ModalAnimationType.PopInOut)
{
OverlayAnimationClass += " pop-out";
StateHasChanged();

await Task.Delay(400);
}

await Parent.DismissInstance(Id, modalResult);
}
Expand Down Expand Up @@ -269,8 +276,12 @@ private string SetModalClass()
private ModalAnimationType SetAnimation()
=> Options.AnimationType ?? GlobalModalOptions.AnimationType ?? ModalAnimationType.FadeInOut;

private string SetAnimationClass()
=> AnimationType is ModalAnimationType.FadeInOut ? "fade-in" : string.Empty;
private string SetAnimationClass() => AnimationType switch
{
ModalAnimationType.FadeInOut => "fade-in",
ModalAnimationType.PopInOut or ModalAnimationType.PopIn => "pop-in",
_ => string.Empty,
};

private bool SetHideHeader()
{
Expand Down
39 changes: 38 additions & 1 deletion src/Blazored.Modal/BlazoredModalInstance.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,41 @@
100% {
opacity: 0;
}
}
}

.bm-container.pop-in .blazored-modal {
animation: 200ms ease-out 0s ModalPopIn;
}

.bm-container.pop-out .blazored-modal {
animation: 300ms ease-in 0s ModalPopOut;
transform: scale(0%);
}

@keyframes ModalPopIn {
0% {
transform: scale(0%);
}

50% {
transform: scale(110%);
}

100% {
transform: scale(100%);
}
}

@keyframes ModalPopOut {
0% {
transform: scale(100%);
}

50% {
transform: scale(110%);
}

100% {
transform: scale(0%);
}
}
4 changes: 3 additions & 1 deletion src/Blazored.Modal/Configuration/ModalAnimationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public enum ModalAnimationType
{
FadeInOut,
PopInOut,
PopIn,
None
}
}

0 comments on commit 898e88d

Please sign in to comment.