mirror of https://github.com/abpframework/abp.git
9 changed files with 125 additions and 85 deletions
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button |
|||
{ |
|||
public enum AbpButtonSize |
|||
{ |
|||
Default, |
|||
Small, |
|||
Large |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button |
|||
{ |
|||
public static class AbpButtonSizeExtensions |
|||
{ |
|||
public static string ToClassName(this AbpButtonSize size) |
|||
{ |
|||
switch (size) |
|||
{ |
|||
case AbpButtonSize.Small: |
|||
return "btn-sm"; |
|||
case AbpButtonSize.Large: |
|||
return "btn-lg"; |
|||
case AbpButtonSize.Default: |
|||
return ""; |
|||
default: |
|||
throw new AbpException("Unknown AbpButtonSize: " + size); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using System; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button |
|||
{ |
|||
public abstract class AbpButtonTagHelperServiceBase<TTagHelper> : AbpTagHelperService<TTagHelper> |
|||
where TTagHelper : TagHelper, IButtonTagHelperBase |
|||
{ |
|||
public override void Process(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
NormalizeTagStyle(context, output); |
|||
AddClasses(context, output); |
|||
AddIcon(context, output); |
|||
AddText(context, output); |
|||
} |
|||
|
|||
protected virtual void NormalizeTagStyle(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.TagMode = TagMode.StartTagAndEndTag; |
|||
} |
|||
|
|||
protected virtual void AddClasses(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Attributes.AddClass("btn"); |
|||
|
|||
if (TagHelper.ButtonType != AbpButtonType.Default) |
|||
{ |
|||
output.Attributes.AddClass("btn-" + TagHelper.ButtonType.ToString().ToLowerInvariant()); |
|||
} |
|||
|
|||
if (TagHelper.Size != AbpButtonSize.Default) |
|||
{ |
|||
output.Attributes.AddClass(TagHelper.Size.ToClassName()); |
|||
} |
|||
} |
|||
|
|||
protected virtual void AddIcon(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (TagHelper.Icon.IsNullOrWhiteSpace()) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
output.Content.AppendHtml($"<i class=\"fa fa-{TagHelper.Icon}\"></i> "); |
|||
} |
|||
|
|||
protected virtual void AddText(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (TagHelper.Text.IsNullOrWhiteSpace()) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
output.Content.AppendHtml($"<span>{TagHelper.Text}</span>"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Button |
|||
{ |
|||
public interface IButtonTagHelperBase |
|||
{ |
|||
AbpButtonType ButtonType { get; } |
|||
|
|||
AbpButtonSize Size { get; } |
|||
|
|||
string Text { get; } |
|||
|
|||
string Icon { get; } |
|||
|
|||
FontIconType IconType { get; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue