-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
TODO - Move tabs between panels - Document SortableList and download its js file - Refactors - Unit tests
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
@using System.Collections.Generic | ||
@using System.Diagnostics.CodeAnalysis | ||
|
||
@inject IJSRuntime JS | ||
|
||
@typeparam T | ||
|
||
<div id="@(this.Id)" class="@(this.CssClass)"> | ||
@foreach (var item in this.Items) | ||
{ | ||
@if (this.SortableItemTemplate is not null) | ||
{ | ||
@(this.SortableItemTemplate(item)) | ||
} | ||
} | ||
</div> | ||
|
||
@code { | ||
|
||
[Parameter] | ||
public RenderFragment<T>? SortableItemTemplate { get; set; } | ||
Check warning on line 21 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Build
Check warning on line 21 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
Check warning on line 21 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
|
||
|
||
[Parameter, AllowNull] | ||
public List<T> Items { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<(int oldIndex, int newIndex)> OnUpdate { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<(int oldIndex, int newIndex)> OnRemove { get; set; } | ||
|
||
[Parameter] | ||
public string Id { get; set; } = Guid.NewGuid().ToString(); | ||
|
||
[Parameter] | ||
public string Group { get; set; } = Guid.NewGuid().ToString(); | ||
|
||
[Parameter] | ||
public string? Pull { get; set; } | ||
Check warning on line 39 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Build
Check warning on line 39 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
Check warning on line 39 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
|
||
|
||
[Parameter] | ||
public bool Put { get; set; } = true; | ||
|
||
[Parameter] | ||
public bool Sort { get; set; } = true; | ||
|
||
[Parameter] | ||
public string Handle { get; set; } = string.Empty; | ||
|
||
[Parameter] | ||
public string? Filter { get; set; } | ||
Check warning on line 51 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Build
Check warning on line 51 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
Check warning on line 51 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
|
||
|
||
[Parameter] | ||
public bool ForceFallback { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Gets or sets the custom css class to be applied in the container component | ||
/// </summary> | ||
[Parameter] | ||
public string CssClass { get; set; } | ||
|
||
private DotNetObjectReference<SortableList<T>>? selfReference; | ||
Check warning on line 62 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Build
Check warning on line 62 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
Check warning on line 62 in COMETwebapp/Components/Shared/SortableList.razor GitHub Actions / Analyze (csharp)
|
||
|
||
protected override async Task OnAfterRenderAsync(bool firstRender) | ||
{ | ||
if (firstRender) | ||
{ | ||
this.selfReference = DotNetObjectReference.Create(this); | ||
var module = await this.JS.InvokeAsync<IJSObjectReference>("import", "./Components/Shared/SortableList.razor.js"); | ||
await module.InvokeAsync<string>("init", this.Id, this.Group, this.Pull, this.Put, this.Sort, this.Handle, this.Filter, this.selfReference, this.ForceFallback); | ||
} | ||
} | ||
|
||
[JSInvokable] | ||
public void OnUpdateJS(int oldIndex, int newIndex) | ||
{ | ||
// invoke the OnUpdate event passing in the oldIndex and the newIndex | ||
this.OnUpdate.InvokeAsync((oldIndex, newIndex)); | ||
} | ||
|
||
[JSInvokable] | ||
public void OnRemoveJS(int oldIndex, int newIndex) | ||
{ | ||
// remove the item from the list | ||
this.OnRemove.InvokeAsync((oldIndex, newIndex)); | ||
} | ||
|
||
public void Dispose() => this.selfReference?.Dispose(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
you need the ::deep identifier if you are using scoped styles like this | ||
because scoped styles are only applied to markup in the component, not | ||
to the markup inside the render fragment. | ||
*/ | ||
|
||
::deep .sortable-ghost { | ||
visibility: hidden; | ||
} | ||
|
||
::deep .sortable-fallback { | ||
opacity: 1 !important | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export function init(id, group, pull, put, sort, handle, filter, component, forceFallback) { | ||
var sortable = new Sortable(document.getElementById(id), { | ||
animation: 200, | ||
group: { | ||
name: group, | ||
pull: pull || true, | ||
put: put | ||
}, | ||
filter: filter || undefined, | ||
sort: sort, | ||
forceFallback: forceFallback, | ||
handle: handle || undefined, | ||
onUpdate: (event) => { | ||
// Revert the DOM to match the .NET state | ||
event.item.remove(); | ||
event.to.insertBefore(event.item, event.to.childNodes[event.oldIndex]); | ||
|
||
// Notify .NET to update its model and re-render | ||
component.invokeMethodAsync('OnUpdateJS', event.oldDraggableIndex, event.newDraggableIndex); | ||
}, | ||
onRemove: (event) => { | ||
if (event.pullMode === 'clone') { | ||
// Remove the clone | ||
event.clone.remove(); | ||
} | ||
|
||
event.item.remove(); | ||
event.from.insertBefore(event.item, event.from.childNodes[event.oldIndex]); | ||
|
||
// Notify .NET to update its model and re-render | ||
component.invokeMethodAsync('OnRemoveJS', event.oldDraggableIndex, event.newDraggableIndex); | ||
} | ||
}); | ||
} |
This file was deleted.