|
1 | | -import { formatEvent, makeCoverImg, makeCell } from "./events.js"; |
| 1 | +import { formatEvent, makeCoverImg } from "./events.js"; |
| 2 | + |
| 3 | +const rowTemplate = document.createElement("template"); |
| 4 | +rowTemplate.innerHTML = ` |
| 5 | + <tr class="pf-v6-c-table__tr" role="row"> |
| 6 | + <td class="pf-v6-c-table__td pf-v6-u-display-none pf-v6-u-display-table-cell-on-md" role="cell" style="vertical-align: middle;" data-slot="cover-desktop"></td> |
| 7 | + <td class="pf-v6-c-table__td" role="cell" style="vertical-align: middle;"> |
| 8 | + <div class="pf-v6-l-flex pf-m-gap-md pf-m-align-items-center"> |
| 9 | + <span class="pf-v6-u-display-inline-block pf-v6-u-display-none-on-md" data-slot="cover-mobile"></span> |
| 10 | + <div> |
| 11 | + <div class="pf-v6-u-font-weight-bold pf-v6-u-display-block pf-v6-u-display-none-on-md" data-slot="name-mobile"></div> |
| 12 | + <div><span data-slot="date"></span> <span class="pf-v6-u-font-size-xs" data-slot="relative"></span></div> |
| 13 | + <small class="pf-v6-u-text-color-subtle" data-slot="time"></small> |
| 14 | + </div> |
| 15 | + </div> |
| 16 | + </td> |
| 17 | + <td class="pf-v6-c-table__td pf-v6-u-display-none pf-v6-u-display-table-cell-on-md" role="cell" style="vertical-align: middle;" data-slot="name-desktop"></td> |
| 18 | + <td class="pf-v6-c-table__td" role="cell" style="vertical-align: middle;" data-slot="location"></td> |
| 19 | + <td class="pf-v6-c-table__td" role="cell" style="vertical-align: middle;"> |
| 20 | + <a data-slot="rsvp" target="_blank" rel="noopener" class="pf-v6-c-button pf-m-link pf-m-inline pf-m-small"> |
| 21 | + RSVP<span class="pf-v6-c-button__icon pf-m-end"><icon-external></icon-external></span> |
| 22 | + </a> |
| 23 | + </td> |
| 24 | + </tr>`; |
2 | 25 |
|
3 | 26 | const renderEventRow = (evt) => { |
4 | 27 | const { name, date, time, relative, lumaUrl, location, coverUrl } = |
5 | 28 | formatEvent(evt); |
| 29 | + const clone = rowTemplate.content.cloneNode(true); |
| 30 | + const $ = (s) => clone.querySelector(`[data-slot="${s}"]`); |
6 | 31 |
|
7 | | - const tr = document.createElement("tr"); |
8 | | - tr.className = "pf-v6-c-table__tr"; |
9 | | - tr.setAttribute("role", "row"); |
| 32 | + const desktopCover = makeCoverImg(coverUrl, name); |
| 33 | + if (desktopCover) $("cover-desktop").append(desktopCover); |
10 | 34 |
|
11 | | - tr.append( |
12 | | - makeCell( |
13 | | - "pf-v6-c-table__td pf-v6-u-display-none pf-v6-u-display-table-cell-on-md", |
14 | | - makeCoverImg(coverUrl, name), |
15 | | - ), |
16 | | - ); |
| 35 | + const mobileCover = makeCoverImg(coverUrl, name); |
| 36 | + if (mobileCover) $("cover-mobile").append(mobileCover); |
17 | 37 |
|
18 | | - const mobileCover = document.createElement("span"); |
19 | | - mobileCover.className = |
20 | | - "pf-v6-u-display-inline-block pf-v6-u-display-none-on-md"; |
21 | | - const mobileCoverImg = makeCoverImg(coverUrl, name); |
22 | | - if (mobileCoverImg) mobileCover.append(mobileCoverImg); |
| 38 | + $("name-mobile").textContent = name; |
| 39 | + $("date").textContent = date; |
| 40 | + $("relative").textContent = relative; |
| 41 | + $("time").textContent = time; |
| 42 | + $("name-desktop").textContent = name; |
| 43 | + $("location").textContent = location; |
| 44 | + $("rsvp").href = lumaUrl; |
23 | 45 |
|
24 | | - const mobileName = document.createElement("div"); |
25 | | - mobileName.className = |
26 | | - "pf-v6-u-font-weight-bold pf-v6-u-display-block pf-v6-u-display-none-on-md"; |
27 | | - mobileName.textContent = name; |
28 | | - |
29 | | - const relativeSpan = document.createElement("span"); |
30 | | - relativeSpan.className = "pf-v6-u-font-size-xs"; |
31 | | - relativeSpan.textContent = relative; |
32 | | - |
33 | | - const dateLine = document.createElement("div"); |
34 | | - dateLine.append(`${date} `, relativeSpan); |
35 | | - |
36 | | - const timeLine = document.createElement("small"); |
37 | | - timeLine.className = "pf-v6-u-text-color-subtle"; |
38 | | - timeLine.textContent = time; |
39 | | - |
40 | | - const textBlock = document.createElement("div"); |
41 | | - textBlock.append(mobileName, dateLine, timeLine); |
42 | | - |
43 | | - const flex = document.createElement("div"); |
44 | | - flex.className = "pf-v6-l-flex pf-m-gap-md pf-m-align-items-center"; |
45 | | - flex.append(mobileCover, textBlock); |
46 | | - |
47 | | - tr.append(makeCell("pf-v6-c-table__td", flex)); |
48 | | - |
49 | | - const nameCell = makeCell( |
50 | | - "pf-v6-c-table__td pf-v6-u-display-none pf-v6-u-display-table-cell-on-md", |
51 | | - ); |
52 | | - nameCell.textContent = name; |
53 | | - tr.append(nameCell); |
54 | | - |
55 | | - const locCell = makeCell("pf-v6-c-table__td"); |
56 | | - locCell.textContent = location; |
57 | | - tr.append(locCell); |
58 | | - |
59 | | - const rsvpLink = document.createElement("a"); |
60 | | - rsvpLink.href = lumaUrl; |
61 | | - rsvpLink.target = "_blank"; |
62 | | - rsvpLink.rel = "noopener"; |
63 | | - rsvpLink.className = "pf-v6-c-button pf-m-link pf-m-inline pf-m-small"; |
64 | | - rsvpLink.append("RSVP", document.createElement("icon-external")); |
65 | | - tr.append(makeCell("pf-v6-c-table__td", rsvpLink)); |
66 | | - |
67 | | - return tr; |
| 46 | + return clone; |
68 | 47 | }; |
69 | 48 |
|
70 | 49 | customElements.define( |
|
0 commit comments