@namespace Connected.Components
@using Connected.Annotations;
@inherits UIComponent
@implements IAsyncDisposable
@if (Parent?.KeepPanelsAlive == true)
{
@ChildContent
}
else
{
@if (Parent?.ActivePanel == this)
{
@ChildContent
}
}
@code {
private Boolean _disposed;
[CascadingParameter] private Tabs Parent { get; set; }
public ElementReference PanelRef;
///
/// Text will be displayed in the TabPanel as TabTitle.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public string Text { get; set; }
///
/// Icon placed before the text if set.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public string Icon { get; set; }
///
/// If true, the tabpanel will be disabled.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public bool Disabled { get; set; }
///
/// Optional information to be showed into a badge
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public object BadgeData { get; set; }
///
/// Optional information to show the badge as a dot.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public bool BadgeDot { get; set; }
///
/// The color of the badge.
///
[Parameter]
[Category(CategoryTypes.Tabs.Appearance)]
public ThemeColor BadgeColor { get; set; } = ThemeColor.Primary;
///
/// Unique TabPanel ID. Useful for activation when Panels are dynamically generated.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public object ID { get; set; }
///
/// Raised when tab is clicked
///
[Parameter] public EventCallback OnClick { get; set; }
///
/// Child content of component.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public RenderFragment ChildContent { get; set; }
///
/// Tab content of component.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public RenderFragment TabContent { get; set; }
///
/// Tab content wrapper of component. It is used to wrap the content of a tab heading in a user supplied div or component.
/// Use @context in the TabWrapperContent to render the tab header within your custom wrapper.
/// This is most useful with tooltips, which must wrap the entire content they refer to.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public RenderFragment TabWrapperContent { get; set; }
///
/// TabPanel Tooltip. It will be ignored if TabContent is provided.
///
[Parameter]
[Category(CategoryTypes.Tabs.Behavior)]
public string ToolTip { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if(firstRender == true && Parent != null)
{
await Parent.SetPanelRef(PanelRef);
}
}
protected override void OnInitialized()
{
// NOTE: we must not throw here because we need the component to be able to live for the API docs to be able to infer default values
//if (Parent == null)
// throw new ArgumentNullException(nameof(Parent), "TabPanel must exist within a Tabs component");
base.OnInitialized();
Parent?.AddPanel(this);
}
public async ValueTask DisposeAsync()
{
if(_disposed == true) { return; }
_disposed = true;
await Parent?.RemovePanel(this);
}
}