Skip to content

Commit 749480d

Browse files
author
Cathy Siller
committed
chore(pr review): comments addressed
1 parent dc4fa3c commit 749480d

File tree

6 files changed

+74
-90
lines changed

6 files changed

+74
-90
lines changed

docs/components/files/drop-zone-demo.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ if (document.getElementById('vue-dropZoneDemo')) {
33
el: '#vue-dropZoneDemo',
44
methods: {
55
onDrop: function (evt) {
6-
// Prevent default behavior (Prevent file from being opened)
76
if (evt.dataTransfer.items) {
87
// Use DataTransferItemList interface to access the file(s)
9-
for (var i = 0; i < evt.dataTransfer.items.length; i++) {
8+
Array.from(evt.dataTransfer.items).forEach(item => {
109
// If dropped items aren't files, reject them
11-
if (evt.dataTransfer.items[i].kind === 'file') {
12-
var file = evt.dataTransfer.items[i].getAsFile();
10+
if (item.kind === 'file') {
11+
let file = item.getAsFile();
1312
alert('File Drop Successful! ' + file.name);
1413
}
15-
}
14+
});
1615
} else {
17-
// TO DO: find solution, alert currently not working in ie11
18-
alert('Cannot detect dropped files in this browser.');
16+
// TODO: find solution, unsure how to pull file info in IE11
17+
alert('We detected a file drop!');
1918
}
2019
},
2120
},

docs/components/files/index.html

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Files
33
minver: 0.12.0
44
also:
5-
components/files/test-drop-zone.html: Testing - Drop Zones
5+
components/files/test-drop-zones.html: Testing - Drop Zones
66
components/files/test-file-selectors.html: Testing - File Selectors
77
components/files/test-file-tiles.html: Testing - File Tiles
88
components/Icons: Icons
@@ -12,59 +12,20 @@
1212
---
1313
{% extends 'component.njk' %}
1414
{% block content %}
15-
<section>
16-
<h2 id="drop-fence">Drop Fence</h2>
17-
<p class="hxSubBody">Added: v0.14.0</p>
18-
<p>A visual container that provides a visual affordance of drag-and-drop capabilities.</p>
19-
<p class="hxSubdued hxSubBody">
20-
<hx-icon type="info-circle"></hx-icon>
21-
Styles always removes padding.
22-
</p>
23-
<div class="example">
24-
<div>
25-
<div class="hxFence">
26-
<hx-file-icon type="paperclip"></hx-file-icon>
27-
<p>
28-
Drop files here or
29-
<hx-file-input
30-
class="hxTertiary"
31-
label="browse your files">
32-
<input type="file" />
33-
</hx-file-input>
34-
</p>
35-
</div>
36-
</div>
37-
38-
<footer>
39-
{% code 'text' %}
40-
<div class="hxFence">
41-
<hx-file-icon type="paperclip"></hx-file-icon>
42-
<p>
43-
Drop files here or
44-
<hx-file-input
45-
class="hxTertiary"
46-
label="browse your files">
47-
<input type="file" />
48-
</hx-file-input>
49-
</p>
50-
</div>
51-
{% endcode %}
52-
</footer>
53-
</div>
54-
</section>
55-
5615
<section>
5716
<h2 id="drop-zone">Drop Zone</h2>
5817
<p class="hxSubBody">Added: v0.14.0</p>
59-
<p>A visual container that provides an overlay, marking the boundaries of where a user can drop a file.</p>
18+
<p>
19+
A container that provides a visual overlay when dragging a file, marking
20+
the boundaries of where a user can drop.
21+
</p>
6022
<p class="hxSubdued hxSubBody">
6123
<hx-icon type="info-circle"></hx-icon>
62-
Styles always removes padding.
24+
The drop zone ignores any padding applied to it.
6325
</p>
6426
<div class="example" id="vue-dropZoneDemo">
6527
<div>
66-
<hx-drop-zone
67-
@drop.prevent="onDrop">
28+
<hx-drop-zone @drop.prevent="onDrop">
6829
<div class="hxFence">
6930
<hx-file-icon type="paperclip"></hx-file-icon>
7031
<p>
@@ -73,14 +34,14 @@ <h2 id="drop-zone">Drop Zone</h2>
7334
class="hxTertiary"
7435
label="browse your files">
7536
<input type="file" />
76-
</hx-file-input>
37+
</hx-file-input>.
7738
</p>
7839
</div>
7940
</hx-drop-zone>
8041
</div>
8142

8243
<footer>
83-
{% code 'text' %}
44+
{% code 'html' %}
8445
<hx-drop-zone>
8546
<div class="hxFence">
8647
<hx-file-icon type="paperclip"></hx-file-icon>
@@ -90,7 +51,7 @@ <h2 id="drop-zone">Drop Zone</h2>
9051
class="hxTertiary"
9152
label="browse your files">
9253
<input type="file" />
93-
</hx-file-input>
54+
</hx-file-input>.
9455
</p>
9556
</div>
9657
</hx-drop-zone>

docs/components/files/test-drop-zone.html renamed to docs/components/files/test-drop-zones.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Testing - Drop Zone
2+
title: Testing - Drop Zones
33
---
44
{% extends 'test.njk' %}
55
{% block content %}
@@ -21,22 +21,22 @@ <h2>Invisible Drop Zone</h2>
2121
<section>
2222
<h2>Visible Drop Zone (file not over element)</h2>
2323
<hx-drop-zone drag="away">
24-
Visible Drop Zone (file not over element)
24+
<p>Visible Drop Zone (file not over element)</p>
2525
</hx-drop-zone>
2626
</section>
2727

2828
<section>
2929
<h2>Visible Drop Zone (file over element)</h2>
3030
<hx-drop-zone drag="over">
31-
Visible Drop Zone (file over element)
31+
<p>Visible Drop Zone (file over element)</p>
3232
</hx-drop-zone>
3333
</section>
3434

3535
<section>
3636
<h2>Drop Zone with Child Fence</h2>
3737
<hx-drop-zone>
3838
<div class="hxFence hxBox hxMd">
39-
Invisible Drop Zone
39+
<p>Invisible Drop Zone</p>
4040
</div>
4141
</hx-drop-zone>
4242
</section>
@@ -45,7 +45,7 @@ <h2>Drop Zone with Child Fence</h2>
4545
<h2>Visible Drop Zone with Child Fence (file not over element)</h2>
4646
<hx-drop-zone drag="away">
4747
<div class="hxFence hxBox hxMd">
48-
Visible Drop Zone (file not over element)
48+
<p>Visible Drop Zone (file not over element)</p>
4949
</div>
5050
</hx-drop-zone>
5151
</section>
@@ -54,7 +54,7 @@ <h2>Visible Drop Zone with Child Fence (file not over element)</h2>
5454
<h2>Visible Drop Zone with Child Fence (file over element)</h2>
5555
<hx-drop-zone drag="over">
5656
<div class="hxFence hxBox hxMd">
57-
Visible Drop Zone (file over element)
57+
<p>Visible Drop Zone (file over element)</p>
5858
</div>
5959
</hx-drop-zone>
6060
</section>

docs/elements/hx-drop-zone/index.html

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
---
77
{% extends 'element.njk' %}
88
{% block content %}
9-
109
<section>
1110
<p>
12-
The custom <code>{{page.title}}</code> element provides an area where a user can drop files.
11+
The custom <code>{{page.title}}</code> element provides a visual overlay
12+
when dragging a file, marking the boundaries of where a user can drop.
1313
</p>
1414

1515
<dl class="hxBox-md metadata hxList">
@@ -27,8 +27,12 @@
2727
Any of the following:
2828
<ul>
2929
<li>
30-
<code>drop</code> - See MDN's <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/File_drag_and_drop"
31-
target="_blank">"File Drag and Drop"</a> for more information.
30+
<code>drop</code> - See MDN's
31+
<a href="https://goo.gl/aKLYsQ" target="_blank">
32+
"File Drag and Drop"
33+
<hx-icon type="external-link"></hx-icon>
34+
</a>
35+
for more information.
3236
</li>
3337
</ul>
3438
</dd>
@@ -37,12 +41,27 @@
3741
</section>
3842
{% endblock %}
3943

44+
{% block attributes %}
45+
<dt>drag {String}</dt>
46+
<dd>
47+
<i>(read-only)</i>
48+
<p>
49+
Its value is automatically set by the element itself and mainly used for CSS styling purposes.
50+
</p>
51+
</dd>
52+
{% endblock %}
53+
4054
{% block properties %}
4155
<dt>drag {String}</dt>
4256
<dd>
57+
<i>(read-only)</i>
58+
<p>
59+
A value of "away" means a file drag is detected on the document,
60+
away from the drop zone.
61+
</p>
4362
<p>
44-
<i>(read-only)</i>
45-
Determines if file is dragged on the document or area.
63+
A value of "over" means a file drag is detected on the document,
64+
over the drop zone.
4665
</p>
4766
</dd>
4867
{% endblock %}

src/helix-ui/elements/HXDropZoneElement.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ export class HXDropZoneElement extends HXElement {
66
}
77

88
$onCreate () {
9-
this._isDragging = false;
9+
this._isDocDragging = false;
1010
this._isZoneDragging = false;
1111
this._onDocDragLeave = this._onDocDragLeave.bind(this);
1212
this._onDocDragOver = this._onDocDragOver.bind(this);
1313
this._onDrop = this._onDrop.bind(this);
14+
this._stopDragging = this._stopDragging.bind(this);
1415
}
1516

1617
$onConnect () {
@@ -31,53 +32,56 @@ export class HXDropZoneElement extends HXElement {
3132
this.removeEventListener('drop', this._onDrop);
3233
}
3334

35+
/**
36+
* @readonly
37+
* @type {String}
38+
*/
3439
get drag () {
3540
return this.getAttribute('drag');
3641
}
3742

3843
/**
3944
* @private
40-
* @see https://goo.gl/zaoexR
45+
* @returns {Boolean}
4146
*/
4247
_isFileDrag (evt) {
43-
if (evt.dataTransfer.types) {
44-
if (evt.dataTransfer.types.indexOf) {
45-
return (evt.dataTransfer.types.indexOf('Files') !== -1);
48+
let _types = evt.dataTransfer.types;
49+
if (_types) {
50+
if (_types.indexOf) {
51+
return (_types.indexOf('Files') !== -1);
4652
} else {
47-
return evt.dataTransfer.types.contains('Files');
53+
return _types.contains('Files');
4854
}
4955
} else {
5056
return false;
5157
}
5258
}
5359

54-
// #2 this gets called when the dragged item leaves the document (leaves to a child element or window altogether)
60+
// #2 this gets called when the dragged item leaves the document
61+
// (leaves to a child element or window altogether)
5562
/** @private */
5663
_onDocDragLeave () {
5764
window.clearTimeout(this._docDragLeaveTimeout);
5865
// callback must be an arrow function to preserve "this"
59-
this._docDragLeaveTimeout = window.setTimeout(() => {
60-
this._isDragging = false;
61-
this.removeAttribute('drag');
62-
}, 250);
66+
this._docDragLeaveTimeout = window.setTimeout(this._stopDragging, 250);
6367
}
6468

6569
// #1 this handler fires continuously as long as the user is dragging on the page
6670
/** @private */
6771
_onDocDragOver (evt) {
68-
if (!this._isDragging) {
69-
this._isDragging = true;
72+
if (!this._isDocDragging) {
73+
this._isDocDragging = true;
7074
if (this._isFileDrag(evt)) {
7175
this.setAttribute('drag', 'away');
7276
}
7377
}
7478
window.clearTimeout(this._docDragLeaveTimeout);
7579
}
7680

77-
// #4 this gets called when the dragged item leaves the zone (leaves to a child element or zone altogether)
81+
// #4 this gets called when the dragged item leaves the zone
82+
// (leaves to a child element or zone altogether)
7883
/** @private */
7984
_onDragLeave () {
80-
//evt.preventDefault();
8185
window.clearTimeout(this._zoneDragLeaveTimeout);
8286
// callback must be an arrow function to preserve "this"
8387
this._zoneDragLeaveTimeout = window.setTimeout(() => {
@@ -89,8 +93,7 @@ export class HXDropZoneElement extends HXElement {
8993
// #3 this handler fires continuously as long as the user is dragging on the zone
9094
/** @private */
9195
_onDragOver (evt) {
92-
// needed for onDrop to work
93-
evt.preventDefault();
96+
evt.preventDefault(); // needed for onDrop to work
9497
if (!this._isZoneDragging) {
9598
this._isZoneDragging = true;
9699
if (this._isFileDrag(evt)) {
@@ -103,8 +106,13 @@ export class HXDropZoneElement extends HXElement {
103106

104107
/** @private */
105108
_onDrop () {
109+
this._stopDragging();
110+
}
111+
112+
/** @private */
113+
_stopDragging () {
106114
this.removeAttribute('drag');
107-
this._isDragging = false;
115+
this._isDocDragging = false;
108116
this._isZoneDragging = false;
109117
}
110118
}

src/helix-ui/styles/elements/hx-drop-zone.less

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
hx-drop-zone {
44
display: block;
55
min-height: 0; // because IE
6+
padding: 0 !important;
67
position: relative;
78

89
&::after {
@@ -28,10 +29,6 @@ hx-drop-zone {
2829
border-style: solid;
2930
}
3031
}
31-
32-
&:not(.hxFence) {
33-
padding: 0 !important;
34-
}
3532
}
3633

3734
.hxFence {

0 commit comments

Comments
 (0)