|
|
@ -1,5 +1,4 @@
|
|
|
|
using Connected.Annotations;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Components.Rendering;
|
|
|
|
using Microsoft.AspNetCore.Components.Rendering;
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
|
|
|
|
|
|
|
@ -15,56 +14,80 @@ public class Element : UIComponent
|
|
|
|
/// Child content
|
|
|
|
/// Child content
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
[Category(CategoryTypes.Element.Misc)]
|
|
|
|
public RenderFragment? ChildContent { get; set; }
|
|
|
|
public RenderFragment ChildContent { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region EventCallbacks
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
|
|
public EventCallback<ElementReference> RefChanged { get; set; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Content placeholders
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// The HTML element that will be rendered in the root by the component
|
|
|
|
/// The Ref to bind to.
|
|
|
|
|
|
|
|
/// Usage: @bind-Ref="myRef"
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
[Category(CategoryTypes.Element.Misc)]
|
|
|
|
public ElementReference? Ref { get; set; }
|
|
|
|
public string HtmlTag { get; set; } = "span";
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Styling properties
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// The ElementReference to bind to.
|
|
|
|
/// A space separated list of class names, added on top of the default class list.
|
|
|
|
/// Use like @bind-Ref="myRef"
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
[Parameter]
|
|
|
|
[Parameter]
|
|
|
|
[Category(CategoryTypes.Element.Misc)]
|
|
|
|
public string? ClassList { get; set; }
|
|
|
|
public ElementReference? Ref { get; set; }
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Behavior properties
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// The HTML element that will be rendered in the root by the component
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
|
|
|
public string HtmlTag { get; set; } = "span";
|
|
|
|
|
|
|
|
|
|
|
|
[Parameter] public EventCallback<ElementReference> RefChanged { get; set; }
|
|
|
|
[Parameter]
|
|
|
|
|
|
|
|
public bool PreventOnClickPropagation { get; set; }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Calling StateHasChanged to refresh the component's state
|
|
|
|
/// Schedules a component's state refresh
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public void Refresh() => StateHasChanged();
|
|
|
|
public void Refresh() => StateHasChanged();
|
|
|
|
|
|
|
|
|
|
|
|
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
|
|
|
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
base.BuildRenderTree(builder);
|
|
|
|
base.BuildRenderTree(builder);
|
|
|
|
//Open
|
|
|
|
|
|
|
|
builder.OpenElement(0, HtmlTag);
|
|
|
|
builder.OpenElement(0, HtmlTag);
|
|
|
|
|
|
|
|
|
|
|
|
//splatted attributes
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Handle splatted attributes
|
|
|
|
|
|
|
|
*/
|
|
|
|
foreach (var attribute in CustomAttributes)
|
|
|
|
foreach (var attribute in CustomAttributes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// checking if the value is null, we can get rid of null event handlers
|
|
|
|
/*
|
|
|
|
// for example `@onmouseenter=@(IsOpen ? HandleEnter : null)`
|
|
|
|
* Checking if the value is null, we can get rid of null event handlers,
|
|
|
|
// this is a powerful feature that in normal HTML elements doesn't work, because
|
|
|
|
* for example `@onmouseenter=@(IsOpen ? HandleEnter : null)`.
|
|
|
|
// Blazor adds always the attribute value and creates an EventCallback
|
|
|
|
* This is a powerful feature that does not work in regular html elements
|
|
|
|
if (attribute.Value != null)
|
|
|
|
* because Blazor always adds the attribute value and creates an EventCallback.
|
|
|
|
|
|
|
|
* */
|
|
|
|
|
|
|
|
if (attribute.Value is not null)
|
|
|
|
builder.AddAttribute(1, attribute.Key, attribute.Value);
|
|
|
|
builder.AddAttribute(1, attribute.Key, attribute.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Class
|
|
|
|
|
|
|
|
builder.AddAttribute(2, "class", AdditionalClassList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StopPropagation
|
|
|
|
builder.AddAttribute(2, "class", ClassList);
|
|
|
|
// the order matters. This has to be before content is added
|
|
|
|
|
|
|
|
if (HtmlTag == "button")
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Stop onclock propagation for buttons. The order matters.
|
|
|
|
|
|
|
|
* This has to be before content is added
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (PreventOnClickPropagation)
|
|
|
|
builder.AddEventStopPropagationAttribute(5, "onclick", true);
|
|
|
|
builder.AddEventStopPropagationAttribute(5, "onclick", true);
|
|
|
|
|
|
|
|
|
|
|
|
//Reference capture
|
|
|
|
/*
|
|
|
|
if (Ref != null)
|
|
|
|
* Add reference capture propagation.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (Ref is not null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
builder.AddElementReferenceCapture(6, async capturedRef =>
|
|
|
|
builder.AddElementReferenceCapture(6, async capturedRef =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -73,10 +96,11 @@ public class Element : UIComponent
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Content
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Render child content
|
|
|
|
|
|
|
|
*/
|
|
|
|
builder.AddContent(10, ChildContent);
|
|
|
|
builder.AddContent(10, ChildContent);
|
|
|
|
|
|
|
|
|
|
|
|
//Close
|
|
|
|
|
|
|
|
builder.CloseElement();
|
|
|
|
builder.CloseElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|