Added Abp Table Tag Helper

pull/279/head
yekalkan 7 years ago
parent 5abab433a4
commit 92a5ff78a8

@ -0,0 +1,9 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Table
{
public enum AbpTableBorderStyle
{
Default,
Bordered,
Borderless
}
}

@ -0,0 +1,9 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Table
{
public enum AbpTableHeaderTheme
{
Default,
Light,
Dark
}
}

@ -0,0 +1,27 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Table
{
public class AbpTableTagHelper : AbpTagHelper<AbpTableTagHelper, AbpTableTagHelperService>
{
public bool? Responsive { get; set; }
public bool? ResponsiveSm { get; set; }
public bool? ResponsiveMd { get; set; }
public bool? ResponsiveLg { get; set; }
public bool? ResponsiveXl { get; set; }
public bool? DarkTheme { get; set; }
public bool? StripedRows { get; set; }
public bool? HoverableRows { get; set; }
public bool? Small { get; set; }
public AbpTableBorderStyle BorderStyle { get; set; } = AbpTableBorderStyle.Default;
public AbpTableTagHelper(AbpTableTagHelperService tagHelperService)
: base(tagHelperService)
{
}
}
}

@ -0,0 +1,99 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Table
{
public class AbpTableTagHelperService : AbpTagHelperService<AbpTableTagHelper>
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "table";
output.Attributes.AddClass("table");
SetResponsiveness(context, output);
SetTheme(context, output);
SetHoverableRows(context, output);
SetBorderStyle(context, output);
SetSmall(context, output);
SetStripedRows(context, output);
}
protected virtual void SetResponsiveness(TagHelperContext context, TagHelperOutput output)
{
if (TagHelper.Responsive ?? false)
{
output.PreElement.SetHtmlContent("<div class=\"table-responsive\">");
}
else if (TagHelper.ResponsiveSm ?? false)
{
output.PreElement.SetHtmlContent("<div class=\"table-responsive-sm\">");
}
else if (TagHelper.ResponsiveMd ?? false)
{
output.PreElement.SetHtmlContent("<div class=\"table-responsive-md\">");
}
else if (TagHelper.ResponsiveLg ?? false)
{
output.PreElement.SetHtmlContent("<div class=\"table-responsive-lg\">");
}
else if (TagHelper.ResponsiveXl ?? false)
{
output.PreElement.SetHtmlContent("<div class=\"table-responsive-xl\">");
}
else
{
return;
}
output.PostElement.SetHtmlContent("</div>");
}
protected virtual void SetTheme(TagHelperContext context, TagHelperOutput output)
{
if (TagHelper.DarkTheme ?? false)
{
output.Attributes.AddClass("table-dark");
}
}
protected virtual void SetStripedRows(TagHelperContext context, TagHelperOutput output)
{
if (TagHelper.StripedRows ?? false)
{
output.Attributes.AddClass("table-striped");
}
}
protected virtual void SetHoverableRows(TagHelperContext context, TagHelperOutput output)
{
if (TagHelper.HoverableRows ?? false)
{
output.Attributes.AddClass("table-hover");
}
}
protected virtual void SetSmall(TagHelperContext context, TagHelperOutput output)
{
if (TagHelper.Small ?? false)
{
output.Attributes.AddClass("table-sm");
}
}
protected virtual void SetBorderStyle(TagHelperContext context, TagHelperOutput output)
{
switch (TagHelper.BorderStyle)
{
case AbpTableBorderStyle.Default:
return;
case AbpTableBorderStyle.Bordered:
output.Attributes.AddClass("table-bordered");
return;
case AbpTableBorderStyle.Borderless:
output.Attributes.AddClass("table-borderless");
return;
}
}
}
}
Loading…
Cancel
Save