From 0671e34c7650008aa063fa0145cee62d4a981dd7 Mon Sep 17 00:00:00 2001 From: m-akinc <7282195+m-akinc@users.noreply.github.com> Date: Wed, 25 Jan 2023 11:24:46 -0600 Subject: [PATCH] Anchor tabs Blazor support (#989) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🤨 Rationale Blazor support for anchor tabs component ## 👩‍💻 Implementation - Adds components NimbleAnchorTabs and NimbleAnchorTab - A few tests - Add to example app - Update README ## 🧪 Testing Ran tests and exercised example app. ## ✅ Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed. --- README.md | 2 +- ...-7ee25a1b-7b0f-4aa5-afe8-afa7bed38547.json | 7 ++ .../Demo.Shared/Pages/ComponentsDemo.razor | 30 ++++++-- .../Demo.Shared/Pages/ComponentsDemo.razor.cs | 1 + .../Components/NimbleAnchorTab.razor | 6 ++ .../Components/NimbleAnchorTab.razor.cs | 27 ++++++++ .../Components/NimbleAnchorTabs.razor | 6 ++ .../Components/NimbleAnchorTabs.razor.cs | 27 ++++++++ .../Unit/Components/NimbleAnchorTabsTests.cs | 69 +++++++++++++++++++ 9 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 change/@ni-nimble-blazor-7ee25a1b-7b0f-4aa5-afe8-afa7bed38547.json create mode 100644 packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor create mode 100644 packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor.cs create mode 100644 packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor create mode 100644 packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor.cs create mode 100644 packages/nimble-blazor/Tests/NimbleBlazor.Tests/Unit/Components/NimbleAnchorTabsTests.cs diff --git a/README.md b/README.md index 35f11845de..499cd00919 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ NOTE: To update the component status: | Accordion | | [Issue](https://github.com/ni/nimble/issues/533) | :o: | :o: | :o: | | Anchor | [XD](https://xd.adobe.com/view/33ffad4a-eb2c-4241-b8c5-ebfff1faf6f6-66ac/screen/bfadf499-caf5-4ca0-9814-e777fbae0d46/) | [Issue](https://github.com/ni/nimble/issues/324) | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/docs/anchor--text-anchor) | :white_check_mark: | :white_check_mark: | | Anchor Button | | [Issue](https://github.com/ni/nimble/issues/324) | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/docs/anchor-button--outline-anchor-button) | :white_check_mark: | :white_check_mark: | -| Anchor Tabs | [XD](https://xd.adobe.com/view/33ffad4a-eb2c-4241-b8c5-ebfff1faf6f6-66ac/screen/b2aa2c0c-03b7-4571-8e0d-de88baf0814b) | [Issue](https://github.com/ni/nimble/issues/479) | [:white_check_mark: - SB](https://nimble.ni.dev/storybook/?path=/docs/anchor-tabs--tabs) | :white_check_mark: | :o: | +| Anchor Tabs | [XD](https://xd.adobe.com/view/33ffad4a-eb2c-4241-b8c5-ebfff1faf6f6-66ac/screen/b2aa2c0c-03b7-4571-8e0d-de88baf0814b) | [Issue](https://github.com/ni/nimble/issues/479) | [:white_check_mark: - SB](https://nimble.ni.dev/storybook/?path=/docs/anchor-tabs--tabs) | :white_check_mark: | :white_check_mark: | | Banners | [XD](https://xd.adobe.com/view/33ffad4a-eb2c-4241-b8c5-ebfff1faf6f6-66ac/screen/29c405f7-08ea-48b6-973f-546970b9dbab) | [Issue](https://github.com/ni/nimble/issues/305) | :o: | :o: | :o: | | Breadcrumb | [XD](https://xd.adobe.com/view/33ffad4a-eb2c-4241-b8c5-ebfff1faf6f6-66ac/screen/7b53bb3e-439b-4f13-9d5f-55adc7da8a2e) | | [:white_check_mark: - SB](https://ni.github.io/nimble/storybook/?path=/docs/breadcrumb--standard-breadcrumb) | :white_check_mark: | :white_check_mark: | | Card | | [Issue](https://github.com/ni/nimble/issues/296) | :o: | :o: | :o: | diff --git a/change/@ni-nimble-blazor-7ee25a1b-7b0f-4aa5-afe8-afa7bed38547.json b/change/@ni-nimble-blazor-7ee25a1b-7b0f-4aa5-afe8-afa7bed38547.json new file mode 100644 index 0000000000..82e0f3781d --- /dev/null +++ b/change/@ni-nimble-blazor-7ee25a1b-7b0f-4aa5-afe8-afa7bed38547.json @@ -0,0 +1,7 @@ +{ + "type": "minor", + "comment": "Support for anchor tabs", + "packageName": "@ni/nimble-blazor", + "email": "7282195+m-akinc@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor b/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor index 54115da7e0..295e6cc0d1 100644 --- a/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor +++ b/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor @@ -206,9 +206,9 @@
Tabs
- Tab 1 - Tab 2 - Tab 3 (Disabled) + Tab 1 + Tab 2 + Tab 3 (Disabled) Toolbar Button @@ -222,12 +222,34 @@
Tab 3 content
- + + Tab 1 Tab 2 Tab 3
+
+
Tabs - Anchor
+ + Tab 1 + Tab 2 + Tab 3 (Disabled) + + Toolbar Button + + + + + Tab 1 + Tab 2 + Tab 3 + +
Text Area
Text Area Label diff --git a/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor.cs b/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor.cs index 163d8d534a..dbc343ccc9 100644 --- a/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor.cs +++ b/packages/nimble-blazor/Examples/Demo.Shared/Pages/ComponentsDemo.razor.cs @@ -11,6 +11,7 @@ public partial class ComponentsDemo { private DrawerLocation _drawerLocation = DrawerLocation.Right; private string? ActiveTabId { get; set; } + private string? ActiveAnchorTabId { get; set; } = "a-tab-1"; private NimbleDialog? _dialog; private string? DialogClosedReason { get; set; } private NimbleDrawer? _drawer; diff --git a/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor new file mode 100644 index 0000000000..14c1dc2361 --- /dev/null +++ b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor @@ -0,0 +1,6 @@ +@namespace NimbleBlazor + + @ChildContent + diff --git a/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor.cs b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor.cs new file mode 100644 index 0000000000..0263107f61 --- /dev/null +++ b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.razor.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Components; + +namespace NimbleBlazor; + +/// +/// A link styled as a tab +/// +public partial class NimbleAnchorTab : ComponentBase +{ + /// + /// The child content of the element. + /// + [Parameter] + public RenderFragment? ChildContent { get; set; } + + /// + /// Whether the tab is disabled (not selectable) + /// + [Parameter] + public bool? Disabled { get; set; } + + /// + /// Any additional attributes that did not match known properties. + /// + [Parameter(CaptureUnmatchedValues = true)] + public IDictionary? AdditionalAttributes { get; set; } +} diff --git a/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor new file mode 100644 index 0000000000..1e284b4227 --- /dev/null +++ b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor @@ -0,0 +1,6 @@ +@namespace NimbleBlazor + + @ChildContent + diff --git a/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor.cs b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor.cs new file mode 100644 index 0000000000..99345c032d --- /dev/null +++ b/packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTabs.razor.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Components; + +namespace NimbleBlazor; + +/// +/// A sequence of links styled as tabs. +/// +public partial class NimbleAnchorTabs : ComponentBase +{ + /// + /// The child content of the element. + /// + [Parameter] + public RenderFragment? ChildContent { get; set; } + + /// + /// The id of the contained NimbleAnchorTab that is marked as active. + /// + [Parameter] + public string? ActiveId { get; set; } + + /// + /// Any additional attributes that did not match known properties. + /// + [Parameter(CaptureUnmatchedValues = true)] + public IDictionary? AdditionalAttributes { get; set; } +} diff --git a/packages/nimble-blazor/Tests/NimbleBlazor.Tests/Unit/Components/NimbleAnchorTabsTests.cs b/packages/nimble-blazor/Tests/NimbleBlazor.Tests/Unit/Components/NimbleAnchorTabsTests.cs new file mode 100644 index 0000000000..b30e0da5bc --- /dev/null +++ b/packages/nimble-blazor/Tests/NimbleBlazor.Tests/Unit/Components/NimbleAnchorTabsTests.cs @@ -0,0 +1,69 @@ +using System.Linq; +using AngleSharp.Dom; +using Bunit; +using Xunit; + +namespace NimbleBlazor.Tests.Unit.Components; + +/// +/// Tests for +/// +public class NimbleAnchorTabsTests +{ + [Fact] + public void NimbleAnchorTabsRendered_HasTabsMarkup() + { + var context = new TestContext(); + context.JSInterop.Mode = JSRuntimeMode.Loose; + var expectedMarkup = "nimble-anchor-tabs"; + var tabs = context.RenderComponent(); + + Assert.Contains(expectedMarkup, tabs.Markup); + } + + [Fact] + public void NimbleAnchorTabsWithChildContent_HasChildMarkup() + { + var tabs = RenderTabsWithContent(); + var expectedChildrenNames = new[] { "nimble-anchor-tab", "nimble-anchor-tab", "nimble-tabs-toolbar" }; + + var actualChildNodeNames = tabs.Nodes.First().ChildNodes.OfType().Select(node => node.LocalName).ToArray(); + Assert.Equal(expectedChildrenNames, actualChildNodeNames); + } + + [Fact] + public void NimbleAnchorTabsWithChildContent_HasActiveIdMarkup() + { + var tabs = RenderTabsWithContent(); + + Assert.Contains("activeid", tabs.Markup); + } + + [Fact] + public void NimbleAnchorTabsWithChildContent_HasDisabledMarkup() + { + var tabs = RenderTabsWithContent(); + + Assert.Contains("disabled", tabs.Markup); + } + + private IRenderedComponent RenderTabsWithContent() + { + var context = new TestContext(); + context.JSInterop.Mode = JSRuntimeMode.Loose; + return context.RenderComponent(AddChildContentToTabs); + } + + private void AddChildContentToTabs(ComponentParameterCollectionBuilder parameters) + { + parameters.Add(x => x.ActiveId, "tab1"); + parameters.AddChildContent(); + parameters.AddChildContent(SetTabDisabled); + parameters.AddChildContent(); + } + + private void SetTabDisabled(ComponentParameterCollectionBuilder parameters) + { + parameters.Add(x => x.Disabled, true); + } +}