forked from smartcontractkit/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangelogCard.astro
More file actions
383 lines (333 loc) · 10.3 KB
/
ChangelogCard.astro
File metadata and controls
383 lines (333 loc) · 10.3 KB
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
---
import { SvgTaillessArrowDownSmall, Typography } from "@chainlink/blocks"
import styles from "./ChangelogCard.module.css"
import type { ChangelogItem } from "./types"
import { clsx } from "~/lib/clsx/clsx"
import CopyButton from "./CopyButton.tsx"
interface Props {
item: ChangelogItem
showBorder?: boolean
autoExpand?: boolean
showCopyButton?: boolean
disableHover?: boolean
showNetworksAndTopic?: boolean
}
const {
item,
showBorder = true,
autoExpand = false,
showCopyButton = true,
disableHover = false,
showNetworksAndTopic = false,
} = Astro.props
// Format the date
const formatDate = (dateString: string) => {
const date = new Date(dateString)
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
})
}
const formattedDate = formatDate(item["date-of-release"])
---
<div
class={clsx(styles.cardWrapper, showBorder && styles.withBorder)}
data-expandable="wrapper"
data-auto-expand={autoExpand}
data-disable-hover={disableHover}
>
<div class={styles.card} data-expandable="card">
<div class={styles.header}>
<div class={styles.metaSection}>
<Typography variant="body-semi" className={styles.changelogType}>
{item.type}
</Typography>
<Typography variant="body-s" color="muted" className={styles.date}>
{formattedDate}
</Typography>
</div>
</div>
<div class={styles.content} data-expandable="content">
{
showNetworksAndTopic && (item.networks || item.topic) && (
<div class={styles.networksAndTopicSection}>
{item.networks && <div set:html={item.networks} />}
{item.topic && <span class="prod-chip">{item.topic}</span>}
</div>
)
}
<Typography
variant="h6"
style={{
marginBottom: "var(--space-2x)",
}}
>
{item.name}
</Typography>
<div class={styles.descriptionContent}>
{item["text-description"] && <div class={styles.description} set:html={item["text-description"]} />}
</div>
</div>
{showCopyButton && <CopyButton client:only="react" url={item.slug} />}
</div>
<div class={styles.contentFooter} data-expandable="footer">
<button class={styles.expandButton} data-expandable="button">
<span data-expandable="text">Show more</span>
<SvgTaillessArrowDownSmall color="muted" />
</button>
</div>
</div>
<script>
function swapDataAttributeImages() {
// Find all images with data-token attribute and swap src
const tokenImages = document.querySelectorAll("img[data-token]")
tokenImages.forEach((img) => {
const imageEl = img as HTMLImageElement
const tokenUrl = imageEl.getAttribute("data-token")
const originalSrc = imageEl.getAttribute("src")
if (tokenUrl && tokenUrl !== originalSrc) {
// Try to load the data-token image
imageEl.setAttribute("src", tokenUrl)
// Fallback to original src if image fails to load
imageEl.onerror = () => {
imageEl.setAttribute("src", originalSrc!)
imageEl.onerror = null // Remove handler to prevent infinite loop
}
}
})
// Find all images with data-network attribute and swap src
const networkImages = document.querySelectorAll("img[data-network]")
networkImages.forEach((img) => {
const imageEl = img as HTMLImageElement
const networkUrl = imageEl.getAttribute("data-network")
const originalSrc = imageEl.getAttribute("src")
if (networkUrl && networkUrl !== originalSrc) {
// Try to load the data-network image
imageEl.setAttribute("src", networkUrl)
// Fallback to original src if image fails to load
imageEl.onerror = () => {
imageEl.setAttribute("src", originalSrc!)
imageEl.onerror = null // Remove handler to prevent infinite loop
}
}
})
}
function initExpandableCards() {
const wrappers = document.querySelectorAll('[data-expandable="wrapper"]')
wrappers.forEach((wrapper) => {
const card = wrapper.querySelector('[data-expandable="card"]') as HTMLElement
const content = wrapper.querySelector('[data-expandable="content"]') as HTMLElement
const footer = wrapper.querySelector('[data-expandable="footer"]') as HTMLElement
const button = wrapper.querySelector('[data-expandable="button"]') as HTMLElement
const text = button?.querySelector('[data-expandable="text"]')
if (!card || !content || !button) return
// Check if auto-expand is enabled
const autoExpand = (wrapper as HTMLElement).dataset.autoExpand === "true"
if (autoExpand) {
// Auto-expand: set to full height and hide footer
;(wrapper as HTMLElement).style.maxHeight = "none"
wrapper.classList.add("expanded")
footer.style.opacity = "0"
footer.style.pointerEvents = "none"
return // Skip the rest of the logic
}
// Wait for images to load before checking height
const images = card.querySelectorAll("img")
let loadedImages = 0
const totalImages = images.length
const checkCardHeight = () => {
// Determine max height based on viewport
const isMobile = window.innerWidth <= 768
const wrapperMaxHeight = isMobile ? 300 : 400
// Check if card exceeds wrapper height
if (card.scrollHeight <= wrapperMaxHeight) {
// Card fits, hide the button and fade
footer.style.opacity = "0"
footer.style.pointerEvents = "none"
} else {
// Card exceeds wrapper, show button and fade
footer.style.opacity = "1"
footer.style.pointerEvents = "auto"
}
}
// Check height after each image loads
if (totalImages > 0) {
images.forEach((img) => {
if (img.complete) {
loadedImages++
if (loadedImages === totalImages) {
checkCardHeight()
}
} else {
img.addEventListener("load", () => {
loadedImages++
if (loadedImages === totalImages) {
checkCardHeight()
}
})
img.addEventListener("error", () => {
loadedImages++
if (loadedImages === totalImages) {
checkCardHeight()
}
})
}
})
} else {
// No images, check immediately
checkCardHeight()
}
let isExpanded = false
button.addEventListener("click", () => {
isExpanded = !isExpanded
if (isExpanded) {
// Expand wrapper to full card height
;(wrapper as HTMLElement).style.maxHeight = card.scrollHeight + "px"
// Hide mask and footer
wrapper.classList.add("expanded")
footer.style.opacity = "0"
footer.style.pointerEvents = "none"
if (text) text.textContent = "Show less"
} else {
// Collapse wrapper back
;(wrapper as HTMLElement).style.maxHeight = ""
// Show mask and footer
wrapper.classList.remove("expanded")
footer.style.opacity = "1"
footer.style.pointerEvents = "auto"
if (text) text.textContent = "Show more"
}
})
})
}
// Initialize on page load
swapDataAttributeImages()
initExpandableCards()
// Re-initialize after navigation (for SPA-like behavior)
document.addEventListener("astro:page-load", () => {
swapDataAttributeImages()
initExpandableCards()
})
// Re-check on resize
let resizeTimer: ReturnType<typeof setTimeout>
window.addEventListener("resize", () => {
clearTimeout(resizeTimer)
resizeTimer = setTimeout(() => {
initExpandableCards()
}, 250)
})
</script>
<style is:global>
/* Data Entry List */
.log-item__data-entry-list {
grid-column-gap: 4px;
grid-row-gap: 4px;
flex-flow: column;
display: flex;
}
/* Data Entry Item */
.log-item__data-entry {
justify-content: flex-start;
align-items: center;
padding-top: 8px;
padding-bottom: 8px;
display: flex;
}
/* Images Container */
.log-item__data-entry-images {
margin-right: 8px;
position: relative;
}
/* Main Image */
.log-item__data-entry-img {
border-radius: 100%;
width: 24px;
height: 24px;
}
.log-item__data-entry-img.log-item__data-entry-img-round {
border-radius: 100%;
}
.description {
> p {
margin-bottom: var(--space-4x);
font-size: 14px;
}
}
/* Overlay Icon */
.log-item__data-entry-img-top {
background-color: #fff;
border: 1px solid #fff;
border-radius: 4px;
width: 12px;
height: 12px;
position: absolute;
inset: auto 0% 0% auto;
}
/* Link Text */
.log-item__data-entry-info {
color: #2e7bff;
font-size: 14px;
font-weight: 600;
line-height: 20px;
}
/* Additional Info */
.log-item__data-entry-info2 {
display: none;
}
.log-item__description > p {
color: var(--muted);
margin-bottom: var(--space-4x);
}
/* Network Icons List */
.log-item__list-chains {
display: flex;
align-items: center;
gap: var(--space-1x);
}
.log-item__img-chain {
width: 24px;
height: 24px;
object-fit: cover;
}
.log-item__more-chains {
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 24px;
background-color: var(--gray-950);
font-size: 10px;
font-weight: 600;
color: var(--white);
border-radius: 3px;
}
/* Hidden filter elements */
.log-item__list-chains .hidden {
display: none;
}
/* Disable hover effects when data-disable-hover is true */
[data-disable-hover="true"]:hover {
background-color: transparent !important;
}
[data-disable-hover="true"]:hover .copyButton {
opacity: 0 !important;
}
[data-disable-hover="true"].withBorder:hover {
background-color: transparent !important;
}
[data-disable-hover="true"].withBorder:hover .contentFooter {
background: none !important;
}
/* Product Chip */
.prod-chip {
background-color: var(--muted-more);
color: var(--mirage);
border-radius: 4px;
margin-bottom: 0;
padding: var(--space-1x) var(--space-2x);
font-size: 12px;
line-height: 16px;
display: inline-block;
}
</style>