added logging and minor cleanup
This commit is contained in:
43
Oqtane.Client/Modules/Controls/TabControl.razor
Normal file
43
Oqtane.Client/Modules/Controls/TabControl.razor
Normal file
@ -0,0 +1,43 @@
|
||||
@namespace Oqtane.Modules.Controls
|
||||
@inherits ThemeControlBase
|
||||
|
||||
<CascadingValue Value="this">
|
||||
<div>
|
||||
@foreach (TabPanel tabPanel in TabPanels)
|
||||
{
|
||||
<button type="button"
|
||||
class="btn @GetButtonClass(tabPanel)"
|
||||
@onclick=@( () => ActivateTabPanel(tabPanel) )>
|
||||
@tabPanel.Text
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
@ChildContent
|
||||
</CascadingValue>
|
||||
|
||||
@code {
|
||||
// Next line is needed so we are able to add <TabPanel> components inside
|
||||
[Parameter]
|
||||
public RenderFragment ChildContent { get; set; }
|
||||
|
||||
public TabPanel ActiveTabPanel { get; set; }
|
||||
List<TabPanel> TabPanels = new List<TabPanel>();
|
||||
|
||||
internal void AddTabPanel(TabPanel tabPanel)
|
||||
{
|
||||
TabPanels.Add(tabPanel);
|
||||
if (TabPanels.Count == 1)
|
||||
ActiveTabPanel = tabPanel;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
string GetButtonClass(TabPanel tabPanel)
|
||||
{
|
||||
return tabPanel == ActiveTabPanel ? "btn-primary" : "btn-secondary";
|
||||
}
|
||||
|
||||
void ActivateTabPanel(TabPanel tabPanel)
|
||||
{
|
||||
ActiveTabPanel = tabPanel;
|
||||
}
|
||||
}
|
27
Oqtane.Client/Modules/Controls/TabPanel.razor
Normal file
27
Oqtane.Client/Modules/Controls/TabPanel.razor
Normal file
@ -0,0 +1,27 @@
|
||||
@namespace Oqtane.Modules.Controls
|
||||
@inherits ThemeControlBase
|
||||
|
||||
@if (Parent.ActiveTabPanel == (TabPanel)(object)this)
|
||||
{
|
||||
@ChildContent
|
||||
}
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private TabControl Parent { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment ChildContent { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Text { get; set; }
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
if (Parent == null)
|
||||
throw new ArgumentNullException(nameof(Parent), "TabPanel must exist within a TabControl");
|
||||
|
||||
base.OnInitialized();
|
||||
Parent.AddTabPanel((TabPanel)(object)this);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user