-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Details to new component generation
- Loading branch information
Showing
11 changed files
with
67 additions
and
56 deletions.
There are no files selected for viewing
36 changes: 18 additions & 18 deletions
36
src/GovUk.Frontend.AspNetCore/ComponentGeneration/DefaultComponentGenerator.Details.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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
using System; | ||
using HtmlTags; | ||
|
||
namespace GovUk.Frontend.AspNetCore.ComponentGeneration; | ||
|
||
public partial class DefaultComponentGenerator | ||
{ | ||
internal const string DetailsElement = "details"; | ||
internal const string DetailsSummaryElement = "summary"; | ||
internal const string DetailsTextElement = "div"; | ||
|
||
/// <inheritdoc/> | ||
public virtual HtmlTag GenerateDetails(DetailsOptions options) | ||
public virtual HtmlTagBuilder GenerateDetails(DetailsOptions options) | ||
{ | ||
ArgumentNullException.ThrowIfNull(options); | ||
options.Validate(); | ||
|
||
return new HtmlTag(DetailsElement) | ||
.AddEncodedAttributeIfNotNull("id", options.Id) | ||
.AddClass("govuk-details") | ||
.AddClasses(ExplodeClasses(options.Classes)) | ||
.AddEncodedAttributeIf(options.Open == true, "open", null) | ||
.MergeEncodedAttributes(options.Attributes) | ||
.Append(new HtmlTag(DetailsSummaryElement) | ||
.AddClass("govuk-details__summary") | ||
.MergeEncodedAttributes(options.SummaryAttributes) | ||
.Append(new HtmlTag("span") | ||
.AddClass("govuk-details__summary-text") | ||
.AppendHtml(GetEncodedTextOrHtml(options.SummaryText, options.SummaryHtml)))) | ||
.Append(new HtmlTag(DetailsTextElement) | ||
.AddClass("govuk-details__text") | ||
.MergeEncodedAttributes(options.TextAttributes) | ||
.AppendHtml(GetEncodedTextOrHtml(options.Text, options.Html))); | ||
return new HtmlTagBuilder(DetailsElement) | ||
.WhenNotNull(options.Id, (id, b) => b.WithAttribute("id", id)) | ||
.WithCssClass("govuk-details") | ||
.WithCssClasses(ExplodeClasses(options.Classes?.ToHtmlString())) | ||
.When(options.Open == true, b => b.WithBooleanAttribute("open")) | ||
.WithAttributes(options.Attributes) | ||
.WithAppendedHtml(new HtmlTagBuilder(DetailsSummaryElement) | ||
.WithCssClass("govuk-details__summary") | ||
.WithAttributes(options.SummaryAttributes) | ||
.WithAppendedHtml(new HtmlTagBuilder("span") | ||
.WithCssClass("govuk-details__summary-text") | ||
.WithAppendedHtml(GetEncodedTextOrHtml(options.SummaryText, options.SummaryHtml)!))) | ||
.WithAppendedHtml(new HtmlTagBuilder(DetailsTextElement) | ||
.WithCssClass("govuk-details__text") | ||
.WithAttributes(options.TextAttributes) | ||
.WithAppendedHtml(GetEncodedTextOrHtml(options.Text, options.Html)!)); | ||
} | ||
} |
16 changes: 8 additions & 8 deletions
16
src/GovUk.Frontend.AspNetCore/ComponentGeneration/DetailsOptions.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
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
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
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
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
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