-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathTooltip.razor.cs
More file actions
148 lines (121 loc) · 4.09 KB
/
Tooltip.razor.cs
File metadata and controls
148 lines (121 loc) · 4.09 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
namespace BlazorBootstrap;
public partial class Tooltip : BlazorBootstrapComponentBase
{
#region Fields and Constants
private TooltipColor color = default!;
private bool isFirstRenderComplete = false;
private DotNetObjectReference<Tooltip> objRef = default!;
private string? title;
#endregion
#region Methods
/// <inheritdoc />
protected override async ValueTask DisposeAsyncCore(bool disposing)
{
if (disposing)
{
try
{
if (IsRenderComplete)
await JSRuntime.InvokeVoidAsync("window.blazorBootstrap.tooltip.dispose", Element);
}
catch (JSDisconnectedException)
{
// do nothing
}
objRef?.Dispose();
}
await base.DisposeAsyncCore(disposing);
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("window.blazorBootstrap.tooltip.initialize", Element);
isFirstRenderComplete = true;
}
await base.OnAfterRenderAsync(firstRender);
}
protected override async Task OnInitializedAsync()
{
objRef ??= DotNetObjectReference.Create(this);
title = Title;
color = Color;
await base.OnInitializedAsync();
}
protected override async Task OnParametersSetAsync()
{
if (isFirstRenderComplete)
if (title != Title || color != Color)
{
title = Title;
color = Color;
await JSRuntime.InvokeVoidAsync("window.blazorBootstrap.tooltip.dispose", Element);
await JSRuntime.InvokeVoidAsync("window.blazorBootstrap.tooltip.update", Element);
}
}
public async Task ShowAsync()
{
await JSRuntime.InvokeVoidAsync("window.blazorBootstrap.tooltip.show", Element);
}
#endregion
#region Properties, Indexers
/// <summary>
/// Gets or sets the content to be rendered within the component.
/// <para>
/// Default value is <see langword="null"/>.
/// </para>
/// </summary>
[AddedVersion("1.0.0")]
[DefaultValue(null)]
[Description("Gets or sets the content to be rendered within the component.")]
[Parameter]
public RenderFragment? ChildContent { get; set; }
/// <summary>
/// Gets or sets the tooltip color.
/// <para>
/// Default value is <see cref="TooltipColor.None" />.
/// </para>
/// </summary>
[AddedVersion("1.10.0")]
[DefaultValue(TooltipColor.None)]
[Description("Gets or sets the tooltip color.")]
[Parameter]
public TooltipColor Color { get; set; } = TooltipColor.None;
private string colorClass => Color.ToTooltipColorClass()!;
/// <summary>
/// Gets or sets a value indicating whether to display the content as HTML instead of text.
/// <para>
/// Default value is <see langword="false"/>.
/// </para>
/// </summary>
[AddedVersion("2.1.0")]
[DefaultValue(false)]
[Description("Gets or sets a value indicating whether to display the content as HTML instead of text.")]
[Parameter]
public bool IsHtml { get; set; }
private string placement => Placement.ToTooltipPlacementName();
/// <summary>
/// Gets or sets the tooltip placement.
/// <para>
/// Default value is <see cref="TooltipPlacement.Top" />.
/// </para>
/// </summary>
[AddedVersion("1.0.0")]
[DefaultValue(TooltipPlacement.Top)]
[Description("Gets or sets the tooltip placement.")]
[Parameter]
public TooltipPlacement Placement { get; set; } = TooltipPlacement.Top;
/// <summary>
/// Displays informative text when users hover, focus, or tap an element.
/// <para>
/// Default value is <see langword="null"/>.
/// </para>
/// </summary>
[AddedVersion("1.0.0")]
[DefaultValue(null)]
[Description("Displays informative text when users hover, focus, or tap an element.")]
[EditorRequired]
[Parameter]
public string? Title { get; set; }
#endregion
}