Browse Source

Abp border tag helper

pull/301/head
yekalkan 9 years ago
parent
commit
419cd5c352
  1. 16
      src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Border/AbpBorderTagHelper.cs
  2. 91
      src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Border/AbpBorderTagHelperService.cs
  3. 106
      src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Border/AbpBorderType.cs
  4. 6
      test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/Components/DynamicForms.cshtml

16
src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Border/AbpBorderTagHelper.cs

@ -0,0 +1,16 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Border
{
[HtmlTargetElement(Attributes = "abp-border")]
public class AbpBorderTagHelper : AbpTagHelper<AbpBorderTagHelper, AbpBorderTagHelperService>
{
public AbpBorderType AbpBorder { get; set; } = AbpBorderType._;
public AbpBorderTagHelper(AbpBorderTagHelperService tagHelperService)
: base(tagHelperService)
{
}
}
}

91
src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Border/AbpBorderTagHelperService.cs

@ -0,0 +1,91 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Border
{
public class AbpBorderTagHelperService : AbpTagHelperService<AbpBorderTagHelper>
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var borderAttributeAsString = TagHelper.AbpBorder.ToString().ToLowerInvariant();
var borderClass = "border" + GetBorderDirection(context, output, borderAttributeAsString) + GetExtensionIfBorderIsSubtractive(context, output, borderAttributeAsString);
output.Attributes.AddClass(borderClass);
SetBorderType(context, output, borderAttributeAsString);
}
protected virtual string GetBorderDirection(TagHelperContext context, TagHelperOutput output, string borderAttributeAsString)
{
if (borderAttributeAsString.Contains("top"))
{
return "-top";
}
if (borderAttributeAsString.Contains("right"))
{
return "-right";
}
if (borderAttributeAsString.Contains("left"))
{
return "-left";
}
if (borderAttributeAsString.Contains("bottom"))
{
return "-bottom";
}
return "";
}
protected virtual string GetExtensionIfBorderIsSubtractive(TagHelperContext context, TagHelperOutput output, string borderAttributeAsString)
{
if (borderAttributeAsString.Contains("_0"))
{
return "-0";
}
return "";
}
protected virtual void SetBorderType(TagHelperContext context, TagHelperOutput output, string borderAttributeAsString)
{
if (borderAttributeAsString.Contains("primary"))
{
output.Attributes.AddClass("border-primary");
}
if (borderAttributeAsString.Contains("secondary"))
{
output.Attributes.AddClass("border-secondary");
}
if (borderAttributeAsString.Contains("success"))
{
output.Attributes.AddClass("border-success");
}
if (borderAttributeAsString.Contains("danger"))
{
output.Attributes.AddClass("border-danger");
}
if (borderAttributeAsString.Contains("warning"))
{
output.Attributes.AddClass("border-warning");
}
if (borderAttributeAsString.Contains("info"))
{
output.Attributes.AddClass("border-info");
}
if (borderAttributeAsString.Contains("light"))
{
output.Attributes.AddClass("border-light");
}
if (borderAttributeAsString.Contains("dark"))
{
output.Attributes.AddClass("border-dark");
}
if (borderAttributeAsString.Contains("white"))
{
output.Attributes.AddClass("border-white");
}
}
}
}

106
src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Border/AbpBorderType.cs

@ -0,0 +1,106 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Border
{
public enum AbpBorderType
{
_,
_0,
Primary,
Secondary,
Success,
Danger,
Warning,
Info,
Light,
Dark,
White,
Primary_0,
Secondary_0,
Success_0,
Danger_0,
Warning_0,
Info_0,
Light_0,
Dark_0,
White_0,
Top,
Top_0,
Top_Primary,
Top_Secondary,
Top_Success,
Top_Danger,
Top_Warning,
Top_Info,
Top_Light,
Top_Dark,
Top_White,
Top_Primary_0,
Top_Secondary_0,
Top_Success_0,
Top_Danger_0,
Top_Warning_0,
Top_Info_0,
Top_Light_0,
Top_Dark_0,
Top_White_0,
Right,
Right_0,
Right_Primary,
Right_Secondary,
Right_Success,
Right_Danger,
Right_Warning,
Right_Info,
Right_Light,
Right_Dark,
Right_White,
Right_Primary_0,
Right_Secondary_0,
Right_Success_0,
Right_Danger_0,
Right_Warning_0,
Right_Info_0,
Right_Light_0,
Right_Dark_0,
Right_White_0,
Left,
Left_0,
Left_Primary,
Left_Secondary,
Left_Success,
Left_Danger,
Left_Warning,
Left_Info,
Left_Light,
Left_Dark,
Left_White,
Left_Primary_0,
Left_Secondary_0,
Left_Success_0,
Left_Danger_0,
Left_Warning_0,
Left_Info_0,
Left_Light_0,
Left_Dark_0,
Left_White_0,
Bottom,
Bottom_0,
Bottom_Primary,
Bottom_Secondary,
Bottom_Success,
Bottom_Danger,
Bottom_Warning,
Bottom_Info,
Bottom_Light,
Bottom_Dark,
Bottom_White,
Bottom_Primary_0,
Bottom_Secondary_0,
Bottom_Success_0,
Bottom_Danger_0,
Bottom_Warning_0,
Bottom_Info_0,
Bottom_Light_0,
Bottom_Dark_0,
Bottom_White_0,
}
}

6
test/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo/Pages/Components/DynamicForms.cshtml

@ -37,7 +37,8 @@
<div class="demo-with-code"> <div class="demo-with-code">
<div class="demo-area"> <div class="demo-area">
<abp-dynamic-form abp-model="@Model.PersonInput"> <abp-dynamic-form abp-model="@Model.PersonInput">
<abp-input asp-for="@Model.PersonInput.Phone.Number" /> <abp-input asp-for="@Model.PersonInput.Name" label="Overrided name" />
<abp-input asp-for="@Model.PersonInput.Phone.Number" label="Overrided number" />
<abp-button button-type="Primary" type="submit" text="submit" /> <abp-button button-type="Primary" type="submit" text="submit" />
</abp-dynamic-form> </abp-dynamic-form>
<hr /> <hr />
@ -55,7 +56,8 @@
<div class="code-area"> <div class="code-area">
<pre> <pre>
&lt;abp-dynamic-form abp-model=&quot;Model.PersonInput&quot;&gt; &lt;abp-dynamic-form abp-model=&quot;Model.PersonInput&quot;&gt;
&lt;abp-input asp-for=&quot;Model.PersonInput.Phone.Number&quot; /&gt; &lt;abp-input asp-for=&quot;Model.PersonInput.Name&quot; label=&quot;Overrided name&quot; /&gt;
&lt;abp-input asp-for=&quot;Model.PersonInput.Phone.Number&quot; label=&quot;Overrided number&quot; /&gt;
&lt;abp-button button-type=&quot;Primary&quot; type=&quot;submit&quot; text=&quot;submit&quot; /&gt; &lt;abp-button button-type=&quot;Primary&quot; type=&quot;submit&quot; text=&quot;submit&quot; /&gt;
&lt;/abp-dynamic-form&gt; &lt;/abp-dynamic-form&gt;
</pre> </pre>

Loading…
Cancel
Save