Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added two new animation types #453

Merged
merged 5 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading