mirror of https://github.com/abpframework/abp.git
8 changed files with 2387 additions and 22 deletions
@ -0,0 +1,37 @@ |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Popover |
|||
{ |
|||
[HtmlTargetElement("button", Attributes = "abp-popover")] |
|||
[HtmlTargetElement("button", Attributes = "abp-popover-right")] |
|||
[HtmlTargetElement("button", Attributes = "abp-popover-left")] |
|||
[HtmlTargetElement("button", Attributes = "abp-popover-top")] |
|||
[HtmlTargetElement("button", Attributes = "abp-popover-bottom")] |
|||
[HtmlTargetElement("abp-button", Attributes = "abp-popover")] |
|||
[HtmlTargetElement("abp-button", Attributes = "abp-popover-right")] |
|||
[HtmlTargetElement("abp-button", Attributes = "abp-popover-left")] |
|||
[HtmlTargetElement("abp-button", Attributes = "abp-popover-top")] |
|||
[HtmlTargetElement("abp-button", Attributes = "abp-popover-bottom")] |
|||
public class AbpPopoverTagHelper : AbpTagHelper<AbpPopoverTagHelper, AbpPopoverTagHelperService> |
|||
{ |
|||
public bool? Disabled { get; set; } |
|||
|
|||
public bool? Dismissible { get; set; } |
|||
|
|||
public string AbpPopover { get; set; } |
|||
|
|||
public string AbpPopoverRight { get; set; } |
|||
|
|||
public string AbpPopoverLeft { get; set; } |
|||
|
|||
public string AbpPopoverTop { get; set; } |
|||
|
|||
public string AbpPopoverBottom { get; set; } |
|||
|
|||
public AbpPopoverTagHelper(AbpPopoverTagHelperService tagHelperService) |
|||
: base(tagHelperService) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,109 @@ |
|||
using System.Linq; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Popover |
|||
{ |
|||
public class AbpPopoverTagHelperService : AbpTagHelperService<AbpPopoverTagHelper> |
|||
{ |
|||
public override void Process(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (!TagHelper.Disabled??true) |
|||
{ |
|||
SetDataToggle(context, output); |
|||
SetDataPlacement(context, output); |
|||
SetPopoverData(context, output); |
|||
SetDataTriggerIfDismissible(context, output); |
|||
} |
|||
else |
|||
{ |
|||
SetDisabled(context,output); |
|||
} |
|||
} |
|||
|
|||
protected virtual void SetDisabled(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
var triggerAsHtml = TagHelper.Dismissible ?? false ? "datatrigger=\"focus\" " : ""; |
|||
|
|||
var dataPlacementAsHtml = "data-placement=\"" +GetDirectory().ToString().ToLowerInvariant() + "\" "; |
|||
|
|||
var titleAttribute = output.Attributes.FirstOrDefault(at => at.Name == "title"); |
|||
var titleAsHtml = titleAttribute == null? "":"title=\""+ titleAttribute.Value +"\" "; |
|||
|
|||
var preElementHtml = "<span class=\"d-inline-block\" "+ titleAsHtml + triggerAsHtml + dataPlacementAsHtml + "data-toggle=\"popover\" data-content=\"" +GetDataContent()+"\">"; |
|||
|
|||
var postElementHtml = "</span>"; |
|||
|
|||
output.PreElement.SetHtmlContent(preElementHtml); |
|||
output.PostElement.SetHtmlContent(postElementHtml); |
|||
|
|||
output.Attributes.Add("style", "pointer-events: none;"); |
|||
} |
|||
|
|||
protected virtual void SetDataTriggerIfDismissible(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
if (TagHelper.Dismissible ?? false) |
|||
{ |
|||
output.Attributes.Add("data-trigger", "focus"); |
|||
} |
|||
} |
|||
|
|||
protected virtual void SetDataToggle(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Attributes.Add("data-toggle", "popover"); |
|||
} |
|||
|
|||
protected virtual void SetDataPlacement(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
var directory = GetDirectory(); |
|||
if (directory == PopoverDirectory.Default) |
|||
{ |
|||
directory = PopoverDirectory.Bottom; |
|||
} |
|||
output.Attributes.Add("data-placement", directory.ToString().ToLowerInvariant()); |
|||
} |
|||
|
|||
protected virtual void SetPopoverData(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Attributes.Add("data-content", GetDataContent()); |
|||
} |
|||
|
|||
protected virtual string GetDataContent() |
|||
{ |
|||
switch (GetDirectory()) |
|||
{ |
|||
case PopoverDirectory.Top: |
|||
return TagHelper.AbpPopoverTop; |
|||
case PopoverDirectory.Right: |
|||
return TagHelper.AbpPopoverRight; |
|||
case PopoverDirectory.Bottom: |
|||
return TagHelper.AbpPopoverBottom; |
|||
case PopoverDirectory.Left: |
|||
return TagHelper.AbpPopoverLeft; |
|||
default: |
|||
return TagHelper.AbpPopover; |
|||
} |
|||
} |
|||
|
|||
protected virtual PopoverDirectory GetDirectory() |
|||
{ |
|||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverTop)) |
|||
{ |
|||
return PopoverDirectory.Top; |
|||
} |
|||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverBottom)) |
|||
{ |
|||
return PopoverDirectory.Bottom; |
|||
} |
|||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverRight)) |
|||
{ |
|||
return PopoverDirectory.Right; |
|||
} |
|||
if (!string.IsNullOrWhiteSpace(TagHelper.AbpPopoverLeft)) |
|||
{ |
|||
return PopoverDirectory.Left; |
|||
} |
|||
|
|||
return PopoverDirectory.Default; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Popover |
|||
{ |
|||
public enum PopoverDirectory |
|||
{ |
|||
Default, |
|||
Right, |
|||
Left, |
|||
Bottom, |
|||
Top |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,47 @@ |
|||
@page |
|||
@model Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Demo.Pages.Components.PopoversModel |
|||
@{ |
|||
ViewData["Title"] = "Badges"; |
|||
} |
|||
|
|||
<h2>Popovers</h2> |
|||
|
|||
<p>Based on <a href="https://getbootstrap.com/docs/4.1/components/Popovers/" target="_blank"> Bootstrap Popovers</a>.</p> |
|||
|
|||
<h4># Popovers Examples</h4> |
|||
|
|||
<div class="demo-with-code"> |
|||
<div class="demo-area"> |
|||
|
|||
<abp-button abp-popover="Hi, i'm popover content!"> |
|||
Popover Default |
|||
</abp-button> |
|||
<abp-button abp-popover-top="Hi, i'm popover content!" title="Popover Title"> |
|||
Popover With Title |
|||
</abp-button> |
|||
<abp-button abp-popover-right="Hi, i'm popover content!" title="Popover Title" dismissible="true"> |
|||
Dismissible Popover |
|||
</abp-button> |
|||
<abp-button abp-popover-left="Hi, i'm popover content!" title="Popover Title" disabled="true"> |
|||
Disabled Popover |
|||
</abp-button> |
|||
|
|||
</div> |
|||
<div class="code-area"> |
|||
<pre> |
|||
<abp-button abp-popover="Hi, i'm popover content!"> |
|||
Popover Default |
|||
</abp-button> |
|||
<abp-button abp-popover-top="Hi, i'm popover content!" title="Popover Title"> |
|||
Popover With Title |
|||
</abp-button> |
|||
<abp-button abp-popover-right="Hi, i'm popover content!" title="Popover Title" dismissible="true"> |
|||
Dismissible Popover |
|||
</abp-button> |
|||
<abp-button abp-popover-left="Hi, i'm popover content!" title="Popover Title" disabled="true"> |
|||
Disabled Popover |
|||
</abp-button> |
|||
</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 PopoversModel : PageModel |
|||
{ |
|||
public void OnGet() |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue