|
20 | 20 | font-weight: 500; |
21 | 21 | } |
22 | 22 |
|
| 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 | + |
23 | 91 | .item-list { |
24 | 92 | display: grid; |
25 | 93 | grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); |
@@ -155,6 +223,17 @@ <h1>Product catalog</h1> |
155 | 223 | <p>Click on any item to view details in a side panel</p> |
156 | 224 | </header> |
157 | 225 |
|
| 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 | + |
158 | 237 | <main> |
159 | 238 | <div class="item-list" id="itemList"> |
160 | 239 | <!-- Items will be inserted here by JavaScript --> |
@@ -243,6 +322,19 @@ <h3>Send feedback</h3> |
243 | 322 | const submitButton = document.getElementById("submitFeedback"); |
244 | 323 | const nameInput = document.getElementById("nameInput"); |
245 | 324 | 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 | +}); |
246 | 338 |
|
247 | 339 | // Render items to the list |
248 | 340 | function renderItems() { |
@@ -274,8 +366,12 @@ <h2>${item.title}</h2> |
274 | 366 | sidePanel.style.transition = 'none'; |
275 | 367 | sidePanel.style.transform = 'translateX(100%)'; |
276 | 368 |
|
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 | + } |
279 | 375 |
|
280 | 376 | // Force a reflow to ensure the transition will occur |
281 | 377 | void sidePanel.offsetWidth; |
|
0 commit comments