Drag Source
tip
Before using this component, make sure you are familiar with the concepts of
Pragmatic Drag and Drop.
This component builds directly on top of draggable and dropTargetForElements from Atlassian's library.
Overview
The DragSourceComponent represents an item that can be dragged and dropped into compatible targets.
It is the core building block for enabling drag-and-drop interactions inside the builder.
This component supports:
- Default or custom rendering template
- Default or custom drag preview
- Configurable dragging behavior (browser preview vs custom preview)
Import
import { DndModule } from 'ngx-builder-dnd';Selector
ngx-drag-source
API Reference
Type Parameters
| Name | Description |
|---|---|
TType | Defines the type of draggable item that the target accepts. |
Inputs
| Name | Default | Description |
|---|---|---|
dragSource: DragSourceData<TType> | - | The draggable item data. Usually includes type (identifier) and imageUrl (visual representation). |
customTemplate: TemplateRef<{ $implicit: DragSourceData<TType> } | - | Custom Angular template for rendering the draggable item. Falls back to the default template if not provided. |
previewComponent: Type<PreviewComponent<DragSourceData<TType>>> | - | A custom component used as the drag preview. Defaults to DragPreviewComponent. |
useBrowserPreview: boolean | string | false | When true, uses the browser's native drag preview. When false, uses the default or a custom preview component. |
operations: DropOperations | { 'reorder-before': 'available', 'reorder-after': 'available' } | Controls which drop operations are allowed. Called repeatedly during drag. |
allowedEdges: Edge[] | ['top', 'bottom'] | Allowed edges used to determine the closest drop position. Called repeatedly during drag. |
Examples
Default Draggable Item
<ngx-drag-source
[dragSource]="{ type: 'button', imageUrl: 'url path' }">
</ngx-drag-source>
- Renders the item with the default template (image inside a span).
- Uses the default preview component (
DragPreviewComponent) when dragging.
Custom Preview Component
<ngx-drag-source
[dragSource]="{ type: 'image', imageUrl: 'url path' }"
[previewComponent]="MyPreviewComponent"
[useBrowserPreview]="false">
</ngx-drag-source>
- Renders with the default template, but shows
MyPreviewComponentwhile dragging. - Data from
dragSourceis available inside the preview component through itsdatainput.
See Also
- Drag Source Model - Describes the data of a drag source.
- Drag Source List Component - Renders and manages multiple drag sources.
- Drag Source Template Directive - Projects custom templates for drag sources.