mirror of https://github.com/abpframework/abp.git
9 changed files with 205 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Breadcrumb |
|||
{ |
|||
public class AbpBreadcrumbItemTagHelper : AbpTagHelper<AbpBreadcrumbItemTagHelper, AbpBreadcrumbItemTagHelperService> |
|||
{ |
|||
public string Href { get; set; } |
|||
|
|||
public string Title { get; set; } |
|||
|
|||
public bool Active { get; set; } |
|||
|
|||
public AbpBreadcrumbItemTagHelper(AbpBreadcrumbItemTagHelperService tagHelperService) |
|||
: base(tagHelperService) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
using System.Collections.Generic; |
|||
using System.Text.Encodings.Web; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Breadcrumb |
|||
{ |
|||
public class AbpBreadcrumbItemTagHelperService : AbpTagHelperService<AbpBreadcrumbItemTagHelper> |
|||
{ |
|||
private readonly HtmlEncoder _encoder; |
|||
|
|||
public AbpBreadcrumbItemTagHelperService(HtmlEncoder encoder) |
|||
{ |
|||
_encoder = encoder; |
|||
} |
|||
public override void Process(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.TagName = "li"; |
|||
output.TagMode = TagMode.StartTagAndEndTag; |
|||
output.Attributes.AddClass("breadcrumb-item"); |
|||
output.Attributes.AddClass(AbpBreadcrumbItemActivePlaceholder); |
|||
|
|||
var list = GetValueFromContext<List<BreadcrumbItem>>(context, BreadcrumbItemsContent); |
|||
|
|||
output.Content.SetHtmlContent(GetInnerHtml(context, output)); |
|||
|
|||
|
|||
list.Add(new BreadcrumbItem |
|||
{ |
|||
Html = RenderTagHelperOutput(output, _encoder), |
|||
Active = TagHelper.Active |
|||
}); |
|||
|
|||
output.SuppressOutput(); |
|||
} |
|||
|
|||
protected virtual string GetInnerHtml(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (string.IsNullOrWhiteSpace(TagHelper.Href)) |
|||
{ |
|||
output.Attributes.Add("aria-current", "page"); |
|||
return TagHelper.Title; |
|||
} |
|||
return "<a href=\"" + TagHelper.Href + "\">" + TagHelper.Title + "</a>"; |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Breadcrumb |
|||
{ |
|||
public class AbpBreadcrumbTagHelper : AbpTagHelper<AbpBreadcrumbTagHelper, AbpBreadcrumbTagHelperService> |
|||
{ |
|||
public AbpBreadcrumbTagHelper(AbpBreadcrumbTagHelperService tagHelperService) |
|||
: base(tagHelperService) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Breadcrumb |
|||
{ |
|||
public class AbpBreadcrumbTagHelperService : AbpTagHelperService<AbpBreadcrumbTagHelper> |
|||
{ |
|||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
var list = InitilizeFormGroupContentsContext(context, output); |
|||
|
|||
await output.GetChildContentAsync(); |
|||
|
|||
SetInnerOlTag(context, output); |
|||
SetInnerList(context, output, list); |
|||
} |
|||
|
|||
protected virtual void SetInnerOlTag(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.PreContent.SetHtmlContent("<ol class=\"breadcrumb\">"); |
|||
output.PostContent.SetHtmlContent("</ol>"); |
|||
} |
|||
|
|||
protected virtual void SetInnerList(TagHelperContext context, TagHelperOutput output, List<BreadcrumbItem> list) |
|||
{ |
|||
var anyActiveItem = list.Any(bc => bc.Active); |
|||
|
|||
if (!anyActiveItem && list.Count > 0) |
|||
{ |
|||
list.Last().Active = true; |
|||
} |
|||
|
|||
var html = new StringBuilder(""); |
|||
|
|||
foreach (var breadcrumbItem in list) |
|||
{ |
|||
var htmlPart = SetActiveClassIfActiveAndGetHtml(breadcrumbItem); |
|||
|
|||
html.AppendLine(htmlPart); |
|||
} |
|||
|
|||
output.Content.SetHtmlContent(html.ToString()); |
|||
} |
|||
|
|||
protected virtual List<BreadcrumbItem> InitilizeFormGroupContentsContext(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
var items = new List<BreadcrumbItem>(); |
|||
context.Items[BreadcrumbItemsContent] = items; |
|||
return items; |
|||
} |
|||
|
|||
protected virtual string SetActiveClassIfActiveAndGetHtml(BreadcrumbItem item) |
|||
{ |
|||
return item.Active ? |
|||
item.Html.Replace(AbpBreadcrumbItemActivePlaceholder, " active") : |
|||
item.Html.Replace(AbpBreadcrumbItemActivePlaceholder, ""); |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Breadcrumb |
|||
{ |
|||
public class BreadcrumbItem |
|||
{ |
|||
public string Html { get; set; } |
|||
|
|||
public bool Active { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
@page |
|||
@model Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.Pages.Components.BreadcrumbsModel |
|||
@{ |
|||
ViewData["Title"] = "Breadcrumbs"; |
|||
} |
|||
|
|||
<h2>Breadcrumbs</h2> |
|||
|
|||
<p>Based on <a href="https://getbootstrap.com/docs/4.1/components/breadcrumbs/" target="_blank"> Bootstrap Breadcrumb</a>.</p> |
|||
|
|||
<h4># Breadcrumb Examples</h4> |
|||
|
|||
<div class="demo-with-code"> |
|||
<div class="demo-area"> |
|||
|
|||
<abp-breadcrumb> |
|||
<abp-breadcrumb-item href="#" title="Home"/> |
|||
<abp-breadcrumb-item href="#" title="Library"/> |
|||
<abp-breadcrumb-item title="Page"/> |
|||
</abp-breadcrumb> |
|||
|
|||
</div> |
|||
<div class="code-area"> |
|||
<pre> |
|||
<abp-breadcrumb> |
|||
<abp-breadcrumb-item href="#" title="Home"/> |
|||
<abp-breadcrumb-item href="#" title="Library"/> |
|||
<abp-breadcrumb-item title="Page"/> |
|||
</abp-breadcrumb> |
|||
</pre> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Microsoft.AspNetCore.Mvc.RazorPages; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.Pages.Components |
|||
{ |
|||
public class BreadcrumbsModel : PageModel |
|||
{ |
|||
public void OnGet() |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue