-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExamplePage.razor
142 lines (117 loc) · 3.32 KB
/
ExamplePage.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@page "/ExamplePage"
<UseBackButton OnBack="OnBack" @bind-OnClickHandler="BackButtonClickHandler" />
@{
RenderFragment firstComponent =
@<div>
<h5>First Step</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<button type="button" style="float:right" @onclick="()=>ActiveComponent=Component.Second">Next →</button>
</div>;
RenderFragment secondComponent =
@<div>
<h5>Second Step</h5>
<p>Consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Click back or use browser back button.</p>
<button type="button" @onclick="BackButtonClickHandler">← Back</button>
</div>;
}
<div class="container">
<div class="card">
<h3>UseBackButton Demo</h3>
<hr />
@if (ActiveComponent == Component.First)
{
<div class="slide-in-left">
@firstComponent
</div>
}
@if (ActiveComponent == Component.Second)
{
<div class="slide-in-right">
@secondComponent
</div>
}
</div>
</div>
@code {
protected Func<Task> BackButtonClickHandler { get; set; } = null!;
private bool OnBack()
{
if (PreviousComponent == Component.None)
{
return false;
}
GoToPreviousComponent();
return true;
}
private Component _ActiveComponent = Component.First;
private Component ActiveComponent
{
get { return _ActiveComponent; }
set
{
PreviousComponent = _ActiveComponent;
_ActiveComponent = value;
if (ActiveComponent == Component.First)
{
PreviousComponent = Component.None;
}
StateHasChanged();
}
}
protected Component PreviousComponent { get; set; } = Component.None;
public void GoToPreviousComponent() => ActiveComponent = PreviousComponent;
protected enum Component
{
None,
First,
Second
}
}
<style>
/* Dont put styles in your components. See style scopes: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-7.0 */
.card {
border: 1px solid #ccc;
border-radius: 5px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
background-color: #fff;
width: 400px;
margin: 20px auto;
overflow: hidden;
}
.container {
display: flex;
justify-content: center;
padding-top: 20px;
}
@@keyframes slideInFromRight {
0% {
opacity: 0;
transform: translateX(100%);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
.slide-in-right {
animation: slideInFromRight 0.3s ease-out;
}
@@keyframes slideInFromLeft {
0% {
opacity: 0;
transform: translateX(-100%);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
.slide-in-left {
animation: slideInFromLeft 0.3s ease-out;
}
body {
font-family: "Helvetica Neue", Arial, sans-serif;
}
</style>