-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
263 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
src/GovUk.Frontend.AspNetCore.DocSamples/Pages/Tabs/Tabs.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
@page | ||
|
||
<govuk-tabs> | ||
<govuk-tabs-item id="past-day" label="Past day"> | ||
<item id="past-day" label="Past day"> | ||
<h2 class="govuk-heading-l">Past day</h2> | ||
</govuk-tabs-item> | ||
<govuk-tabs-item id="past-week" label="Past week"> | ||
</item> | ||
<item id="past-week" label="Past week"> | ||
<h2 class="govuk-heading-l">Past week</h2> | ||
</govuk-tabs-item> | ||
<govuk-tabs-item id="past-month" label="Past month"> | ||
</item> | ||
<item id="past-month" label="Past month"> | ||
<h2 class="govuk-heading-l">Past month</h2> | ||
</govuk-tabs-item> | ||
<govuk-tabs-item id="past-year" label="Past year"> | ||
</item> | ||
<item id="past-year" label="Past year"> | ||
<h2 class="govuk-heading-l">Past year</h2> | ||
</govuk-tabs-item> | ||
</item> | ||
</govuk-tabs> |
67 changes: 67 additions & 0 deletions
67
src/GovUk.Frontend.AspNetCore/ComponentGeneration/DefaultComponentGenerator.Tabs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Html; | ||
|
||
namespace GovUk.Frontend.AspNetCore.ComponentGeneration; | ||
|
||
public partial class DefaultComponentGenerator | ||
{ | ||
internal const string TabsDefaultTitle = "Contents"; | ||
internal const string TabsElement = "div"; | ||
internal const string TabsItemPanelElement = "div"; | ||
|
||
/// <inheritdoc/> | ||
public virtual HtmlTagBuilder GenerateTabs(TabsOptions options) | ||
{ | ||
ArgumentNullException.ThrowIfNull(options); | ||
options.Validate(); | ||
|
||
HtmlTagBuilder TabListItem(TabsOptionsItem item, int index) | ||
{ | ||
var tabPanelId = item.Id?.NormalizeEmptyString() is IHtmlContent id ? id : new HtmlString($"{options.IdPrefix}-{index}"); | ||
|
||
return new HtmlTagBuilder("li") | ||
.WithCssClass("govuk-tabs__list-item") | ||
.When(index == 1, b => b.WithCssClass("govuk-tabs__list-item--selected")) | ||
.WithAppendedHtml(new HtmlTagBuilder("a") | ||
.WithCssClass("govuk-tabs__tab") | ||
.WithAttribute("href", $"#{tabPanelId.ToHtmlString()}", encodeValue: false) | ||
.WithAttributes(item.Attributes) | ||
.WithAppendedHtml(item.Label!)); | ||
} | ||
|
||
HtmlTagBuilder TabPanel(TabsOptionsItem item, int index) | ||
{ | ||
var tabPanelId = item.Id?.NormalizeEmptyString() is IHtmlContent id ? id : new HtmlString($"{options.IdPrefix}-{index}"); | ||
|
||
return new HtmlTagBuilder(TabsItemPanelElement) | ||
.WithCssClass("govuk-tabs__panel") | ||
.When(index > 1, b => b.WithCssClass("govuk-tabs__panel--hidden")) | ||
.WithAttribute("id", tabPanelId) | ||
.WithAttributes(item.Panel?.Attributes) | ||
.When( | ||
GetEncodedTextOrHtml(item.Panel?.Text, item.Panel?.Html) is not null, | ||
b => b.WithAppendedHtml( | ||
item.Panel?.Html.NormalizeEmptyString() is IHtmlContent html | ||
? html | ||
: new HtmlTagBuilder("p").WithCssClass("govuk-body").WithAppendedText(item.Panel!.Text!))); | ||
} | ||
|
||
return new HtmlTagBuilder(TabsElement) | ||
.WhenNotNull(options.Id, (id, b) => b.WithAttribute("id", id)) | ||
.WithCssClass("govuk-tabs") | ||
.WithCssClasses(ExplodeClasses(options.Classes?.ToHtmlString())) | ||
.WithAttributes(options.Attributes) | ||
.WithAttribute("data-module", "govuk-tabs", encodeValue: false) | ||
.WithAppendedHtml(new HtmlTagBuilder("h2") | ||
.WithCssClass("govuk-tabs__title") | ||
.WithAppendedHtml(options.Title.NormalizeEmptyString() ?? new HtmlString(TabsDefaultTitle))) | ||
.When( | ||
options.Items?.Count > 0, | ||
b => b | ||
.WithAppendedHtml(new HtmlTagBuilder("ul") | ||
.WithCssClass("govuk-tabs__list") | ||
.WithAppendedHtml(options.Items!.Select((item, index) => TabListItem(item, index + 1)))) | ||
.WithAppendedHtml(options.Items!.Select((item, index) => TabPanel(item, index + 1)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 0 additions & 127 deletions
127
src/GovUk.Frontend.AspNetCore/HtmlGeneration/ComponentGenerator.Tabs.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.