-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathside-panel-dialog.html
430 lines (378 loc) · 10.1 KB
/
side-panel-dialog.html
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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Side Panel Modal with Dialog Element</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Helvetica, Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
h1, h2, h3 {
font-weight: 500;
}
.controls {
margin-bottom: 20px;
background-color: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.toggle-container {
display: flex;
align-items: center;
gap: 10px;
}
.toggle-switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.toggle-slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .toggle-slider {
background-color: #4a6cf7;
}
input:checked + .toggle-slider:before {
transform: translateX(26px);
}
.toggle-label {
font-weight: bold;
}
.mode-label {
font-size: 14px;
color: #666;
}
.item-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
margin-top: 20px;
}
.item-card {
background-color: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
.item-card:hover {
transform: translateY(-3px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
.item-card h3 {
margin-top: 0;
margin-bottom: 8px;
}
dialog {
position: fixed;
margin: 0;
padding: 0;
border: none;
width: 80%;
height: 100vh;
top: 0;
right: 0;
left: auto;
background-color: white;
box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
transform: translateX(100%);
transition: transform 0.1s cubic-bezier(0.2, 0, 0.38, 0.9);
max-height: none; /* Default is calc(100% - 2em - 6px) */
}
dialog::backdrop {
background-color: rgba(0, 0, 0, 0.5);
opacity: 0;
transition: opacity 0.1s cubic-bezier(0.2, 0, 0.38, 0.9);
}
/* We're handling the transform in JavaScript for better control */
dialog[open]::backdrop {
opacity: 1;
}
.dialog-content {
padding: 24px;
height: 100%;
overflow-y: auto;
}
.dialog-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 24px;
}
.close-button {
background: none;
border: none;
font-size: 24px;
cursor: pointer;
padding: 8px;
margin: -8px;
color: #555;
}
.item-details h2 {
margin-top: 0;
}
.item-image {
width: 100%;
height: 200px;
background-color: #e0e0e0;
border-radius: 8px;
margin-bottom: 16px;
display: flex;
align-items: center;
justify-content: center;
color: #666;
}
input, textarea {
font-size: 16px;
font-family: Helvetica, Arial, sans-serif;
width: 100%;
padding: 12px;
margin-bottom: 16px;
border: 1px solid #ddd;
border-radius: 4px;
}
textarea {
min-height: 120px;
resize: vertical;
}
.feedback-form h3 {
margin-top: 32px;
}
button.submit-button {
background-color: #4a6cf7;
color: white;
border: none;
border-radius: 4px;
padding: 12px 24px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.2s;
}
button.submit-button:hover {
background-color: #3a5ce6;
}
</style>
</head>
<body>
<header>
<h1>Product catalog</h1>
<p>Click on any item to view details in a side panel</p>
</header>
<div class="controls">
<div class="toggle-container">
<span class="toggle-label">Dialog Mode:</span>
<label class="toggle-switch">
<input type="checkbox" id="dialogModeToggle">
<span class="toggle-slider"></span>
</label>
<span class="mode-label" id="modeLabel">show() - Non-modal dialog</span>
</div>
</div>
<main>
<div class="item-list" id="itemList">
<!-- Items will be inserted here by JavaScript -->
</div>
</main>
<dialog id="sidePanel">
<div class="dialog-content">
<div class="dialog-header">
<h2>Item details</h2>
<button class="close-button" id="closeDialog">×</button>
</div>
<div class="item-details" id="itemDetails">
<!-- Item details will be inserted here by JavaScript -->
</div>
<div class="feedback-form">
<h3>Send feedback</h3>
<input type="text" placeholder="Your name" id="nameInput">
<textarea placeholder="Your thoughts about this item..." id="feedbackInput"></textarea>
<button class="submit-button" id="submitFeedback">Submit feedback</button>
</div>
</div>
</dialog>
<script type="module">
// Fix animation issues with dialog element
document.addEventListener('DOMContentLoaded', () => {
const dialog = document.getElementById('sidePanel');
// Force browser to recognize dialog animations by adding a small delay
dialog.addEventListener('cancel', (event) => {
event.preventDefault();
});
});
// Sample data
const items = [
{
id: 1,
title: "Wireless headphones",
description: "Premium noise-cancelling wireless headphones with 30-hour battery life and superior sound quality.",
category: "Electronics",
price: "$249.99"
},
{
id: 2,
title: "Ergonomic office chair",
description: "Adjustable office chair with lumbar support, breathable mesh back, and smooth-rolling casters.",
category: "Furniture",
price: "$189.99"
},
{
id: 3,
title: "Smart fitness tracker",
description: "Water-resistant fitness tracker with heart rate monitoring, sleep tracking, and 7-day battery life.",
category: "Wearables",
price: "$79.99"
},
{
id: 4,
title: "Ceramic coffee mug",
description: "Hand-crafted ceramic mug with heat-retention technology and ergonomic handle.",
category: "Kitchenware",
price: "$24.99"
},
{
id: 5,
title: "Portable power bank",
description: "20,000mAh portable charger with fast charging and dual USB ports for multiple devices.",
category: "Electronics",
price: "$49.99"
},
{
id: 6,
title: "Bamboo cutting board",
description: "Sustainable bamboo cutting board with juice groove and non-slip feet.",
category: "Kitchenware",
price: "$34.99"
}
];
// Get DOM elements
const itemList = document.getElementById("itemList");
const sidePanel = document.getElementById("sidePanel");
const closeButton = document.getElementById("closeDialog");
const itemDetails = document.getElementById("itemDetails");
const submitButton = document.getElementById("submitFeedback");
const nameInput = document.getElementById("nameInput");
const feedbackInput = document.getElementById("feedbackInput");
const dialogModeToggle = document.getElementById("dialogModeToggle");
const modeLabel = document.getElementById("modeLabel");
// Track current dialog mode
let useModalMode = false;
// Toggle between show() and showModal()
dialogModeToggle.addEventListener("change", (event) => {
useModalMode = event.target.checked;
modeLabel.textContent = useModalMode ?
"showModal() - Modal dialog (blocks interaction)" :
"show() - Non-modal dialog";
});
// Render items to the list
function renderItems() {
itemList.innerHTML = "";
items.forEach(item => {
const itemCard = document.createElement("div");
itemCard.className = "item-card";
itemCard.innerHTML = `
<h3>${item.title}</h3>
<p>${item.category}</p>
<p>${item.price}</p>
`;
itemCard.addEventListener("click", () => showItemDetails(item));
itemList.appendChild(itemCard);
});
}
// Show item details in the side panel
function showItemDetails(item) {
itemDetails.innerHTML = `
<div class="item-image">Product Image Placeholder</div>
<h2>${item.title}</h2>
<p><strong>Category:</strong> ${item.category}</p>
<p><strong>Price:</strong> ${item.price}</p>
<p>${item.description}</p>
`;
// Reset any existing transitions
sidePanel.style.transition = 'none';
sidePanel.style.transform = 'translateX(100%)';
// Show the dialog using the selected method
if (useModalMode) {
sidePanel.showModal();
} else {
sidePanel.show();
}
// Force a reflow to ensure the transition will occur
void sidePanel.offsetWidth;
// Restore the transition and apply the transform
sidePanel.style.transition = 'transform 0.1s cubic-bezier(0.2, 0, 0.38, 0.9)';
sidePanel.style.transform = 'translateX(0)';
// Store the current item ID for feedback submission
submitButton.dataset.itemId = item.id;
}
// Close the dialog when clicking the close button
closeButton.addEventListener("click", () => {
animateCloseDialog();
});
// Close the dialog when clicking on the backdrop
sidePanel.addEventListener("click", (event) => {
if (event.target === sidePanel) {
animateCloseDialog();
}
});
// Animate the dialog closing
function animateCloseDialog() {
// Animate the panel sliding out
sidePanel.style.transform = 'translateX(100%)';
// After animation completes, close the dialog
setTimeout(() => {
sidePanel.close();
}, 100);
}
// Handle feedback submission
submitButton.addEventListener("click", () => {
const itemId = submitButton.dataset.itemId;
const name = nameInput.value.trim();
const feedback = feedbackInput.value.trim();
if (name && feedback) {
console.log(`Feedback for item #${itemId}:`, { name, feedback });
alert("Thank you for your feedback!");
nameInput.value = "";
feedbackInput.value = "";
} else {
alert("Please fill out both fields to submit feedback.");
}
});
// Initialize the page
renderItems();
</script>
</body>
</html>