Raxol.UI.Interactions.DragDrop (Raxol v2.0.1)
View SourceUniversal drag and drop system for all Raxol UI components.
This module provides:
- Universal drag and drop for any component
- Visual drag feedback and ghost images
- Drop zones with validation and highlighting
- Drag constraints (horizontal, vertical, bounds)
- Multi-item drag support
- Drag and drop with custom data transfer
- Accessibility support for keyboard-based drag/drop
Summary
Functions
Handle the end of a drag operation (drop or cancel).
Handle drag movement during an active drag operation.
Handle keyboard-based drag and drop for accessibility.
Initialize the drag and drop system state.
Make a component draggable with the specified options.
Register a drop zone that can accept dragged elements.
Handle the start of a drag operation.
Types
@type drag_options() :: %{ optional(:draggable) => boolean(), optional(:drag_data) => map(), optional(:constraints) => %{ optional(:horizontal) => boolean(), optional(:vertical) => boolean(), optional(:bounds) => %{ x: number(), y: number(), width: number(), height: number() } }, optional(:visual_feedback) => %{ optional(:ghost_opacity) => float(), optional(:drag_preview) => term(), optional(:cursor_style) => atom() }, optional(:drop_validation) => (term(), map() -> boolean()), optional(:accessibility) => %{ optional(:announce_drag_start) => boolean(), optional(:announce_drop) => boolean(), optional(:keyboard_enabled) => boolean() } }
@type drag_state() :: %{ active: boolean(), dragging_element: term() | nil, drag_data: map(), start_position: %{x: number(), y: number()} | nil, current_position: %{x: number(), y: number()} | nil, drag_offset: %{x: number(), y: number()}, constraints: map(), visual_feedback: map(), drop_zones: list(), valid_drop_target: term() | nil }
Functions
Handle the end of a drag operation (drop or cancel).
Handle drag movement during an active drag operation.
Handle keyboard-based drag and drop for accessibility.
Initialize the drag and drop system state.
Examples
iex> DragDrop.init()
%{active: false, dragging_element: nil, ...}
Make a component draggable with the specified options.
Examples
iex> DragDrop.make_draggable("my_button", %{
...> drag_data: %{type: :button, id: "my_button"},
...> constraints: %{horizontal: true},
...> visual_feedback: %{ghost_opacity: 0.8}
...> })
Register a drop zone that can accept dragged elements.
Examples
iex> DragDrop.register_drop_zone("sidebar", %{
...> accepts: [:button, :widget],
...> bounds: %{x: 0, y: 0, width: 200, height: 600},
...> validation: &validate_sidebar_drop/2,
...> visual_feedback: %{highlight_color: :blue}
...> })
Handle the start of a drag operation.
Parameters
state- Current drag/drop stateelement_id- ID of element being draggedposition- Mouse position where drag starteddrag_config- Configuration for the draggable element
Returns
Updated drag/drop state with drag operation active.