Skip to content

Commit cdcd42f

Browse files
authored
1 parent e0a5bcd commit cdcd42f

File tree

1 file changed

+98
-2
lines changed

1 file changed

+98
-2
lines changed

side-panel-dialog.html

+98-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,74 @@
2020
font-weight: 500;
2121
}
2222

23+
.controls {
24+
margin-bottom: 20px;
25+
background-color: white;
26+
padding: 15px;
27+
border-radius: 8px;
28+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
29+
}
30+
31+
.toggle-container {
32+
display: flex;
33+
align-items: center;
34+
gap: 10px;
35+
}
36+
37+
.toggle-switch {
38+
position: relative;
39+
display: inline-block;
40+
width: 60px;
41+
height: 34px;
42+
}
43+
44+
.toggle-switch input {
45+
opacity: 0;
46+
width: 0;
47+
height: 0;
48+
}
49+
50+
.toggle-slider {
51+
position: absolute;
52+
cursor: pointer;
53+
top: 0;
54+
left: 0;
55+
right: 0;
56+
bottom: 0;
57+
background-color: #ccc;
58+
transition: .4s;
59+
border-radius: 34px;
60+
}
61+
62+
.toggle-slider:before {
63+
position: absolute;
64+
content: "";
65+
height: 26px;
66+
width: 26px;
67+
left: 4px;
68+
bottom: 4px;
69+
background-color: white;
70+
transition: .4s;
71+
border-radius: 50%;
72+
}
73+
74+
input:checked + .toggle-slider {
75+
background-color: #4a6cf7;
76+
}
77+
78+
input:checked + .toggle-slider:before {
79+
transform: translateX(26px);
80+
}
81+
82+
.toggle-label {
83+
font-weight: bold;
84+
}
85+
86+
.mode-label {
87+
font-size: 14px;
88+
color: #666;
89+
}
90+
2391
.item-list {
2492
display: grid;
2593
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
@@ -155,6 +223,17 @@ <h1>Product catalog</h1>
155223
<p>Click on any item to view details in a side panel</p>
156224
</header>
157225

226+
<div class="controls">
227+
<div class="toggle-container">
228+
<span class="toggle-label">Dialog Mode:</span>
229+
<label class="toggle-switch">
230+
<input type="checkbox" id="dialogModeToggle">
231+
<span class="toggle-slider"></span>
232+
</label>
233+
<span class="mode-label" id="modeLabel">show() - Non-modal dialog</span>
234+
</div>
235+
</div>
236+
158237
<main>
159238
<div class="item-list" id="itemList">
160239
<!-- Items will be inserted here by JavaScript -->
@@ -243,6 +322,19 @@ <h3>Send feedback</h3>
243322
const submitButton = document.getElementById("submitFeedback");
244323
const nameInput = document.getElementById("nameInput");
245324
const feedbackInput = document.getElementById("feedbackInput");
325+
const dialogModeToggle = document.getElementById("dialogModeToggle");
326+
const modeLabel = document.getElementById("modeLabel");
327+
328+
// Track current dialog mode
329+
let useModalMode = false;
330+
331+
// Toggle between show() and showModal()
332+
dialogModeToggle.addEventListener("change", (event) => {
333+
useModalMode = event.target.checked;
334+
modeLabel.textContent = useModalMode ?
335+
"showModal() - Modal dialog (blocks interaction)" :
336+
"show() - Non-modal dialog";
337+
});
246338

247339
// Render items to the list
248340
function renderItems() {
@@ -274,8 +366,12 @@ <h2>${item.title}</h2>
274366
sidePanel.style.transition = 'none';
275367
sidePanel.style.transform = 'translateX(100%)';
276368

277-
// Show the dialog
278-
sidePanel.showModal();
369+
// Show the dialog using the selected method
370+
if (useModalMode) {
371+
sidePanel.showModal();
372+
} else {
373+
sidePanel.show();
374+
}
279375

280376
// Force a reflow to ensure the transition will occur
281377
void sidePanel.offsetWidth;

0 commit comments

Comments
 (0)