|
21 | 21 | max-width: 1500px; |
22 | 22 | border-radius: 1rem; |
23 | 23 | } |
24 | | - |
| 24 | + |
25 | 25 | .sticky { |
| 26 | + view-transition-name: match-element; |
26 | 27 | background: #fffa87; |
27 | 28 | border: 1px solid #e0e0e0; |
28 | 29 | border-radius: .5rem; |
@@ -232,32 +233,36 @@ <h2>Ship v0</h2> |
232 | 233 | </div> |
233 | 234 |
|
234 | 235 | <script> |
| 236 | + const COLUMNS = ["backlog", "doing", "review", "done"]; |
| 237 | + |
235 | 238 | addEventListener("click", e => { |
236 | 239 | const backButton = e.target.closest("button.move-back"); |
237 | 240 | const forwardButton = e.target.closest("button.move-forward"); |
238 | 241 | const sticky = e.target.closest(".sticky"); |
239 | 242 |
|
240 | | - if (backButton) { |
241 | | - const column = sticky.dataset.column; |
242 | | - if (column === "doing") { |
243 | | - sticky.dataset.column = "backlog"; |
244 | | - } else if (column === "review") { |
245 | | - sticky.dataset.column = "doing"; |
246 | | - } else if (column === "done") { |
247 | | - sticky.dataset.column = "review"; |
248 | | - } |
| 243 | + if (!backButton && !forwardButton) { |
| 244 | + return; |
| 245 | + } |
| 246 | + |
| 247 | + const currentColumn = sticky.dataset.column; |
| 248 | + const currentIndex = COLUMNS.indexOf(currentColumn); |
| 249 | + const nextColumn = backButton ? COLUMNS[currentIndex - 1] : COLUMNS[currentIndex + 1]; |
| 250 | + |
| 251 | + if (!nextColumn) { |
| 252 | + return; |
249 | 253 | } |
250 | 254 |
|
251 | | - if (forwardButton) { |
252 | | - const column = sticky.dataset.column; |
253 | | - if (column === "backlog") { |
254 | | - sticky.dataset.column = "doing"; |
255 | | - } else if (column === "doing") { |
256 | | - sticky.dataset.column = "review"; |
257 | | - } else if (column === "review") { |
258 | | - sticky.dataset.column = "done"; |
259 | | - } |
| 255 | + if (!document.startViewTransition) { |
| 256 | + sticky.dataset.column = nextColumn; |
| 257 | + return; |
260 | 258 | } |
| 259 | + |
| 260 | + document.startViewTransition(() => { |
| 261 | + sticky.dataset.column = nextColumn; |
| 262 | + // Move the sticky to be the first child of the column. |
| 263 | + const columnElements = document.querySelectorAll(`[data-column="${nextColumn}"]`); |
| 264 | + columnElements[0].parentNode.insertBefore(sticky, columnElements[1]); |
| 265 | + }); |
261 | 266 | }); |
262 | 267 | </script> |
263 | 268 | </body> |
|
0 commit comments