forked from ThariqS/html-effectiveness
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-prototype-interaction.html
More file actions
396 lines (377 loc) · 10.5 KB
/
08-prototype-interaction.html
File metadata and controls
396 lines (377 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Acme — Sidebar drag-to-reorder</title>
<style>
:root {
--ivory: #FAF9F5;
--slate: #141413;
--clay: #D97757;
--oat: #E3DACC;
--olive: #788C5D;
--gray-50: #F0EEE6;
--gray-200: #D1CFC5;
--gray-500: #87867F;
--gray-800: #3D3D3A;
--white: #ffffff;
--serif: ui-serif, Georgia, "Times New Roman", serif;
--sans: system-ui, -apple-system, "Segoe UI", sans-serif;
--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
background: var(--ivory);
color: var(--slate);
font-family: var(--sans);
font-size: 14px;
line-height: 1.55;
}
.wrap {
max-width: 1040px;
margin: 0 auto;
padding: 48px 32px 64px;
}
header { margin-bottom: 28px; }
.eyebrow {
font-family: var(--mono);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--gray-500);
}
h1 {
font-family: var(--serif);
font-weight: 500;
font-size: 30px;
letter-spacing: -0.01em;
margin: 6px 0 4px;
}
.sub {
color: var(--gray-500);
max-width: 600px;
}
code.inline {
font-family: var(--mono);
font-size: 12px;
background: var(--gray-50);
border: 1.5px solid var(--gray-200);
padding: 1px 5px;
border-radius: 4px;
}
/* ---------- layout ---------- */
.bench {
display: grid;
grid-template-columns: 300px 1fr;
gap: 28px;
align-items: start;
}
/* ---------- sidebar mock ---------- */
.sidebar {
width: 260px;
background: var(--white);
border: 1.5px solid var(--gray-200);
border-radius: 12px;
padding: 14px 10px;
}
.sidebar-title {
font-family: var(--mono);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
color: var(--gray-500);
padding: 4px 10px 10px;
}
.list {
position: relative;
list-style: none;
margin: 0;
padding: 0;
}
.item {
display: flex;
align-items: center;
gap: 10px;
padding: 9px 10px;
margin: 2px 0;
border-radius: 8px;
background: var(--white);
cursor: grab;
user-select: none;
transition: background 120ms linear, transform 120ms ease-out, opacity 120ms linear;
}
.item:hover { background: var(--gray-50); }
.item:hover .grip i { background: var(--gray-800); }
.item.dragging {
opacity: 0.35;
transform: rotate(2deg);
background: var(--gray-50);
cursor: grabbing;
}
.item .label { font-size: 14px; color: var(--slate); }
.item .count {
margin-left: auto;
font-family: var(--mono);
font-size: 11px;
color: var(--gray-500);
}
/* grip: 2 × 3 dot grid, pure css */
.grip {
flex: none;
width: 10px;
height: 16px;
display: grid;
grid-template-columns: repeat(2, 3px);
grid-template-rows: repeat(3, 3px);
gap: 3px;
align-content: center;
}
.grip i {
width: 3px;
height: 3px;
border-radius: 50%;
background: var(--gray-200);
transition: background 120ms linear;
}
/* drop indicator line */
.indicator {
position: absolute;
left: 6px;
right: 6px;
height: 2px;
background: var(--clay);
border-radius: 2px;
pointer-events: none;
display: none;
}
.indicator::before {
content: "";
position: absolute;
left: -5px;
top: -3px;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--clay);
}
.indicator.on { display: block; }
/* ---------- annotation panel ---------- */
.notes {
background: var(--white);
border: 1.5px solid var(--gray-200);
border-radius: 12px;
padding: 22px 24px;
}
.notes h2 {
font-family: var(--serif);
font-weight: 500;
font-size: 18px;
margin: 0 0 6px;
}
.notes .lede {
color: var(--gray-500);
font-size: 13px;
margin: 0 0 16px;
}
.notes ul {
list-style: none;
margin: 0;
padding: 0;
}
.notes li {
position: relative;
padding: 10px 0 10px 22px;
border-top: 1.5px solid var(--gray-50);
font-size: 13px;
color: var(--gray-800);
}
.notes li:first-child { border-top: none; }
.notes li::before {
content: "";
position: absolute;
left: 4px;
top: 16px;
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--clay);
}
.notes li b { color: var(--slate); font-weight: 600; }
/* ---------- open questions ---------- */
.questions {
margin-top: 28px;
background: var(--oat);
border: 1.5px solid var(--gray-200);
border-radius: 12px;
padding: 20px 24px;
}
.questions h2 {
font-family: var(--serif);
font-weight: 500;
font-size: 17px;
margin: 0 0 12px;
}
.questions ol {
margin: 0;
padding-left: 20px;
}
.questions li {
font-size: 13px;
color: var(--gray-800);
padding: 4px 0;
}
.questions li::marker {
font-family: var(--mono);
color: var(--olive);
font-weight: 600;
}
.footnote {
margin-top: 18px;
font-family: var(--mono);
font-size: 11px;
color: var(--gray-500);
}
</style>
</head>
<body>
<div class="wrap">
<header>
<div class="eyebrow">Acme / prototype / interaction</div>
<h1>Sidebar drag-to-reorder</h1>
<p class="sub">
Throwaway HTML so we can <em>feel</em> the reorder before porting it to
React. Native <code class="inline">dragstart / dragover / drop</code>,
~40 lines of JS, no libraries. Grab a row by the dots and move it.
</p>
</header>
<div class="bench">
<div>
<nav class="sidebar">
<div class="sidebar-title">Views</div>
<ul class="list" id="list">
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">Inbox</span>
<span class="count">14</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">Today</span>
<span class="count">3</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">Upcoming</span>
<span class="count">21</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">Projects</span>
<span class="count">8</span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">Archive</span>
<span class="count"></span>
</li>
<li class="item" draggable="true">
<span class="grip"><i></i><i></i><i></i><i></i><i></i><i></i></span>
<span class="label">Trash</span>
<span class="count"></span>
</li>
<div class="indicator" id="indicator"></div>
</ul>
</nav>
<p class="footnote">Order persists in the DOM only — refresh to reset.</p>
</div>
<div>
<section class="notes">
<h2>What you're feeling</h2>
<p class="lede">Design decisions baked into this prototype, so you can push back on them.</p>
<ul>
<li>
<b>Drop indicator snaps to the nearest gap</b>, not the raw cursor Y.
It only moves when you cross a row's midpoint — feels more decisive,
less jittery.
</li>
<li>
<b>Dragged row stays in place at 35% opacity</b> with a 2° tilt.
Keeping the ghost in the list preserves your sense of where you
started; the tilt reads as "lifted."
</li>
<li>
<b>Grip dots are the affordance, but the whole row is draggable.</b>
Dots darken on hover to teach the gesture without forcing a
tiny hit target.
</li>
<li>
<b>No auto-scroll, no drop animation.</b> Left out on purpose so the
core feel is easy to judge — say the word and we add them next.
</li>
</ul>
</section>
<section class="questions">
<h2>Open questions</h2>
<ol>
<li>Should <b>Trash</b> (and maybe <b>Archive</b>) be pinned to the bottom and excluded from reordering?</li>
<li>Do we want rows to <b>slide</b> to their new slot on drop, or is the instant snap acceptable?</li>
<li>Keyboard path: is <code class="inline">Alt + Arrow</code> to move the focused row enough for the first ship?</li>
</ol>
</section>
</div>
</div>
</div>
<script>
var list = document.getElementById('list');
var indicator = document.getElementById('indicator');
var dragging = null;
var dropBefore = null; // node to insert before, or null = append
list.addEventListener('dragstart', function (e) {
var item = e.target.closest('.item');
if (!item) return;
dragging = item;
item.classList.add('dragging');
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/plain', '');
});
list.addEventListener('dragover', function (e) {
if (!dragging) return;
e.preventDefault();
var siblings = Array.prototype.filter.call(
list.children,
function (el) { return el.classList && el.classList.contains('item'); }
);
dropBefore = null;
for (var i = 0; i < siblings.length; i++) {
var r = siblings[i].getBoundingClientRect();
if (e.clientY < r.top + r.height / 2) { dropBefore = siblings[i]; break; }
}
var listRect = list.getBoundingClientRect();
var edge = dropBefore
? dropBefore.getBoundingClientRect().top
: siblings[siblings.length - 1].getBoundingClientRect().bottom;
indicator.style.top = (edge - listRect.top - 1) + 'px';
indicator.classList.add('on');
});
list.addEventListener('drop', function (e) {
e.preventDefault();
if (!dragging) return;
if (dropBefore) list.insertBefore(dragging, dropBefore);
else list.insertBefore(dragging, indicator);
cleanup();
});
list.addEventListener('dragleave', function (e) {
if (!list.contains(e.relatedTarget)) indicator.classList.remove('on');
});
document.addEventListener('dragend', cleanup);
function cleanup() {
if (dragging) dragging.classList.remove('dragging');
dragging = null;
dropBefore = null;
indicator.classList.remove('on');
}
</script>
</body>
</html>