-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathFluentCompoundButton.razor.cs
More file actions
175 lines (147 loc) · 5.71 KB
/
FluentCompoundButton.razor.cs
File metadata and controls
175 lines (147 loc) · 5.71 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
// ------------------------------------------------------------------------
// This file is licensed to you under the MIT License.
// ------------------------------------------------------------------------
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
namespace Microsoft.FluentUI.AspNetCore.Components;
/// <summary>
/// A FluentUI AnchorButton component.
/// </summary>
public partial class FluentCompoundButton : FluentComponentBase, ITooltipComponent
{
/// <summary />
public FluentCompoundButton(LibraryConfiguration configuration) : base(configuration) { }
/// <summary />
protected string? ClassValue => DefaultClassBuilder
.Build();
/// <summary />
protected string? StyleValue => DefaultStyleBuilder
.AddStyle("background-color", BackgroundColor, when: () => !string.IsNullOrEmpty(BackgroundColor))
.AddStyle("color", Color, when: () => !string.IsNullOrEmpty(Color))
.Build();
/// <summary>
/// Gets or sets whether the button should be focused when the page is loaded.
/// </summary>
[Parameter]
public bool AutoFocus { get; set; } = false;
/// <summary>
/// Gets or sets the shape of the button.
/// The default value is `null`. Internally the component uses <see cref="ButtonShape.Rounded"/> as its default value.
/// </summary>
[Parameter]
public ButtonShape? Shape { get; set; }
/// <summary>
/// Gets or sets the size of the button.
/// The default value is `null`. Internally the component uses <see cref="ButtonSize.Medium"/> as its default value.
/// </summary>
[Parameter]
public ButtonSize? Size { get; set; }
/// <summary>
/// Gets or sets the name of the element.
/// Allows access by name from the associated form.
/// </summary>
[Parameter]
public string? Name { get; set; }
/// <summary>
/// Gets or sets the visual appearance.
/// The default value is `null`. Internally the component uses <see cref="ButtonAppearance.Outline"/> as its default value.
/// </summary>
[Parameter]
public ButtonAppearance? Appearance { get; set; }
/// <summary>
/// Gets or sets the background color of this button (overrides the <see cref="Appearance"/> property).
/// Set the value `rgba(0, 0, 0, 0)` to display a transparent button.
/// </summary>
[Parameter]
public string? BackgroundColor { get; set; }
/// <summary>
/// Gets or sets the color of the font (overrides the <see cref="Appearance"/> property).
/// </summary>
[Parameter]
public string? Color { get; set; }
/// <summary>
/// Gets or sets the <see cref="Icon"/> displayed at the start of button content.
/// </summary>
[Parameter]
public Icon? IconStart { get; set; }
/// <summary>
/// Gets or sets the <see cref="Icon"/> displayed at the end of button content.
/// </summary>
[Parameter]
public Icon? IconEnd { get; set; }
/// <summary>
/// Gets or sets the title of the button.
/// The text usually displayed in a `tooltip` popup when the mouse is over the button.
/// </summary>
[Parameter]
public string? Title { get; set; }
/// <summary>
/// Gets or sets the element's disabled state, ensuring it doesn't participate in form submission.
/// </summary>
[Parameter]
public bool Disabled { get; set; } = false;
/// <summary>
/// Gets or sets the value indicating the button is focusable.
/// </summary>
[Parameter]
public bool DisabledFocusable { get; set; } = false;
/// <summary>
/// Gets or sets a way to prevent further propagation of the current event in the capturing and bubbling phases.
/// </summary>
[Parameter]
public bool StopPropagation { get; set; } = false;
/// <summary>
/// Gets or sets a value indicating whether the button renders icon-only (no visible text label).
/// Typically used when <see cref="IconStart"/> or <see cref="IconEnd"/> is set and no text label is needed.
/// </summary>
[Parameter]
public bool IconOnly { get; set; }
/// <summary>
/// Gets or sets the plain-text label rendered as the primary button text (e.g., <c>Label="Open"</c>).
/// For rich content, use <see cref="ChildContent"/> instead. See also <see cref="Description"/> for secondary text.
/// </summary>
[Parameter]
public string? Label { get; set; }
/// <summary>
/// Gets or sets the secondary description content rendered below the primary label (e.g., a subtitle or hint).
/// See also <see cref="Label"/> for the primary button text.
/// </summary>
[Parameter]
public RenderFragment? Description { get; set; }
/// <summary>
/// Gets or sets the content to be rendered inside the button.
/// </summary>
[Parameter]
public RenderFragment? ChildContent { get; set; }
/// <summary>
/// Command executed when the user clicks on the button.
/// </summary>
[Parameter]
public EventCallback<MouseEventArgs> OnClick { get; set; }
/// <inheritdoc cref="ITooltipComponent.Tooltip" />
[Parameter]
public string? Tooltip { get; set; }
/// <summary />
protected override async Task OnInitializedAsync()
{
await base.RenderTooltipAsync(Tooltip);
}
/// <summary />
protected async Task OnClickHandlerAsync(MouseEventArgs e)
{
if (!Disabled && OnClick.HasDelegate)
{
await OnClick.InvokeAsync(e);
}
await Task.CompletedTask;
}
/// <summary>
/// Disables the button.
/// </summary>
/// <param name="disabled">True to disable the button</param>
public void SetDisabled(bool disabled)
{
Disabled = disabled;
StateHasChanged();
}
}