| --- |
| |
| import { Image } from 'astro:assets'; |
|
|
| interface Props { |
| |
| src: any; |
| |
| alt: string; |
| |
| caption?: string; |
| |
| figureClass?: string; |
| |
| [key: string]: any; |
| } |
|
|
| const { caption, figureClass, ...imgProps } = Astro.props as Props; |
| const hasCaptionSlot = Astro.slots.has('caption'); |
| const hasCaption = hasCaptionSlot || (typeof caption === 'string' && caption.length > 0); |
| --- |
|
|
| {hasCaption ? ( |
| <figure class={figureClass}> |
| <Image {...imgProps} /> |
| <figcaption> |
| {hasCaptionSlot ? ( |
| <slot name="caption" /> |
| ) : ( |
| caption && <span set:html={caption} /> |
| )} |
| </figcaption> |
| </figure> |
| ) : ( |
| <Image {...imgProps} /> |
| )} |
|
|
|
|
|
|