2
2
3
3
Droppable is built on top of Draggable and allows you to declare draggable and droppable elements via options.
4
4
Droppable fires two events on top of the draggable events: ` droppable:dropped ` and ` droppable:returned ` .
5
+ Droppable elements must begin in an occupied dropzone (see below, [ Classes] ( #classes ) and example),
6
+ so they may returned if the drag is canceled or returned.
5
7
6
8
### Import
7
9
@@ -23,19 +25,19 @@ import Droppable from '@shopify/draggable/lib/droppable';
23
25
24
26
### API
25
27
26
- Check out [ Draggables API] ( ../Draggable#api ) for the base API
28
+ Check out [ Draggable API] ( ../Draggable#api ) for the base API
27
29
28
30
### Options
29
31
30
- Check out [ Draggables options] ( ../Draggable#options ) for the base options
32
+ Check out [ Draggable options] ( ../Draggable#options ) for the base options
31
33
32
34
** ` dropzone {String|HTMLElement[]|NodeList|Function} ` **
33
35
A css selector string, an array of elements, a NodeList or a function returning elements for dropzone
34
36
elements within the ` containers ` .
35
37
36
38
### Events
37
39
38
- Check out [ Draggables events] ( ../Draggable#events ) for base events
40
+ Check out [ Draggable events] ( ../Draggable#events ) for the base events
39
41
40
42
| Name | Description | Cancelable | Cancelable action |
41
43
| ----------------------------------------- | --------------------------------------------------------------- | ---------- | ----------------- |
@@ -47,23 +49,41 @@ Check out [Draggables events](../Draggable#events) for base events
47
49
48
50
### Classes
49
51
50
- Check out [ Draggables class identifiers] ( ../Draggable#classes )
52
+ Check out [ Draggable class identifiers] ( ../Draggable#classes ) for the base class identifiers
51
53
52
- | Name | Description | Default |
53
- | -------------------- | ---------------------------------------------------------------------------------------- | ------------------------------- |
54
- | ` droppable:active ` | Class added to the droppable container _ ( dropzone) _ when drag starts | ` draggable-droppable--active ` |
55
- | ` droppable:occupied ` | Class added to the droppable container _ ( dropzone) _ when it contains a draggable element | ` draggable-droppable--occupied ` |
54
+ | Name | Description | Default |
55
+ | -------------------- | ------------------------------------------------------------------------------ | ------------------------------- |
56
+ | ` droppable:active ` | Class added to the unoccupied dropzone elements when drag starts | ` draggable-droppable--active ` |
57
+ | ` droppable:occupied ` | Class added to the dropzone element when it contains a draggable element | ` draggable-droppable--occupied ` |
56
58
57
59
### Example
58
60
59
- This sample code will make list items draggable and allows to drop them inside another element:
61
+ This sample HTML and JavaScript will make ` .item ` elements draggable and droppable among all ` .dropzone ` elements:
62
+
63
+ ``` html
64
+ <div class =" container" >
65
+ <div class =" dropzone draggable-dropzone--occupied" ><div class =" item" >A</div ></div >
66
+ <div class =" dropzone draggable-dropzone--occupied" ><div class =" item" >B</div ></div >
67
+ <div class =" dropzone draggable-dropzone--occupied" ><div class =" item" >C</div ></div >
68
+ </div >
69
+
70
+ <div class =" container" >
71
+ <div class =" dropzone" ></div >
72
+ </div >
73
+
74
+ <style >
75
+ .item { height : 100% ; }
76
+ .dropzone { outline : solid 1px ; height : 50px ; }
77
+ .draggable-dropzone--occupied { background : lightgreen ; }
78
+ </style >
79
+ ```
60
80
61
81
``` js
62
82
import { Droppable } from ' @shopify/draggable' ;
63
83
64
- const droppable = new Droppable (document .querySelectorAll (' ul ' ), {
65
- draggable: ' li ' ,
66
- dropzone: ' # dropzone'
84
+ const droppable = new Droppable (document .querySelectorAll (' .container ' ), {
85
+ draggable: ' .item ' ,
86
+ dropzone: ' . dropzone'
67
87
});
68
88
69
89
droppable .on (' droppable:dropped' , () => console .log (' droppable:dropped' ));
0 commit comments