-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlideTransition.razor
41 lines (32 loc) · 1.12 KB
/
SlideTransition.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@using BlazorTransitionGroup
@inherits TransitionBase
<Transition Key="Key" Context="transitionState" In="true">
<div style="@(GetActualStyle(transitionState))" class="@Class">
@ChildContent
</div>
</Transition>
@code {
string GetActualStyle(TransitionState state) {
var (x, opacity) = (GetX(state), GetOpacity(state));
return $"opacity: {opacity};transform:translateX({x});transition:opacity {Duration / 2}ms ease-in-out,transform {Duration}ms ease-in-out;{Style}";
}
string GetOpacity(TransitionState state) {
return state switch {
TransitionState.Entering or TransitionState.Entered => "1",
_ => "0",
};
}
double Duration => 800;
string GetX(TransitionState state) {
return state switch {
TransitionState.Entering or TransitionState.Entered => "0%",
_ => "-50%",
};
}
[Parameter]
public string? Style { get; set; }
[Parameter]
public string? Class { get; set; }
[Parameter]
public RenderFragment? ChildContent { get; set; }
}