forked from bitfoundation/bitplatform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitProPanel.razor.cs
More file actions
202 lines (157 loc) · 6 KB
/
BitProPanel.razor.cs
File metadata and controls
202 lines (157 loc) · 6 KB
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
namespace Bit.BlazorUI;
/// <summary>
/// ProPanel is an advanced version of normal Panel with additional features that tailored to more usual use-cases.
/// </summary>
public partial class BitProPanel : BitComponentBase
{
private bool _internIsOpen;
/// <summary>
/// Enables the auto scrollbar toggle behavior of the panel.
/// </summary>
[Parameter] public bool AutoToggleScroll { get; set; }
/// <summary>
/// The alias of the ChildContent.
/// </summary>
[Parameter] public RenderFragment? Body { get; set; }
/// <summary>
/// Whether the panel can be dismissed by clicking outside of it on the overlay.
/// </summary>
[Parameter] public bool Blocking { get; set; }
/// <summary>
/// The content of the panel.
/// </summary>
[Parameter] public RenderFragment? ChildContent { get; set; }
/// <summary>
/// Custom CSS classes for different parts of the panel.
/// </summary>
[Parameter] public BitProPanelClassStyles? Classes { get; set; }
/// <summary>
/// Gets or sets the icon to display in the close button using custom CSS classes for external icon libraries.
/// Takes precedence over <see cref="CloseIconName"/> when both are set.
/// </summary>
/// <remarks>
/// Use this property to render icons from external libraries like FontAwesome, Material Icons, or Bootstrap Icons.
/// For built-in Fluent UI icons, use <see cref="CloseIconName"/> instead.
/// </remarks>
[Parameter] public BitIconInfo? CloseIcon { get; set; }
/// <summary>
/// Gets or sets the name of the icon to display in the close button from the built-in Fluent UI icons.
/// </summary>
/// <remarks>
/// The icon name should be from the Fluent UI icon set (e.g., <c>BitIconName.Cancel</c>).
/// <br />
/// For external icon libraries, use <see cref="CloseIcon"/> instead.
/// </remarks>
[Parameter] public string? CloseIconName { get; set; }
/// <summary>
/// The template used to render the footer section of the panel.
/// </summary>
[Parameter] public RenderFragment? Footer { get; set; }
/// <summary>
/// The text of the footer section of the panel.
/// </summary>
[Parameter] public string? FooterText { get; set; }
/// <summary>
/// The template used to render the header section of the panel.
/// </summary>
[Parameter] public RenderFragment? Header { get; set; }
/// <summary>
/// The text of the header section of the panel.
/// </summary>
[Parameter] public string? HeaderText { get; set; }
/// <summary>
/// Determines the openness of the panel.
/// </summary>
[Parameter, TwoWayBound]
public bool IsOpen { get; set; }
/// <summary>
/// Renders the overlay in full mode that gives it an opaque background.
/// </summary>
[Parameter, ResetClassBuilder]
public bool ModeFull { get; set; }
/// <summary>
/// Removes the overlay element of the panel.
/// </summary>
[Parameter] public bool Modeless { get; set; }
/// <summary>
/// A callback function for when the panel is dismissed.
/// </summary>
[Parameter] public EventCallback<MouseEventArgs> OnDismiss { get; set; }
/// <summary>
/// A callback function for when the panel is opened.
/// </summary>
[Parameter] public EventCallback OnOpen { get; set; }
/// <summary>
/// The event callback for when the swipe action starts on the container of the panel.
/// </summary>
[Parameter] public EventCallback<decimal> OnSwipeStart { get; set; }
/// <summary>
/// The event callback for when the swipe action moves on the container of the panel.
/// </summary>
[Parameter] public EventCallback<decimal> OnSwipeMove { get; set; }
/// <summary>
/// The event callback for when the swipe action ends on the container of the panel.
/// </summary>
[Parameter] public EventCallback<decimal> OnSwipeEnd { get; set; }
/// <summary>
/// The position of the panel to show on the screen.
/// </summary>
[Parameter] public BitPanelPosition? Position { get; set; }
/// <summary>
/// The value of the height or width (based on the position) of the panel.
/// </summary>
[Parameter] public double? Size { get; set; }
/// <summary>
/// Specifies the element selector for which the panel disables its scroll if applicable.
/// </summary>
[Parameter] public string? ScrollerSelector { get; set; }
/// <summary>
/// Shows the close button of the panel.
/// </summary>
[Parameter] public bool ShowCloseButton { get; set; }
/// <summary>
/// Custom CSS styles for different parts of the panel component.
/// </summary>
[Parameter] public BitProPanelClassStyles? Styles { get; set; }
/// <summary>
/// The swiping point (difference percentage) based on the width of the panel container to trigger the close action (default is 0.25m).
/// </summary>
[Parameter] public decimal? SwipeTrigger { get; set; }
public async Task Open()
{
if (await AssignIsOpen(true) is false) return;
StateHasChanged();
}
public async Task Close()
{
if (await AssignIsOpen(false) is false) return;
StateHasChanged();
}
protected override string RootElementClass => "bit-ppl";
protected override void RegisterCssClasses()
{
ClassBuilder.Register(() => ModeFull ? "bit-ppl-mfl" : string.Empty);
}
protected override Task OnAfterRenderAsync(bool firstRender)
{
if (IsOpen)
{
if (_internIsOpen is false)
{
_internIsOpen = true;
OnOpen.InvokeAsync();
}
}
else
{
_internIsOpen = false;
}
return base.OnAfterRenderAsync(firstRender);
}
private async Task ClosePanel(MouseEventArgs e)
{
if (IsEnabled is false) return;
if (await AssignIsOpen(false) is false) return;
_ = OnDismiss.InvokeAsync(e);
}
}