forked from radzenhq/radzen-blazor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRadzenAlert.razor.cs
224 lines (196 loc) · 6.75 KB
/
RadzenAlert.razor.cs
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using System;
using System.Threading.Tasks;
namespace Radzen.Blazor
{
/// <summary>
/// RadzenAlert component.
/// </summary>
/// <example>
/// <code>
/// <RadzenAlert>
/// <ChildContent>
/// Content
/// </ChildContent>
/// </RadzenAlert>
/// </code>
/// </example>
public partial class RadzenAlert : RadzenComponentWithChildren
{
private string GetAlertSize()
{
return Size == AlertSize.Medium ? "md" : Size == AlertSize.Large ? "lg" : Size == AlertSize.Small ? "sm" : "xs";
}
/// <summary>
/// Gets or sets a value indicating whether close is allowed. Set to <c>true</c> by default.
/// </summary>
/// <value><c>true</c> if close is allowed; otherwise, <c>false</c>.</value>
[Parameter]
public bool AllowClose { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether icon should be shown. Set to <c>true</c> by default.
/// </summary>
/// <value><c>true</c> if icon is shown; otherwise, <c>false</c>.</value>
[Parameter]
public bool ShowIcon { get; set; } = true;
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
[Parameter]
public string Title { get; set; }
/// <summary>
/// Gets or sets the text of the alert. Overriden by <see cref="RadzenComponentWithChildren.ChildContent" />.
/// </summary>
/// <value>The title.</value>
[Parameter]
public string Text { get; set; }
/// <summary>
/// Gets or sets the icon.
/// </summary>
/// <value>The icon.</value>
[Parameter]
public string Icon { get; set; }
/// <summary>
/// Gets or sets the icon color.
/// </summary>
/// <value>The icon color.</value>
[Parameter]
public string IconColor { get; set; }
/// <summary>
/// Gets or sets the severity.
/// </summary>
/// <value>The severity.</value>
[Parameter]
public AlertStyle AlertStyle { get; set; } = AlertStyle.Base;
/// <summary>
/// Gets or sets the design variant of the alert.
/// </summary>
/// <value>The variant of the alert.</value>
[Parameter]
public Variant Variant { get; set; } = Variant.Filled;
/// <summary>
/// Gets or sets the color shade of the alert.
/// </summary>
/// <value>The color shade of the alert.</value>
[Parameter]
public Shade Shade { get; set; } = Shade.Default;
/// <summary>
/// Gets or sets the size.
/// </summary>
/// <value>The size.</value>
[Parameter]
public AlertSize Size { get; set; } = AlertSize.Medium;
ButtonSize GetCloseButtonSize()
{
return Size == AlertSize.ExtraSmall ? ButtonSize.ExtraSmall : ButtonSize.Small;
}
Shade GetCloseButtonShade()
{
if (Shade == Shade.Light || Shade == Shade.Lighter)
{
return Shade.Darker;
}
else
{
return Shade.Default;
}
}
ButtonStyle GetCloseButtonStyle()
{
if (Shade == Shade.Light || Shade == Shade.Lighter)
{
switch (AlertStyle)
{
case AlertStyle.Success:
return ButtonStyle.Success;
case AlertStyle.Danger:
return ButtonStyle.Danger;
case AlertStyle.Warning:
return ButtonStyle.Warning;
case AlertStyle.Info:
return ButtonStyle.Info;
case AlertStyle.Primary:
return ButtonStyle.Primary;
case AlertStyle.Secondary:
return ButtonStyle.Secondary;
case AlertStyle.Light:
case AlertStyle.Base:
return ButtonStyle.Dark;
default:
return ButtonStyle.Light;
}
}
else
{
switch (AlertStyle)
{
case AlertStyle.Light:
case AlertStyle.Base:
return ButtonStyle.Dark;
default:
return ButtonStyle.Light;
}
}
}
bool visible;
/// <inheritdoc />
protected override void OnInitialized()
{
base.OnInitialized();
visible = Visible;
}
/// <inheritdoc />
protected override string GetComponentCssClass()
{
return $"rz-alert rz-alert-{GetAlertSize()} rz-variant-{Enum.GetName(typeof(Variant), Variant).ToLowerInvariant()} rz-{Enum.GetName(typeof(AlertStyle), AlertStyle).ToLowerInvariant()} rz-shade-{Enum.GetName(typeof(Shade), Shade).ToLowerInvariant()}";
}
string GetIcon()
{
if (!string.IsNullOrEmpty(Icon))
{
return Icon;
}
switch (AlertStyle)
{
case AlertStyle.Success:
return "check_circle";
case AlertStyle.Danger:
return "error";
case AlertStyle.Warning:
return "warning_amber";
case AlertStyle.Info:
return "info";
default:
return "lightbulb";
}
}
async Task OnClose()
{
visible = false;
await VisibleChanged.InvokeAsync(false);
await Close.InvokeAsync(null);
}
/// <summary>
/// Gets or sets the callback which is invoked when the alert is shown or hidden.
/// </summary>
[Parameter]
public EventCallback<bool> VisibleChanged { get; set; }
/// <summary>
/// Gets or sets the callback which is invoked when the alert is closed by the user.
/// </summary>
[Parameter]
public EventCallback Close { get; set; }
/// <inheritdoc />
public override async Task SetParametersAsync(ParameterView parameters)
{
var visibleChanged = parameters.DidParameterChange(nameof(Visible), Visible);
await base.SetParametersAsync(parameters);
if (visibleChanged)
{
visible = Visible;
}
}
}
}