diff --git a/WaxComponents/WaxComponents.csproj b/WaxComponents/WaxComponents.csproj index 3046cbb..aaa7618 100644 --- a/WaxComponents/WaxComponents.csproj +++ b/WaxComponents/WaxComponents.csproj @@ -4,7 +4,7 @@ net7.0 enable enable - 0.1.0 + 0.1.1 WaxComponents lllggghhhaaa Simple components for blazor, free and opensource diff --git a/WaxComponents/WaxTab.razor b/WaxComponents/WaxTab.razor index 50af5a3..2865a5d 100644 --- a/WaxComponents/WaxTab.razor +++ b/WaxComponents/WaxTab.razor @@ -5,27 +5,4 @@
@_activeTab?.Content
- - -@code { - - [Parameter] - public RenderFragment? ChildContent { get; set; } - - [Parameter] - public string Style { get; set; } = String.Empty; - - private WaxTabItem? _activeTab; - - public void SetTab(WaxTabItem tab, bool initialization = false) - { - if (initialization && _activeTab is not null) return; - - _activeTab?.ChangeActive(false); - tab.ChangeActive(true); - - _activeTab = tab; - StateHasChanged(); - } - -} \ No newline at end of file + \ No newline at end of file diff --git a/WaxComponents/WaxTab.razor.cs b/WaxComponents/WaxTab.razor.cs new file mode 100644 index 0000000..5669337 --- /dev/null +++ b/WaxComponents/WaxTab.razor.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Components; + +namespace WaxComponents; + +public partial class WaxTab +{ + [Parameter] + public RenderFragment? ChildContent { get; set; } + + [Parameter] + public string Style { get; set; } = String.Empty; + + private List _tabs = new(); + + private WaxTabItem? _activeTab; + + public void RegisterTab(WaxTabItem tab) + { + _tabs.Add(tab); + + tab.SetAsLast(); + if (_tabs.Count == 1) + { + tab.SetAsFirst(); + SetTab(tab); + } + else + _tabs[^2].SetAsLast(true); + } + + public void SetTab(WaxTabItem tab) + { + _activeTab?.ChangeActive(false); + tab.ChangeActive(true); + + _activeTab = tab; + StateHasChanged(); + } +} \ No newline at end of file diff --git a/WaxComponents/WaxTab.razor.css b/WaxComponents/WaxTab.razor.css index 9221d6f..05e4d36 100644 --- a/WaxComponents/WaxTab.razor.css +++ b/WaxComponents/WaxTab.razor.css @@ -1,6 +1,7 @@ .waxTab { overflow: hidden; margin-top: 10px; + margin-left: 4px; } .waxTabContent { diff --git a/WaxComponents/WaxTabItem.razor b/WaxComponents/WaxTabItem.razor index ba653a1..2db6b99 100644 --- a/WaxComponents/WaxTabItem.razor +++ b/WaxComponents/WaxTabItem.razor @@ -1,45 +1,4 @@ - - -@code { - - [Parameter] - public RenderFragment? Text { get; set; } - - [Parameter] - public RenderFragment? Icon { get; set; } - - [Parameter] - public RenderFragment? Content { get; set; } - - [CascadingParameter] - public WaxTab? Parent { get; set; } - - [Parameter] - public string FontSize { get; set; } = "12px"; - - [Parameter] - public string Style { get; set; } = String.Empty; - - private string _bgColor = "white"; - - private void OnTabClicked() - { - if (Parent is not null) Parent.SetTab(this); - } - - protected override void OnInitialized() - { - if (Parent is not null) Parent.SetTab(this, true); - - base.OnInitialized(); - } - - public void ChangeActive(bool active) - { - _bgColor = active ? "rgba(255, 20, 147, 0.2) !important" : "white"; - } - -} \ No newline at end of file + \ No newline at end of file diff --git a/WaxComponents/WaxTabItem.razor.cs b/WaxComponents/WaxTabItem.razor.cs new file mode 100644 index 0000000..06a28a0 --- /dev/null +++ b/WaxComponents/WaxTabItem.razor.cs @@ -0,0 +1,45 @@ +using Microsoft.AspNetCore.Components; + +namespace WaxComponents; + +public partial class WaxTabItem +{ + [Parameter] + public RenderFragment? Text { get; set; } + + [Parameter] + public RenderFragment? Icon { get; set; } + + [Parameter] + public RenderFragment? Content { get; set; } + + [CascadingParameter] + public WaxTab? Parent { get; set; } + + [Parameter] + public string FontSize { get; set; } = "12px"; + + [Parameter] + public string Style { get; set; } = String.Empty; + + private string _bgColor = "white"; + private string _borderTopRight = "0"; + private string _borderTopLeft = "0"; + + protected override void OnInitialized() + { + if (Parent is not null) Parent.RegisterTab(this); + + base.OnInitialized(); + } + + public void ChangeActive(bool active) => _bgColor = active ? "rgba(255, 20, 147, 0.2) !important" : "white"; + + public void SetAsFirst(bool remove = false) => _borderTopLeft = remove ? "0" : "5px"; + public void SetAsLast(bool remove = false) => _borderTopRight = remove ? "0" : "5px"; + + private void OnTabClicked() + { + if (Parent is not null) Parent.SetTab(this); + } +} \ No newline at end of file diff --git a/WaxComponents/WaxTabItem.razor.css b/WaxComponents/WaxTabItem.razor.css index a1b990c..ffb33ba 100644 --- a/WaxComponents/WaxTabItem.razor.css +++ b/WaxComponents/WaxTabItem.razor.css @@ -1,7 +1,7 @@ .waxTabItem { display: flex; float: left; - margin-right: 1px; + margin-right: -1px; white-space: nowrap; padding: 2px 10px; @@ -9,7 +9,6 @@ border: 1px solid deeppink; border-bottom: none; - border-radius: 5px 5px 0 0; } .waxTabItem:hover {