Skip to content

DroppableWidget

Namespace: Hex1b.Widgets

Assembly: Hex1b.dll

A widget that defines a drop target region. When a draggable item is dragged over this region, the builder lambda receives a with the current drag-hover state so the content can render differently to indicate drop availability.

csharp
public sealed record DroppableWidget : Hex1bWidget, IEquatable<Hex1bWidget>, IEquatable<DroppableWidget>

Inheritance

ObjectHex1bWidgetDroppableWidget

Implements

Constructors

DroppableWidget(Func<DroppableContext, Hex1bWidget>)

A widget that defines a drop target region. When a draggable item is dragged over this region, the builder lambda receives a with the current drag-hover state so the content can render differently to indicate drop availability.

Parameters:

csharp
public DroppableWidget(Func<DroppableContext, Hex1bWidget> Builder)

Properties

Builder

Returns: Func<DroppableContext, Hex1bWidget>

csharp
public Func<DroppableContext, Hex1bWidget> Builder { get; init; }

Methods

Accept(Func<object, bool>)

Sets a predicate that determines whether this target accepts the given drag data. When a drag hovers over this target, the predicate is evaluated and the result is available via .

Parameters:

Returns: DroppableWidget

csharp
public DroppableWidget Accept(Func<object, bool> predicate)

OnDrop(Action<DropEventArgs>)

Sets a synchronous drop handler.

Parameters:

Returns: DroppableWidget

csharp
public DroppableWidget OnDrop(Action<DropEventArgs> handler)

OnDrop(Func<DropEventArgs, Task>)

Sets an asynchronous drop handler.

Parameters:

Returns: DroppableWidget

csharp
public DroppableWidget OnDrop(Func<DropEventArgs, Task> handler)

OnDropTarget(Action<DropTargetEventArgs>)

Sets a synchronous handler for drops on specific insertion points.

Parameters:

Returns: DroppableWidget

csharp
public DroppableWidget OnDropTarget(Action<DropTargetEventArgs> handler)

OnDropTarget(Func<DropTargetEventArgs, Task>)

Sets an asynchronous handler for drops on specific insertion points.

Parameters:

Returns: DroppableWidget

csharp
public DroppableWidget OnDropTarget(Func<DropTargetEventArgs, Task> handler)

Examples

csharp
ctx.Droppable(dc => [
    dc.Text(dc.IsHoveredByDrag ? "Drop here!" : "Target area"),
])
.Accept(data => data is string s && s.EndsWith(".txt"))
.OnDrop(e => HandleDrop(e.DragData))

Released under the MIT License.