mirror of https://github.com/abpframework/abp.git
8 changed files with 115 additions and 127 deletions
@ -1,64 +1,34 @@ |
|||
using System.Collections.Generic; |
|||
using System.Text.Encodings.Web; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Nav |
|||
{ |
|||
public class AbpNavItemTagHelperService : AbpTagHelperService<AbpNavItemTagHelper> |
|||
{ |
|||
private readonly HtmlEncoder _encoder; |
|||
|
|||
public AbpNavItemTagHelperService(HtmlEncoder encoder) |
|||
{ |
|||
_encoder = encoder; |
|||
} |
|||
|
|||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.TagName = "a"; |
|||
output.TagMode = TagMode.StartTagAndEndTag; |
|||
output.Attributes.Add("href",TagHelper.Href); |
|||
SetClasses(context, output); |
|||
|
|||
output.Content.SetHtmlContent(await output.GetChildContentAsync()); |
|||
|
|||
var list = GetValueFromContext<List<NavItem>>(context, NavItemContents); |
|||
|
|||
list.Add(new NavItem |
|||
{ |
|||
Html = SurroundTagWithNavItem(context, output,RenderTagHelperOutput(output, _encoder)), |
|||
Active = TagHelper.Active??false |
|||
}); |
|||
|
|||
output.SuppressOutput(); |
|||
} |
|||
|
|||
protected virtual void SetClasses(TagHelperContext context, TagHelperOutput output) |
|||
public override void Process(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Attributes.AddClass("nav-link"); |
|||
output.TagName = "li"; |
|||
output.Attributes.AddClass("nav-item"); |
|||
|
|||
SetDisabledClass(context, output); |
|||
SetDropdownClass(context, output); |
|||
SetActiveClass(context, output); |
|||
} |
|||
|
|||
protected virtual void SetDisabledClass(TagHelperContext context, TagHelperOutput output) |
|||
|
|||
protected virtual void SetDropdownClass(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (TagHelper.Disabled ?? false) |
|||
if (TagHelper.Dropdown ?? false) |
|||
{ |
|||
output.Attributes.AddClass("disabled"); |
|||
output.Attributes.AddClass("dropdown"); |
|||
} |
|||
} |
|||
|
|||
protected virtual void SetActiveClass(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Attributes.AddClass(AbpNavItemActivePlaceholder); |
|||
} |
|||
|
|||
protected virtual string SurroundTagWithNavItem(TagHelperContext context, TagHelperOutput output, string html) |
|||
{ |
|||
return "<li class=\"nav-item "+ AbpNavItemResponsiveAlignPlaceholder +" " + AbpNavItemResponsiveFlexPlaceholder + "\">" + html + "</li>"; |
|||
if (TagHelper.Active ?? false) |
|||
{ |
|||
output.Attributes.AddClass("active"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Nav |
|||
{ |
|||
[HtmlTargetElement(Attributes = "abp-nav-link")] |
|||
public class AbpNavLinkTagHelper : AbpTagHelper<AbpNavLinkTagHelper, AbpNavLinkTagHelperService> |
|||
{ |
|||
public bool? Active { get; set; } |
|||
|
|||
public bool? Disabled { get; set; } |
|||
|
|||
public string Href { get; set; } |
|||
|
|||
public AbpNavLinkTagHelper(AbpNavLinkTagHelperService tagHelperService) |
|||
: base(tagHelperService) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using System.Collections.Generic; |
|||
using System.Text.Encodings.Web; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Nav |
|||
{ |
|||
public class AbpNavLinkTagHelperService : AbpTagHelperService<AbpNavLinkTagHelper> |
|||
{ |
|||
private readonly HtmlEncoder _encoder; |
|||
|
|||
public AbpNavLinkTagHelperService(HtmlEncoder encoder) |
|||
{ |
|||
_encoder = encoder; |
|||
} |
|||
|
|||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.TagName = "a"; |
|||
output.TagMode = TagMode.StartTagAndEndTag; |
|||
output.Attributes.Add("href",TagHelper.Href??""); |
|||
SetClasses(context, output); |
|||
} |
|||
|
|||
protected virtual void SetClasses(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Attributes.AddClass("nav-link"); |
|||
|
|||
SetDisabledClass(context, output); |
|||
SetActiveClass(context, output); |
|||
|
|||
output.Attributes.RemoveAll("abp-nav-link"); |
|||
} |
|||
|
|||
protected virtual void SetDisabledClass(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (TagHelper.Disabled ?? false) |
|||
{ |
|||
output.Attributes.AddClass("disabled"); |
|||
} |
|||
} |
|||
|
|||
protected virtual void SetActiveClass(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (TagHelper.Active??false) |
|||
{ |
|||
output.Attributes.AddClass("active"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue