Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from IvanJosipovic/dev
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
IvanJosipovic authored Dec 4, 2019
2 parents 45a1d3d + 6f9f907 commit 1cacb43
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/BlazorTable/Components/Column.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@typeparam TableItem

<CascadingValue Value="(IColumn<TableItem>)this" Name="Column">
<Popover Target="@($"Filter-{Title}")" IsOpen="@FilterOpen" Placement="Placement.Bottom" DismissOnNextClick="false">
<Popover Reference="@this.FilterRef" IsOpen="@FilterOpen" Placement="Placement.Bottom" DismissOnNextClick="false">
<h3 class="popover-header">Filter</h3>
<div class="popover-body">

Expand Down
2 changes: 2 additions & 0 deletions src/BlazorTable/Components/Column.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public string Title

public Type Type { get; private set; }

public ElementReference FilterRef { get; set; }

public IFilter<TableItem> FilterControl { get; set; }

public void Dispose()
Expand Down
7 changes: 3 additions & 4 deletions src/BlazorTable/Components/Popover.razor
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@namespace BlazorTable


@if ((IsOpen ?? false))
@if (IsOpen ?? false)
{
<DynamicElement Id="@Id" @attributes="@UnknownParameters" TagName="div" class="@Classname" role="tooltip" @onclick="OnClick">
<div @attributes="@UnknownParameters" class="@Classname" role="tooltip" @onclick="OnClick" @ref="MyRef">
<div @ref="Arrow" class="arrow"></div>
@ChildContent
</DynamicElement>
</div>
}
62 changes: 24 additions & 38 deletions src/BlazorTable/Components/Popover.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ namespace BlazorTable
{
public partial class Popover
{
internal ElementReference MyRef { get; set; }
[Parameter(CaptureUnmatchedValues = true)]
public IDictionary<string, object> UnknownParameters { get; set; }

[Parameter]
[Parameter]
public EventCallback<bool> IsOpenChanged { get; set; }

[Parameter]
public string AnimationClass { get; set; }

[Parameter]
public bool? IsOpen
{
Expand All @@ -35,64 +33,52 @@ public bool? IsOpen
}
}

public bool Manual { get; set; } = false;
[Parameter]
public Placement Placement { get; set; } = Placement.Auto;

[Parameter]
public ElementReference Reference { get; set; }

[Parameter]
public RenderFragment ChildContent { get; set; }

[Parameter]
public bool DismissOnNextClick { get; set; } = true;

[Inject]
protected IJSRuntime JSRuntime { get; set; }

public bool Manual { get; set; }

private bool _isOpen { get; set; }

internal virtual Task Changed(bool e)
protected virtual Task Changed(bool e)
{
return Task.CompletedTask;
}

public virtual void Show()
{
_isOpen = true;
if (!Manual) Changed(_isOpen);
IsOpenChanged.InvokeAsync(true);
}

public virtual void Hide()
{
_isOpen = false;
if (!Manual) Changed(_isOpen);
IsOpenChanged.InvokeAsync(false);
}

public virtual void Toggle()
{
_isOpen = !_isOpen;
if (!Manual) Changed(_isOpen);
IsOpenChanged.InvokeAsync(_isOpen);
}

[Parameter(CaptureUnmatchedValues = true)]
public IDictionary<string, object> UnknownParameters { get; set; }

[Inject]
protected IJSRuntime JSRuntime { get; set; }

protected string Classname => $"popover bs-popover-{Placement.ToDescriptionString()} {(IsOpen == true ? "show" : string.Empty)}";

protected ElementReference MyRef { get; set; }

protected ElementReference Arrow { get; set; }

protected override void OnAfterRender(bool firstrun)
protected override void OnAfterRender(bool firstRender)
{
if (IsOpen ?? false)
{
var placement = Placement.ToDescriptionString();
JSRuntime.InvokeVoidAsync("BlazorTablePopper", Target, Id, Arrow, placement);
JSRuntime.InvokeVoidAsync("BlazorTablePopper", Reference, MyRef, Arrow, placement);
}
}

protected string Id => Target + "-popover";

[Parameter] public Placement Placement { get; set; } = Placement.Auto;
[Parameter] public string Target { get; set; }
[Parameter] public string Class { get; set; }
[Parameter] public string Style { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
[Parameter] public bool DismissOnNextClick { get; set; } = true;

protected void OnClick()
{
if (DismissOnNextClick)
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorTable/Components/Table.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@if (column.Filterable)
{
<div class="float-right">
<a href="javascript:;" id="@($"Filter-{column.Title}")" @onclick="@((x) => column.ToggleFilter())" style="text-decoration: none"><span style="@(column.Filter == null ? "opacity: 0.2;" : string.Empty)">&#128269;</span></a>
<a href="javascript:;" @ref="column.FilterRef" id="@($"Filter-{column.Title}")" @onclick="@((x) => column.ToggleFilter())" style="text-decoration: none"><span style="@(column.Filter == null ? "opacity: 0.2;" : string.Empty)">&#128269;</span></a>
</div>
}
</th>
Expand Down
5 changes: 5 additions & 0 deletions src/BlazorTable/Interfaces/IColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,10 @@ public interface IColumn<TableItem>
/// Horizontal alignment
/// </summary>
Align Align { get; set; }

/// <summary>
/// Filter Icon Element
/// </summary>
ElementReference FilterRef { get; set; }
}
}
5 changes: 1 addition & 4 deletions src/BlazorTable/wwwroot/BlazorTable.min.js

Large diffs are not rendered by default.

0 comments on commit 1cacb43

Please sign in to comment.