Skip to content

Commit 88f7853

Browse files
authored
Merge pull request #315 from richardkmichael/droppable-documentation
Improve Droppable documentation and example
2 parents 9f5e23c + 582b4f4 commit 88f7853

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/Droppable/README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Droppable is built on top of Draggable and allows you to declare draggable and droppable elements via options.
44
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.
57

68
### Import
79

@@ -23,19 +25,19 @@ import Droppable from '@shopify/draggable/lib/droppable';
2325

2426
### API
2527

26-
Check out [Draggables API](../Draggable#api) for the base API
28+
Check out [Draggable API](../Draggable#api) for the base API
2729

2830
### Options
2931

30-
Check out [Draggables options](../Draggable#options) for the base options
32+
Check out [Draggable options](../Draggable#options) for the base options
3133

3234
**`dropzone {String|HTMLElement[]|NodeList|Function}`**
3335
A css selector string, an array of elements, a NodeList or a function returning elements for dropzone
3436
elements within the `containers`.
3537

3638
### Events
3739

38-
Check out [Draggables events](../Draggable#events) for base events
40+
Check out [Draggable events](../Draggable#events) for the base events
3941

4042
| Name | Description | Cancelable | Cancelable action |
4143
| ----------------------------------------- | --------------------------------------------------------------- | ---------- | ----------------- |
@@ -47,23 +49,41 @@ Check out [Draggables events](../Draggable#events) for base events
4749

4850
### Classes
4951

50-
Check out [Draggables class identifiers](../Draggable#classes)
52+
Check out [Draggable class identifiers](../Draggable#classes) for the base class identifiers
5153

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` |
5658

5759
### Example
5860

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+
```
6080

6181
```js
6282
import { Droppable } from '@shopify/draggable';
6383

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'
6787
});
6888

6989
droppable.on('droppable:dropped', () => console.log('droppable:dropped'));

0 commit comments

Comments
 (0)