optional url

This commit is contained in:
Ulysia 2024-10-16 12:50:38 +02:00
parent b774721530
commit c0963fcbf0

View file

@ -55,22 +55,29 @@ export default (() => {
return groups return groups
} }
// Function to render button content based on contentType // Updated renderButtonContent function
function renderButtonContent(button: any): preact.VNode | null { function renderButtonContent(button: any): preact.VNode | null {
const contentType = button.contentType || "image" // Default to 'image' const contentType = button.contentType || "image" // Default to 'image'
if (contentType === "image") { if (contentType === "image") {
return ( // Create the <img> element
<a href={button.url}> const imgElement = (
<img <img
src={button.image} src={button.image}
alt={button.alt} alt={button.alt}
title={button.title} title={button.title}
loading="lazy" loading="lazy"
decoding="async" decoding="async"
/> />
</a>
) )
// If `button.url` is present, wrap the image in an `<a>` tag
if (button.url) {
return <a href={button.url}>{imgElement}</a>
} else {
// If no `url`, return the image element without wrapping
return imgElement
}
} else if (contentType === "iframe") { } else if (contentType === "iframe") {
const iframeAttrs = button.iframeAttributes || {} const iframeAttrs = button.iframeAttributes || {}
return <iframe src={button.url} title={button.title} {...iframeAttrs}></iframe> return <iframe src={button.url} title={button.title} {...iframeAttrs}></iframe>
@ -79,5 +86,6 @@ export default (() => {
return null return null
} }
} }
return Btn8831 return Btn8831
}) satisfies QuartzComponentConstructor }) satisfies QuartzComponentConstructor